2009-05-20 13:08:56 +03:00
|
|
|
#include "../stdafx.h"
|
2008-03-16 02:09:43 +02:00
|
|
|
#include "CAdvmapInterface.h"
|
2008-08-27 13:19:18 +03:00
|
|
|
#include "CBattleInterface.h"
|
2009-05-20 13:08:56 +03:00
|
|
|
#include "../CCallback.h"
|
2008-08-27 13:19:18 +03:00
|
|
|
#include "CCastleInterface.h"
|
2010-02-06 15:27:58 +02:00
|
|
|
#include "CKingdomInterface.h"
|
2008-08-27 13:19:18 +03:00
|
|
|
#include "CCursorHandler.h"
|
|
|
|
#include "CGameInfo.h"
|
|
|
|
#include "CHeroWindow.h"
|
2007-11-19 00:58:28 +02:00
|
|
|
#include "CMessage.h"
|
2008-08-27 13:19:18 +03:00
|
|
|
#include "CPlayerInterface.h"
|
2008-12-17 23:16:19 +02:00
|
|
|
//#include "SDL_Extensions.h"
|
2007-11-19 00:58:28 +02:00
|
|
|
#include "SDL_Extensions.h"
|
2008-12-17 23:16:19 +02:00
|
|
|
//#include "SDL_framerate.h"
|
|
|
|
|
2008-08-27 13:19:18 +03:00
|
|
|
#include "SDL_framerate.h"
|
2009-05-20 13:08:56 +03:00
|
|
|
#include "CConfigHandler.h"
|
|
|
|
#include "CCreatureAnimation.h"
|
|
|
|
#include "Graphics.h"
|
2010-12-20 23:22:53 +02:00
|
|
|
#include "../lib/CArtHandler.h"
|
|
|
|
#include "../lib/CGeneralTextHandler.h"
|
|
|
|
#include "../lib/CHeroHandler.h"
|
|
|
|
#include "../lib/CLodHandler.h"
|
|
|
|
#include "../lib/CObjectHandler.h"
|
2009-05-20 13:08:56 +03:00
|
|
|
#include "../lib/Connection.h"
|
2010-12-20 23:22:53 +02:00
|
|
|
#include "../lib/CSpellHandler.h"
|
|
|
|
#include "../lib/CTownHandler.h"
|
|
|
|
#include "CMusicHandler.h"
|
2009-05-20 13:08:56 +03:00
|
|
|
#include "../lib/CondSh.h"
|
|
|
|
#include "../lib/NetPacks.h"
|
|
|
|
#include "../lib/map.h"
|
2009-10-10 08:47:59 +03:00
|
|
|
#include "../lib/VCMIDirs.h"
|
2010-04-06 16:19:54 +03:00
|
|
|
#include "mapHandler.h"
|
2009-05-20 13:08:56 +03:00
|
|
|
#include "../timeHandler.h"
|
2009-02-09 18:18:48 +02:00
|
|
|
#include <boost/lexical_cast.hpp>
|
2010-02-27 03:05:39 +02:00
|
|
|
#include <boost/format.hpp>
|
2008-01-29 15:00:45 +02:00
|
|
|
#include <boost/algorithm/string.hpp>
|
|
|
|
#include <boost/algorithm/string/replace.hpp>
|
2010-01-25 05:09:42 +02:00
|
|
|
#include <boost/assign/std/vector.hpp>
|
2008-10-17 19:30:56 +03:00
|
|
|
#include <boost/assign/list_of.hpp>
|
2009-03-28 02:38:48 +02:00
|
|
|
#include <boost/date_time/posix_time/posix_time.hpp>
|
2008-08-27 13:19:18 +03:00
|
|
|
#include <boost/thread.hpp>
|
2008-05-23 22:50:11 +03:00
|
|
|
#include <cmath>
|
2008-08-27 13:19:18 +03:00
|
|
|
#include <queue>
|
|
|
|
#include <sstream>
|
2009-12-28 06:08:24 +02:00
|
|
|
#include <boost/filesystem.hpp>
|
2010-02-20 15:24:38 +02:00
|
|
|
#include "../StartInfo.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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
|
|
|
|
extern Point screenLTmax;
|
2009-04-21 01:57:07 +03:00
|
|
|
|
2009-03-12 20:50:36 +02:00
|
|
|
extern std::queue<SDL_Event*> events;
|
2008-07-27 20:07:37 +03:00
|
|
|
extern boost::mutex eventsM;
|
2008-01-30 16:19:35 +02:00
|
|
|
|
2009-04-21 01:57:07 +03:00
|
|
|
CPlayerInterface * LOCPLINT;
|
2010-02-19 18:02:34 +02:00
|
|
|
|
|
|
|
CBattleInterface * CPlayerInterface::battleInt;
|
|
|
|
|
2009-04-21 01:57:07 +03:00
|
|
|
enum EMoveState {STOP_MOVE, WAITING_MOVE, CONTINUE_MOVE, DURING_MOVE};
|
|
|
|
CondSh<EMoveState> stillMoveHero; //used during hero movement
|
2008-07-31 00:27:15 +03:00
|
|
|
|
2010-05-27 00:59:58 +03:00
|
|
|
int CPlayerInterface::howManyPeople = 0;
|
2010-02-20 15:24:38 +02:00
|
|
|
|
|
|
|
|
2008-12-17 23:16:19 +02:00
|
|
|
struct OCM_HLP_CGIN
|
2007-11-19 00:58:28 +02:00
|
|
|
{
|
2008-11-28 14:11:31 +02:00
|
|
|
bool inline operator ()(const std::pair<const CGObjectInstance*,SDL_Rect> & a, const std::pair<const CGObjectInstance*,SDL_Rect> & b) const
|
2007-11-19 00:58:28 +02:00
|
|
|
{
|
|
|
|
return (*a.first)<(*b.first);
|
|
|
|
}
|
|
|
|
} ocmptwo_cgin ;
|
2008-11-02 00:32:56 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2010-08-03 14:36:52 +03:00
|
|
|
CPlayerInterface::CPlayerInterface(int Player)
|
2008-01-26 21:36:31 +02:00
|
|
|
{
|
2010-12-23 02:33:48 +02:00
|
|
|
observerInDuelMode = false;
|
2010-02-20 15:24:38 +02:00
|
|
|
howManyPeople++;
|
2009-08-18 11:22:56 +03:00
|
|
|
GH.defActionsDef = 0;
|
2009-05-19 21:23:04 +03:00
|
|
|
LOCPLINT = this;
|
|
|
|
curAction = NULL;
|
|
|
|
playerID=Player;
|
|
|
|
human=true;
|
|
|
|
castleInt = NULL;
|
|
|
|
battleInt = NULL;
|
|
|
|
pim = new boost::recursive_mutex;
|
|
|
|
makingTurn = false;
|
|
|
|
showingDialog = new CondSh<bool>(false);
|
2009-07-18 06:13:13 +03:00
|
|
|
sysOpts = GDefaultOptions;
|
2009-05-19 21:23:04 +03:00
|
|
|
//initializing framerate keeper
|
|
|
|
mainFPSmng = new FPSmanager;
|
|
|
|
SDL_initFramerate(mainFPSmng);
|
|
|
|
SDL_setFramerate(mainFPSmng, 48);
|
|
|
|
//framerate keeper initialized
|
|
|
|
cingconsole = new CInGameConsole;
|
2009-11-01 03:15:16 +02:00
|
|
|
terminate_cond.set(false);
|
2009-12-28 06:08:24 +02:00
|
|
|
firstCall = 1; //if loading will be overwritten in serialize
|
|
|
|
autosaveCount = 0;
|
2008-01-26 21:36:31 +02:00
|
|
|
}
|
2009-05-19 21:23:04 +03:00
|
|
|
CPlayerInterface::~CPlayerInterface()
|
2008-05-23 22:50:11 +03:00
|
|
|
{
|
2010-02-20 15:24:38 +02:00
|
|
|
howManyPeople--;
|
2009-05-19 21:23:04 +03:00
|
|
|
delete pim;
|
|
|
|
delete showingDialog;
|
|
|
|
delete mainFPSmng;
|
2010-02-22 15:30:46 +02:00
|
|
|
if(adventureInt)
|
|
|
|
{
|
|
|
|
if(adventureInt->active & CIntObject::KEYBOARD)
|
|
|
|
adventureInt->deactivateKeys();
|
|
|
|
delete adventureInt;
|
|
|
|
adventureInt = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(cingconsole->active) //TODO
|
|
|
|
cingconsole->deactivate();
|
2009-05-19 21:23:04 +03:00
|
|
|
delete cingconsole;
|
2008-05-23 22:50:11 +03:00
|
|
|
|
2009-11-01 03:15:16 +02:00
|
|
|
LOCPLINT = NULL;
|
2009-02-04 15:40:54 +02:00
|
|
|
}
|
2009-05-19 21:23:04 +03:00
|
|
|
void CPlayerInterface::init(ICallback * CB)
|
2008-01-26 21:36:31 +02:00
|
|
|
{
|
2009-05-19 21:23:04 +03:00
|
|
|
cb = dynamic_cast<CCallback*>(CB);
|
2010-12-23 02:33:48 +02:00
|
|
|
if(observerInDuelMode)
|
|
|
|
{
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-02-20 15:24:38 +02:00
|
|
|
if(!adventureInt)
|
|
|
|
adventureInt = new CAdvMapInt();
|
|
|
|
|
2010-02-26 13:18:09 +02:00
|
|
|
if(!towns.size() && !wanderingHeroes.size())
|
|
|
|
{
|
|
|
|
recreateHeroTownList();
|
|
|
|
}
|
2008-01-26 21:36:31 +02:00
|
|
|
}
|
2009-05-19 21:23:04 +03:00
|
|
|
void CPlayerInterface::yourTurn()
|
2008-01-26 21:36:31 +02:00
|
|
|
{
|
2010-02-20 15:24:38 +02:00
|
|
|
{
|
|
|
|
boost::unique_lock<boost::recursive_mutex> un(*pim);
|
|
|
|
boost::unique_lock<boost::mutex> lock(eventsM); //block handling events until interface is ready
|
2010-02-13 06:47:31 +02:00
|
|
|
|
2010-02-20 15:24:38 +02:00
|
|
|
LOCPLINT = this;
|
|
|
|
GH.curInt = this;
|
2010-02-28 14:39:38 +02:00
|
|
|
adventureInt->selection = NULL;
|
2009-04-14 15:47:09 +03:00
|
|
|
|
2010-02-20 15:24:38 +02:00
|
|
|
if(firstCall)
|
2009-05-19 21:23:04 +03:00
|
|
|
{
|
2010-02-20 15:24:38 +02:00
|
|
|
if(howManyPeople == 1)
|
|
|
|
adventureInt->setPlayer(playerID);
|
2009-03-27 01:05:40 +02:00
|
|
|
|
2010-02-20 15:24:38 +02:00
|
|
|
autosaveCount = getLastIndex("Autosave_");
|
2009-05-19 21:23:04 +03:00
|
|
|
|
2010-02-20 15:24:38 +02:00
|
|
|
if(!GH.listInt.size())
|
|
|
|
{
|
|
|
|
GH.pushInt(adventureInt);
|
|
|
|
adventureInt->activateKeys();
|
|
|
|
}
|
2009-05-19 21:23:04 +03:00
|
|
|
|
2010-02-20 15:24:38 +02:00
|
|
|
if(firstCall > 0) //new game, not loaded
|
|
|
|
{
|
|
|
|
int index = getLastIndex("Newgame_Autosave_");
|
|
|
|
index %= SAVES_COUNT;
|
|
|
|
cb->save("Newgame_Autosave_" + boost::lexical_cast<std::string>(index + 1));
|
|
|
|
}
|
|
|
|
firstCall = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LOCPLINT->cb->save("Autosave_" + boost::lexical_cast<std::string>(autosaveCount++ + 1));
|
|
|
|
autosaveCount %= 5;
|
|
|
|
}
|
2009-05-19 21:23:04 +03:00
|
|
|
|
2010-07-24 14:46:04 +03:00
|
|
|
if(adventureInt->player != playerID)
|
|
|
|
adventureInt->setPlayer(playerID);
|
|
|
|
|
2010-02-20 15:24:38 +02:00
|
|
|
if(howManyPeople > 1) //hot seat message
|
|
|
|
{
|
|
|
|
adventureInt->startHotSeatWait(playerID);
|
2010-02-24 15:03:36 +02:00
|
|
|
|
|
|
|
makingTurn = true;
|
2010-02-20 15:24:38 +02:00
|
|
|
std::string msg = CGI->generaltexth->allTexts[13];
|
2010-08-03 14:36:52 +03:00
|
|
|
boost::replace_first(msg, "%s", cb->getStartInfo()->playerInfos.find(playerID)->second.name);
|
2010-02-20 15:24:38 +02:00
|
|
|
std::vector<SComponent*> cmp;
|
|
|
|
cmp.push_back(new SComponent(SComponent::flag, playerID, 0));
|
|
|
|
showInfoDialog(msg, cmp);
|
|
|
|
}
|
|
|
|
else
|
2010-02-24 15:03:36 +02:00
|
|
|
{
|
|
|
|
makingTurn = true;
|
2010-02-20 15:24:38 +02:00
|
|
|
adventureInt->startTurn();
|
2010-02-24 15:03:36 +02:00
|
|
|
}
|
2010-02-20 15:24:38 +02:00
|
|
|
}
|
2009-11-01 03:15:16 +02:00
|
|
|
|
2010-02-20 15:24:38 +02:00
|
|
|
acceptTurn();
|
2008-01-26 21:36:31 +02:00
|
|
|
}
|
2009-05-19 21:23:04 +03:00
|
|
|
|
2010-08-16 16:51:31 +03:00
|
|
|
STRONG_INLINE void subRect(const int & x, const int & y, const int & z, const SDL_Rect & r, const int & hid)
|
2008-01-26 21:36:31 +02:00
|
|
|
{
|
2009-05-19 21:23:04 +03:00
|
|
|
TerrainTile2 & hlp = CGI->mh->ttiles[x][y][z];
|
|
|
|
for(int h=0; h<hlp.objects.size(); ++h)
|
|
|
|
if(hlp.objects[h].first->id==hid)
|
|
|
|
{
|
|
|
|
hlp.objects[h].second = r;
|
|
|
|
return;
|
|
|
|
}
|
2008-01-26 21:36:31 +02:00
|
|
|
}
|
2009-05-19 21:23:04 +03:00
|
|
|
|
2010-08-16 16:51:31 +03:00
|
|
|
STRONG_INLINE void delObjRect(const int & x, const int & y, const int & z, const int & hid)
|
2008-04-11 20:41:02 +03:00
|
|
|
{
|
2009-05-19 21:23:04 +03:00
|
|
|
TerrainTile2 & hlp = CGI->mh->ttiles[x][y][z];
|
|
|
|
for(int h=0; h<hlp.objects.size(); ++h)
|
|
|
|
if(hlp.objects[h].first->id==hid)
|
|
|
|
{
|
|
|
|
hlp.objects.erase(hlp.objects.begin()+h);
|
|
|
|
return;
|
|
|
|
}
|
2008-04-11 20:41:02 +03:00
|
|
|
}
|
2009-07-03 22:57:14 +03:00
|
|
|
void CPlayerInterface::heroMoved(const TryMoveHero & details)
|
2008-01-26 21:36:31 +02:00
|
|
|
{
|
2010-02-20 15:24:38 +02:00
|
|
|
if(LOCPLINT != this)
|
|
|
|
return;
|
2009-05-19 21:23:04 +03:00
|
|
|
boost::unique_lock<boost::recursive_mutex> un(*pim);
|
2009-07-03 22:57:14 +03:00
|
|
|
const CGHeroInstance * ho = cb->getHeroInfo(details.id); //object representing this hero
|
2010-01-02 03:48:44 +02:00
|
|
|
int3 hp = details.start;
|
2009-05-19 21:23:04 +03:00
|
|
|
|
2010-03-21 00:17:19 +02:00
|
|
|
adventureInt->centerOn(ho); //actualizing screen pos
|
2009-05-19 21:23:04 +03:00
|
|
|
adventureInt->minimap.draw(screen2);
|
|
|
|
adventureInt->heroList.draw(screen2);
|
|
|
|
|
2010-05-06 15:13:31 +03:00
|
|
|
bool directlyAttackingCreature =
|
|
|
|
CGI->mh->map->isInTheMap(details.attackedFrom)
|
2010-11-13 22:26:15 +02:00
|
|
|
&& adventureInt->terrain.currentPath //in case if movement has been canceled in the meantime and path was already erased
|
|
|
|
&& adventureInt->terrain.currentPath->nodes.size() == 3;//FIXME should be 2 but works nevertheless...
|
2009-07-31 23:10:22 +03:00
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
if(makingTurn && ho->tempOwner == playerID) //we are moving our hero - we may need to update assigned path
|
2008-08-02 18:08:03 +03:00
|
|
|
{
|
2010-02-12 02:53:25 +02:00
|
|
|
if(details.result == TryMoveHero::TELEPORTATION || details.start == details.end)
|
2010-01-02 03:48:44 +02:00
|
|
|
{
|
2010-02-12 02:53:25 +02:00
|
|
|
if(adventureInt->terrain.currentPath)
|
2010-02-20 15:24:38 +02:00
|
|
|
eraseCurrentPathOf(ho);
|
2010-01-02 03:48:44 +02:00
|
|
|
return; //teleport - no fancy moving animation
|
|
|
|
//TODO: smooth disappear / appear effect
|
|
|
|
}
|
|
|
|
|
2010-05-06 15:13:31 +03:00
|
|
|
if (details.result != TryMoveHero::SUCCESS && details.result != TryMoveHero::FAILED //hero didn't change tile but visit succeeded
|
|
|
|
|| directlyAttackingCreature) // or creature was attacked from endangering tile.
|
2008-01-26 21:36:31 +02:00
|
|
|
{
|
2010-02-20 15:24:38 +02:00
|
|
|
eraseCurrentPathOf(ho);
|
2008-01-26 21:36:31 +02:00
|
|
|
}
|
2009-11-13 21:04:36 +02:00
|
|
|
else if(adventureInt->terrain.currentPath && details.result == TryMoveHero::SUCCESS) //&& hero is moving
|
2009-07-31 23:10:22 +03:00
|
|
|
{
|
|
|
|
//remove one node from the path (the one we went)
|
|
|
|
adventureInt->terrain.currentPath->nodes.erase(adventureInt->terrain.currentPath->nodes.end()-1);
|
|
|
|
if(!adventureInt->terrain.currentPath->nodes.size()) //if it was the last one, remove entire path
|
2010-02-20 15:24:38 +02:00
|
|
|
eraseCurrentPathOf(ho);
|
2009-07-31 23:10:22 +03:00
|
|
|
}
|
|
|
|
}
|
2009-07-03 22:57:14 +03:00
|
|
|
|
2009-07-31 23:10:22 +03:00
|
|
|
if (details.result != TryMoveHero::SUCCESS) //hero failed to move
|
|
|
|
{
|
2009-07-03 22:57:14 +03:00
|
|
|
ho->isStanding = true;
|
2009-05-19 21:23:04 +03:00
|
|
|
stillMoveHero.setn(STOP_MOVE);
|
2009-08-07 01:36:51 +03:00
|
|
|
GH.totalRedraw();
|
2009-05-19 21:23:04 +03:00
|
|
|
return;
|
2008-01-26 21:36:31 +02:00
|
|
|
}
|
2009-05-19 21:23:04 +03:00
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
initMovement(details, ho, hp);
|
2009-05-19 21:23:04 +03:00
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
//first initializing done
|
|
|
|
SDL_framerateDelay(mainFPSmng); // after first move
|
2009-05-19 21:23:04 +03:00
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
//main moving
|
|
|
|
for(int i=1; i<32; i+=2*sysOpts.heroMoveSpeed)
|
|
|
|
{
|
|
|
|
movementPxStep(details, i, hp, ho);
|
|
|
|
adventureInt->updateScreen = true;
|
|
|
|
adventureInt->show(screen);
|
|
|
|
CSDL_Ext::update(screen);
|
|
|
|
SDL_framerateDelay(mainFPSmng); //for animation purposes
|
|
|
|
} //for(int i=1; i<32; i+=4)
|
|
|
|
//main moving done
|
2009-05-19 21:23:04 +03:00
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
//finishing move
|
|
|
|
finishMovement(details, hp, ho);
|
|
|
|
ho->isStanding = true;
|
2009-05-19 21:23:04 +03:00
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
//move finished
|
|
|
|
adventureInt->minimap.draw(screen2);
|
|
|
|
adventureInt->heroList.updateMove(ho);
|
2009-05-19 21:23:04 +03:00
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
//check if user cancelled movement
|
2008-08-17 12:11:16 +03:00
|
|
|
{
|
2010-01-02 03:48:44 +02:00
|
|
|
boost::unique_lock<boost::mutex> un(eventsM);
|
|
|
|
while(events.size())
|
|
|
|
{
|
|
|
|
SDL_Event *ev = events.front();
|
|
|
|
events.pop();
|
|
|
|
switch(ev->type)
|
|
|
|
{
|
|
|
|
case SDL_MOUSEBUTTONDOWN:
|
|
|
|
stillMoveHero.setn(STOP_MOVE);
|
|
|
|
break;
|
|
|
|
case SDL_KEYDOWN:
|
|
|
|
if(ev->key.keysym.sym < SDLK_F1 || ev->key.keysym.sym > SDLK_F15)
|
|
|
|
stillMoveHero.setn(STOP_MOVE);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
delete ev;
|
|
|
|
}
|
|
|
|
}
|
2009-05-19 21:23:04 +03:00
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
if(stillMoveHero.get() == WAITING_MOVE)
|
|
|
|
stillMoveHero.setn(DURING_MOVE);
|
2009-05-19 21:23:04 +03:00
|
|
|
|
2010-05-06 15:13:31 +03:00
|
|
|
// Hero attacked creature directly, set direction to face it.
|
|
|
|
if (directlyAttackingCreature) {
|
|
|
|
// Get direction to attacker.
|
|
|
|
int3 posOffset = details.attackedFrom - details.end + int3(2, 1, 0);
|
2010-10-31 00:53:41 +03:00
|
|
|
static const ui8 dirLookup[3][3] = {
|
|
|
|
{ 1, 2, 3 },
|
|
|
|
{ 8, 0, 4 },
|
|
|
|
{ 7, 6, 5 }
|
2010-05-06 15:13:31 +03:00
|
|
|
};
|
|
|
|
// FIXME: Avoid const_cast, make moveDir mutable in some other way?
|
|
|
|
const_cast<CGHeroInstance *>(ho)->moveDir = dirLookup[posOffset.y][posOffset.x];
|
|
|
|
}
|
2010-01-02 03:48:44 +02:00
|
|
|
}
|
|
|
|
void CPlayerInterface::heroKilled(const CGHeroInstance* hero)
|
|
|
|
{
|
|
|
|
boost::unique_lock<boost::recursive_mutex> un(*pim);
|
|
|
|
wanderingHeroes -= hero;
|
|
|
|
adventureInt->heroList.updateHList(hero);
|
|
|
|
}
|
|
|
|
void CPlayerInterface::heroCreated(const CGHeroInstance * hero)
|
|
|
|
{
|
|
|
|
boost::unique_lock<boost::recursive_mutex> un(*pim);
|
|
|
|
wanderingHeroes.push_back(hero);
|
|
|
|
adventureInt->heroList.updateHList();
|
|
|
|
}
|
|
|
|
void CPlayerInterface::openTownWindow(const CGTownInstance * town)
|
|
|
|
{
|
2010-07-27 02:20:21 +03:00
|
|
|
if (castleInt)
|
|
|
|
GH.popIntTotally(castleInt);
|
2010-01-02 03:48:44 +02:00
|
|
|
castleInt = new CCastleInterface(town);
|
|
|
|
GH.pushInt(castleInt);
|
|
|
|
}
|
2009-05-19 21:23:04 +03:00
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
SDL_Surface * CPlayerInterface::infoWin(const CGObjectInstance * specific) //specific=0 => draws info about selected town/hero
|
|
|
|
{
|
2010-03-21 00:17:19 +02:00
|
|
|
if(!specific)
|
|
|
|
specific = adventureInt->selection;
|
|
|
|
|
|
|
|
assert(specific);
|
|
|
|
|
|
|
|
switch(specific->ID)
|
2010-01-02 03:48:44 +02:00
|
|
|
{
|
2010-03-21 00:17:19 +02:00
|
|
|
case HEROI_TYPE:
|
2010-01-02 03:48:44 +02:00
|
|
|
{
|
2010-03-21 00:17:19 +02:00
|
|
|
InfoAboutHero iah;
|
|
|
|
bool gotInfo = LOCPLINT->cb->getHeroInfo(specific, iah);
|
|
|
|
assert(gotInfo);
|
|
|
|
return graphics->drawHeroInfoWin(iah);
|
2010-01-02 03:48:44 +02:00
|
|
|
}
|
2010-03-21 00:17:19 +02:00
|
|
|
case TOWNI_TYPE:
|
|
|
|
case 33: // Garrison
|
|
|
|
case 219:
|
2010-01-02 03:48:44 +02:00
|
|
|
{
|
2010-03-21 00:17:19 +02:00
|
|
|
InfoAboutTown iah;
|
|
|
|
bool gotInfo = LOCPLINT->cb->getTownInfo(specific, iah);
|
|
|
|
assert(gotInfo);
|
|
|
|
return graphics->drawTownInfoWin(iah);
|
2010-01-02 03:48:44 +02:00
|
|
|
}
|
2010-03-21 00:17:19 +02:00
|
|
|
default:
|
|
|
|
return NULL;
|
2010-01-02 03:48:44 +02:00
|
|
|
}
|
|
|
|
}
|
2008-04-19 19:15:04 +03:00
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
int3 CPlayerInterface::repairScreenPos(int3 pos)
|
|
|
|
{
|
|
|
|
if(pos.x<-CGI->mh->frameW)
|
|
|
|
pos.x = -CGI->mh->frameW;
|
|
|
|
if(pos.y<-CGI->mh->frameH)
|
|
|
|
pos.y = -CGI->mh->frameH;
|
2010-08-16 16:51:31 +03:00
|
|
|
if(pos.x>CGI->mh->sizes.x - adventureInt->terrain.tilesw + CGI->mh->frameW)
|
|
|
|
pos.x = CGI->mh->sizes.x - adventureInt->terrain.tilesw + CGI->mh->frameW;
|
|
|
|
if(pos.y>CGI->mh->sizes.y - adventureInt->terrain.tilesh + CGI->mh->frameH)
|
|
|
|
pos.y = CGI->mh->sizes.y - adventureInt->terrain.tilesh + CGI->mh->frameH;
|
2010-01-02 03:48:44 +02:00
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
void CPlayerInterface::heroPrimarySkillChanged(const CGHeroInstance * hero, int which, si64 val)
|
|
|
|
{
|
2010-07-20 12:16:48 +03:00
|
|
|
boost::unique_lock<boost::recursive_mutex> un(*pim);
|
2010-07-20 09:05:45 +03:00
|
|
|
if(which == 4)
|
|
|
|
{
|
|
|
|
if(CAltarWindow *ctw = dynamic_cast<CAltarWindow *>(GH.topInt()))
|
|
|
|
ctw->setExpToLevel();
|
|
|
|
}
|
2010-07-20 12:16:48 +03:00
|
|
|
else if(which < PRIMARY_SKILLS) //no need to redraw infowin if this is experience (exp is treated as prim skill with id==4)
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
boost::unique_lock<boost::recursive_mutex> un(*pim);
|
2010-03-21 00:17:19 +02:00
|
|
|
updateInfo(hero);
|
2010-01-02 03:48:44 +02:00
|
|
|
}
|
|
|
|
void CPlayerInterface::heroMovePointsChanged(const CGHeroInstance * hero)
|
|
|
|
{
|
|
|
|
boost::unique_lock<boost::recursive_mutex> un(*pim);
|
2010-03-01 20:22:22 +02:00
|
|
|
if(makingTurn && hero->tempOwner == playerID)
|
|
|
|
adventureInt->heroList.redraw();
|
2010-01-02 03:48:44 +02:00
|
|
|
}
|
|
|
|
void CPlayerInterface::receivedResource(int type, int val)
|
|
|
|
{
|
|
|
|
boost::unique_lock<boost::recursive_mutex> un(*pim);
|
2010-07-20 09:05:45 +03:00
|
|
|
if(CMarketplaceWindow *mw = dynamic_cast<CMarketplaceWindow *>(GH.topInt()))
|
|
|
|
mw->resourceChanged(type, val);
|
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
GH.totalRedraw();
|
|
|
|
}
|
2008-01-26 21:36:31 +02:00
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
void CPlayerInterface::heroGotLevel(const CGHeroInstance *hero, int pskill, std::vector<ui16>& skills, boost::function<void(ui32)> &callback)
|
|
|
|
{
|
|
|
|
waitWhileDialog();
|
2010-12-19 16:39:56 +02:00
|
|
|
CCS->soundh->playSound(soundBase::heroNewLevel);
|
2009-05-19 21:23:04 +03:00
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
boost::unique_lock<boost::recursive_mutex> un(*pim);
|
|
|
|
CLevelWindow *lw = new CLevelWindow(hero,pskill,skills,callback);
|
|
|
|
GH.pushInt(lw);
|
|
|
|
}
|
|
|
|
void CPlayerInterface::heroInGarrisonChange(const CGTownInstance *town)
|
|
|
|
{
|
|
|
|
boost::unique_lock<boost::recursive_mutex> un(*pim);
|
2010-03-21 00:17:19 +02:00
|
|
|
updateInfo(town);
|
2009-05-19 21:23:04 +03:00
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
if(town->garrisonHero && vstd::contains(wanderingHeroes,town->garrisonHero)) //wandering hero moved to the garrison
|
2008-01-26 21:36:31 +02:00
|
|
|
{
|
2010-01-02 03:48:44 +02:00
|
|
|
CGI->mh->hideObject(town->garrisonHero);
|
|
|
|
wanderingHeroes -= town->garrisonHero;
|
|
|
|
}
|
2008-01-26 21:36:31 +02:00
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
if(town->visitingHero && !vstd::contains(wanderingHeroes,town->visitingHero)) //hero leaves garrison
|
|
|
|
{
|
|
|
|
CGI->mh->printObject(town->visitingHero);
|
|
|
|
wanderingHeroes.push_back(town->visitingHero);
|
|
|
|
}
|
2009-04-11 04:32:50 +03:00
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
//adventureInt->heroList.updateHList();
|
2009-04-11 04:32:50 +03:00
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
CCastleInterface *c = castleInt;
|
|
|
|
if(c)
|
|
|
|
{
|
|
|
|
c->garr->highlighted = NULL;
|
|
|
|
c->hslotup.hero = town->garrisonHero;
|
|
|
|
c->garr->odown = c->hslotdown.hero = town->visitingHero;
|
2010-05-02 21:20:26 +03:00
|
|
|
c->garr->set2 = town->visitingHero;
|
2010-11-06 16:43:48 +02:00
|
|
|
c->garr->ourUp = LOCPLINT->playerID==(town->garrisonHero ? town->garrisonHero->tempOwner : town->tempOwner);
|
2010-11-05 23:44:11 +02:00
|
|
|
c->garr->ourDown = (town->visitingHero ? LOCPLINT->playerID==town->visitingHero->tempOwner : false);
|
2010-01-02 03:48:44 +02:00
|
|
|
c->garr->recreateSlots();
|
2008-08-15 15:11:42 +03:00
|
|
|
}
|
2010-01-02 03:48:44 +02:00
|
|
|
GH.totalRedraw();
|
|
|
|
}
|
|
|
|
void CPlayerInterface::heroVisitsTown(const CGHeroInstance* hero, const CGTownInstance * town)
|
|
|
|
{
|
2010-08-12 18:54:25 +03:00
|
|
|
if(hero->tempOwner != playerID )
|
2010-01-02 03:48:44 +02:00
|
|
|
return;
|
|
|
|
boost::unique_lock<boost::recursive_mutex> un(*pim);
|
|
|
|
openTownWindow(town);
|
|
|
|
}
|
|
|
|
void CPlayerInterface::garrisonChanged(const CGObjectInstance * obj)
|
|
|
|
{
|
|
|
|
boost::unique_lock<boost::recursive_mutex> un(*pim);
|
2010-03-21 00:17:19 +02:00
|
|
|
updateInfo(obj);
|
2009-04-14 15:47:09 +03:00
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
for(std::list<IShowActivable*>::iterator i = GH.listInt.begin(); i != GH.listInt.end(); i++)
|
2008-01-31 23:35:30 +02:00
|
|
|
{
|
2010-01-02 03:48:44 +02:00
|
|
|
if((*i)->type & IShowActivable::WITH_GARRISON)
|
2008-01-31 23:35:30 +02:00
|
|
|
{
|
2010-07-22 03:32:45 +03:00
|
|
|
CGarrisonHolder *cgh = static_cast<CGarrisonHolder*>(*i);
|
|
|
|
cgh->updateGarrisons();
|
2010-05-26 12:47:53 +03:00
|
|
|
}
|
2010-07-20 09:05:45 +03:00
|
|
|
else if(CTradeWindow *cmw = dynamic_cast<CTradeWindow*>(*i))
|
2010-05-26 12:47:53 +03:00
|
|
|
{
|
|
|
|
if(obj == cmw->hero)
|
|
|
|
cmw->garrisonChanged();
|
2010-02-06 15:27:58 +02:00
|
|
|
}
|
2008-01-31 23:35:30 +02:00
|
|
|
}
|
2008-05-18 20:33:39 +03:00
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
GH.totalRedraw();
|
2008-05-18 20:33:39 +03:00
|
|
|
}
|
2010-01-02 03:48:44 +02:00
|
|
|
|
|
|
|
void CPlayerInterface::buildChanged(const CGTownInstance *town, int buildingID, int what) //what: 1 - built, 2 - demolished
|
2008-05-18 20:33:39 +03:00
|
|
|
{
|
2009-05-19 21:23:04 +03:00
|
|
|
boost::unique_lock<boost::recursive_mutex> un(*pim);
|
2010-01-02 03:48:44 +02:00
|
|
|
switch (buildingID)
|
|
|
|
{
|
|
|
|
case 7: case 8: case 9: case 10: case 11: case 12: case 13: case 15:
|
2010-03-21 00:17:19 +02:00
|
|
|
updateInfo(town);
|
|
|
|
break;
|
2010-01-02 03:48:44 +02:00
|
|
|
}
|
2010-03-21 00:17:19 +02:00
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
if(!castleInt)
|
|
|
|
return;
|
|
|
|
if(castleInt->town!=town)
|
|
|
|
return;
|
|
|
|
switch(what)
|
|
|
|
{
|
|
|
|
case 1:
|
2010-12-19 16:39:56 +02:00
|
|
|
CCS->soundh->playSound(soundBase::newBuilding);
|
2010-01-02 03:48:44 +02:00
|
|
|
castleInt->addBuilding(buildingID);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
castleInt->removeBuilding(buildingID);
|
|
|
|
break;
|
|
|
|
}
|
2008-05-18 20:33:39 +03:00
|
|
|
}
|
2010-01-02 03:48:44 +02:00
|
|
|
|
2010-12-04 21:15:20 +02:00
|
|
|
void CPlayerInterface::battleStart(const CCreatureSet *army1, const CCreatureSet *army2, int3 tile, const CGHeroInstance *hero1, const CGHeroInstance *hero2, bool side)
|
2008-05-18 20:33:39 +03:00
|
|
|
{
|
2010-02-19 18:02:34 +02:00
|
|
|
if(LOCPLINT != this)
|
|
|
|
{ //another local interface should do this
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
while(showingDialog->get())
|
|
|
|
SDL_Delay(20);
|
|
|
|
|
2009-05-19 21:23:04 +03:00
|
|
|
boost::unique_lock<boost::recursive_mutex> un(*pim);
|
2010-12-19 16:39:56 +02:00
|
|
|
CCS->musich->playMusicFromSet(CCS->musich->battleMusics, -1);
|
2010-01-02 03:48:44 +02:00
|
|
|
GH.pushInt(battleInt);
|
2008-05-18 20:33:39 +03:00
|
|
|
}
|
2010-01-02 03:48:44 +02:00
|
|
|
|
2008-05-18 20:33:39 +03:00
|
|
|
|
2010-05-07 15:29:41 +03:00
|
|
|
void CPlayerInterface::battleStacksHealedRes(const std::vector<std::pair<ui32, ui32> > & healedStacks, bool lifeDrain, si32 lifeDrainFrom)
|
2008-05-18 20:33:39 +03:00
|
|
|
{
|
2010-02-19 18:02:34 +02:00
|
|
|
if(LOCPLINT != this)
|
|
|
|
{ //another local interface should do this
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
for(int b=0; b<healedStacks.size(); ++b)
|
2008-05-18 20:33:39 +03:00
|
|
|
{
|
2010-01-02 03:48:44 +02:00
|
|
|
const CStack * healed = cb->battleGetStackByID(healedStacks[b].first);
|
|
|
|
if(battleInt->creAnims[healed->ID]->getType() == 5)
|
2008-05-18 20:33:39 +03:00
|
|
|
{
|
2010-01-02 03:48:44 +02:00
|
|
|
//stack has been resurrected
|
|
|
|
battleInt->creAnims[healed->ID]->setType(2);
|
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);
|
|
|
|
if (attacker)
|
|
|
|
{
|
|
|
|
battleInt->displayEffect(50, attacker->position);
|
|
|
|
}
|
|
|
|
//print info about life drain
|
|
|
|
int textOff = 0;
|
|
|
|
if (attacker->count > 1)
|
|
|
|
{
|
|
|
|
textOff += 1;
|
|
|
|
}
|
|
|
|
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-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
|
|
|
{
|
2010-02-19 18:02:34 +02:00
|
|
|
if(LOCPLINT != this)
|
|
|
|
{ //another local interface should do this
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
//changing necessary things in battle interface
|
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)
|
|
|
|
{
|
2010-02-19 18:02:34 +02:00
|
|
|
if(LOCPLINT != this)
|
|
|
|
{ //another local interface should do this
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
for(std::set<si32>::const_iterator it = removedObstacles.begin(); it != removedObstacles.end(); ++it)
|
2008-05-18 20:33:39 +03:00
|
|
|
{
|
2010-01-02 03:48:44 +02:00
|
|
|
for(std::map< int, CDefHandler * >::iterator itBat = battleInt->idToObstacle.begin(); itBat != battleInt->idToObstacle.end(); ++itBat)
|
2008-05-18 20:33:39 +03:00
|
|
|
{
|
2010-01-02 03:48:44 +02:00
|
|
|
if(itBat->first == *it) //remove this obstacle
|
2008-05-18 20:33:39 +03:00
|
|
|
{
|
2010-01-02 03:48:44 +02:00
|
|
|
battleInt->idToObstacle.erase(itBat);
|
|
|
|
break;
|
2008-05-18 20:33:39 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
{
|
2010-02-19 18:02:34 +02:00
|
|
|
if(LOCPLINT != this)
|
|
|
|
{ //another local interface should do this
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
battleInt->stackIsCatapulting(ca);
|
2008-05-18 20:33:39 +03:00
|
|
|
}
|
2010-01-02 03:48:44 +02:00
|
|
|
|
|
|
|
void CPlayerInterface::battleStacksRemoved(const BattleStacksRemoved & bsr)
|
2008-05-18 20:33:39 +03:00
|
|
|
{
|
2010-02-19 18:02:34 +02:00
|
|
|
if(LOCPLINT != this)
|
|
|
|
{ //another local interface should do this
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
for(std::set<ui32>::const_iterator it = bsr.stackIDs.begin(); it != bsr.stackIDs.end(); ++it) //for each removed stack
|
|
|
|
{
|
2010-12-23 22:18:10 +02:00
|
|
|
battleInt->stackRemoved(LOCPLINT->cb->battleGetStackByID(*it));
|
2010-01-02 03:48:44 +02:00
|
|
|
}
|
2008-05-18 20:33:39 +03:00
|
|
|
}
|
2010-01-02 03:48:44 +02:00
|
|
|
|
|
|
|
void CPlayerInterface::battleNewRound(int round) //called at the beggining of each turn, round=-1 is the tactic phase, round=0 is the first "normal" turn
|
2008-05-31 23:37:54 +03:00
|
|
|
{
|
2010-02-19 18:02:34 +02:00
|
|
|
if(LOCPLINT != this)
|
|
|
|
{ //another local interface should do this
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-05-19 21:23:04 +03:00
|
|
|
boost::unique_lock<boost::recursive_mutex> un(*pim);
|
2010-01-02 03:48:44 +02:00
|
|
|
battleInt->newRound(round);
|
2008-05-31 23:37:54 +03:00
|
|
|
}
|
2010-01-02 03:48:44 +02:00
|
|
|
|
|
|
|
void CPlayerInterface::actionStarted(const BattleAction* action)
|
2008-05-18 20:33:39 +03:00
|
|
|
{
|
2010-02-19 18:02:34 +02:00
|
|
|
if(LOCPLINT != this)
|
|
|
|
{ //another local interface should do this
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-05-19 21:23:04 +03:00
|
|
|
boost::unique_lock<boost::recursive_mutex> un(*pim);
|
2010-01-02 03:48:44 +02:00
|
|
|
curAction = new BattleAction(*action);
|
|
|
|
battleInt->startAction(action);
|
2008-05-18 20:33:39 +03:00
|
|
|
}
|
2010-01-02 03:48:44 +02:00
|
|
|
|
|
|
|
void CPlayerInterface::actionFinished(const BattleAction* action)
|
2008-05-18 20:33:39 +03:00
|
|
|
{
|
2010-02-19 18:02:34 +02:00
|
|
|
if(LOCPLINT != this)
|
|
|
|
{ //another local interface should do this
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-05-19 21:23:04 +03:00
|
|
|
boost::unique_lock<boost::recursive_mutex> un(*pim);
|
2010-01-02 03:48:44 +02:00
|
|
|
delete curAction;
|
|
|
|
curAction = NULL;
|
|
|
|
battleInt->endAction(action);
|
2008-05-27 16:16:35 +03:00
|
|
|
}
|
2008-08-13 03:44:31 +03:00
|
|
|
|
2010-12-23 22:18:10 +02:00
|
|
|
BattleAction CPlayerInterface::activeStack(const CStack * stack) //called when it's turn of that stack
|
2008-08-13 03:44:31 +03:00
|
|
|
{
|
2010-02-19 18:02:34 +02:00
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
CBattleInterface *b = battleInt;
|
|
|
|
{
|
|
|
|
boost::unique_lock<boost::recursive_mutex> un(*pim);
|
|
|
|
|
|
|
|
if(vstd::contains(stack->state,MOVED)) //this stack has moved and makes second action -> high morale
|
|
|
|
{
|
|
|
|
std::string hlp = CGI->generaltexth->allTexts[33];
|
2010-11-20 19:36:02 +02:00
|
|
|
boost::algorithm::replace_first(hlp,"%s",(stack->count != 1) ? stack->getCreature()->namePl : stack->getCreature()->nameSing);
|
2010-01-02 03:48:44 +02:00
|
|
|
battleInt->displayEffect(20,stack->position);
|
|
|
|
battleInt->console->addText(hlp);
|
|
|
|
}
|
|
|
|
|
2010-12-23 22:18:10 +02:00
|
|
|
b->stackActivated(stack);
|
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)
|
|
|
|
b->givenCommand->cond.wait(lock);
|
|
|
|
|
|
|
|
//tidy up
|
|
|
|
BattleAction ret = *(b->givenCommand->data);
|
|
|
|
delete b->givenCommand->data;
|
|
|
|
b->givenCommand->data = NULL;
|
|
|
|
|
|
|
|
//return command
|
|
|
|
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
|
|
|
{
|
2010-02-19 18:02:34 +02:00
|
|
|
if(LOCPLINT != this)
|
|
|
|
{ //another local interface should do this
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-05-19 21:23:04 +03:00
|
|
|
boost::unique_lock<boost::recursive_mutex> un(*pim);
|
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
|
|
|
|
2010-12-23 22:18:10 +02:00
|
|
|
void CPlayerInterface::battleStackMoved(int ID, THex dest, int distance, bool end)
|
2008-08-13 03:44:31 +03:00
|
|
|
{
|
2010-02-19 18:02:34 +02:00
|
|
|
if(LOCPLINT != this)
|
|
|
|
{ //another local interface should do this
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-05-19 21:23:04 +03:00
|
|
|
boost::unique_lock<boost::recursive_mutex> un(*pim);
|
2010-01-02 03:48:44 +02:00
|
|
|
battleInt->stackMoved(ID, dest, end, distance);
|
|
|
|
}
|
2010-12-04 21:44:23 +02:00
|
|
|
void CPlayerInterface::battleSpellCast( const BattleSpellCast *sc )
|
2010-01-02 03:48:44 +02:00
|
|
|
{
|
2010-02-19 18:02:34 +02:00
|
|
|
if(LOCPLINT != this)
|
|
|
|
{ //another local interface should do this
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
boost::unique_lock<boost::recursive_mutex> un(*pim);
|
|
|
|
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
|
|
|
{
|
2010-02-19 18:02:34 +02:00
|
|
|
if(LOCPLINT != this)
|
|
|
|
{ //another local interface should do this
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
boost::unique_lock<boost::recursive_mutex> un(*pim);
|
|
|
|
battleInt->battleStacksEffectsSet(sse);
|
|
|
|
}
|
2010-12-04 21:44:23 +02:00
|
|
|
void CPlayerInterface::battleStacksAttacked(const std::vector<BattleStackAttacked> & bsa)
|
2010-01-02 03:48:44 +02:00
|
|
|
{
|
2010-02-19 18:02:34 +02:00
|
|
|
if(LOCPLINT != this)
|
|
|
|
{ //another local interface should do this
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
tlog5 << "CPlayerInterface::battleStackAttacked - locking...";
|
|
|
|
boost::unique_lock<boost::recursive_mutex> un(*pim);
|
|
|
|
tlog5 << "done!\n";
|
2009-06-11 20:21:06 +03:00
|
|
|
|
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
std::vector<SStackAttackedInfo> arg;
|
2010-12-04 21:44:23 +02:00
|
|
|
for(std::vector<BattleStackAttacked>::const_iterator i = bsa.begin(); i != bsa.end(); i++)
|
2009-02-14 15:51:21 +02:00
|
|
|
{
|
2010-01-02 03:48:44 +02:00
|
|
|
if(i->isEffect() && i->effect != 12) //and not armageddon
|
|
|
|
{
|
|
|
|
const CStack *stack = cb->battleGetStackByID(i->stackAttacked, false);
|
|
|
|
if (stack != NULL)
|
|
|
|
battleInt->displayEffect(i->effect, stack->position);
|
|
|
|
}
|
|
|
|
SStackAttackedInfo to_put = {i->stackAttacked, i->damageAmount, i->killedAmount, i->attackerID, LOCPLINT->curAction->actionType==7, i->killed()};
|
|
|
|
arg.push_back(to_put);
|
2010-05-07 15:29:41 +03:00
|
|
|
|
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
|
|
|
{
|
2010-02-19 18:02:34 +02:00
|
|
|
if(LOCPLINT != this)
|
|
|
|
{ //another local interface should do this
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
tlog5 << "CPlayerInterface::battleAttack - locking...";
|
|
|
|
boost::unique_lock<boost::recursive_mutex> un(*pim);
|
|
|
|
tlog5 << "done!\n";
|
|
|
|
assert(curAction);
|
|
|
|
if(ba->lucky()) //lucky hit
|
|
|
|
{
|
|
|
|
const CStack *stack = cb->battleGetStackByID(ba->stackAttacking);
|
|
|
|
std::string hlp = CGI->generaltexth->allTexts[45];
|
2010-11-20 19:36:02 +02: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);
|
|
|
|
battleInt->displayEffect(18,stack->position);
|
|
|
|
}
|
|
|
|
//TODO: bad luck?
|
2009-02-14 16:37:13 +02:00
|
|
|
|
2010-12-23 22:18:10 +02:00
|
|
|
const CStack * attacker = cb->battleGetStackByID(ba->stackAttacking);
|
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
if(ba->shot())
|
2009-02-14 16:37:13 +02:00
|
|
|
{
|
2010-12-04 21:44:23 +02:00
|
|
|
for(std::vector<BattleStackAttacked>::const_iterator i = ba->bsa.begin(); i != ba->bsa.end(); i++)
|
2010-12-23 22:18:10 +02:00
|
|
|
{
|
|
|
|
const CStack * attacked = cb->battleGetStackByID(i->stackAttacked);
|
|
|
|
battleInt->stackAttacking(attacker, cb->battleGetPos(i->stackAttacked), attacked, true);
|
|
|
|
}
|
2010-01-02 03:48:44 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{//WARNING: does not support multiple attacked creatures
|
|
|
|
int shift = 0;
|
|
|
|
if(ba->counter() && BattleInfo::mutualPosition(curAction->destinationTile, attacker->position) < 0)
|
|
|
|
{
|
2010-07-29 15:54:30 +03:00
|
|
|
int distp = BattleInfo::getDistance(curAction->destinationTile + 1, attacker->position);
|
|
|
|
int distm = BattleInfo::getDistance(curAction->destinationTile - 1, attacker->position);
|
|
|
|
|
|
|
|
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
|
|
|
}
|
2010-01-02 03:48:44 +02:00
|
|
|
|
|
|
|
void CPlayerInterface::showComp(SComponent comp)
|
2008-08-13 03:44:31 +03:00
|
|
|
{
|
2009-05-19 21:23:04 +03:00
|
|
|
boost::unique_lock<boost::recursive_mutex> un(*pim);
|
2010-01-02 03:48:44 +02:00
|
|
|
|
2010-12-19 16:39:56 +02:00
|
|
|
CCS->soundh->playSoundFromSet(CCS->soundh->pickupSounds);
|
2010-01-02 03:48:44 +02:00
|
|
|
|
|
|
|
adventureInt->infoBar.showComp(&comp,4000);
|
2008-08-17 12:11:16 +03:00
|
|
|
}
|
2010-01-02 03:48:44 +02:00
|
|
|
|
|
|
|
void CPlayerInterface::showInfoDialog(const std::string &text, const std::vector<Component*> &components, int soundID)
|
|
|
|
{
|
|
|
|
std::vector<SComponent*> intComps;
|
|
|
|
for(int i=0;i<components.size();i++)
|
|
|
|
intComps.push_back(new SComponent(*components[i]));
|
|
|
|
showInfoDialog(text,intComps,soundID);
|
|
|
|
}
|
|
|
|
|
2010-07-21 13:09:29 +03:00
|
|
|
void CPlayerInterface::showInfoDialog(const std::string &text, const std::vector<SComponent*> & components, int soundID, bool delComps)
|
2008-08-17 12:11:16 +03:00
|
|
|
{
|
2010-01-02 03:48:44 +02:00
|
|
|
waitWhileDialog();
|
2009-05-19 21:23:04 +03:00
|
|
|
boost::unique_lock<boost::recursive_mutex> un(*pim);
|
2010-05-14 05:18:37 +03:00
|
|
|
|
|
|
|
stopMovement();
|
2010-03-08 00:56:51 +02:00
|
|
|
CInfoWindow *temp = CInfoWindow::create(text, playerID, &components);
|
2010-07-21 13:09:29 +03:00
|
|
|
temp->setDelComps(delComps);
|
2010-02-22 15:30:46 +02:00
|
|
|
if(makingTurn && GH.listInt.size() && LOCPLINT == this)
|
2008-08-17 12:11:16 +03:00
|
|
|
{
|
2010-12-19 16:39:56 +02:00
|
|
|
CCS->soundh->playSound(static_cast<soundBase::soundID>(soundID));
|
2010-01-02 03:48:44 +02:00
|
|
|
showingDialog->set(true);
|
|
|
|
GH.pushInt(temp);
|
2008-08-17 12:11:16 +03:00
|
|
|
}
|
2010-01-02 03:48:44 +02:00
|
|
|
else
|
2009-05-19 21:23:04 +03:00
|
|
|
{
|
2010-01-02 03:48:44 +02:00
|
|
|
dialogs.push_back(temp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPlayerInterface::showYesNoDialog(const std::string &text, const std::vector<SComponent*> & components, CFunctionList<void()> onYes, CFunctionList<void()> onNo, bool DelComps)
|
|
|
|
{
|
|
|
|
boost::unique_lock<boost::recursive_mutex> un(*pim);
|
2010-05-14 05:18:37 +03:00
|
|
|
|
|
|
|
stopMovement();
|
2010-01-02 03:48:44 +02:00
|
|
|
LOCPLINT->showingDialog->setn(true);
|
|
|
|
CInfoWindow::showYesNoDialog(text, &components, onYes, onNo, DelComps, playerID);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPlayerInterface::showBlockingDialog( const std::string &text, const std::vector<Component> &components, ui32 askID, int soundID, bool selection, bool cancel )
|
|
|
|
{
|
|
|
|
waitWhileDialog();
|
|
|
|
boost::unique_lock<boost::recursive_mutex> un(*pim);
|
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
|
|
|
|
{
|
|
|
|
std::vector<SComponent*> intComps;
|
|
|
|
for(int i=0;i<components.size();i++)
|
|
|
|
intComps.push_back(new SComponent(components[i])); //will be deleted by close in window
|
2009-04-14 15:47:09 +03:00
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
showYesNoDialog(text,intComps,boost::bind(&CCallback::selectionMade,cb,1,askID),boost::bind(&CCallback::selectionMade,cb,0,askID),true);
|
2009-05-19 21:23:04 +03:00
|
|
|
}
|
2010-01-02 03:48:44 +02:00
|
|
|
else if(selection)
|
2009-05-19 21:23:04 +03:00
|
|
|
{
|
2010-01-02 03:48:44 +02:00
|
|
|
std::vector<CSelectableComponent*> intComps;
|
|
|
|
for(int i=0;i<components.size();i++)
|
|
|
|
intComps.push_back(new CSelectableComponent(components[i])); //will be deleted by CSelWindow::close
|
|
|
|
|
|
|
|
std::vector<std::pair<std::string,CFunctionList<void()> > > pom;
|
|
|
|
pom.push_back(std::pair<std::string,CFunctionList<void()> >("IOKAY.DEF",0));
|
|
|
|
if(cancel)
|
2009-05-19 21:23:04 +03:00
|
|
|
{
|
2010-01-02 03:48:44 +02:00
|
|
|
pom.push_back(std::pair<std::string,CFunctionList<void()> >("ICANCEL.DEF",0));
|
2009-05-19 21:23:04 +03:00
|
|
|
}
|
2010-01-02 03:48:44 +02:00
|
|
|
|
|
|
|
int charperline = 35;
|
|
|
|
if (pom.size() > 1)
|
2010-01-25 05:09:42 +02:00
|
|
|
charperline = 50;
|
2010-01-02 03:48:44 +02:00
|
|
|
CSelWindow * temp = new CSelWindow(text, playerID, charperline, intComps, pom, askID);
|
|
|
|
GH.pushInt(temp);
|
|
|
|
intComps[0]->clickLeft(true, false);
|
2009-05-19 21:23:04 +03:00
|
|
|
}
|
|
|
|
|
2008-08-27 13:19:18 +03:00
|
|
|
}
|
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
void CPlayerInterface::tileRevealed(const std::set<int3> &pos)
|
2008-08-27 13:19:18 +03:00
|
|
|
{
|
2009-05-19 21:23:04 +03:00
|
|
|
boost::unique_lock<boost::recursive_mutex> un(*pim);
|
2010-01-02 03:48:44 +02:00
|
|
|
for(std::set<int3>::const_iterator i=pos.begin(); i!=pos.end();i++)
|
|
|
|
adventureInt->minimap.showTile(*i);
|
|
|
|
if(pos.size())
|
|
|
|
GH.totalRedraw();
|
2008-08-27 13:19:18 +03:00
|
|
|
}
|
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
void CPlayerInterface::tileHidden(const std::set<int3> &pos)
|
2008-08-27 13:19:18 +03:00
|
|
|
{
|
2009-05-19 21:23:04 +03:00
|
|
|
boost::unique_lock<boost::recursive_mutex> un(*pim);
|
2010-01-02 03:48:44 +02:00
|
|
|
for(std::set<int3>::const_iterator i=pos.begin(); i!=pos.end();i++)
|
|
|
|
adventureInt->minimap.hideTile(*i);
|
2010-06-06 09:05:39 +03:00
|
|
|
if(pos.size())
|
|
|
|
GH.totalRedraw();
|
2008-09-07 06:38:37 +03:00
|
|
|
}
|
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
void CPlayerInterface::openHeroWindow(const CGHeroInstance *hero)
|
2008-09-07 06:38:37 +03:00
|
|
|
{
|
2010-01-02 03:48:44 +02:00
|
|
|
boost::unique_lock<boost::recursive_mutex> un(*pim);
|
2010-12-17 00:32:53 +02:00
|
|
|
adventureInt->heroWindow = new CHeroWindow(hero);
|
2010-01-02 03:48:44 +02:00
|
|
|
adventureInt->heroWindow->setHero(hero);
|
|
|
|
GH.pushInt(adventureInt->heroWindow);
|
2008-09-07 06:38:37 +03: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);
|
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
|
|
|
{
|
2010-01-02 03:48:44 +02:00
|
|
|
boost::unique_lock<boost::recursive_mutex> un(*pim);
|
|
|
|
if(castleInt && town->ID == TOWNI_TYPE)
|
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)
|
|
|
|
fs->draw(castleInt,false);
|
|
|
|
}
|
2010-05-15 11:33:32 +03:00
|
|
|
else if(GH.listInt.size() && (town->ID == 17 || town->ID == 20 || town->ID == 106)) //external dwelling
|
2010-01-02 03:48:44 +02:00
|
|
|
{
|
|
|
|
CRecruitmentWindow *crw = dynamic_cast<CRecruitmentWindow*>(GH.topInt());
|
|
|
|
if(crw)
|
|
|
|
crw->initCres();
|
2009-09-05 17:10:26 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-02 21:20:26 +03:00
|
|
|
void CPlayerInterface::heroBonusChanged( const CGHeroInstance *hero, const Bonus &bonus, bool gain )
|
2008-09-07 06:38:37 +03:00
|
|
|
{
|
2010-05-02 21:20:26 +03:00
|
|
|
if(bonus.type == Bonus::NONE) return;
|
2009-05-19 21:23:04 +03:00
|
|
|
boost::unique_lock<boost::recursive_mutex> un(*pim);
|
2010-03-21 00:17:19 +02:00
|
|
|
updateInfo(hero);
|
2010-05-15 18:00:19 +03:00
|
|
|
if (bonus.type == Bonus::FLYING_MOVEMENT || bonus.type == Bonus::WATER_WALKING && !gain)
|
|
|
|
{
|
|
|
|
//recalculate paths because hero has lost bonus influencing pathfinding
|
|
|
|
cb->recalculatePaths();
|
2010-05-16 16:42:19 +03:00
|
|
|
eraseCurrentPathOf(hero, false);
|
2010-05-15 18:00:19 +03:00
|
|
|
}
|
2008-09-07 06:38:37 +03:00
|
|
|
}
|
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
template <typename Handler> void CPlayerInterface::serializeTempl( Handler &h, const int version )
|
2008-09-07 06:38:37 +03:00
|
|
|
{
|
2010-08-03 14:36:52 +03:00
|
|
|
h & playerID;
|
2010-01-02 03:48:44 +02:00
|
|
|
h & sysOpts;
|
2010-07-21 13:09:29 +03:00
|
|
|
h & spellbookSettings;
|
2008-09-07 06:38:37 +03:00
|
|
|
}
|
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
void CPlayerInterface::serialize( COSer<CSaveFile> &h, const int version )
|
2008-09-07 06:38:37 +03:00
|
|
|
{
|
2010-01-02 03:48:44 +02:00
|
|
|
serializeTempl(h,version);
|
2008-09-07 06:38:37 +03:00
|
|
|
}
|
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
void CPlayerInterface::serialize( CISer<CLoadFile> &h, const int version )
|
2008-09-07 06:38:37 +03:00
|
|
|
{
|
2010-01-02 03:48:44 +02:00
|
|
|
serializeTempl(h,version);
|
|
|
|
sysOpts.apply();
|
|
|
|
firstCall = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CPlayerInterface::moveHero( const CGHeroInstance *h, CGPath path )
|
|
|
|
{
|
|
|
|
if (!h)
|
|
|
|
return false; //can't find hero
|
|
|
|
|
2010-03-21 00:17:19 +02:00
|
|
|
pim->unlock();
|
2010-01-02 03:48:44 +02:00
|
|
|
bool result = false;
|
|
|
|
|
|
|
|
{
|
2010-03-21 00:17:19 +02:00
|
|
|
path.convert(0);
|
|
|
|
boost::unique_lock<boost::mutex> un(stillMoveHero.mx);
|
|
|
|
stillMoveHero.data = CONTINUE_MOVE;
|
|
|
|
|
|
|
|
enum TerrainTile::EterrainType currentTerrain = TerrainTile::border; // not init yet
|
|
|
|
enum TerrainTile::EterrainType newTerrain;
|
|
|
|
int sh = -1;
|
|
|
|
|
2010-05-16 16:42:19 +03:00
|
|
|
const TerrainTile * curTile = cb->getTileInfo(CGHeroInstance::convertPosition(h->pos, false));
|
|
|
|
|
|
|
|
for(int i=path.nodes.size()-1; i>0 && (stillMoveHero.data == CONTINUE_MOVE || curTile->blocked); i--)
|
2008-09-07 06:38:37 +03:00
|
|
|
{
|
2010-03-21 00:17:19 +02: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)
|
|
|
|
{
|
|
|
|
stillMoveHero.data = STOP_MOVE;
|
|
|
|
break;
|
|
|
|
}
|
2010-05-06 15:13:31 +03:00
|
|
|
|
2010-03-21 00:17:19 +02:00
|
|
|
// Start a new sound for the hero movement or let the existing one carry on.
|
2010-01-02 03:48:44 +02:00
|
|
|
#if 0
|
2010-03-21 00:17:19 +02:00
|
|
|
// TODO
|
|
|
|
if (hero is flying && sh == -1)
|
2010-12-19 16:39:56 +02:00
|
|
|
sh = CCS->soundh->playSound(soundBase::horseFlying, -1);
|
2010-01-02 03:48:44 +02:00
|
|
|
#endif
|
2010-03-21 00:17:19 +02:00
|
|
|
{
|
|
|
|
newTerrain = cb->getTileInfo(CGHeroInstance::convertPosition(path.nodes[i].coord, false))->tertype;
|
2009-05-19 21:23:04 +03:00
|
|
|
|
2010-03-21 00:17:19 +02:00
|
|
|
if (newTerrain != currentTerrain) {
|
2010-12-19 16:39:56 +02:00
|
|
|
CCS->soundh->stopSound(sh);
|
|
|
|
sh = CCS->soundh->playSound(CCS->soundh->horseSounds[newTerrain], -1);
|
2010-03-21 00:17:19 +02:00
|
|
|
currentTerrain = newTerrain;
|
|
|
|
}
|
2010-01-02 03:48:44 +02:00
|
|
|
}
|
2009-05-19 21:23:04 +03:00
|
|
|
|
2010-03-21 00:17:19 +02:00
|
|
|
stillMoveHero.data = WAITING_MOVE;
|
2009-05-19 21:23:04 +03:00
|
|
|
|
2010-03-21 00:17:19 +02:00
|
|
|
int3 endpos(path.nodes[i-1].coord.x, path.nodes[i-1].coord.y, h->pos.z);
|
2010-05-06 15:13:31 +03:00
|
|
|
bool guarded = CGI->mh->map->isInTheMap(cb->guardingCreaturePosition(endpos - int3(1, 0, 0)));
|
|
|
|
|
2010-03-21 00:17:19 +02:00
|
|
|
cb->moveHero(h,endpos);
|
2010-02-28 14:39:38 +02:00
|
|
|
|
2010-03-21 00:17:19 +02:00
|
|
|
eventsM.unlock();
|
|
|
|
while(stillMoveHero.data != STOP_MOVE && stillMoveHero.data != CONTINUE_MOVE)
|
|
|
|
stillMoveHero.cond.wait(un);
|
|
|
|
eventsM.lock();
|
2010-05-06 15:13:31 +03:00
|
|
|
|
|
|
|
if (guarded) // Abort movement if a guard was fought.
|
|
|
|
break;
|
2010-03-21 00:17:19 +02:00
|
|
|
}
|
2008-09-07 06:38:37 +03:00
|
|
|
|
2010-12-19 16:39:56 +02:00
|
|
|
CCS->soundh->stopSound(sh);
|
2010-03-21 00:17:19 +02:00
|
|
|
cb->recalculatePaths();
|
|
|
|
}
|
2008-09-07 06:38:37 +03:00
|
|
|
|
2010-03-21 00:17:19 +02:00
|
|
|
pim->lock();
|
2010-01-02 03:48:44 +02:00
|
|
|
return result;
|
2008-09-07 06:38:37 +03:00
|
|
|
}
|
2010-01-02 03:48:44 +02:00
|
|
|
|
|
|
|
bool CPlayerInterface::shiftPressed() const
|
2008-09-07 06:38:37 +03:00
|
|
|
{
|
2010-01-02 03:48:44 +02:00
|
|
|
return SDL_GetKeyState(NULL)[SDLK_LSHIFT] || SDL_GetKeyState(NULL)[SDLK_RSHIFT];
|
|
|
|
}
|
2008-09-07 06:38:37 +03:00
|
|
|
|
2010-07-21 13:09:29 +03:00
|
|
|
bool CPlayerInterface::altPressed() const
|
|
|
|
{
|
|
|
|
return SDL_GetKeyState(NULL)[SDLK_LALT] || SDL_GetKeyState(NULL)[SDLK_RALT];
|
|
|
|
}
|
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
void CPlayerInterface::showGarrisonDialog( const CArmedInstance *up, const CGHeroInstance *down, bool removableUnits, boost::function<void()> &onEnd )
|
|
|
|
{
|
|
|
|
if(stillMoveHero.get() == DURING_MOVE && adventureInt->terrain.currentPath->nodes.size() > 1) //to ignore calls on passing through garrisons
|
|
|
|
return;
|
2008-09-07 06:38:37 +03:00
|
|
|
|
|
|
|
{
|
2010-01-02 03:48:44 +02:00
|
|
|
boost::unique_lock<boost::mutex> un(showingDialog->mx);
|
|
|
|
while(showingDialog->data)
|
|
|
|
showingDialog->cond.wait(un);
|
2009-05-19 21:23:04 +03:00
|
|
|
}
|
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
boost::unique_lock<boost::recursive_mutex> un(*pim);
|
|
|
|
while(dialogs.size())
|
2009-05-19 21:23:04 +03:00
|
|
|
{
|
2010-01-02 03:48:44 +02:00
|
|
|
pim->unlock();
|
|
|
|
SDL_Delay(20);
|
|
|
|
pim->lock();
|
2008-09-07 06:38:37 +03:00
|
|
|
}
|
2010-01-02 03:48:44 +02:00
|
|
|
CGarrisonWindow *cgw = new CGarrisonWindow(up,down,removableUnits);
|
|
|
|
cgw->quit->callback += onEnd;
|
|
|
|
GH.pushInt(cgw);
|
|
|
|
}
|
2008-09-25 17:09:31 +03:00
|
|
|
|
2010-02-27 03:05:39 +02:00
|
|
|
/**
|
|
|
|
* Shows the dialog that appears when right-clicking an artifact that can be assembled
|
|
|
|
* into a combinational one on an artifact screen. Does not require the combination of
|
|
|
|
* artifacts to be legal.
|
|
|
|
* @param artifactID ID of a constituent artifact.
|
|
|
|
* @param assembleTo ID of artifact to assemble a constituent into, not used when assemble
|
|
|
|
* is false.
|
|
|
|
* @param assemble True if the artifact is to be assembled, false if it is to be disassembled.
|
|
|
|
*/
|
|
|
|
void CPlayerInterface::showArtifactAssemblyDialog (ui32 artifactID, ui32 assembleTo, bool assemble, CFunctionList<void()> onYes, CFunctionList<void()> onNo)
|
|
|
|
{
|
2010-06-26 19:02:10 +03:00
|
|
|
const CArtifact &artifact = *CGI->arth->artifacts[artifactID];
|
2010-02-27 03:05:39 +02:00
|
|
|
std::string text = artifact.Description();
|
|
|
|
text += "\n\n";
|
|
|
|
std::vector<SComponent*> scs;
|
|
|
|
|
|
|
|
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.
|
|
|
|
SComponent* sc = new SComponent;
|
2010-02-27 17:59:21 +02:00
|
|
|
sc->type = SComponent::artifact;
|
2010-02-27 03:05:39 +02:00
|
|
|
sc->subtype = assembledArtifact.id;
|
|
|
|
sc->description = assembledArtifact.Description();
|
|
|
|
sc->subtitle = assembledArtifact.Name();
|
|
|
|
scs.push_back(sc);
|
|
|
|
} else {
|
|
|
|
// Do you wish to disassemble this artifact?
|
|
|
|
text += CGI->generaltexth->allTexts[733];
|
|
|
|
}
|
|
|
|
|
|
|
|
showYesNoDialog(text, scs, onYes, onNo, true);
|
|
|
|
}
|
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
void CPlayerInterface::requestRealized( PackageApplied *pa )
|
|
|
|
{
|
|
|
|
if(stillMoveHero.get() == DURING_MOVE)
|
|
|
|
stillMoveHero.setn(CONTINUE_MOVE);
|
2009-05-19 21:23:04 +03:00
|
|
|
}
|
2010-01-02 03:48:44 +02:00
|
|
|
|
|
|
|
void CPlayerInterface::heroExchangeStarted(si32 hero1, si32 hero2)
|
2008-09-25 17:09:31 +03:00
|
|
|
{
|
2009-05-19 21:23:04 +03:00
|
|
|
boost::unique_lock<boost::recursive_mutex> un(*pim);
|
2010-08-12 18:54:25 +03:00
|
|
|
GH.pushInt(new CExchangeWindow(hero1, hero2));
|
2010-01-02 03:48:44 +02:00
|
|
|
}
|
2009-05-06 13:14:48 +03:00
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
void CPlayerInterface::objectPropertyChanged(const SetObjectProperty * sop)
|
|
|
|
{
|
|
|
|
//redraw minimap if owner changed
|
|
|
|
boost::unique_lock<boost::recursive_mutex> un(*pim);
|
2010-05-02 21:20:26 +03:00
|
|
|
if(sop->what == ObjProperty::OWNER)
|
2009-05-19 21:23:04 +03:00
|
|
|
{
|
2010-01-02 03:48:44 +02:00
|
|
|
const CGObjectInstance * obj = cb->getObjectInfo(sop->id);
|
|
|
|
std::set<int3> pos = obj->getBlockedPos();
|
|
|
|
for(std::set<int3>::const_iterator it = pos.begin(); it != pos.end(); ++it)
|
2009-08-18 14:49:34 +03:00
|
|
|
{
|
2010-01-02 03:48:44 +02:00
|
|
|
if(cb->isVisible(*it))
|
|
|
|
adventureInt->minimap.showTile(*it);
|
2009-08-18 14:49:34 +03:00
|
|
|
}
|
2010-01-02 03:48:44 +02:00
|
|
|
|
|
|
|
if(obj->ID == TOWNI_TYPE)
|
2010-02-26 13:18:09 +02:00
|
|
|
if(obj->tempOwner == playerID)
|
|
|
|
towns.push_back(static_cast<const CGTownInstance *>(obj));
|
|
|
|
else
|
|
|
|
towns -= obj;
|
|
|
|
|
|
|
|
assert(cb->getTownsInfo().size() == towns.size());
|
2009-05-08 05:58:41 +03:00
|
|
|
}
|
2010-01-02 03:48:44 +02:00
|
|
|
|
2008-09-25 17:09:31 +03:00
|
|
|
}
|
|
|
|
|
2010-02-26 13:18:09 +02:00
|
|
|
void CPlayerInterface::recreateHeroTownList()
|
2008-09-25 17:09:31 +03:00
|
|
|
{
|
2010-01-02 03:48:44 +02:00
|
|
|
wanderingHeroes.clear();
|
|
|
|
std::vector<const CGHeroInstance*> heroes = cb->getHeroesInfo();
|
|
|
|
for(size_t i = 0; i < heroes.size(); i++)
|
|
|
|
if(!heroes[i]->inTownGarrison)
|
|
|
|
wanderingHeroes.push_back(heroes[i]);
|
2010-02-26 13:18:09 +02:00
|
|
|
|
|
|
|
towns.clear();
|
|
|
|
std::vector<const CGTownInstance*> townInfo = cb->getTownsInfo();
|
|
|
|
for(size_t i = 0; i < townInfo.size(); i++)
|
|
|
|
towns.push_back(townInfo[i]);
|
2008-09-25 17:09:31 +03:00
|
|
|
}
|
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
const CGHeroInstance * CPlayerInterface::getWHero( int pos )
|
2008-09-25 17:09:31 +03:00
|
|
|
{
|
2010-01-02 03:48:44 +02:00
|
|
|
if(pos < 0 || pos >= wanderingHeroes.size())
|
|
|
|
return NULL;
|
|
|
|
return wanderingHeroes[pos];
|
2008-09-25 17:09:31 +03:00
|
|
|
}
|
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
void CPlayerInterface::showRecruitmentDialog(const CGDwelling *dwelling, const CArmedInstance *dst, int level)
|
2008-09-25 17:09:31 +03:00
|
|
|
{
|
2009-07-21 02:34:06 +03:00
|
|
|
waitWhileDialog();
|
2009-05-19 21:23:04 +03:00
|
|
|
boost::unique_lock<boost::recursive_mutex> un(*pim);
|
2010-07-10 19:50:23 +03:00
|
|
|
CRecruitmentWindow *cr = new CRecruitmentWindow(dwelling, level, dst, boost::bind(&CCallback::recruitCreatures, cb, dwelling, _1, _2, -1));
|
2010-01-02 03:48:44 +02:00
|
|
|
GH.pushInt(cr);
|
|
|
|
}
|
2009-03-28 02:38:48 +02:00
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
void CPlayerInterface::waitWhileDialog()
|
|
|
|
{
|
|
|
|
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
|
|
|
{
|
2009-05-19 21:23:04 +03:00
|
|
|
boost::unique_lock<boost::recursive_mutex> un(*pim);
|
2010-01-02 03:48:44 +02:00
|
|
|
int state = obj->state();
|
|
|
|
std::vector<si32> cost;
|
|
|
|
obj->getBoatCost(cost);
|
2010-02-13 06:47:31 +02:00
|
|
|
CShipyardWindow *csw = new CShipyardWindow(cost, state, obj->getBoatType(), boost::bind(&CCallback::buildBoat, cb, obj));
|
2010-01-02 03:48:44 +02:00
|
|
|
GH.pushInt(csw);
|
2008-09-25 17:09:31 +03:00
|
|
|
}
|
2008-10-26 22:58:34 +02:00
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
void CPlayerInterface::newObject( const CGObjectInstance * obj )
|
2008-10-26 22:58:34 +02:00
|
|
|
{
|
2009-05-19 21:23:04 +03:00
|
|
|
boost::unique_lock<boost::recursive_mutex> un(*pim);
|
2010-01-02 03:48:44 +02:00
|
|
|
CGI->mh->printObject(obj);
|
|
|
|
//we might have built a boat in shipyard in opened town screen
|
2010-01-25 05:09:42 +02:00
|
|
|
if(obj->ID == 8
|
|
|
|
&& LOCPLINT->castleInt
|
2010-01-02 03:48:44 +02:00
|
|
|
&& obj->pos-obj->getVisitableOffset() == LOCPLINT->castleInt->town->bestLocation())
|
2009-02-09 18:18:48 +02:00
|
|
|
{
|
2010-12-19 16:39:56 +02:00
|
|
|
CCS->soundh->playSound(soundBase::newBuilding);
|
2010-01-02 03:48:44 +02:00
|
|
|
LOCPLINT->castleInt->recreateBuildings();
|
2009-02-09 18:18:48 +02:00
|
|
|
}
|
2010-01-02 03:48:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CPlayerInterface::centerView (int3 pos, int focusTime)
|
|
|
|
{
|
2010-08-18 13:53:59 +03:00
|
|
|
waitWhileDialog();
|
2010-02-20 15:24:38 +02:00
|
|
|
adventureInt->centerOn (pos);
|
2010-01-02 03:48:44 +02:00
|
|
|
if(focusTime)
|
2009-02-09 18:18:48 +02:00
|
|
|
{
|
2010-01-02 03:48:44 +02:00
|
|
|
bool activeAdv = (GH.topInt() == adventureInt && adventureInt->isActive());
|
|
|
|
if(activeAdv)
|
|
|
|
adventureInt->deactivate();
|
2009-05-19 21:23:04 +03:00
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
SDL_Delay(focusTime);
|
2008-10-26 22:58:34 +02:00
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
if(activeAdv)
|
|
|
|
adventureInt->activate();
|
2009-05-19 21:23:04 +03:00
|
|
|
}
|
2008-10-26 22:58:34 +02:00
|
|
|
}
|
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
void CPlayerInterface::objectRemoved( const CGObjectInstance *obj )
|
2008-10-26 22:58:34 +02:00
|
|
|
{
|
2010-01-02 03:48:44 +02:00
|
|
|
if(obj->ID == HEROI_TYPE && obj->tempOwner == playerID)
|
|
|
|
{
|
|
|
|
const CGHeroInstance *h = static_cast<const CGHeroInstance*>(obj);
|
|
|
|
heroKilled(h);
|
|
|
|
}
|
2008-10-26 22:58:34 +02:00
|
|
|
}
|
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
bool CPlayerInterface::ctrlPressed() const
|
2008-10-26 22:58:34 +02:00
|
|
|
{
|
2010-01-02 03:48:44 +02:00
|
|
|
return SDL_GetKeyState(NULL)[SDLK_LCTRL] || SDL_GetKeyState(NULL)[SDLK_RCTRL];
|
2008-10-26 22:58:34 +02:00
|
|
|
}
|
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
void CPlayerInterface::update()
|
2008-10-26 22:58:34 +02:00
|
|
|
{
|
2010-02-13 06:47:31 +02:00
|
|
|
while(!terminate_cond.get() && !pim->try_lock()) //try acquiring long until it succeeds or we are told to terminate
|
|
|
|
boost::this_thread::sleep(boost::posix_time::milliseconds(15));
|
|
|
|
|
|
|
|
if(terminate_cond.get())
|
|
|
|
return;
|
2010-06-01 02:53:35 +03:00
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
//if there are any waiting dialogs, show them
|
2010-07-24 14:46:04 +03:00
|
|
|
if((howManyPeople <= 1 || makingTurn) && dialogs.size() && !showingDialog->get())
|
2009-02-09 18:18:48 +02:00
|
|
|
{
|
2010-01-02 03:48:44 +02:00
|
|
|
showingDialog->set(true);
|
|
|
|
GH.pushInt(dialogs.front());
|
|
|
|
dialogs.pop_front();
|
2009-02-09 18:18:48 +02:00
|
|
|
}
|
2010-01-02 03:48:44 +02:00
|
|
|
|
2010-06-01 02:53:35 +03:00
|
|
|
//in some conditions we may receive calls before selection is initialized - we must ignore them
|
2010-12-23 02:33:48 +02:00
|
|
|
if(adventureInt && !adventureInt->selection && GH.topInt() == adventureInt)
|
2010-06-01 02:53:35 +03:00
|
|
|
return;
|
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
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();
|
|
|
|
|
2010-12-19 16:39:56 +02:00
|
|
|
CCS->curh->draw1();
|
2010-01-02 03:48:44 +02:00
|
|
|
CSDL_Ext::update(screen);
|
2010-12-19 16:39:56 +02:00
|
|
|
CCS->curh->draw2();
|
2010-01-02 03:48:44 +02:00
|
|
|
|
2010-08-26 18:33:55 +03:00
|
|
|
screenLTmax = Point(conf.cc.resx - screen->w, conf.cc.resy - screen->h);
|
2010-08-23 19:13:30 +03:00
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
pim->unlock();
|
|
|
|
|
|
|
|
SDL_framerateDelay(mainFPSmng);
|
|
|
|
}
|
|
|
|
|
|
|
|
int CPlayerInterface::getLastIndex( std::string namePrefix)
|
|
|
|
{
|
|
|
|
using namespace boost::filesystem;
|
|
|
|
using namespace boost::algorithm;
|
|
|
|
|
|
|
|
std::map<std::time_t, int> dates; //save number => datestamp
|
|
|
|
|
|
|
|
directory_iterator enddir;
|
2010-01-25 05:09:42 +02:00
|
|
|
for (directory_iterator dir(GVCMIDirs.UserPath + "/Games"); dir!=enddir; dir++)
|
2010-01-02 03:48:44 +02:00
|
|
|
{
|
|
|
|
if(is_regular(dir->status()))
|
2009-06-28 16:49:39 +03:00
|
|
|
{
|
2010-01-02 03:48:44 +02:00
|
|
|
std::string name = dir->path().leaf();
|
|
|
|
if(starts_with(name, namePrefix) && ends_with(name, ".vlgm1"))
|
2009-06-28 16:49:39 +03:00
|
|
|
{
|
2010-01-02 03:48:44 +02:00
|
|
|
char nr = name[namePrefix.size()];
|
|
|
|
if(std::isdigit(nr))
|
|
|
|
{
|
|
|
|
dates[last_write_time(dir->path())] = boost::lexical_cast<int>(nr);
|
|
|
|
}
|
2009-06-28 16:49:39 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-01-02 03:48:44 +02:00
|
|
|
|
|
|
|
if(dates.size())
|
|
|
|
return (--dates.end())->second; //return latest file number
|
|
|
|
return 0;
|
2008-10-26 22:58:34 +02:00
|
|
|
}
|
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
void CPlayerInterface::initMovement( const TryMoveHero &details, const CGHeroInstance * ho, const int3 &hp )
|
2008-10-26 22:58:34 +02:00
|
|
|
{
|
2010-01-02 03:48:44 +02:00
|
|
|
if(details.end.x+1 == details.start.x && details.end.y+1 == details.start.y) //tl
|
2009-07-26 13:43:22 +03:00
|
|
|
{
|
2010-01-02 03:48:44 +02:00
|
|
|
//ho->moveDir = 1;
|
|
|
|
ho->isStanding = false;
|
|
|
|
CGI->mh->ttiles[hp.x-3][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, -31)));
|
|
|
|
CGI->mh->ttiles[hp.x-2][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 1, -31)));
|
|
|
|
CGI->mh->ttiles[hp.x-1][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 33, -31)));
|
|
|
|
CGI->mh->ttiles[hp.x][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 65, -31)));
|
2009-02-09 18:18:48 +02:00
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
CGI->mh->ttiles[hp.x-3][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, 1)));
|
|
|
|
subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1, 1), ho->id);
|
|
|
|
subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33, 1), ho->id);
|
|
|
|
subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65, 1), ho->id);
|
2009-04-03 18:55:26 +03:00
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
CGI->mh->ttiles[hp.x-3][hp.y][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, 33)));
|
|
|
|
subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1, 33), ho->id);
|
|
|
|
subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33, 33), ho->id);
|
|
|
|
subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65, 33), ho->id);
|
2009-04-03 18:55:26 +03:00
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
std::stable_sort(CGI->mh->ttiles[hp.x-3][hp.y-2][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-3][hp.y-2][hp.z].objects.end(), ocmptwo_cgin);
|
|
|
|
std::stable_sort(CGI->mh->ttiles[hp.x-2][hp.y-2][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-2][hp.y-2][hp.z].objects.end(), ocmptwo_cgin);
|
|
|
|
std::stable_sort(CGI->mh->ttiles[hp.x-1][hp.y-2][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-1][hp.y-2][hp.z].objects.end(), ocmptwo_cgin);
|
|
|
|
std::stable_sort(CGI->mh->ttiles[hp.x][hp.y-2][hp.z].objects.begin(), CGI->mh->ttiles[hp.x][hp.y-2][hp.z].objects.end(), ocmptwo_cgin);
|
2009-04-03 18:55:26 +03:00
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
std::stable_sort(CGI->mh->ttiles[hp.x-3][hp.y-1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-3][hp.y-1][hp.z].objects.end(), ocmptwo_cgin);
|
2009-04-03 18:55:26 +03:00
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
std::stable_sort(CGI->mh->ttiles[hp.x-3][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-3][hp.y][hp.z].objects.end(), ocmptwo_cgin);
|
2009-04-04 22:26:41 +03:00
|
|
|
}
|
2010-01-02 03:48:44 +02:00
|
|
|
else if(details.end.x == details.start.x && details.end.y+1 == details.start.y) //t
|
|
|
|
{
|
|
|
|
//ho->moveDir = 2;
|
|
|
|
ho->isStanding = false;
|
|
|
|
CGI->mh->ttiles[hp.x-2][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 0, -31)));
|
|
|
|
CGI->mh->ttiles[hp.x-1][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 32, -31)));
|
|
|
|
CGI->mh->ttiles[hp.x][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 64, -31)));
|
2009-05-19 21:23:04 +03:00
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 0, 1), ho->id);
|
|
|
|
subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 32, 1), ho->id);
|
|
|
|
subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 64, 1), ho->id);
|
2009-04-04 22:26:41 +03:00
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 0, 33), ho->id);
|
|
|
|
subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 32, 33), ho->id);
|
|
|
|
subRect(hp.x, hp.y, hp.z, genRect(32, 32, 64, 33), ho->id);
|
2009-04-05 17:37:14 +03:00
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
std::stable_sort(CGI->mh->ttiles[hp.x-2][hp.y-2][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-2][hp.y-2][hp.z].objects.end(), ocmptwo_cgin);
|
|
|
|
std::stable_sort(CGI->mh->ttiles[hp.x-1][hp.y-2][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-1][hp.y-2][hp.z].objects.end(), ocmptwo_cgin);
|
|
|
|
std::stable_sort(CGI->mh->ttiles[hp.x][hp.y-2][hp.z].objects.begin(), CGI->mh->ttiles[hp.x][hp.y-2][hp.z].objects.end(), ocmptwo_cgin);
|
|
|
|
}
|
|
|
|
else if(details.end.x-1 == details.start.x && details.end.y+1 == details.start.y) //tr
|
2009-04-03 18:55:26 +03:00
|
|
|
{
|
2010-01-02 03:48:44 +02:00
|
|
|
//ho->moveDir = 3;
|
|
|
|
ho->isStanding = false;
|
|
|
|
CGI->mh->ttiles[hp.x-2][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -1, -31)));
|
|
|
|
CGI->mh->ttiles[hp.x-1][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 31, -31)));
|
|
|
|
CGI->mh->ttiles[hp.x][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 63, -31)));
|
|
|
|
CGI->mh->ttiles[hp.x+1][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, -31)));
|
2009-05-19 21:23:04 +03:00
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1, 1), ho->id);
|
|
|
|
subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31, 1), ho->id);
|
|
|
|
subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63, 1), ho->id);
|
|
|
|
CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, 1)));
|
2009-04-03 18:55:26 +03:00
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1, 33), ho->id);
|
|
|
|
subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31, 33), ho->id);
|
|
|
|
subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63, 33), ho->id);
|
|
|
|
CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, 33)));
|
2009-05-19 21:23:04 +03:00
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
std::stable_sort(CGI->mh->ttiles[hp.x-2][hp.y-2][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-2][hp.y-2][hp.z].objects.end(), ocmptwo_cgin);
|
|
|
|
std::stable_sort(CGI->mh->ttiles[hp.x-1][hp.y-2][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-1][hp.y-2][hp.z].objects.end(), ocmptwo_cgin);
|
|
|
|
std::stable_sort(CGI->mh->ttiles[hp.x][hp.y-2][hp.z].objects.begin(), CGI->mh->ttiles[hp.x][hp.y-2][hp.z].objects.end(), ocmptwo_cgin);
|
|
|
|
std::stable_sort(CGI->mh->ttiles[hp.x+1][hp.y-2][hp.z].objects.begin(), CGI->mh->ttiles[hp.x+1][hp.y-2][hp.z].objects.end(), ocmptwo_cgin);
|
2009-05-19 21:23:04 +03:00
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
std::stable_sort(CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.end(), ocmptwo_cgin);
|
2009-05-19 21:23:04 +03:00
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
std::stable_sort(CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.end(), ocmptwo_cgin);
|
|
|
|
}
|
|
|
|
else if(details.end.x-1 == details.start.x && details.end.y == details.start.y) //r
|
|
|
|
{
|
|
|
|
//ho->moveDir = 4;
|
|
|
|
ho->isStanding = false;
|
|
|
|
subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1, 0), ho->id);
|
|
|
|
subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31, 0), ho->id);
|
|
|
|
subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63, 0), ho->id);
|
|
|
|
CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, 0)));
|
2009-04-03 18:55:26 +03:00
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1, 32), ho->id);
|
|
|
|
subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31, 32), ho->id);
|
|
|
|
subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63, 32), ho->id);
|
|
|
|
CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, 32)));
|
2009-04-03 18:55:26 +03:00
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
std::stable_sort(CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.end(), ocmptwo_cgin);
|
2009-12-20 19:14:14 +02:00
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
std::stable_sort(CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.end(), ocmptwo_cgin);
|
2009-04-04 22:26:41 +03:00
|
|
|
}
|
2010-01-02 03:48:44 +02:00
|
|
|
else if(details.end.x-1 == details.start.x && details.end.y-1 == details.start.y) //br
|
2009-04-04 22:26:41 +03:00
|
|
|
{
|
2010-01-02 03:48:44 +02:00
|
|
|
//ho->moveDir = 5;
|
|
|
|
ho->isStanding = false;
|
|
|
|
subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1, -1), ho->id);
|
|
|
|
subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31, -1), ho->id);
|
|
|
|
subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63, -1), ho->id);
|
|
|
|
CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, -1)));
|
2009-04-14 15:47:09 +03:00
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1, 31), ho->id);
|
|
|
|
subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31, 31), ho->id);
|
|
|
|
subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63, 31), ho->id);
|
|
|
|
CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, 31)));
|
2009-04-14 15:47:09 +03:00
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
CGI->mh->ttiles[hp.x-2][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -1, 63)));
|
|
|
|
CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 31, 63)));
|
|
|
|
CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 63, 63)));
|
|
|
|
CGI->mh->ttiles[hp.x+1][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, 63)));
|
2009-06-16 14:18:14 +03:00
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
std::stable_sort(CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.end(), ocmptwo_cgin);
|
|
|
|
|
|
|
|
std::stable_sort(CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.end(), ocmptwo_cgin);
|
|
|
|
|
|
|
|
std::stable_sort(CGI->mh->ttiles[hp.x-2][hp.y+1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-2][hp.y+1][hp.z].objects.end(), ocmptwo_cgin);
|
|
|
|
std::stable_sort(CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.end(), ocmptwo_cgin);
|
|
|
|
std::stable_sort(CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.end(), ocmptwo_cgin);
|
|
|
|
std::stable_sort(CGI->mh->ttiles[hp.x+1][hp.y+1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x+1][hp.y+1][hp.z].objects.end(), ocmptwo_cgin);
|
|
|
|
}
|
|
|
|
else if(details.end.x == details.start.x && details.end.y-1 == details.start.y) //b
|
2009-07-30 15:49:45 +03:00
|
|
|
{
|
2010-01-02 03:48:44 +02:00
|
|
|
//ho->moveDir = 6;
|
|
|
|
ho->isStanding = false;
|
|
|
|
subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 0, -1), ho->id);
|
|
|
|
subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 32, -1), ho->id);
|
|
|
|
subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 64, -1), ho->id);
|
2009-08-22 16:59:15 +03:00
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 0, 31), ho->id);
|
|
|
|
subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 32, 31), ho->id);
|
|
|
|
subRect(hp.x, hp.y, hp.z, genRect(32, 32, 64, 31), ho->id);
|
2009-07-30 15:49:45 +03:00
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
CGI->mh->ttiles[hp.x-2][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 0, 63)));
|
|
|
|
CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 32, 63)));
|
|
|
|
CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 64, 63)));
|
2009-07-30 15:49:45 +03:00
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
std::stable_sort(CGI->mh->ttiles[hp.x-2][hp.y+1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-2][hp.y+1][hp.z].objects.end(), ocmptwo_cgin);
|
|
|
|
std::stable_sort(CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.end(), ocmptwo_cgin);
|
|
|
|
std::stable_sort(CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.end(), ocmptwo_cgin);
|
|
|
|
}
|
|
|
|
else if(details.end.x+1 == details.start.x && details.end.y-1 == details.start.y) //bl
|
|
|
|
{
|
|
|
|
//ho->moveDir = 7;
|
|
|
|
ho->isStanding = false;
|
|
|
|
CGI->mh->ttiles[hp.x-3][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, -1)));
|
|
|
|
subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1, -1), ho->id);
|
|
|
|
subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33, -1), ho->id);
|
|
|
|
subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65, -1), ho->id);
|
2009-06-11 20:21:06 +03:00
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
CGI->mh->ttiles[hp.x-3][hp.y][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, 31)));
|
|
|
|
subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1, 31), ho->id);
|
|
|
|
subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33, 31), ho->id);
|
|
|
|
subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65, 31), ho->id);
|
2009-07-06 22:41:27 +03:00
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
CGI->mh->ttiles[hp.x-3][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, 63)));
|
|
|
|
CGI->mh->ttiles[hp.x-2][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 1, 63)));
|
|
|
|
CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 33, 63)));
|
|
|
|
CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 65, 63)));
|
2009-07-18 06:13:13 +03:00
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
std::stable_sort(CGI->mh->ttiles[hp.x-3][hp.y-1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-3][hp.y-1][hp.z].objects.end(), ocmptwo_cgin);
|
2009-07-21 02:34:06 +03:00
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
std::stable_sort(CGI->mh->ttiles[hp.x-3][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-3][hp.y][hp.z].objects.end(), ocmptwo_cgin);
|
2009-07-26 06:33:13 +03:00
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
std::stable_sort(CGI->mh->ttiles[hp.x-3][hp.y+1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-3][hp.y+1][hp.z].objects.end(), ocmptwo_cgin);
|
|
|
|
std::stable_sort(CGI->mh->ttiles[hp.x-2][hp.y+1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-2][hp.y+1][hp.z].objects.end(), ocmptwo_cgin);
|
|
|
|
std::stable_sort(CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.end(), ocmptwo_cgin);
|
|
|
|
std::stable_sort(CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.end(), ocmptwo_cgin);
|
2009-07-26 06:33:13 +03:00
|
|
|
}
|
2010-01-02 03:48:44 +02:00
|
|
|
else if(details.end.x+1 == details.start.x && details.end.y == details.start.y) //l
|
2009-08-13 04:03:11 +03:00
|
|
|
{
|
2010-01-02 03:48:44 +02:00
|
|
|
//ho->moveDir = 8;
|
|
|
|
ho->isStanding = false;
|
|
|
|
CGI->mh->ttiles[hp.x-3][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, 0)));
|
|
|
|
subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1, 0), ho->id);
|
|
|
|
subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33, 0), ho->id);
|
|
|
|
subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65, 0), ho->id);
|
2009-08-13 04:03:11 +03:00
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
CGI->mh->ttiles[hp.x-3][hp.y][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, 32)));
|
|
|
|
subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1, 32), ho->id);
|
|
|
|
subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33, 32), ho->id);
|
|
|
|
subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65, 32), ho->id);
|
2009-08-13 04:03:11 +03:00
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
std::stable_sort(CGI->mh->ttiles[hp.x-3][hp.y-1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-3][hp.y-1][hp.z].objects.end(), ocmptwo_cgin);
|
|
|
|
|
|
|
|
std::stable_sort(CGI->mh->ttiles[hp.x-3][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-3][hp.y][hp.z].objects.end(), ocmptwo_cgin);
|
2009-08-13 04:03:11 +03:00
|
|
|
}
|
2009-08-11 10:50:29 +03:00
|
|
|
}
|
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
void CPlayerInterface::movementPxStep( const TryMoveHero &details, int i, const int3 &hp, const CGHeroInstance * ho )
|
2009-08-04 02:53:18 +03:00
|
|
|
{
|
2010-01-02 03:48:44 +02:00
|
|
|
if(details.end.x+1 == details.start.x && details.end.y+1 == details.start.y) //tl
|
2009-08-04 02:53:18 +03:00
|
|
|
{
|
2010-01-02 03:48:44 +02:00
|
|
|
//setting advmap shift
|
|
|
|
adventureInt->terrain.moveX = i-32;
|
|
|
|
adventureInt->terrain.moveY = i-32;
|
|
|
|
|
|
|
|
subRect(hp.x-3, hp.y-2, hp.z, genRect(32, 32, -31+i, -31+i), ho->id);
|
|
|
|
subRect(hp.x-2, hp.y-2, hp.z, genRect(32, 32, 1+i, -31+i), ho->id);
|
|
|
|
subRect(hp.x-1, hp.y-2, hp.z, genRect(32, 32, 33+i, -31+i), ho->id);
|
|
|
|
subRect(hp.x, hp.y-2, hp.z, genRect(32, 32, 65+i, -31+i), ho->id);
|
|
|
|
|
|
|
|
subRect(hp.x-3, hp.y-1, hp.z, genRect(32, 32, -31+i, 1+i), ho->id);
|
|
|
|
subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1+i, 1+i), ho->id);
|
|
|
|
subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33+i, 1+i), ho->id);
|
|
|
|
subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65+i, 1+i), ho->id);
|
|
|
|
|
|
|
|
subRect(hp.x-3, hp.y, hp.z, genRect(32, 32, -31+i, 33+i), ho->id);
|
|
|
|
subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1+i, 33+i), ho->id);
|
|
|
|
subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33+i, 33+i), ho->id);
|
|
|
|
subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65+i, 33+i), ho->id);
|
2009-08-04 02:53:18 +03:00
|
|
|
}
|
2010-01-02 03:48:44 +02:00
|
|
|
else if(details.end.x == details.start.x && details.end.y+1 == details.start.y) //t
|
|
|
|
{
|
|
|
|
//setting advmap shift
|
|
|
|
adventureInt->terrain.moveY = i-32;
|
2009-08-04 02:53:18 +03:00
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
subRect(hp.x-2, hp.y-2, hp.z, genRect(32, 32, 0, -31+i), ho->id);
|
|
|
|
subRect(hp.x-1, hp.y-2, hp.z, genRect(32, 32, 32, -31+i), ho->id);
|
|
|
|
subRect(hp.x, hp.y-2, hp.z, genRect(32, 32, 64, -31+i), ho->id);
|
2009-11-29 04:46:30 +02:00
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 0, 1+i), ho->id);
|
|
|
|
subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 32, 1+i), ho->id);
|
|
|
|
subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 64, 1+i), ho->id);
|
2009-12-28 06:08:24 +02:00
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 0, 33+i), ho->id);
|
|
|
|
subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 32, 33+i), ho->id);
|
|
|
|
subRect(hp.x, hp.y, hp.z, genRect(32, 32, 64, 33+i), ho->id);
|
|
|
|
}
|
|
|
|
else if(details.end.x-1 == details.start.x && details.end.y+1 == details.start.y) //tr
|
2009-12-28 06:08:24 +02:00
|
|
|
{
|
2010-01-02 03:48:44 +02:00
|
|
|
//setting advmap shift
|
|
|
|
adventureInt->terrain.moveX = -i+32;
|
|
|
|
adventureInt->terrain.moveY = i-32;
|
|
|
|
|
|
|
|
subRect(hp.x-2, hp.y-2, hp.z, genRect(32, 32, -1-i, -31+i), ho->id);
|
|
|
|
subRect(hp.x-1, hp.y-2, hp.z, genRect(32, 32, 31-i, -31+i), ho->id);
|
|
|
|
subRect(hp.x, hp.y-2, hp.z, genRect(32, 32, 63-i, -31+i), ho->id);
|
|
|
|
subRect(hp.x+1, hp.y-2, hp.z, genRect(32, 32, 95-i, -31+i), ho->id);
|
|
|
|
|
|
|
|
subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1-i, 1+i), ho->id);
|
|
|
|
subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31-i, 1+i), ho->id);
|
|
|
|
subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63-i, 1+i), ho->id);
|
|
|
|
subRect(hp.x+1, hp.y-1, hp.z, genRect(32, 32, 95-i, 1+i), ho->id);
|
|
|
|
|
|
|
|
subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1-i, 33+i), ho->id);
|
|
|
|
subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31-i, 33+i), ho->id);
|
|
|
|
subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63-i, 33+i), ho->id);
|
|
|
|
subRect(hp.x+1, hp.y, hp.z, genRect(32, 32, 95-i, 33+i), ho->id);
|
|
|
|
}
|
|
|
|
else if(details.end.x-1 == details.start.x && details.end.y == details.start.y) //r
|
|
|
|
{
|
|
|
|
//setting advmap shift
|
|
|
|
adventureInt->terrain.moveX = -i+32;
|
|
|
|
|
|
|
|
subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1-i, 0), ho->id);
|
|
|
|
subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31-i, 0), ho->id);
|
|
|
|
subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63-i, 0), ho->id);
|
|
|
|
subRect(hp.x+1, hp.y-1, hp.z, genRect(32, 32, 95-i, 0), ho->id);
|
|
|
|
|
|
|
|
subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1-i, 32), ho->id);
|
|
|
|
subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31-i, 32), ho->id);
|
|
|
|
subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63-i, 32), ho->id);
|
|
|
|
subRect(hp.x+1, hp.y, hp.z, genRect(32, 32, 95-i, 32), ho->id);
|
2009-12-28 06:08:24 +02:00
|
|
|
}
|
2010-01-02 03:48:44 +02:00
|
|
|
else if(details.end.x-1 == details.start.x && details.end.y-1 == details.start.y) //br
|
|
|
|
{
|
2009-12-28 06:08:24 +02:00
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
//setting advmap shift
|
|
|
|
adventureInt->terrain.moveX = -i+32;
|
|
|
|
adventureInt->terrain.moveY = -i+32;
|
2009-12-28 06:08:24 +02:00
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1-i, -1-i), ho->id);
|
|
|
|
subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31-i, -1-i), ho->id);
|
|
|
|
subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63-i, -1-i), ho->id);
|
|
|
|
subRect(hp.x+1, hp.y-1, hp.z, genRect(32, 32, 95-i, -1-i), ho->id);
|
2009-12-28 06:08:24 +02:00
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1-i, 31-i), ho->id);
|
|
|
|
subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31-i, 31-i), ho->id);
|
|
|
|
subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63-i, 31-i), ho->id);
|
|
|
|
subRect(hp.x+1, hp.y, hp.z, genRect(32, 32, 95-i, 31-i), ho->id);
|
2009-12-28 06:08:24 +02:00
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
subRect(hp.x-2, hp.y+1, hp.z, genRect(32, 32, -1-i, 63-i), ho->id);
|
|
|
|
subRect(hp.x-1, hp.y+1, hp.z, genRect(32, 32, 31-i, 63-i), ho->id);
|
|
|
|
subRect(hp.x, hp.y+1, hp.z, genRect(32, 32, 63-i, 63-i), ho->id);
|
|
|
|
subRect(hp.x+1, hp.y+1, hp.z, genRect(32, 32, 95-i, 63-i), ho->id);
|
|
|
|
}
|
|
|
|
else if(details.end.x == details.start.x && details.end.y-1 == details.start.y) //b
|
|
|
|
{
|
|
|
|
//setting advmap shift
|
|
|
|
adventureInt->terrain.moveY = -i+32;
|
2009-12-28 06:08:24 +02:00
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 0, -1-i), ho->id);
|
|
|
|
subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 32, -1-i), ho->id);
|
|
|
|
subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 64, -1-i), ho->id);
|
|
|
|
|
|
|
|
subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 0, 31-i), ho->id);
|
|
|
|
subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 32, 31-i), ho->id);
|
|
|
|
subRect(hp.x, hp.y, hp.z, genRect(32, 32, 64, 31-i), ho->id);
|
|
|
|
|
|
|
|
subRect(hp.x-2, hp.y+1, hp.z, genRect(32, 32, 0, 63-i), ho->id);
|
|
|
|
subRect(hp.x-1, hp.y+1, hp.z, genRect(32, 32, 32, 63-i), ho->id);
|
|
|
|
subRect(hp.x, hp.y+1, hp.z, genRect(32, 32, 64, 63-i), ho->id);
|
|
|
|
}
|
|
|
|
else if(details.end.x+1 == details.start.x && details.end.y-1 == details.start.y) //bl
|
|
|
|
{
|
|
|
|
//setting advmap shift
|
|
|
|
adventureInt->terrain.moveX = i-32;
|
|
|
|
adventureInt->terrain.moveY = -i+32;
|
|
|
|
|
|
|
|
subRect(hp.x-3, hp.y-1, hp.z, genRect(32, 32, -31+i, -1-i), ho->id);
|
|
|
|
subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1+i, -1-i), ho->id);
|
|
|
|
subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33+i, -1-i), ho->id);
|
|
|
|
subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65+i, -1-i), ho->id);
|
|
|
|
|
|
|
|
subRect(hp.x-3, hp.y, hp.z, genRect(32, 32, -31+i, 31-i), ho->id);
|
|
|
|
subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1+i, 31-i), ho->id);
|
|
|
|
subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33+i, 31-i), ho->id);
|
|
|
|
subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65+i, 31-i), ho->id);
|
|
|
|
|
|
|
|
subRect(hp.x-3, hp.y+1, hp.z, genRect(32, 32, -31+i, 63-i), ho->id);
|
|
|
|
subRect(hp.x-2, hp.y+1, hp.z, genRect(32, 32, 1+i, 63-i), ho->id);
|
|
|
|
subRect(hp.x-1, hp.y+1, hp.z, genRect(32, 32, 33+i, 63-i), ho->id);
|
|
|
|
subRect(hp.x, hp.y+1, hp.z, genRect(32, 32, 65+i, 63-i), ho->id);
|
|
|
|
}
|
|
|
|
else if(details.end.x+1 == details.start.x && details.end.y == details.start.y) //l
|
|
|
|
{
|
|
|
|
//setting advmap shift
|
|
|
|
adventureInt->terrain.moveX = i-32;
|
|
|
|
|
|
|
|
subRect(hp.x-3, hp.y-1, hp.z, genRect(32, 32, -31+i, 0), ho->id);
|
|
|
|
subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1+i, 0), ho->id);
|
|
|
|
subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33+i, 0), ho->id);
|
|
|
|
subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65+i, 0), ho->id);
|
|
|
|
|
|
|
|
subRect(hp.x-3, hp.y, hp.z, genRect(32, 32, -31+i, 32), ho->id);
|
|
|
|
subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1+i, 32), ho->id);
|
|
|
|
subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33+i, 32), ho->id);
|
|
|
|
subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65+i, 32), ho->id);
|
|
|
|
}
|
2009-12-28 06:08:24 +02:00
|
|
|
}
|
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
void CPlayerInterface::finishMovement( const TryMoveHero &details, const int3 &hp, const CGHeroInstance * ho )
|
2009-12-28 06:08:24 +02:00
|
|
|
{
|
2010-01-02 03:48:44 +02:00
|
|
|
adventureInt->terrain.moveX = adventureInt->terrain.moveY = 0;
|
2009-12-28 06:08:24 +02:00
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
if(details.end.x+1 == details.start.x && details.end.y+1 == details.start.y) //tl
|
2009-12-28 06:08:24 +02:00
|
|
|
{
|
2010-01-02 03:48:44 +02:00
|
|
|
delObjRect(hp.x, hp.y-2, hp.z, ho->id);
|
|
|
|
delObjRect(hp.x, hp.y-1, hp.z, ho->id);
|
|
|
|
delObjRect(hp.x, hp.y, hp.z, ho->id);
|
|
|
|
delObjRect(hp.x-1, hp.y, hp.z, ho->id);
|
|
|
|
delObjRect(hp.x-2, hp.y, hp.z, ho->id);
|
|
|
|
delObjRect(hp.x-3, hp.y, hp.z, ho->id);
|
|
|
|
}
|
|
|
|
else if(details.end.x == details.start.x && details.end.y+1 == details.start.y) //t
|
|
|
|
{
|
|
|
|
delObjRect(hp.x, hp.y, hp.z, ho->id);
|
|
|
|
delObjRect(hp.x-1, hp.y, hp.z, ho->id);
|
|
|
|
delObjRect(hp.x-2, hp.y, hp.z, ho->id);
|
|
|
|
}
|
|
|
|
else if(details.end.x-1 == details.start.x && details.end.y+1 == details.start.y) //tr
|
|
|
|
{
|
|
|
|
delObjRect(hp.x-2, hp.y-2, hp.z, ho->id);
|
|
|
|
delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
|
|
|
|
delObjRect(hp.x+1, hp.y, hp.z, ho->id);
|
|
|
|
delObjRect(hp.x, hp.y, hp.z, ho->id);
|
|
|
|
delObjRect(hp.x-1, hp.y, hp.z, ho->id);
|
|
|
|
delObjRect(hp.x-2, hp.y, hp.z, ho->id);
|
|
|
|
}
|
|
|
|
else if(details.end.x-1 == details.start.x && details.end.y == details.start.y) //r
|
|
|
|
{
|
|
|
|
delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
|
|
|
|
delObjRect(hp.x-2, hp.y, hp.z, ho->id);
|
|
|
|
}
|
|
|
|
else if(details.end.x-1 == details.start.x && details.end.y-1 == details.start.y) //br
|
|
|
|
{
|
|
|
|
delObjRect(hp.x-2, hp.y+1, hp.z, ho->id);
|
|
|
|
delObjRect(hp.x-2, hp.y, hp.z, ho->id);
|
|
|
|
delObjRect(hp.x+1, hp.y-1, hp.z, ho->id);
|
|
|
|
delObjRect(hp.x, hp.y-1, hp.z, ho->id);
|
|
|
|
delObjRect(hp.x-1, hp.y-1, hp.z, ho->id);
|
|
|
|
delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
|
|
|
|
}
|
|
|
|
else if(details.end.x == details.start.x && details.end.y-1 == details.start.y) //b
|
|
|
|
{
|
|
|
|
delObjRect(hp.x, hp.y-1, hp.z, ho->id);
|
|
|
|
delObjRect(hp.x-1, hp.y-1, hp.z, ho->id);
|
|
|
|
delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
|
|
|
|
}
|
|
|
|
else if(details.end.x+1 == details.start.x && details.end.y-1 == details.start.y) //bl
|
|
|
|
{
|
|
|
|
delObjRect(hp.x, hp.y-1, hp.z, ho->id);
|
|
|
|
delObjRect(hp.x-1, hp.y-1, hp.z, ho->id);
|
|
|
|
delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
|
|
|
|
delObjRect(hp.x-3, hp.y-1, hp.z, ho->id);
|
|
|
|
delObjRect(hp.x, hp.y, hp.z, ho->id);
|
|
|
|
delObjRect(hp.x, hp.y+1, hp.z, ho->id);
|
|
|
|
}
|
|
|
|
else if(details.end.x+1 == details.start.x && details.end.y == details.start.y) //l
|
|
|
|
{
|
|
|
|
delObjRect(hp.x, hp.y-1, hp.z, ho->id);
|
|
|
|
delObjRect(hp.x, hp.y, hp.z, ho->id);
|
2009-12-28 06:08:24 +02:00
|
|
|
}
|
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
//restoring good rects
|
|
|
|
subRect(details.end.x-2, details.end.y-1, details.end.z, genRect(32, 32, 0, 0), ho->id);
|
|
|
|
subRect(details.end.x-1, details.end.y-1, details.end.z, genRect(32, 32, 32, 0), ho->id);
|
|
|
|
subRect(details.end.x, details.end.y-1, details.end.z, genRect(32, 32, 64, 0), ho->id);
|
|
|
|
|
|
|
|
subRect(details.end.x-2, details.end.y, details.end.z, genRect(32, 32, 0, 32), ho->id);
|
|
|
|
subRect(details.end.x-1, details.end.y, details.end.z, genRect(32, 32, 32, 32), ho->id);
|
|
|
|
subRect(details.end.x, details.end.y, details.end.z, genRect(32, 32, 64, 32), ho->id);
|
|
|
|
|
|
|
|
//restoring good order of objects
|
|
|
|
std::stable_sort(CGI->mh->ttiles[details.end.x-2][details.end.y-1][details.end.z].objects.begin(), CGI->mh->ttiles[details.end.x-2][details.end.y-1][details.end.z].objects.end(), ocmptwo_cgin);
|
|
|
|
std::stable_sort(CGI->mh->ttiles[details.end.x-1][details.end.y-1][details.end.z].objects.begin(), CGI->mh->ttiles[details.end.x-1][details.end.y-1][details.end.z].objects.end(), ocmptwo_cgin);
|
|
|
|
std::stable_sort(CGI->mh->ttiles[details.end.x][details.end.y-1][details.end.z].objects.begin(), CGI->mh->ttiles[details.end.x][details.end.y-1][details.end.z].objects.end(), ocmptwo_cgin);
|
2009-12-28 06:08:24 +02:00
|
|
|
|
2010-01-02 03:48:44 +02:00
|
|
|
std::stable_sort(CGI->mh->ttiles[details.end.x-2][details.end.y][details.end.z].objects.begin(), CGI->mh->ttiles[details.end.x-2][details.end.y][details.end.z].objects.end(), ocmptwo_cgin);
|
|
|
|
std::stable_sort(CGI->mh->ttiles[details.end.x-1][details.end.y][details.end.z].objects.begin(), CGI->mh->ttiles[details.end.x-1][details.end.y][details.end.z].objects.end(), ocmptwo_cgin);
|
|
|
|
std::stable_sort(CGI->mh->ttiles[details.end.x][details.end.y][details.end.z].objects.begin(), CGI->mh->ttiles[details.end.x][details.end.y][details.end.z].objects.end(), ocmptwo_cgin);
|
|
|
|
}
|
2010-01-29 22:52:45 +02:00
|
|
|
|
|
|
|
void CPlayerInterface::gameOver(ui8 player, bool victory )
|
|
|
|
{
|
2010-02-22 15:30:46 +02:00
|
|
|
if(LOCPLINT != this)
|
|
|
|
return;
|
|
|
|
|
2010-01-29 22:52:45 +02:00
|
|
|
if(player == playerID)
|
|
|
|
{
|
|
|
|
if(!victory)
|
|
|
|
showInfoDialog(CGI->generaltexth->allTexts[95]);
|
|
|
|
// else
|
|
|
|
// showInfoDialog("Placeholder message: you won!");
|
|
|
|
|
2010-02-24 15:03:36 +02:00
|
|
|
makingTurn = true;
|
|
|
|
while(showingDialog->get() || dialogs.size()); //wait till all dialogs are displayed and closed
|
|
|
|
makingTurn = false;
|
2010-01-29 22:52:45 +02:00
|
|
|
|
2010-07-24 14:46:04 +03:00
|
|
|
howManyPeople--;
|
|
|
|
if(!howManyPeople) //all human players eliminated
|
|
|
|
{
|
2010-08-18 12:50:25 +03:00
|
|
|
if(cb->getStartInfo()->mode != StartInfo::CAMPAIGN)
|
|
|
|
requestReturningToMainMenu();
|
2010-08-20 16:34:39 +03:00
|
|
|
else
|
|
|
|
requestStoppingClient();
|
2010-07-24 14:46:04 +03:00
|
|
|
}
|
2010-08-18 12:50:25 +03:00
|
|
|
|
2010-01-29 22:52:45 +02:00
|
|
|
}
|
2010-02-01 19:07:46 +02:00
|
|
|
else
|
|
|
|
{
|
2010-09-03 21:42:54 +03:00
|
|
|
if(!victory && cb->getPlayerStatus(playerID) == PlayerState::INGAME) //enemy has lost
|
2010-02-01 19:07:46 +02:00
|
|
|
{
|
|
|
|
std::string txt = CGI->generaltexth->allTexts[5]; //%s has been vanquished!
|
|
|
|
boost::algorithm::replace_first(txt, "%s", CGI->generaltexth->capColors[player]);
|
2010-09-03 21:42:54 +03:00
|
|
|
showInfoDialog(txt,std::vector<SComponent*>(1, new SComponent(SComponent::flag, player, 0)));
|
2010-02-01 19:07:46 +02:00
|
|
|
}
|
|
|
|
}
|
2010-01-29 22:52:45 +02:00
|
|
|
}
|
|
|
|
|
2010-05-02 21:20:26 +03:00
|
|
|
void CPlayerInterface::playerBonusChanged( const Bonus &bonus, bool gain )
|
2010-02-10 04:56:00 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPlayerInterface::showPuzzleMap()
|
|
|
|
{
|
|
|
|
waitWhileDialog();
|
2010-03-01 20:22:22 +02:00
|
|
|
boost::unique_lock<boost::recursive_mutex> un(*pim);
|
2010-02-10 04:56:00 +02:00
|
|
|
|
|
|
|
//TODO: interface should not know the real position of Grail...
|
|
|
|
float ratio = 0;
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
if (spellID == Spells::FLY || spellID == Spells::WATER_WALK)
|
|
|
|
{
|
|
|
|
cb->recalculatePaths();
|
|
|
|
eraseCurrentPathOf(caster, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-18 06:13:13 +03:00
|
|
|
void SystemOptions::setMusicVolume( int newVolume )
|
|
|
|
{
|
|
|
|
musicVolume = newVolume;
|
2010-12-19 16:39:56 +02:00
|
|
|
CCS->musich->setVolume(newVolume);
|
2009-07-18 06:13:13 +03:00
|
|
|
settingsChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SystemOptions::setSoundVolume( int newVolume )
|
|
|
|
{
|
|
|
|
soundVolume = newVolume;
|
2010-12-19 16:39:56 +02:00
|
|
|
CCS->soundh->setVolume(newVolume);
|
2009-07-18 06:13:13 +03:00
|
|
|
settingsChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SystemOptions::setHeroMoveSpeed( int newSpeed )
|
|
|
|
{
|
|
|
|
heroMoveSpeed = newSpeed;
|
|
|
|
settingsChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SystemOptions::setMapScrollingSpeed( int newSpeed )
|
|
|
|
{
|
|
|
|
mapScrollingSpeed = newSpeed;
|
|
|
|
settingsChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SystemOptions::settingsChanged()
|
|
|
|
{
|
2009-10-10 08:47:59 +03:00
|
|
|
CSaveFile settings(GVCMIDirs.UserPath + "/config/sysopts.bin");
|
2009-07-18 06:13:13 +03:00
|
|
|
|
|
|
|
if(settings.sfile)
|
|
|
|
settings << *this;
|
|
|
|
else
|
2009-10-04 05:02:45 +03:00
|
|
|
tlog1 << "Cannot save settings to config/sysopts.bin!\n";
|
2009-07-18 06:13:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void SystemOptions::apply()
|
|
|
|
{
|
2010-12-19 16:39:56 +02:00
|
|
|
if(CCS->musich->getVolume() != musicVolume)
|
|
|
|
CCS->musich->setVolume(musicVolume);
|
|
|
|
if(CCS->soundh->getVolume() != soundVolume)
|
|
|
|
CCS->soundh->setVolume(soundVolume);
|
2009-09-24 16:23:52 +03:00
|
|
|
|
2009-07-18 06:13:13 +03:00
|
|
|
settingsChanged();
|
2009-08-06 08:08:17 +03:00
|
|
|
}
|
2009-09-24 16:23:52 +03:00
|
|
|
|
|
|
|
SystemOptions::SystemOptions()
|
|
|
|
{
|
|
|
|
heroMoveSpeed = 2;
|
|
|
|
mapScrollingSpeed = 2;
|
|
|
|
musicVolume = 88;
|
|
|
|
soundVolume = 88;
|
|
|
|
|
|
|
|
printCellBorders = true;
|
|
|
|
printStackRange = true;
|
|
|
|
animSpeed = 2;
|
|
|
|
printMouseShadow = true;
|
|
|
|
showQueue = true;
|
2010-10-24 14:35:14 +03:00
|
|
|
|
|
|
|
playerName = "Player";
|
|
|
|
}
|
|
|
|
|
|
|
|
void SystemOptions::setPlayerName(const std::string &newPlayerName)
|
|
|
|
{
|
|
|
|
playerName = newPlayerName;
|
|
|
|
settingsChanged();
|
2009-10-04 05:02:45 +03:00
|
|
|
}
|
2010-02-20 15:24:38 +02:00
|
|
|
|
2010-05-16 16:42:19 +03:00
|
|
|
void CPlayerInterface::eraseCurrentPathOf( const CGHeroInstance * ho, bool checkForExistanceOfPath /*= true */ )
|
2010-02-20 15:24:38 +02:00
|
|
|
{
|
2010-05-16 16:42:19 +03:00
|
|
|
if(checkForExistanceOfPath)
|
|
|
|
{
|
|
|
|
assert(vstd::contains(paths, ho));
|
|
|
|
}
|
|
|
|
else if (!vstd::contains(paths, ho))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2010-02-20 15:24:38 +02:00
|
|
|
assert(ho == adventureInt->selection);
|
|
|
|
|
|
|
|
paths.erase(ho);
|
|
|
|
adventureInt->terrain.currentPath = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
CGPath * CPlayerInterface::getAndVerifyPath(const CGHeroInstance * h)
|
|
|
|
{
|
|
|
|
if(vstd::contains(paths,h)) //hero has assigned path
|
|
|
|
{
|
|
|
|
CGPath &path = paths[h];
|
|
|
|
if(!path.nodes.size())
|
|
|
|
{
|
|
|
|
tlog3 << "Warning: empty path found...\n";
|
|
|
|
paths.erase(h);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
assert(h->getPosition(false) == path.startPos());
|
|
|
|
//update the hero path in case of something has changed on map
|
|
|
|
if(LOCPLINT->cb->getPath2(path.endPos(), path))
|
|
|
|
return &path;
|
|
|
|
else
|
|
|
|
paths.erase(h);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPlayerInterface::acceptTurn()
|
|
|
|
{
|
|
|
|
waitWhileDialog();
|
|
|
|
|
|
|
|
if(howManyPeople > 1)
|
|
|
|
adventureInt->startTurn();
|
|
|
|
|
|
|
|
boost::unique_lock<boost::recursive_mutex> un(*pim);
|
|
|
|
|
|
|
|
/* TODO: This isn't quite right. First day in game should play
|
|
|
|
* NEWDAY. And we don't play NEWMONTH. */
|
|
|
|
int day = cb->getDate(1);
|
|
|
|
if (day != 1)
|
2010-12-19 16:39:56 +02:00
|
|
|
CCS->soundh->playSound(soundBase::newDay);
|
2010-02-20 15:24:38 +02:00
|
|
|
else
|
2010-12-19 16:39:56 +02:00
|
|
|
CCS->soundh->playSound(soundBase::newWeek);
|
2010-02-20 15:24:38 +02:00
|
|
|
|
|
|
|
adventureInt->infoBar.newDay(day);
|
|
|
|
|
|
|
|
//select first hero if available.
|
|
|
|
//TODO: check if hero is slept
|
|
|
|
if(wanderingHeroes.size())
|
2010-02-26 13:18:09 +02:00
|
|
|
adventureInt->select(wanderingHeroes.front());
|
2010-02-20 15:24:38 +02:00
|
|
|
else
|
2010-02-26 13:18:09 +02:00
|
|
|
adventureInt->select(towns.front());
|
2010-02-20 15:24:38 +02:00
|
|
|
|
|
|
|
adventureInt->showAll(screen);
|
2010-02-24 15:03:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CPlayerInterface::tryDiggging(const CGHeroInstance *h)
|
|
|
|
{
|
|
|
|
std::string hlp;
|
|
|
|
if(h->movement < h->maxMovePoints(true))
|
|
|
|
showInfoDialog(CGI->generaltexth->allTexts[56]); //"Digging for artifacts requires a whole day, try again tomorrow."
|
|
|
|
else if(cb->getTileInfo(h->getPosition(false))->tertype == TerrainTile::water)
|
|
|
|
showInfoDialog(CGI->generaltexth->allTexts[60]); //Try looking on land!
|
|
|
|
else
|
|
|
|
{
|
2010-03-02 22:12:32 +02:00
|
|
|
const TerrainTile *t = cb->getTileInfo(h->getPosition());
|
2010-02-24 15:03:36 +02:00
|
|
|
CGI->mh->getTerrainDescr(h->getPosition(false), hlp, false);
|
2010-03-02 22:12:32 +02:00
|
|
|
if(hlp.length() || t->blockingObjects.size() > 1)
|
2010-02-24 15:03:36 +02:00
|
|
|
showInfoDialog(CGI->generaltexth->allTexts[97]); //Try searching on clear ground.
|
|
|
|
else
|
|
|
|
cb->dig(h);
|
|
|
|
}
|
2010-02-27 17:59:21 +02:00
|
|
|
}
|
2010-03-21 00:17:19 +02:00
|
|
|
|
|
|
|
void CPlayerInterface::updateInfo(const CGObjectInstance * specific)
|
|
|
|
{
|
|
|
|
adventureInt->infoBar.updateSelection(specific);
|
|
|
|
// if (adventureInt->selection == specific)
|
|
|
|
// adventureInt->infoBar.showAll(screen);
|
2010-05-07 15:29:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CPlayerInterface::battleNewRoundFirst( int round )
|
|
|
|
{
|
|
|
|
if(LOCPLINT != this)
|
|
|
|
{ //another local interface should do this
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
boost::unique_lock<boost::recursive_mutex> un(*pim);
|
|
|
|
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)
|
|
|
|
{
|
2010-07-20 09:05:45 +03:00
|
|
|
if(market->o->ID == 2) //Altar
|
|
|
|
{
|
|
|
|
EMarketMode mode = market->availableModes().front();
|
|
|
|
if(market->allowsTrade(ARTIFACT_EXP) && visitor->getAlignment() != EVIL)
|
|
|
|
GH.pushInt(new CAltarWindow(market, visitor, ARTIFACT_EXP));
|
|
|
|
else if(market->allowsTrade(CREATURE_EXP) && visitor->getAlignment() != GOOD)
|
|
|
|
GH.pushInt(new CAltarWindow(market, visitor, CREATURE_EXP));
|
|
|
|
}
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
CUniversityWindow *cuw = new CUniversityWindow(visitor, market);
|
|
|
|
GH.pushInt(cuw);
|
|
|
|
}
|
|
|
|
|
2010-07-22 03:32:45 +03:00
|
|
|
void CPlayerInterface::showHillFortWindow(const CGObjectInstance *object, const CGHeroInstance *visitor)
|
|
|
|
{
|
|
|
|
CHillFortWindow *chfw = new CHillFortWindow(visitor, object);
|
|
|
|
GH.pushInt(chfw);
|
|
|
|
}
|
|
|
|
|
2010-06-27 19:03:01 +03:00
|
|
|
void CPlayerInterface::availableArtifactsChanged(const CGBlackMarket *bm /*= NULL*/)
|
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
CTavernWindow *tv = new CTavernWindow(townOrTavern);
|
|
|
|
GH.pushInt(tv);
|
2010-07-13 08:25:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CPlayerInterface::showShipyardDialogOrProblemPopup(const IShipyard *obj)
|
|
|
|
{
|
|
|
|
if(obj->state())
|
|
|
|
{
|
|
|
|
MetaString txt;
|
|
|
|
obj->getProblemText(txt);
|
|
|
|
showInfoDialog(txt.toString());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
showShipyardDialog(obj);
|
2010-07-21 13:09:29 +03:00
|
|
|
}
|
|
|
|
|
2010-08-18 12:50:25 +03:00
|
|
|
void CPlayerInterface::requestReturningToMainMenu()
|
2010-08-20 16:34:39 +03:00
|
|
|
{
|
|
|
|
sendCustomEvent(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPlayerInterface::requestStoppingClient()
|
|
|
|
{
|
|
|
|
sendCustomEvent(3);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPlayerInterface::sendCustomEvent( int code )
|
2010-08-18 12:50:25 +03:00
|
|
|
{
|
|
|
|
SDL_Event event;
|
|
|
|
event.type = SDL_USEREVENT;
|
2010-08-20 16:34:39 +03:00
|
|
|
event.user.code = code;
|
2010-08-18 12:50:25 +03:00
|
|
|
SDL_PushEvent(&event);
|
|
|
|
}
|
|
|
|
|
2010-12-14 23:55:23 +02:00
|
|
|
void CPlayerInterface::stackChagedCount(const StackLocation &location, const TQuantity &change, bool isAbsolute)
|
|
|
|
{
|
|
|
|
garrisonChanged(location.army);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPlayerInterface::stackChangedType(const StackLocation &location, const CCreature &newType)
|
|
|
|
{
|
|
|
|
garrisonChanged(location.army);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPlayerInterface::stacksErased(const StackLocation &location)
|
|
|
|
{
|
|
|
|
garrisonChanged(location.army);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPlayerInterface::stacksSwapped(const StackLocation &loc1, const StackLocation &loc2)
|
|
|
|
{
|
|
|
|
garrisonChanged(loc1.army);
|
|
|
|
if(loc2.army != loc1.army)
|
|
|
|
garrisonChanged(loc2.army);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPlayerInterface::newStackInserted(const StackLocation &location, const CStackInstance &stack)
|
|
|
|
{
|
|
|
|
garrisonChanged(location.army);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPlayerInterface::stacksRebalanced(const StackLocation &src, const StackLocation &dst, TQuantity count)
|
|
|
|
{
|
|
|
|
garrisonChanged(src.army);
|
|
|
|
if(dst.army != src.army)
|
|
|
|
garrisonChanged(dst.army);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|