CPlayerInterface.cpp 64 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842
  1. #include "../stdafx.h"
  2. #include "CAdvmapInterface.h"
  3. #include "CBattleInterface.h"
  4. #include "../CCallback.h"
  5. #include "CCastleInterface.h"
  6. #include "CCursorHandler.h"
  7. #include "CGameInfo.h"
  8. #include "CHeroWindow.h"
  9. #include "CMessage.h"
  10. #include "CPlayerInterface.h"
  11. //#include "SDL_Extensions.h"
  12. #include "SDL_Extensions.h"
  13. //#include "SDL_framerate.h"
  14. #include "SDL_framerate.h"
  15. #include "CConfigHandler.h"
  16. #include "CCreatureAnimation.h"
  17. #include "Graphics.h"
  18. #include "../hch/CArtHandler.h"
  19. #include "../hch/CGeneralTextHandler.h"
  20. #include "../hch/CHeroHandler.h"
  21. #include "../hch/CLodHandler.h"
  22. #include "../hch/CObjectHandler.h"
  23. #include "../lib/Connection.h"
  24. #include "../hch/CSpellHandler.h"
  25. #include "../hch/CTownHandler.h"
  26. #include "../lib/CondSh.h"
  27. #include "../lib/NetPacks.h"
  28. #include "../lib/map.h"
  29. #include "../mapHandler.h"
  30. #include "../timeHandler.h"
  31. #include <boost/lexical_cast.hpp>
  32. #include <boost/algorithm/string.hpp>
  33. #include <boost/algorithm/string/replace.hpp>
  34. #include <boost/assign/std/vector.hpp>
  35. #include <boost/assign/list_of.hpp>
  36. #include <boost/date_time/posix_time/posix_time.hpp>
  37. #include <boost/thread.hpp>
  38. #include <cmath>
  39. #include <queue>
  40. #include <sstream>
  41. #ifdef min
  42. #undef min
  43. #endif
  44. #ifdef max
  45. #undef max
  46. #endif
  47. /*
  48. * CPlayerInterface.cpp, part of VCMI engine
  49. *
  50. * Authors: listed in file AUTHORS in main folder
  51. *
  52. * License: GNU General Public License v2.0 or later
  53. * Full text of license available in license.txt file, in main folder
  54. *
  55. */
  56. using namespace boost::assign;
  57. using namespace CSDL_Ext;
  58. void processCommand(const std::string &message, CClient *&client);
  59. extern std::queue<SDL_Event*> events;
  60. extern boost::mutex eventsM;
  61. CPlayerInterface * LOCPLINT;
  62. enum EMoveState {STOP_MOVE, WAITING_MOVE, CONTINUE_MOVE, DURING_MOVE};
  63. CondSh<EMoveState> stillMoveHero; //used during hero movement
  64. struct OCM_HLP_CGIN
  65. {
  66. bool inline operator ()(const std::pair<const CGObjectInstance*,SDL_Rect> & a, const std::pair<const CGObjectInstance*,SDL_Rect> & b) const
  67. {
  68. return (*a.first)<(*b.first);
  69. }
  70. } ocmptwo_cgin ;
  71. CPlayerInterface::CPlayerInterface(int Player, int serial)
  72. {
  73. LOCPLINT = this;
  74. curAction = NULL;
  75. playerID=Player;
  76. serialID=serial;
  77. human=true;
  78. castleInt = NULL;
  79. adventureInt = NULL;
  80. battleInt = NULL;
  81. pim = new boost::recursive_mutex;
  82. makingTurn = false;
  83. showingDialog = new CondSh<bool>(false);
  84. sysOpts = GDefaultOptions;
  85. //initializing framerate keeper
  86. mainFPSmng = new FPSmanager;
  87. SDL_initFramerate(mainFPSmng);
  88. SDL_setFramerate(mainFPSmng, 48);
  89. //framerate keeper initialized
  90. cingconsole = new CInGameConsole;
  91. }
  92. CPlayerInterface::~CPlayerInterface()
  93. {
  94. delete pim;
  95. delete showingDialog;
  96. delete mainFPSmng;
  97. delete adventureInt;
  98. delete cingconsole;
  99. for(std::map<int,SDL_Surface*>::iterator i=graphics->heroWins.begin(); i!= graphics->heroWins.end(); i++)
  100. SDL_FreeSurface(i->second);
  101. for(std::map<int,SDL_Surface*>::iterator i=graphics->townWins.begin(); i!= graphics->townWins.end(); i++)
  102. SDL_FreeSurface(i->second);
  103. }
  104. void CPlayerInterface::init(ICallback * CB)
  105. {
  106. cb = dynamic_cast<CCallback*>(CB);
  107. adventureInt = new CAdvMapInt(playerID);
  108. std::vector<const CGTownInstance*> tt = cb->getTownsInfo(false);
  109. for(int i=0;i<tt.size();i++)
  110. {
  111. SDL_Surface * pom = infoWin(tt[i]);
  112. graphics->townWins.insert(std::pair<int,SDL_Surface*>(tt[i]->id,pom));
  113. }
  114. recreateWanderingHeroes();
  115. }
  116. void CPlayerInterface::yourTurn()
  117. {
  118. try
  119. {
  120. LOCPLINT = this;
  121. makingTurn = true;
  122. static bool firstCall = true;
  123. static int autosaveCount = 0;
  124. if(firstCall)
  125. firstCall = false;
  126. else
  127. LOCPLINT->cb->save("Autosave_" + boost::lexical_cast<std::string>(autosaveCount++ + 1));
  128. autosaveCount %= 5;
  129. for(std::map<int,SDL_Surface*>::iterator i=graphics->heroWins.begin(); i!=graphics->heroWins.end();i++) //redraw hero infoboxes
  130. SDL_FreeSurface(i->second);
  131. graphics->heroWins.clear();
  132. std::vector <const CGHeroInstance *> hh = cb->getHeroesInfo(false);
  133. for(int i=0;i<hh.size();i++)
  134. {
  135. SDL_Surface * pom = infoWin(hh[i]);
  136. graphics->heroWins.insert(std::pair<int,SDL_Surface*>(hh[i]->subID,pom));
  137. }
  138. /* TODO: This isn't quite right. First day in game should play
  139. * NEWDAY. And we don't play NEWMONTH. */
  140. int day = cb->getDate(1);
  141. if (day != 1)
  142. CGI->soundh->playSound(soundBase::newDay);
  143. else
  144. CGI->soundh->playSound(soundBase::newWeek);
  145. adventureInt->infoBar.newDay(day);
  146. //select first hero if available.
  147. //TODO: check if hero is slept
  148. if(wanderingHeroes.size())
  149. adventureInt->select(wanderingHeroes[0]);
  150. else
  151. adventureInt->select(adventureInt->townList.items[0]);
  152. adventureInt->showAll(screen);
  153. pushInt(adventureInt);
  154. adventureInt->KeyInterested::activate();
  155. timeHandler th;
  156. th.getDif();
  157. while(makingTurn) // main loop
  158. {
  159. updateWater();
  160. pim->lock();
  161. //if there are any waiting dialogs, show them
  162. if(dialogs.size() && !showingDialog->get())
  163. {
  164. showingDialog->set(true);
  165. pushInt(dialogs.front());
  166. dialogs.pop_front();
  167. }
  168. int tv = th.getDif();
  169. std::list<TimeInterested*> hlp = timeinterested;
  170. for (std::list<TimeInterested*>::iterator i=hlp.begin(); i != hlp.end();i++)
  171. {
  172. if(!vstd::contains(timeinterested,*i)) continue;
  173. if ((*i)->toNextTick>=0)
  174. (*i)->toNextTick-=tv;
  175. if ((*i)->toNextTick<0)
  176. (*i)->tick();
  177. }
  178. while(true)
  179. {
  180. SDL_Event *ev = NULL;
  181. {
  182. boost::unique_lock<boost::mutex> lock(eventsM);
  183. if(!events.size())
  184. {
  185. break;
  186. }
  187. else
  188. {
  189. ev = events.front();
  190. events.pop();
  191. }
  192. }
  193. handleEvent(ev);
  194. delete ev;
  195. }
  196. if(!adventureInt->active && adventureInt->scrollingDir) //player force map scrolling though interface is disabled
  197. {
  198. totalRedraw();
  199. }
  200. else
  201. {
  202. //update only top interface and draw background
  203. if(objsToBlit.size() > 1)
  204. blitAt(screen2,0,0,screen); //blit background
  205. objsToBlit.back()->show(screen); //blit active interface/window
  206. }
  207. CGI->curh->draw1();
  208. CSDL_Ext::update(screen);
  209. CGI->curh->draw2();
  210. pim->unlock();
  211. SDL_framerateDelay(mainFPSmng);
  212. }
  213. adventureInt->KeyInterested::deactivate();
  214. popInt(adventureInt);
  215. cb->endTurn();
  216. } HANDLE_EXCEPTION
  217. }
  218. inline void subRect(const int & x, const int & y, const int & z, const SDL_Rect & r, const int & hid)
  219. {
  220. TerrainTile2 & hlp = CGI->mh->ttiles[x][y][z];
  221. for(int h=0; h<hlp.objects.size(); ++h)
  222. if(hlp.objects[h].first->id==hid)
  223. {
  224. hlp.objects[h].second = r;
  225. return;
  226. }
  227. }
  228. inline void delObjRect(const int & x, const int & y, const int & z, const int & hid)
  229. {
  230. TerrainTile2 & hlp = CGI->mh->ttiles[x][y][z];
  231. for(int h=0; h<hlp.objects.size(); ++h)
  232. if(hlp.objects[h].first->id==hid)
  233. {
  234. hlp.objects.erase(hlp.objects.begin()+h);
  235. return;
  236. }
  237. }
  238. void CPlayerInterface::heroMoved(const TryMoveHero & details)
  239. {
  240. boost::unique_lock<boost::recursive_mutex> un(*pim);
  241. const CGHeroInstance * ho = cb->getHeroInfo(details.id); //object representing this hero
  242. adventureInt->centerOn(ho->pos); //actualizing screen pos
  243. adventureInt->minimap.draw(screen2);
  244. adventureInt->heroList.draw(screen2);
  245. if(details.result == TryMoveHero::TELEPORTATION || details.start == details.end)
  246. return;
  247. int3 hp = details.start;
  248. if(makingTurn && ho->tempOwner == playerID) //we are moving our hero
  249. {
  250. if (details.result != TryMoveHero::SUCCESS && details.result != TryMoveHero::FAILED) //hero didn't change tile but visit succeeded
  251. {
  252. adventureInt->paths.erase(ho);
  253. adventureInt->terrain.currentPath = NULL;
  254. }
  255. else if(adventureInt->terrain.currentPath) //&& hero is moving
  256. {
  257. //remove one node from the path (the one we went)
  258. adventureInt->terrain.currentPath->nodes.erase(adventureInt->terrain.currentPath->nodes.end()-1);
  259. if(!adventureInt->terrain.currentPath->nodes.size()) //if it was the last one, remove entire path
  260. {
  261. adventureInt->paths.erase(ho);
  262. adventureInt->terrain.currentPath = NULL;
  263. }
  264. }
  265. }
  266. if (details.result != TryMoveHero::SUCCESS) //hero failed to move
  267. {
  268. ho->isStanding = true;
  269. stillMoveHero.setn(STOP_MOVE);
  270. LOCPLINT->totalRedraw();
  271. return;
  272. }
  273. //initializing objects and performing first step of move
  274. if(details.end.x+1 == details.start.x && details.end.y+1 == details.start.y) //tl
  275. {
  276. //ho->moveDir = 1;
  277. ho->isStanding = false;
  278. CGI->mh->ttiles[hp.x-3][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, -31)));
  279. CGI->mh->ttiles[hp.x-2][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 1, -31)));
  280. CGI->mh->ttiles[hp.x-1][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 33, -31)));
  281. CGI->mh->ttiles[hp.x][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 65, -31)));
  282. CGI->mh->ttiles[hp.x-3][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, 1)));
  283. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1, 1), ho->id);
  284. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33, 1), ho->id);
  285. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65, 1), ho->id);
  286. CGI->mh->ttiles[hp.x-3][hp.y][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, 33)));
  287. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1, 33), ho->id);
  288. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33, 33), ho->id);
  289. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65, 33), ho->id);
  290. 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);
  291. 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);
  292. 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);
  293. 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);
  294. 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);
  295. 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);
  296. }
  297. else if(details.end.x == details.start.x && details.end.y+1 == details.start.y) //t
  298. {
  299. //ho->moveDir = 2;
  300. ho->isStanding = false;
  301. CGI->mh->ttiles[hp.x-2][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 0, -31)));
  302. CGI->mh->ttiles[hp.x-1][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 32, -31)));
  303. CGI->mh->ttiles[hp.x][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 64, -31)));
  304. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 0, 1), ho->id);
  305. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 32, 1), ho->id);
  306. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 64, 1), ho->id);
  307. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 0, 33), ho->id);
  308. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 32, 33), ho->id);
  309. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 64, 33), ho->id);
  310. 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);
  311. 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);
  312. 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);
  313. }
  314. else if(details.end.x-1 == details.start.x && details.end.y+1 == details.start.y) //tr
  315. {
  316. //ho->moveDir = 3;
  317. ho->isStanding = false;
  318. CGI->mh->ttiles[hp.x-2][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -1, -31)));
  319. CGI->mh->ttiles[hp.x-1][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 31, -31)));
  320. CGI->mh->ttiles[hp.x][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 63, -31)));
  321. CGI->mh->ttiles[hp.x+1][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, -31)));
  322. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1, 1), ho->id);
  323. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31, 1), ho->id);
  324. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63, 1), ho->id);
  325. CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, 1)));
  326. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1, 33), ho->id);
  327. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31, 33), ho->id);
  328. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63, 33), ho->id);
  329. CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, 33)));
  330. 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);
  331. 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);
  332. 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);
  333. 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);
  334. 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);
  335. 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);
  336. }
  337. else if(details.end.x-1 == details.start.x && details.end.y == details.start.y) //r
  338. {
  339. //ho->moveDir = 4;
  340. ho->isStanding = false;
  341. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1, 0), ho->id);
  342. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31, 0), ho->id);
  343. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63, 0), ho->id);
  344. CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, 0)));
  345. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1, 32), ho->id);
  346. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31, 32), ho->id);
  347. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63, 32), ho->id);
  348. CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, 32)));
  349. 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);
  350. 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);
  351. }
  352. else if(details.end.x-1 == details.start.x && details.end.y-1 == details.start.y) //br
  353. {
  354. //ho->moveDir = 5;
  355. ho->isStanding = false;
  356. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1, -1), ho->id);
  357. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31, -1), ho->id);
  358. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63, -1), ho->id);
  359. CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, -1)));
  360. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1, 31), ho->id);
  361. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31, 31), ho->id);
  362. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63, 31), ho->id);
  363. CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, 31)));
  364. CGI->mh->ttiles[hp.x-2][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -1, 63)));
  365. CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 31, 63)));
  366. CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 63, 63)));
  367. CGI->mh->ttiles[hp.x+1][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, 63)));
  368. 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);
  369. 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);
  370. 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);
  371. 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);
  372. 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);
  373. 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);
  374. }
  375. else if(details.end.x == details.start.x && details.end.y-1 == details.start.y) //b
  376. {
  377. //ho->moveDir = 6;
  378. ho->isStanding = false;
  379. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 0, -1), ho->id);
  380. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 32, -1), ho->id);
  381. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 64, -1), ho->id);
  382. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 0, 31), ho->id);
  383. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 32, 31), ho->id);
  384. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 64, 31), ho->id);
  385. CGI->mh->ttiles[hp.x-2][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 0, 63)));
  386. CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 32, 63)));
  387. CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 64, 63)));
  388. 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);
  389. 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);
  390. 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);
  391. }
  392. else if(details.end.x+1 == details.start.x && details.end.y-1 == details.start.y) //bl
  393. {
  394. //ho->moveDir = 7;
  395. ho->isStanding = false;
  396. CGI->mh->ttiles[hp.x-3][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, -1)));
  397. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1, -1), ho->id);
  398. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33, -1), ho->id);
  399. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65, -1), ho->id);
  400. CGI->mh->ttiles[hp.x-3][hp.y][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, 31)));
  401. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1, 31), ho->id);
  402. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33, 31), ho->id);
  403. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65, 31), ho->id);
  404. CGI->mh->ttiles[hp.x-3][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, 63)));
  405. CGI->mh->ttiles[hp.x-2][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 1, 63)));
  406. CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 33, 63)));
  407. CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 65, 63)));
  408. 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);
  409. 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);
  410. 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);
  411. 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);
  412. 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);
  413. 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);
  414. }
  415. else if(details.end.x+1 == details.start.x && details.end.y == details.start.y) //l
  416. {
  417. //ho->moveDir = 8;
  418. ho->isStanding = false;
  419. CGI->mh->ttiles[hp.x-3][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, 0)));
  420. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1, 0), ho->id);
  421. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33, 0), ho->id);
  422. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65, 0), ho->id);
  423. CGI->mh->ttiles[hp.x-3][hp.y][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, 32)));
  424. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1, 32), ho->id);
  425. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33, 32), ho->id);
  426. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65, 32), ho->id);
  427. 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);
  428. 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);
  429. }
  430. //first initializing done
  431. SDL_framerateDelay(mainFPSmng); // after first move
  432. //main moving
  433. for(int i=1; i<32; i+=2*sysOpts.heroMoveSpeed)
  434. {
  435. if(details.end.x+1 == details.start.x && details.end.y+1 == details.start.y) //tl
  436. {
  437. //setting advmap shift
  438. adventureInt->terrain.moveX = i-32;
  439. adventureInt->terrain.moveY = i-32;
  440. subRect(hp.x-3, hp.y-2, hp.z, genRect(32, 32, -31+i, -31+i), ho->id);
  441. subRect(hp.x-2, hp.y-2, hp.z, genRect(32, 32, 1+i, -31+i), ho->id);
  442. subRect(hp.x-1, hp.y-2, hp.z, genRect(32, 32, 33+i, -31+i), ho->id);
  443. subRect(hp.x, hp.y-2, hp.z, genRect(32, 32, 65+i, -31+i), ho->id);
  444. subRect(hp.x-3, hp.y-1, hp.z, genRect(32, 32, -31+i, 1+i), ho->id);
  445. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1+i, 1+i), ho->id);
  446. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33+i, 1+i), ho->id);
  447. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65+i, 1+i), ho->id);
  448. subRect(hp.x-3, hp.y, hp.z, genRect(32, 32, -31+i, 33+i), ho->id);
  449. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1+i, 33+i), ho->id);
  450. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33+i, 33+i), ho->id);
  451. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65+i, 33+i), ho->id);
  452. }
  453. else if(details.end.x == details.start.x && details.end.y+1 == details.start.y) //t
  454. {
  455. //setting advmap shift
  456. adventureInt->terrain.moveY = i-32;
  457. subRect(hp.x-2, hp.y-2, hp.z, genRect(32, 32, 0, -31+i), ho->id);
  458. subRect(hp.x-1, hp.y-2, hp.z, genRect(32, 32, 32, -31+i), ho->id);
  459. subRect(hp.x, hp.y-2, hp.z, genRect(32, 32, 64, -31+i), ho->id);
  460. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 0, 1+i), ho->id);
  461. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 32, 1+i), ho->id);
  462. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 64, 1+i), ho->id);
  463. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 0, 33+i), ho->id);
  464. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 32, 33+i), ho->id);
  465. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 64, 33+i), ho->id);
  466. }
  467. else if(details.end.x-1 == details.start.x && details.end.y+1 == details.start.y) //tr
  468. {
  469. //setting advmap shift
  470. adventureInt->terrain.moveX = -i+32;
  471. adventureInt->terrain.moveY = i-32;
  472. subRect(hp.x-2, hp.y-2, hp.z, genRect(32, 32, -1-i, -31+i), ho->id);
  473. subRect(hp.x-1, hp.y-2, hp.z, genRect(32, 32, 31-i, -31+i), ho->id);
  474. subRect(hp.x, hp.y-2, hp.z, genRect(32, 32, 63-i, -31+i), ho->id);
  475. subRect(hp.x+1, hp.y-2, hp.z, genRect(32, 32, 95-i, -31+i), ho->id);
  476. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1-i, 1+i), ho->id);
  477. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31-i, 1+i), ho->id);
  478. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63-i, 1+i), ho->id);
  479. subRect(hp.x+1, hp.y-1, hp.z, genRect(32, 32, 95-i, 1+i), ho->id);
  480. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1-i, 33+i), ho->id);
  481. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31-i, 33+i), ho->id);
  482. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63-i, 33+i), ho->id);
  483. subRect(hp.x+1, hp.y, hp.z, genRect(32, 32, 95-i, 33+i), ho->id);
  484. }
  485. else if(details.end.x-1 == details.start.x && details.end.y == details.start.y) //r
  486. {
  487. //setting advmap shift
  488. adventureInt->terrain.moveX = -i+32;
  489. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1-i, 0), ho->id);
  490. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31-i, 0), ho->id);
  491. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63-i, 0), ho->id);
  492. subRect(hp.x+1, hp.y-1, hp.z, genRect(32, 32, 95-i, 0), ho->id);
  493. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1-i, 32), ho->id);
  494. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31-i, 32), ho->id);
  495. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63-i, 32), ho->id);
  496. subRect(hp.x+1, hp.y, hp.z, genRect(32, 32, 95-i, 32), ho->id);
  497. }
  498. else if(details.end.x-1 == details.start.x && details.end.y-1 == details.start.y) //br
  499. {
  500. //setting advmap shift
  501. adventureInt->terrain.moveX = -i+32;
  502. adventureInt->terrain.moveY = -i+32;
  503. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1-i, -1-i), ho->id);
  504. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31-i, -1-i), ho->id);
  505. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63-i, -1-i), ho->id);
  506. subRect(hp.x+1, hp.y-1, hp.z, genRect(32, 32, 95-i, -1-i), ho->id);
  507. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1-i, 31-i), ho->id);
  508. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31-i, 31-i), ho->id);
  509. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63-i, 31-i), ho->id);
  510. subRect(hp.x+1, hp.y, hp.z, genRect(32, 32, 95-i, 31-i), ho->id);
  511. subRect(hp.x-2, hp.y+1, hp.z, genRect(32, 32, -1-i, 63-i), ho->id);
  512. subRect(hp.x-1, hp.y+1, hp.z, genRect(32, 32, 31-i, 63-i), ho->id);
  513. subRect(hp.x, hp.y+1, hp.z, genRect(32, 32, 63-i, 63-i), ho->id);
  514. subRect(hp.x+1, hp.y+1, hp.z, genRect(32, 32, 95-i, 63-i), ho->id);
  515. }
  516. else if(details.end.x == details.start.x && details.end.y-1 == details.start.y) //b
  517. {
  518. //setting advmap shift
  519. adventureInt->terrain.moveY = -i+32;
  520. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 0, -1-i), ho->id);
  521. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 32, -1-i), ho->id);
  522. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 64, -1-i), ho->id);
  523. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 0, 31-i), ho->id);
  524. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 32, 31-i), ho->id);
  525. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 64, 31-i), ho->id);
  526. subRect(hp.x-2, hp.y+1, hp.z, genRect(32, 32, 0, 63-i), ho->id);
  527. subRect(hp.x-1, hp.y+1, hp.z, genRect(32, 32, 32, 63-i), ho->id);
  528. subRect(hp.x, hp.y+1, hp.z, genRect(32, 32, 64, 63-i), ho->id);
  529. }
  530. else if(details.end.x+1 == details.start.x && details.end.y-1 == details.start.y) //bl
  531. {
  532. //setting advmap shift
  533. adventureInt->terrain.moveX = i-32;
  534. adventureInt->terrain.moveY = -i+32;
  535. subRect(hp.x-3, hp.y-1, hp.z, genRect(32, 32, -31+i, -1-i), ho->id);
  536. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1+i, -1-i), ho->id);
  537. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33+i, -1-i), ho->id);
  538. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65+i, -1-i), ho->id);
  539. subRect(hp.x-3, hp.y, hp.z, genRect(32, 32, -31+i, 31-i), ho->id);
  540. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1+i, 31-i), ho->id);
  541. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33+i, 31-i), ho->id);
  542. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65+i, 31-i), ho->id);
  543. subRect(hp.x-3, hp.y+1, hp.z, genRect(32, 32, -31+i, 63-i), ho->id);
  544. subRect(hp.x-2, hp.y+1, hp.z, genRect(32, 32, 1+i, 63-i), ho->id);
  545. subRect(hp.x-1, hp.y+1, hp.z, genRect(32, 32, 33+i, 63-i), ho->id);
  546. subRect(hp.x, hp.y+1, hp.z, genRect(32, 32, 65+i, 63-i), ho->id);
  547. }
  548. else if(details.end.x+1 == details.start.x && details.end.y == details.start.y) //l
  549. {
  550. //setting advmap shift
  551. adventureInt->terrain.moveX = i-32;
  552. subRect(hp.x-3, hp.y-1, hp.z, genRect(32, 32, -31+i, 0), ho->id);
  553. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1+i, 0), ho->id);
  554. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33+i, 0), ho->id);
  555. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65+i, 0), ho->id);
  556. subRect(hp.x-3, hp.y, hp.z, genRect(32, 32, -31+i, 32), ho->id);
  557. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1+i, 32), ho->id);
  558. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33+i, 32), ho->id);
  559. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65+i, 32), ho->id);
  560. }
  561. adventureInt->updateScreen = true;
  562. adventureInt->show(screen);
  563. //LOCPLINT->adventureInt->show(); //updating screen
  564. CSDL_Ext::update(screen);
  565. SDL_Delay(5);
  566. SDL_framerateDelay(mainFPSmng); //for animation purposes
  567. } //for(int i=1; i<32; i+=4)
  568. //main moving done
  569. //finishing move
  570. //restoring adventureInt->terrain.move*
  571. adventureInt->terrain.moveX = adventureInt->terrain.moveY = 0;
  572. if(details.end.x+1 == details.start.x && details.end.y+1 == details.start.y) //tl
  573. {
  574. delObjRect(hp.x, hp.y-2, hp.z, ho->id);
  575. delObjRect(hp.x, hp.y-1, hp.z, ho->id);
  576. delObjRect(hp.x, hp.y, hp.z, ho->id);
  577. delObjRect(hp.x-1, hp.y, hp.z, ho->id);
  578. delObjRect(hp.x-2, hp.y, hp.z, ho->id);
  579. delObjRect(hp.x-3, hp.y, hp.z, ho->id);
  580. }
  581. else if(details.end.x == details.start.x && details.end.y+1 == details.start.y) //t
  582. {
  583. delObjRect(hp.x, hp.y, hp.z, ho->id);
  584. delObjRect(hp.x-1, hp.y, hp.z, ho->id);
  585. delObjRect(hp.x-2, hp.y, hp.z, ho->id);
  586. }
  587. else if(details.end.x-1 == details.start.x && details.end.y+1 == details.start.y) //tr
  588. {
  589. delObjRect(hp.x-2, hp.y-2, hp.z, ho->id);
  590. delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
  591. delObjRect(hp.x+1, hp.y, hp.z, ho->id);
  592. delObjRect(hp.x, hp.y, hp.z, ho->id);
  593. delObjRect(hp.x-1, hp.y, hp.z, ho->id);
  594. delObjRect(hp.x-2, hp.y, hp.z, ho->id);
  595. }
  596. else if(details.end.x-1 == details.start.x && details.end.y == details.start.y) //r
  597. {
  598. delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
  599. delObjRect(hp.x-2, hp.y, hp.z, ho->id);
  600. }
  601. else if(details.end.x-1 == details.start.x && details.end.y-1 == details.start.y) //br
  602. {
  603. delObjRect(hp.x-2, hp.y+1, hp.z, ho->id);
  604. delObjRect(hp.x-2, hp.y, hp.z, ho->id);
  605. delObjRect(hp.x+1, hp.y-1, hp.z, ho->id);
  606. delObjRect(hp.x, hp.y-1, hp.z, ho->id);
  607. delObjRect(hp.x-1, hp.y-1, hp.z, ho->id);
  608. delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
  609. }
  610. else if(details.end.x == details.start.x && details.end.y-1 == details.start.y) //b
  611. {
  612. delObjRect(hp.x, hp.y-1, hp.z, ho->id);
  613. delObjRect(hp.x-1, hp.y-1, hp.z, ho->id);
  614. delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
  615. }
  616. else if(details.end.x+1 == details.start.x && details.end.y-1 == details.start.y) //bl
  617. {
  618. delObjRect(hp.x, hp.y-1, hp.z, ho->id);
  619. delObjRect(hp.x-1, hp.y-1, hp.z, ho->id);
  620. delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
  621. delObjRect(hp.x-3, hp.y-1, hp.z, ho->id);
  622. delObjRect(hp.x, hp.y, hp.z, ho->id);
  623. delObjRect(hp.x, hp.y+1, hp.z, ho->id);
  624. }
  625. else if(details.end.x+1 == details.start.x && details.end.y == details.start.y) //l
  626. {
  627. delObjRect(hp.x, hp.y-1, hp.z, ho->id);
  628. delObjRect(hp.x, hp.y, hp.z, ho->id);
  629. }
  630. //restoring good rects
  631. subRect(details.end.x-2, details.end.y-1, details.end.z, genRect(32, 32, 0, 0), ho->id);
  632. subRect(details.end.x-1, details.end.y-1, details.end.z, genRect(32, 32, 32, 0), ho->id);
  633. subRect(details.end.x, details.end.y-1, details.end.z, genRect(32, 32, 64, 0), ho->id);
  634. subRect(details.end.x-2, details.end.y, details.end.z, genRect(32, 32, 0, 32), ho->id);
  635. subRect(details.end.x-1, details.end.y, details.end.z, genRect(32, 32, 32, 32), ho->id);
  636. subRect(details.end.x, details.end.y, details.end.z, genRect(32, 32, 64, 32), ho->id);
  637. //restoring good order of objects
  638. 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);
  639. 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);
  640. 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);
  641. 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);
  642. 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);
  643. 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);
  644. ho->isStanding = true;
  645. //move finished
  646. adventureInt->minimap.draw(screen2);
  647. adventureInt->heroList.updateMove(ho);
  648. //check if user cancelled movement
  649. {
  650. boost::unique_lock<boost::mutex> un(eventsM);
  651. while(events.size())
  652. {
  653. SDL_Event *ev = events.front();
  654. events.pop();
  655. switch(ev->type)
  656. {
  657. case SDL_MOUSEBUTTONDOWN:
  658. stillMoveHero.setn(STOP_MOVE);
  659. break;
  660. case SDL_KEYDOWN:
  661. if(ev->key.keysym.sym < SDLK_F1 || ev->key.keysym.sym > SDLK_F15)
  662. stillMoveHero.setn(STOP_MOVE);
  663. break;
  664. }
  665. delete ev;
  666. }
  667. }
  668. if(stillMoveHero.get() == 1)
  669. stillMoveHero.setn(DURING_MOVE);
  670. }
  671. void CPlayerInterface::heroKilled(const CGHeroInstance* hero)
  672. {
  673. boost::unique_lock<boost::recursive_mutex> un(*pim);
  674. graphics->heroWins.erase(hero->ID);
  675. wanderingHeroes -= hero;
  676. adventureInt->heroList.updateHList(hero);
  677. }
  678. void CPlayerInterface::heroCreated(const CGHeroInstance * hero)
  679. {
  680. boost::unique_lock<boost::recursive_mutex> un(*pim);
  681. if(graphics->heroWins.find(hero->subID)==graphics->heroWins.end())
  682. graphics->heroWins.insert(std::pair<int,SDL_Surface*>(hero->subID,infoWin(hero)));
  683. wanderingHeroes.push_back(hero);
  684. adventureInt->heroList.updateHList();
  685. }
  686. void CPlayerInterface::openTownWindow(const CGTownInstance * town)
  687. {
  688. castleInt = new CCastleInterface(town);
  689. LOCPLINT->pushInt(castleInt);
  690. }
  691. SDL_Surface * CPlayerInterface::infoWin(const CGObjectInstance * specific) //specific=0 => draws info about selected town/hero
  692. {
  693. if (specific)
  694. {
  695. switch (specific->ID)
  696. {
  697. case HEROI_TYPE:
  698. return graphics->drawHeroInfoWin(dynamic_cast<const CGHeroInstance*>(specific));
  699. break;
  700. case TOWNI_TYPE:
  701. return graphics->drawTownInfoWin(dynamic_cast<const CGTownInstance*>(specific));
  702. break;
  703. default:
  704. return NULL;
  705. break;
  706. }
  707. }
  708. else
  709. {
  710. switch (adventureInt->selection->ID)
  711. {
  712. case HEROI_TYPE:
  713. {
  714. const CGHeroInstance * curh = (const CGHeroInstance *)adventureInt->selection;
  715. return graphics->drawHeroInfoWin(curh);
  716. }
  717. case TOWNI_TYPE:
  718. {
  719. return graphics->drawTownInfoWin((const CGTownInstance *)adventureInt->selection);
  720. }
  721. default:
  722. tlog1 << "Strange... selection is neither hero nor town\n";
  723. return NULL;
  724. }
  725. }
  726. }
  727. void CPlayerInterface::handleMouseMotion(SDL_Event *sEvent)
  728. {
  729. //sending active, hovered hoverable objects hover() call
  730. std::vector<Hoverable*> hlp;
  731. for(std::list<Hoverable*>::iterator i=hoverable.begin(); i != hoverable.end();i++)
  732. {
  733. if (isItIn(&(*i)->pos,sEvent->motion.x,sEvent->motion.y))
  734. {
  735. if (!(*i)->hovered)
  736. hlp.push_back((*i));
  737. }
  738. else if ((*i)->hovered)
  739. {
  740. (*i)->hover(false);
  741. }
  742. }
  743. for(int i=0; i<hlp.size();i++)
  744. hlp[i]->hover(true);
  745. //sending active, MotionInterested objects mouseMoved() call
  746. std::list<MotionInterested*> miCopy = motioninterested;
  747. for(std::list<MotionInterested*>::iterator i=miCopy.begin(); i != miCopy.end();i++)
  748. {
  749. if ((*i)->strongInterest || isItIn(&(*i)->pos,sEvent->motion.x,sEvent->motion.y))
  750. {
  751. (*i)->mouseMoved(sEvent->motion);
  752. }
  753. }
  754. //adventure map scrolling with mouse
  755. if(!SDL_GetKeyState(NULL)[SDLK_LCTRL] && adventureInt->active)
  756. {
  757. if(sEvent->motion.x<15)
  758. {
  759. adventureInt->scrollingDir |= CAdvMapInt::LEFT;
  760. }
  761. else
  762. {
  763. adventureInt->scrollingDir &= ~CAdvMapInt::LEFT;
  764. }
  765. if(sEvent->motion.x>screen->w-15)
  766. {
  767. adventureInt->scrollingDir |= CAdvMapInt::RIGHT;
  768. }
  769. else
  770. {
  771. adventureInt->scrollingDir &= ~CAdvMapInt::RIGHT;
  772. }
  773. if(sEvent->motion.y<15)
  774. {
  775. adventureInt->scrollingDir |= CAdvMapInt::UP;
  776. }
  777. else
  778. {
  779. adventureInt->scrollingDir &= ~CAdvMapInt::UP;
  780. }
  781. if(sEvent->motion.y>screen->h-15)
  782. {
  783. adventureInt->scrollingDir |= CAdvMapInt::DOWN;
  784. }
  785. else
  786. {
  787. adventureInt->scrollingDir &= ~CAdvMapInt::DOWN;
  788. }
  789. }
  790. }
  791. void CPlayerInterface::handleEvent(SDL_Event *sEvent)
  792. {
  793. current = sEvent;
  794. if (sEvent->type==SDL_KEYDOWN || sEvent->type==SDL_KEYUP)
  795. {
  796. SDL_KeyboardEvent key = sEvent->key;
  797. //translate numpad keys
  798. if (key.keysym.sym >= SDLK_KP0 && key.keysym.sym <= SDLK_KP9)
  799. {
  800. key.keysym.sym = (SDLKey) (key.keysym.sym - SDLK_KP0 + SDLK_0);
  801. }
  802. else if(key.keysym.sym == SDLK_KP_ENTER)
  803. {
  804. key.keysym.sym = (SDLKey)SDLK_RETURN;
  805. }
  806. bool keysCaptured = false;
  807. for(std::list<KeyInterested*>::iterator i=keyinterested.begin(); i != keyinterested.end();i++)
  808. {
  809. if((*i)->captureAllKeys)
  810. {
  811. keysCaptured = true;
  812. break;
  813. }
  814. }
  815. std::list<KeyInterested*> miCopy = keyinterested;
  816. for(std::list<KeyInterested*>::iterator i=miCopy.begin(); i != miCopy.end();i++)
  817. if(vstd::contains(keyinterested,*i) && (!keysCaptured || (*i)->captureAllKeys))
  818. (**i).keyPressed(key);
  819. }
  820. else if(sEvent->type==SDL_MOUSEMOTION)
  821. {
  822. CGI->curh->cursorMove(sEvent->motion.x, sEvent->motion.y);
  823. handleMouseMotion(sEvent);
  824. }
  825. else if ((sEvent->type==SDL_MOUSEBUTTONDOWN) && (sEvent->button.button == SDL_BUTTON_LEFT))
  826. {
  827. std::list<ClickableL*> hlp = lclickable;
  828. for(std::list<ClickableL*>::iterator i=hlp.begin(); i != hlp.end();i++)
  829. {
  830. if(!vstd::contains(lclickable,*i)) continue;
  831. if (isItIn(&(*i)->pos,sEvent->motion.x,sEvent->motion.y))
  832. {
  833. (*i)->clickLeft(true);
  834. }
  835. }
  836. }
  837. else if ((sEvent->type==SDL_MOUSEBUTTONUP) && (sEvent->button.button == SDL_BUTTON_LEFT))
  838. {
  839. std::list<ClickableL*> hlp = lclickable;
  840. for(std::list<ClickableL*>::iterator i=hlp.begin(); i != hlp.end();i++)
  841. {
  842. if(!vstd::contains(lclickable,*i)) continue;
  843. if (isItIn(&(*i)->pos,sEvent->motion.x,sEvent->motion.y))
  844. {
  845. (*i)->clickLeft(false);
  846. }
  847. else
  848. (*i)->clickLeft(boost::logic::indeterminate);
  849. }
  850. }
  851. else if ((sEvent->type==SDL_MOUSEBUTTONDOWN) && (sEvent->button.button == SDL_BUTTON_RIGHT))
  852. {
  853. std::list<ClickableR*> hlp = rclickable;
  854. for(std::list<ClickableR*>::iterator i=hlp.begin(); i != hlp.end();i++)
  855. {
  856. if(!vstd::contains(rclickable,*i)) continue;
  857. if (isItIn(&(*i)->pos,sEvent->motion.x,sEvent->motion.y))
  858. {
  859. (*i)->clickRight(true);
  860. }
  861. }
  862. }
  863. else if ((sEvent->type==SDL_MOUSEBUTTONUP) && (sEvent->button.button == SDL_BUTTON_RIGHT))
  864. {
  865. std::list<ClickableR*> hlp = rclickable;
  866. for(std::list<ClickableR*>::iterator i=hlp.begin(); i != hlp.end();i++)
  867. {
  868. if(!vstd::contains(rclickable,*i)) continue;
  869. if (isItIn(&(*i)->pos,sEvent->motion.x,sEvent->motion.y))
  870. {
  871. (*i)->clickRight(false);
  872. }
  873. else
  874. (*i)->clickRight(boost::logic::indeterminate);
  875. }
  876. }
  877. current = NULL;
  878. } //event end
  879. int3 CPlayerInterface::repairScreenPos(int3 pos)
  880. {
  881. if(pos.x<-CGI->mh->frameW)
  882. pos.x = -CGI->mh->frameW;
  883. if(pos.y<-CGI->mh->frameH)
  884. pos.y = -CGI->mh->frameH;
  885. if(pos.x>CGI->mh->map->width - this->adventureInt->terrain.tilesw + CGI->mh->frameW)
  886. pos.x = CGI->mh->map->width - this->adventureInt->terrain.tilesw + CGI->mh->frameW;
  887. if(pos.y>CGI->mh->map->height - this->adventureInt->terrain.tilesh + CGI->mh->frameH)
  888. pos.y = CGI->mh->map->height - this->adventureInt->terrain.tilesh + CGI->mh->frameH;
  889. return pos;
  890. }
  891. void CPlayerInterface::heroPrimarySkillChanged(const CGHeroInstance * hero, int which, int val)
  892. {
  893. if(which >= PRIMARY_SKILLS) //no need to redraw infowin if this is experience (exp is treated as prim skill with id==4)
  894. return;
  895. boost::unique_lock<boost::recursive_mutex> un(*pim);
  896. redrawHeroWin(hero);
  897. }
  898. void CPlayerInterface::heroManaPointsChanged(const CGHeroInstance * hero)
  899. {
  900. boost::unique_lock<boost::recursive_mutex> un(*pim);
  901. redrawHeroWin(hero);
  902. }
  903. void CPlayerInterface::heroMovePointsChanged(const CGHeroInstance * hero)
  904. {
  905. boost::unique_lock<boost::recursive_mutex> un(*pim);
  906. //adventureInt->heroList.draw();
  907. }
  908. void CPlayerInterface::receivedResource(int type, int val)
  909. {
  910. boost::unique_lock<boost::recursive_mutex> un(*pim);
  911. LOCPLINT->totalRedraw();
  912. }
  913. void CPlayerInterface::heroGotLevel(const CGHeroInstance *hero, int pskill, std::vector<ui16>& skills, boost::function<void(ui32)> &callback)
  914. {
  915. waitWhileDialog();
  916. CGI->soundh->playSound(soundBase::heroNewLevel);
  917. boost::unique_lock<boost::recursive_mutex> un(*pim);
  918. CLevelWindow *lw = new CLevelWindow(hero,pskill,skills,callback);
  919. LOCPLINT->pushInt(lw);
  920. }
  921. void CPlayerInterface::heroInGarrisonChange(const CGTownInstance *town)
  922. {
  923. boost::unique_lock<boost::recursive_mutex> un(*pim);
  924. //redraw infowindow
  925. SDL_FreeSurface(graphics->townWins[town->id]);
  926. graphics->townWins[town->id] = infoWin(town);
  927. if(town->garrisonHero && vstd::contains(wanderingHeroes,town->garrisonHero)) //wandering hero moved to the garrison
  928. {
  929. CGI->mh->hideObject(town->garrisonHero);
  930. wanderingHeroes -= town->garrisonHero;
  931. }
  932. if(town->visitingHero && !vstd::contains(wanderingHeroes,town->visitingHero)) //hero leaves garrison
  933. {
  934. CGI->mh->printObject(town->visitingHero);
  935. wanderingHeroes.push_back(town->visitingHero);
  936. }
  937. //adventureInt->heroList.updateHList();
  938. CCastleInterface *c = castleInt;
  939. if(c)
  940. {
  941. c->garr->highlighted = NULL;
  942. c->hslotup.hero = town->garrisonHero;
  943. c->garr->odown = c->hslotdown.hero = town->visitingHero;
  944. c->garr->set2 = town->visitingHero ? &town->visitingHero->army : NULL;
  945. c->garr->recreateSlots();
  946. }
  947. LOCPLINT->totalRedraw();
  948. }
  949. void CPlayerInterface::heroVisitsTown(const CGHeroInstance* hero, const CGTownInstance * town)
  950. {
  951. if(hero->tempOwner != town->tempOwner)
  952. return;
  953. boost::unique_lock<boost::recursive_mutex> un(*pim);
  954. openTownWindow(town);
  955. }
  956. void CPlayerInterface::garrisonChanged(const CGObjectInstance * obj)
  957. {
  958. boost::unique_lock<boost::recursive_mutex> un(*pim);
  959. if(obj->ID == HEROI_TYPE) //hero
  960. {
  961. const CGHeroInstance * hh;
  962. if(hh = dynamic_cast<const CGHeroInstance*>(obj))
  963. {
  964. SDL_FreeSurface(graphics->heroWins[hh->subID]);
  965. graphics->heroWins[hh->subID] = infoWin(hh);
  966. }
  967. }
  968. else if (obj->ID == TOWNI_TYPE) //town
  969. {
  970. const CGTownInstance * tt;
  971. if(tt = static_cast<const CGTownInstance*>(obj))
  972. {
  973. SDL_FreeSurface(graphics->townWins[tt->id]);
  974. graphics->townWins[tt->id] = infoWin(tt);
  975. }
  976. if(tt->visitingHero)
  977. {
  978. SDL_FreeSurface(graphics->heroWins[tt->visitingHero->subID]);
  979. graphics->heroWins[tt->visitingHero->subID] = infoWin(tt->visitingHero);
  980. }
  981. }
  982. bool wasGarrison = false;
  983. for(std::list<IShowActivable*>::iterator i = listInt.begin(); i != listInt.end(); i++)
  984. {
  985. if((*i)->type & IShowActivable::WITH_GARRISON)
  986. {
  987. CWindowWithGarrison *wwg = static_cast<CWindowWithGarrison*>(*i);
  988. wwg->garr->recreateSlots();
  989. wasGarrison = true;
  990. }
  991. }
  992. LOCPLINT->totalRedraw();
  993. }
  994. void CPlayerInterface::buildChanged(const CGTownInstance *town, int buildingID, int what) //what: 1 - built, 2 - demolished
  995. {
  996. boost::unique_lock<boost::recursive_mutex> un(*pim);
  997. switch (buildingID)
  998. {
  999. case 7: case 8: case 9: case 10: case 11: case 12: case 13: case 15:
  1000. {
  1001. SDL_FreeSurface(graphics->townWins[town->id]);
  1002. graphics->townWins[town->id] = infoWin(town);
  1003. break;
  1004. }
  1005. }
  1006. if(!castleInt)
  1007. return;
  1008. if(castleInt->town!=town)
  1009. return;
  1010. switch(what)
  1011. {
  1012. case 1:
  1013. CGI->soundh->playSound(soundBase::newBuilding);
  1014. castleInt->addBuilding(buildingID);
  1015. break;
  1016. case 2:
  1017. castleInt->removeBuilding(buildingID);
  1018. break;
  1019. }
  1020. }
  1021. void CPlayerInterface::battleStart(CCreatureSet *army1, CCreatureSet *army2, int3 tile, CGHeroInstance *hero1, CGHeroInstance *hero2, bool side) //called by engine when battle starts; side=0 - left, side=1 - right
  1022. {
  1023. while(showingDialog->get())
  1024. SDL_Delay(20);
  1025. boost::unique_lock<boost::recursive_mutex> un(*pim);
  1026. battleInt = new CBattleInterface(army1, army2, hero1, hero2, genRect(600, 800, (conf.cc.resx - 800)/2, (conf.cc.resy - 600)/2));
  1027. CGI->musich->playMusicFromSet(CGI->musich->battleMusics, -1);
  1028. pushInt(battleInt);
  1029. }
  1030. void CPlayerInterface::battlefieldPrepared(int battlefieldType, std::vector<CObstacle*> obstacles) //called when battlefield is prepared, prior the battle beginning
  1031. {
  1032. }
  1033. 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
  1034. {
  1035. boost::unique_lock<boost::recursive_mutex> un(*pim);
  1036. battleInt->newRound(round);
  1037. }
  1038. void CPlayerInterface::actionStarted(const BattleAction* action)
  1039. {
  1040. boost::unique_lock<boost::recursive_mutex> un(*pim);
  1041. curAction = new BattleAction(*action);
  1042. if( (action->actionType==2 || (action->actionType==6 && action->destinationTile!=cb->battleGetPos(action->stackNumber))) )
  1043. {
  1044. battleInt->moveStarted = true;
  1045. if(battleInt->creAnims[action->stackNumber]->framesInGroup(20))
  1046. {
  1047. battleInt->creAnims[action->stackNumber]->setType(20);
  1048. }
  1049. }
  1050. battleInt->deactivate();
  1051. CStack *stack = cb->battleGetStackByID(action->stackNumber);
  1052. char txt[400];
  1053. if(action->actionType == 1)
  1054. {
  1055. if(action->side)
  1056. battleInt->defendingHero->setPhase(4);
  1057. else
  1058. battleInt->attackingHero->setPhase(4);
  1059. return;
  1060. }
  1061. if(!stack)
  1062. {
  1063. tlog1<<"Something wrong with stackNumber in actionStarted. Stack number: "<<action->stackNumber<<std::endl;
  1064. return;
  1065. }
  1066. int txtid = 0;
  1067. switch(action->actionType)
  1068. {
  1069. case 3: //defend
  1070. txtid = 120;
  1071. break;
  1072. case 8: //wait
  1073. txtid = 136;
  1074. break;
  1075. case 11: //bad morale
  1076. txtid = -34; //negative -> no separate singular/plural form
  1077. battleInt->displayEffect(30,stack->position);
  1078. break;
  1079. }
  1080. if(txtid > 0 && stack->amount != 1)
  1081. txtid++; //move to plural text
  1082. else if(txtid < 0)
  1083. txtid = -txtid;
  1084. if(txtid)
  1085. {
  1086. sprintf(txt, CGI->generaltexth->allTexts[txtid].c_str(), (stack->amount != 1) ? stack->creature->namePl.c_str() : stack->creature->nameSing.c_str(), 0);
  1087. LOCPLINT->battleInt->console->addText(txt);
  1088. }
  1089. }
  1090. void CPlayerInterface::actionFinished(const BattleAction* action)
  1091. {
  1092. boost::unique_lock<boost::recursive_mutex> un(*pim);
  1093. delete curAction;
  1094. curAction = NULL;
  1095. //if((action->actionType==2 || (action->actionType==6 && action->destinationTile!=cb->battleGetPos(action->stackNumber)))) //activating interface when move is finished
  1096. {
  1097. battleInt->activate();
  1098. }
  1099. if(action->actionType == 1)
  1100. {
  1101. if(action->side)
  1102. battleInt->defendingHero->setPhase(0);
  1103. else
  1104. battleInt->attackingHero->setPhase(0);
  1105. }
  1106. if(action->actionType == 6 || action->actionType == 2 && battleInt->creAnims[action->stackNumber]->getType() != 2) //walk or walk & attack
  1107. {
  1108. battleInt->handleEndOfMove(action->stackNumber, action->destinationTile);
  1109. }
  1110. }
  1111. BattleAction CPlayerInterface::activeStack(int stackID) //called when it's turn of that stack
  1112. {
  1113. CBattleInterface *b = battleInt;
  1114. {
  1115. boost::unique_lock<boost::recursive_mutex> un(*pim);
  1116. CStack *stack = cb->battleGetStackByID(stackID);
  1117. if(vstd::contains(stack->state,MOVED)) //this stack has moved and makes second action -> high morale
  1118. {
  1119. std::string hlp = CGI->generaltexth->allTexts[33];
  1120. boost::algorithm::replace_first(hlp,"%s",(stack->amount != 1) ? stack->creature->namePl : stack->creature->nameSing);
  1121. battleInt->displayEffect(20,stack->position);
  1122. battleInt->console->addText(hlp);
  1123. }
  1124. b->stackActivated(stackID);
  1125. }
  1126. //wait till BattleInterface sets its command
  1127. boost::unique_lock<boost::mutex> lock(b->givenCommand->mx);
  1128. while(!b->givenCommand->data)
  1129. b->givenCommand->cond.wait(lock);
  1130. //tidy up
  1131. BattleAction ret = *(b->givenCommand->data);
  1132. delete b->givenCommand->data;
  1133. b->givenCommand->data = NULL;
  1134. //return command
  1135. return ret;
  1136. }
  1137. void CPlayerInterface::battleEnd(BattleResult *br)
  1138. {
  1139. boost::unique_lock<boost::recursive_mutex> un(*pim);
  1140. battleInt->battleFinished(*br);
  1141. }
  1142. void CPlayerInterface::battleStackMoved(int ID, int dest, int distance, bool end)
  1143. {
  1144. boost::unique_lock<boost::recursive_mutex> un(*pim);
  1145. battleInt->stackMoved(ID, dest, end, distance);
  1146. }
  1147. void CPlayerInterface::battleSpellCast(SpellCast *sc)
  1148. {
  1149. boost::unique_lock<boost::recursive_mutex> un(*pim);
  1150. battleInt->spellCast(sc);
  1151. }
  1152. void CPlayerInterface::battleStacksEffectsSet(SetStackEffect & sse)
  1153. {
  1154. boost::unique_lock<boost::recursive_mutex> un(*pim);
  1155. battleInt->battleStacksEffectsSet(sse);
  1156. }
  1157. void CPlayerInterface::battleStacksAttacked(std::set<BattleStackAttacked> & bsa)
  1158. {
  1159. tlog5 << "CPlayerInterface::battleStackAttacked - locking...";
  1160. boost::unique_lock<boost::recursive_mutex> un(*pim);
  1161. tlog5 << "done!\n";
  1162. std::vector<CBattleInterface::SStackAttackedInfo> arg;
  1163. for(std::set<BattleStackAttacked>::iterator i = bsa.begin(); i != bsa.end(); i++)
  1164. {
  1165. if(i->isEffect() && i->effect != 12) //and not armageddon
  1166. {
  1167. battleInt->displayEffect(i->effect, cb->battleGetStackByID(i->stackAttacked)->position);
  1168. }
  1169. CBattleInterface::SStackAttackedInfo to_put = {i->stackAttacked, i->damageAmount, i->killedAmount, LOCPLINT->curAction->stackNumber, LOCPLINT->curAction->actionType==7, i->killed()};
  1170. arg.push_back(to_put);
  1171. }
  1172. if(bsa.begin()->isEffect() && bsa.begin()->effect == 12) //for armageddon - I hope this condition is enough
  1173. {
  1174. battleInt->displayEffect(bsa.begin()->effect, -1);
  1175. }
  1176. battleInt->stacksAreAttacked(arg);
  1177. }
  1178. void CPlayerInterface::battleAttack(BattleAttack *ba)
  1179. {
  1180. tlog5 << "CPlayerInterface::battleAttack - locking...";
  1181. boost::unique_lock<boost::recursive_mutex> un(*pim);
  1182. tlog5 << "done!\n";
  1183. assert(curAction);
  1184. if(ba->lucky()) //lucky hit
  1185. {
  1186. CStack *stack = cb->battleGetStackByID(ba->stackAttacking);
  1187. std::string hlp = CGI->generaltexth->allTexts[45];
  1188. boost::algorithm::replace_first(hlp,"%s",(stack->amount != 1) ? stack->creature->namePl.c_str() : stack->creature->nameSing.c_str());
  1189. battleInt->console->addText(hlp);
  1190. battleInt->displayEffect(18,stack->position);
  1191. }
  1192. //TODO: bad luck?
  1193. if(ba->shot())
  1194. {
  1195. for(std::set<BattleStackAttacked>::iterator i = ba->bsa.begin(); i != ba->bsa.end(); i++)
  1196. battleInt->stackIsShooting(ba->stackAttacking,cb->battleGetPos(i->stackAttacked));
  1197. }
  1198. else
  1199. {
  1200. CStack * attacker = cb->battleGetStackByID(ba->stackAttacking);
  1201. int shift = 0;
  1202. if(ba->counter() && BattleInfo::mutualPosition(curAction->destinationTile, attacker->position) < 0)
  1203. {
  1204. if(attacker->attackerOwned)
  1205. shift = 1;
  1206. else
  1207. shift = -1;
  1208. }
  1209. battleInt->stackAttacking( ba->stackAttacking, ba->counter() ? curAction->destinationTile + shift : curAction->additionalInfo );
  1210. }
  1211. }
  1212. void CPlayerInterface::showComp(SComponent comp)
  1213. {
  1214. boost::unique_lock<boost::recursive_mutex> un(*pim);
  1215. CGI->soundh->playSoundFromSet(CGI->soundh->pickupSounds);
  1216. adventureInt->infoBar.showComp(&comp,4000);
  1217. }
  1218. void CPlayerInterface::showInfoDialog(const std::string &text, const std::vector<Component*> &components, int soundID)
  1219. {
  1220. std::vector<SComponent*> intComps;
  1221. for(int i=0;i<components.size();i++)
  1222. intComps.push_back(new SComponent(*components[i]));
  1223. showInfoDialog(text,intComps,soundID);
  1224. }
  1225. void CPlayerInterface::showInfoDialog(const std::string &text, const std::vector<SComponent*> & components, int soundID)
  1226. {
  1227. waitWhileDialog();
  1228. boost::unique_lock<boost::recursive_mutex> un(*pim);
  1229. if(stillMoveHero.get() == DURING_MOVE)//if we are in the middle of hero movement
  1230. stillMoveHero.setn(STOP_MOVE); //after showing dialog movement will be stopped
  1231. std::vector<std::pair<std::string,CFunctionList<void()> > > pom;
  1232. pom.push_back(std::pair<std::string,CFunctionList<void()> >("IOKAY.DEF",0));
  1233. CInfoWindow * temp = new CInfoWindow(text,playerID,0,components,pom,false);
  1234. if(makingTurn && listInt.size())
  1235. {
  1236. CGI->soundh->playSound(static_cast<soundBase::soundID>(soundID));
  1237. showingDialog->set(true);
  1238. pushInt(temp);
  1239. }
  1240. else
  1241. {
  1242. dialogs.push_back(temp);
  1243. }
  1244. }
  1245. void CPlayerInterface::showYesNoDialog(const std::string &text, const std::vector<SComponent*> & components, CFunctionList<void()> onYes, CFunctionList<void()> onNo, bool DelComps)
  1246. {
  1247. boost::unique_lock<boost::recursive_mutex> un(*pim);
  1248. LOCPLINT->showingDialog->setn(true);
  1249. std::vector<std::pair<std::string,CFunctionList<void()> > > pom;
  1250. pom.push_back(std::pair<std::string,CFunctionList<void()> >("IOKAY.DEF",0));
  1251. pom.push_back(std::pair<std::string,CFunctionList<void()> >("ICANCEL.DEF",0));
  1252. CInfoWindow * temp = new CInfoWindow(text,playerID,0,components,pom,DelComps);
  1253. temp->delComps = DelComps;
  1254. for(int i=0;i<onYes.funcs.size();i++)
  1255. temp->buttons[0]->callback += onYes.funcs[i];
  1256. for(int i=0;i<onNo.funcs.size();i++)
  1257. temp->buttons[1]->callback += onNo.funcs[i];
  1258. LOCPLINT->pushInt(temp);
  1259. }
  1260. void CPlayerInterface::showBlockingDialog( const std::string &text, const std::vector<Component> &components, ui32 askID, int soundID, bool selection, bool cancel )
  1261. {
  1262. waitWhileDialog();
  1263. boost::unique_lock<boost::recursive_mutex> un(*pim);
  1264. CGI->soundh->playSound(static_cast<soundBase::soundID>(soundID));
  1265. if(!selection && cancel) //simple yes/no dialog
  1266. {
  1267. std::vector<SComponent*> intComps;
  1268. for(int i=0;i<components.size();i++)
  1269. intComps.push_back(new SComponent(components[i])); //will be deleted by close in window
  1270. showYesNoDialog(text,intComps,boost::bind(&CCallback::selectionMade,cb,1,askID),boost::bind(&CCallback::selectionMade,cb,0,askID),true);
  1271. }
  1272. else if(selection)
  1273. {
  1274. std::vector<CSelectableComponent*> intComps;
  1275. for(int i=0;i<components.size();i++)
  1276. intComps.push_back(new CSelectableComponent(components[i])); //will be deleted by CSelWindow::close
  1277. std::vector<std::pair<std::string,CFunctionList<void()> > > pom;
  1278. pom.push_back(std::pair<std::string,CFunctionList<void()> >("IOKAY.DEF",0));
  1279. if(cancel)
  1280. {
  1281. pom.push_back(std::pair<std::string,CFunctionList<void()> >("ICANCEL.DEF",0));
  1282. }
  1283. CSelWindow * temp = new CSelWindow(text,playerID,35,intComps,pom,askID);
  1284. pushInt(temp);
  1285. intComps[0]->clickLeft(true);
  1286. }
  1287. }
  1288. void CPlayerInterface::tileRevealed(const std::set<int3> &pos)
  1289. {
  1290. boost::unique_lock<boost::recursive_mutex> un(*pim);
  1291. for(std::set<int3>::const_iterator i=pos.begin(); i!=pos.end();i++)
  1292. adventureInt->minimap.showTile(*i);
  1293. }
  1294. void CPlayerInterface::tileHidden(const std::set<int3> &pos)
  1295. {
  1296. boost::unique_lock<boost::recursive_mutex> un(*pim);
  1297. for(std::set<int3>::const_iterator i=pos.begin(); i!=pos.end();i++)
  1298. adventureInt->minimap.hideTile(*i);
  1299. }
  1300. void CPlayerInterface::openHeroWindow(const CGHeroInstance *hero)
  1301. {
  1302. boost::unique_lock<boost::recursive_mutex> un(*pim);
  1303. adventureInt->heroWindow->setHero(hero);
  1304. adventureInt->heroWindow->quitButton->callback = boost::bind(&CHeroWindow::quit,adventureInt->heroWindow);
  1305. pushInt(adventureInt->heroWindow);
  1306. }
  1307. void CPlayerInterface::heroArtifactSetChanged(const CGHeroInstance*hero)
  1308. {
  1309. boost::unique_lock<boost::recursive_mutex> un(*pim);
  1310. if(adventureInt->heroWindow->curHero) //hero window is opened
  1311. {
  1312. adventureInt->heroWindow->deactivate();
  1313. adventureInt->heroWindow->setHero(adventureInt->heroWindow->curHero);
  1314. adventureInt->heroWindow->activate();
  1315. return;
  1316. }
  1317. CExchangeWindow* cew = dynamic_cast<CExchangeWindow*>(listInt.front());
  1318. if(cew) //exchange window is open
  1319. {
  1320. cew->deactivate();
  1321. for(int g=0; g<ARRAY_COUNT(cew->heroInst); ++g)
  1322. {
  1323. if(cew->heroInst[g] == hero)
  1324. {
  1325. cew->artifs[g]->setHero(hero);
  1326. }
  1327. }
  1328. cew->prepareBackground();
  1329. cew->activate();
  1330. }
  1331. }
  1332. void CPlayerInterface::updateWater()
  1333. {
  1334. }
  1335. void CPlayerInterface::availableCreaturesChanged( const CGDwelling *town )
  1336. {
  1337. boost::unique_lock<boost::recursive_mutex> un(*pim);
  1338. if(castleInt && town->ID == TOWNI_TYPE)
  1339. {
  1340. CFortScreen *fs = dynamic_cast<CFortScreen*>(listInt.front());
  1341. if(fs)
  1342. fs->draw(castleInt,false);
  1343. }
  1344. else if(listInt.size() && (town->ID == 17 || town->ID == 20)) //external dwelling
  1345. {
  1346. CRecruitmentWindow *crw = dynamic_cast<CRecruitmentWindow*>(listInt.front());
  1347. if(crw)
  1348. crw->initCres();
  1349. }
  1350. }
  1351. void CPlayerInterface::heroBonusChanged( const CGHeroInstance *hero, const HeroBonus &bonus, bool gain )
  1352. {
  1353. if(bonus.type == HeroBonus::NONE) return;
  1354. boost::unique_lock<boost::recursive_mutex> un(*pim);
  1355. redrawHeroWin(hero);
  1356. }
  1357. template <typename Handler> void CPlayerInterface::serializeTempl( Handler &h, const int version )
  1358. {
  1359. h & playerID & serialID;
  1360. h & sysOpts;
  1361. h & CBattleInterface::settings;
  1362. }
  1363. void CPlayerInterface::serialize( COSer<CSaveFile> &h, const int version )
  1364. {
  1365. serializeTempl(h,version);
  1366. }
  1367. void CPlayerInterface::serialize( CISer<CLoadFile> &h, const int version )
  1368. {
  1369. serializeTempl(h,version);
  1370. sysOpts.apply();
  1371. }
  1372. void CPlayerInterface::redrawHeroWin(const CGHeroInstance * hero)
  1373. {
  1374. if(!vstd::contains(graphics->heroWins,hero->subID))
  1375. {
  1376. tlog1 << "Cannot redraw infowindow for hero with subID=" << hero->subID << " - not present in our map\n";
  1377. return;
  1378. }
  1379. SDL_FreeSurface(graphics->heroWins[hero->subID]);
  1380. graphics->heroWins[hero->subID] = infoWin(hero);
  1381. if (adventureInt->selection == hero)
  1382. adventureInt->infoBar.draw(screen);
  1383. }
  1384. bool CPlayerInterface::moveHero( const CGHeroInstance *h, CPath path )
  1385. {
  1386. if (!h)
  1387. return false; //can't find hero
  1388. bool result = false;
  1389. path.convert(0);
  1390. boost::unique_lock<boost::mutex> un(stillMoveHero.mx);
  1391. stillMoveHero.data = CONTINUE_MOVE;
  1392. enum TerrainTile::EterrainType currentTerrain = TerrainTile::border; // not init yet
  1393. enum TerrainTile::EterrainType newTerrain;
  1394. int sh = -1;
  1395. for(int i=path.nodes.size()-1; i>0 && stillMoveHero.data == CONTINUE_MOVE; i--)
  1396. {
  1397. //stop sending move requests if hero exhausted all his move points
  1398. if(!h->movement)
  1399. {
  1400. stillMoveHero.data = STOP_MOVE;
  1401. break;
  1402. }
  1403. // Start a new sound for the hero movement or let the existing one carry on.
  1404. #if 0
  1405. // TODO
  1406. if (hero is flying && sh == -1)
  1407. sh = CGI->soundh->playSound(soundBase::horseFlying, -1);
  1408. }
  1409. else if (hero is in a boat && sh = -1) {
  1410. sh = CGI->soundh->playSound(soundBase::sound_todo, -1);
  1411. } else
  1412. #endif
  1413. {
  1414. newTerrain = cb->getTileInfo(CGHeroInstance::convertPosition(path.nodes[i].coord, false))->tertype;
  1415. if (newTerrain != currentTerrain) {
  1416. CGI->soundh->stopSound(sh);
  1417. sh = CGI->soundh->playSound(CGI->soundh->horseSounds[newTerrain], -1);
  1418. currentTerrain = newTerrain;
  1419. }
  1420. }
  1421. stillMoveHero.data = WAITING_MOVE;
  1422. int3 endpos(path.nodes[i-1].coord.x, path.nodes[i-1].coord.y, h->pos.z);
  1423. cb->moveHero(h,endpos);
  1424. while(stillMoveHero.data != STOP_MOVE && stillMoveHero.data != CONTINUE_MOVE)
  1425. stillMoveHero.cond.wait(un);
  1426. }
  1427. CGI->soundh->stopSound(sh);
  1428. //stillMoveHero = false;
  1429. return result;
  1430. }
  1431. bool CPlayerInterface::shiftPressed() const
  1432. {
  1433. return SDL_GetKeyState(NULL)[SDLK_LSHIFT] || SDL_GetKeyState(NULL)[SDLK_RSHIFT];
  1434. }
  1435. void CPlayerInterface::showGarrisonDialog( const CArmedInstance *up, const CGHeroInstance *down, boost::function<void()> &onEnd )
  1436. {
  1437. {
  1438. boost::unique_lock<boost::mutex> un(showingDialog->mx);
  1439. while(showingDialog->data)
  1440. showingDialog->cond.wait(un);
  1441. }
  1442. boost::unique_lock<boost::recursive_mutex> un(*pim);
  1443. while(dialogs.size())
  1444. {
  1445. pim->unlock();
  1446. SDL_Delay(20);
  1447. pim->lock();
  1448. }
  1449. CGarrisonWindow *cgw = new CGarrisonWindow(up,down);
  1450. cgw->quit->callback += onEnd;
  1451. pushInt(cgw);
  1452. }
  1453. void CPlayerInterface::popInt( IShowActivable *top )
  1454. {
  1455. assert(listInt.front() == top);
  1456. top->deactivate();
  1457. listInt.pop_front();
  1458. objsToBlit -= top;
  1459. if(listInt.size())
  1460. listInt.front()->activate();
  1461. totalRedraw();
  1462. }
  1463. void CPlayerInterface::popIntTotally( IShowActivable *top )
  1464. {
  1465. assert(listInt.front() == top);
  1466. popInt(top);
  1467. delete top;
  1468. }
  1469. void CPlayerInterface::pushInt( IShowActivable *newInt )
  1470. {
  1471. //a new interface will be present, we'll need to use buffer surface (unless it's advmapint that will alter screenBuf on activate anyway)
  1472. screenBuf = screen2;
  1473. if(listInt.size())
  1474. listInt.front()->deactivate();
  1475. listInt.push_front(newInt);
  1476. newInt->activate();
  1477. objsToBlit += newInt;
  1478. LOCPLINT->totalRedraw();
  1479. }
  1480. void CPlayerInterface::popInts( int howMany )
  1481. {
  1482. if(!howMany) return; //senseless but who knows...
  1483. assert(listInt.size() > howMany);
  1484. listInt.front()->deactivate();
  1485. for(int i=0; i < howMany; i++)
  1486. {
  1487. objsToBlit -= listInt.front();
  1488. delete listInt.front();
  1489. listInt.pop_front();
  1490. }
  1491. listInt.front()->activate();
  1492. totalRedraw();
  1493. }
  1494. IShowActivable * CPlayerInterface::topInt()
  1495. {
  1496. if(!listInt.size())
  1497. return NULL;
  1498. else
  1499. return listInt.front();
  1500. }
  1501. void CPlayerInterface::totalRedraw()
  1502. {
  1503. for(int i=0;i<objsToBlit.size();i++)
  1504. objsToBlit[i]->showAll(screen2);
  1505. blitAt(screen2,0,0,screen);
  1506. if(objsToBlit.size())
  1507. objsToBlit.back()->showAll(screen);
  1508. }
  1509. void CPlayerInterface::requestRealized( PackageApplied *pa )
  1510. {
  1511. if(stillMoveHero.get() == DURING_MOVE)
  1512. stillMoveHero.setn(CONTINUE_MOVE);
  1513. }
  1514. void CPlayerInterface::heroExchangeStarted(si32 hero1, si32 hero2)
  1515. {
  1516. pushInt(new CExchangeWindow(hero2, hero1));
  1517. }
  1518. void CPlayerInterface::objectPropertyChanged(const SetObjectProperty * sop)
  1519. {
  1520. //redraw minimap if owner changed
  1521. if(sop->what == 1)
  1522. {
  1523. const CGObjectInstance * obj = cb->getObjectInfo(sop->id);
  1524. std::set<int3> pos = obj->getBlockedPos();
  1525. for(std::set<int3>::const_iterator it = pos.begin(); it != pos.end(); ++it)
  1526. {
  1527. if(cb->isVisible(*it))
  1528. adventureInt->minimap.showTile(*it);
  1529. }
  1530. }
  1531. }
  1532. void CPlayerInterface::recreateWanderingHeroes()
  1533. {
  1534. wanderingHeroes.clear();
  1535. std::vector<const CGHeroInstance*> heroes = cb->getHeroesInfo();
  1536. for(size_t i = 0; i < heroes.size(); i++)
  1537. if(!heroes[i]->inTownGarrison)
  1538. wanderingHeroes.push_back(heroes[i]);
  1539. }
  1540. const CGHeroInstance * CPlayerInterface::getWHero( int pos )
  1541. {
  1542. if(pos < 0 || pos >= wanderingHeroes.size())
  1543. return NULL;
  1544. return wanderingHeroes[pos];
  1545. }
  1546. void CPlayerInterface::showRecruitmentDialog(const CGDwelling *dwelling, const CArmedInstance *dst, int level)
  1547. {
  1548. waitWhileDialog();
  1549. boost::unique_lock<boost::recursive_mutex> un(*pim);
  1550. CRecruitmentWindow *cr = new CRecruitmentWindow(dwelling, level, dst, boost::bind(&CCallback::recruitCreatures, cb, dwelling, _1, _2));
  1551. pushInt(cr);
  1552. }
  1553. void CPlayerInterface::waitWhileDialog()
  1554. {
  1555. boost::unique_lock<boost::mutex> un(showingDialog->mx);
  1556. while(showingDialog->data)
  1557. showingDialog->cond.wait(un);
  1558. }
  1559. void CPlayerInterface::showShipyardDialog(const IShipyard *obj)
  1560. {
  1561. boost::unique_lock<boost::recursive_mutex> un(*pim);
  1562. int state = obj->state();
  1563. std::vector<si32> cost;
  1564. obj->getBoatCost(cost);
  1565. CShipyardWindow *csw = new CShipyardWindow(cost, state, boost::bind(&CCallback::buildBoat, cb, obj));
  1566. pushInt(csw);
  1567. }
  1568. void CPlayerInterface::newObject( const CGObjectInstance * obj )
  1569. {
  1570. boost::unique_lock<boost::recursive_mutex> un(*pim);
  1571. CGI->mh->printObject(obj);
  1572. //we might have built a boat in shipyard in opened town screen
  1573. if(obj->ID == 8
  1574. && LOCPLINT->castleInt
  1575. && obj->pos-obj->getVisitableOffset() == LOCPLINT->castleInt->town->bestLocation())
  1576. {
  1577. CGI->soundh->playSound(soundBase::newBuilding);
  1578. LOCPLINT->castleInt->recreateBuildings();
  1579. }
  1580. }
  1581. void CPlayerInterface::objectRemoved( const CGObjectInstance *obj )
  1582. {
  1583. if(obj->ID == HEROI_TYPE && obj->tempOwner == playerID)
  1584. {
  1585. const CGHeroInstance *h = static_cast<const CGHeroInstance*>(obj);
  1586. heroKilled(h);
  1587. }
  1588. }
  1589. void SystemOptions::setMusicVolume( int newVolume )
  1590. {
  1591. musicVolume = newVolume;
  1592. CGI->musich->setVolume(newVolume);
  1593. settingsChanged();
  1594. }
  1595. void SystemOptions::setSoundVolume( int newVolume )
  1596. {
  1597. soundVolume = newVolume;
  1598. CGI->soundh->setVolume(newVolume);
  1599. settingsChanged();
  1600. }
  1601. void SystemOptions::setHeroMoveSpeed( int newSpeed )
  1602. {
  1603. heroMoveSpeed = newSpeed;
  1604. settingsChanged();
  1605. }
  1606. void SystemOptions::setMapScrollingSpeed( int newSpeed )
  1607. {
  1608. mapScrollingSpeed = newSpeed;
  1609. settingsChanged();
  1610. }
  1611. void SystemOptions::settingsChanged()
  1612. {
  1613. CSaveFile settings("config" PATHSEPARATOR "sysopts.bin");
  1614. if(settings.sfile)
  1615. settings << *this;
  1616. else
  1617. tlog1 << "Cannot save settings to config" PATHSEPARATOR "sysopts.bin!\n";
  1618. }
  1619. void SystemOptions::apply()
  1620. {
  1621. CGI->musich->setVolume(musicVolume);
  1622. CGI->soundh->setVolume(soundVolume);
  1623. settingsChanged();
  1624. }