CPlayerInterface.cpp 64 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829
  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. }
  1107. BattleAction CPlayerInterface::activeStack(int stackID) //called when it's turn of that stack
  1108. {
  1109. CBattleInterface *b = battleInt;
  1110. {
  1111. boost::unique_lock<boost::recursive_mutex> un(*pim);
  1112. CStack *stack = cb->battleGetStackByID(stackID);
  1113. if(vstd::contains(stack->state,MOVED)) //this stack has moved and makes second action -> high morale
  1114. {
  1115. std::string hlp = CGI->generaltexth->allTexts[33];
  1116. boost::algorithm::replace_first(hlp,"%s",(stack->amount != 1) ? stack->creature->namePl : stack->creature->nameSing);
  1117. battleInt->displayEffect(20,stack->position);
  1118. battleInt->console->addText(hlp);
  1119. }
  1120. b->stackActivated(stackID);
  1121. }
  1122. //wait till BattleInterface sets its command
  1123. boost::unique_lock<boost::mutex> lock(b->givenCommand->mx);
  1124. while(!b->givenCommand->data)
  1125. b->givenCommand->cond.wait(lock);
  1126. //tidy up
  1127. BattleAction ret = *(b->givenCommand->data);
  1128. delete b->givenCommand->data;
  1129. b->givenCommand->data = NULL;
  1130. //return command
  1131. return ret;
  1132. }
  1133. void CPlayerInterface::battleEnd(BattleResult *br)
  1134. {
  1135. boost::unique_lock<boost::recursive_mutex> un(*pim);
  1136. battleInt->battleFinished(*br);
  1137. }
  1138. void CPlayerInterface::battleStackMoved(int ID, int dest, int distance, bool end)
  1139. {
  1140. boost::unique_lock<boost::recursive_mutex> un(*pim);
  1141. battleInt->stackMoved(ID, dest, end, distance);
  1142. }
  1143. void CPlayerInterface::battleSpellCast(SpellCast *sc)
  1144. {
  1145. boost::unique_lock<boost::recursive_mutex> un(*pim);
  1146. battleInt->spellCast(sc);
  1147. }
  1148. void CPlayerInterface::battleStacksEffectsSet(SetStackEffect & sse)
  1149. {
  1150. boost::unique_lock<boost::recursive_mutex> un(*pim);
  1151. battleInt->battleStacksEffectsSet(sse);
  1152. }
  1153. void CPlayerInterface::battleStacksAttacked(std::set<BattleStackAttacked> & bsa)
  1154. {
  1155. tlog5 << "CPlayerInterface::battleStackAttacked - locking...";
  1156. boost::unique_lock<boost::recursive_mutex> un(*pim);
  1157. tlog5 << "done!\n";
  1158. std::vector<CBattleInterface::SStackAttackedInfo> arg;
  1159. for(std::set<BattleStackAttacked>::iterator i = bsa.begin(); i != bsa.end(); i++)
  1160. {
  1161. if(i->isEffect() && i->effect != 12) //and not armageddon
  1162. {
  1163. battleInt->displayEffect(i->effect, cb->battleGetStackByID(i->stackAttacked)->position);
  1164. }
  1165. CBattleInterface::SStackAttackedInfo to_put = {i->stackAttacked, i->damageAmount, i->killedAmount, LOCPLINT->curAction->stackNumber, LOCPLINT->curAction->actionType==7, i->killed()};
  1166. arg.push_back(to_put);
  1167. }
  1168. if(bsa.begin()->isEffect() && bsa.begin()->effect == 12) //for armageddon - I hope this condition is enough
  1169. {
  1170. battleInt->displayEffect(bsa.begin()->effect, -1);
  1171. }
  1172. battleInt->stacksAreAttacked(arg);
  1173. }
  1174. void CPlayerInterface::battleAttack(BattleAttack *ba)
  1175. {
  1176. tlog5 << "CPlayerInterface::battleAttack - locking...";
  1177. boost::unique_lock<boost::recursive_mutex> un(*pim);
  1178. tlog5 << "done!\n";
  1179. assert(curAction);
  1180. if(ba->lucky()) //lucky hit
  1181. {
  1182. CStack *stack = cb->battleGetStackByID(ba->stackAttacking);
  1183. std::string hlp = CGI->generaltexth->allTexts[45];
  1184. boost::algorithm::replace_first(hlp,"%s",(stack->amount != 1) ? stack->creature->namePl.c_str() : stack->creature->nameSing.c_str());
  1185. battleInt->console->addText(hlp);
  1186. battleInt->displayEffect(18,stack->position);
  1187. }
  1188. //TODO: bad luck?
  1189. if(ba->shot())
  1190. {
  1191. for(std::set<BattleStackAttacked>::iterator i = ba->bsa.begin(); i != ba->bsa.end(); i++)
  1192. battleInt->stackIsShooting(ba->stackAttacking,cb->battleGetPos(i->stackAttacked));
  1193. }
  1194. else
  1195. {
  1196. CStack * attacker = cb->battleGetStackByID(ba->stackAttacking);
  1197. int shift = 0;
  1198. if(ba->counter() && BattleInfo::mutualPosition(curAction->destinationTile, attacker->position) < 0)
  1199. {
  1200. if(attacker->attackerOwned)
  1201. shift = 1;
  1202. else
  1203. shift = -1;
  1204. }
  1205. battleInt->stackAttacking( ba->stackAttacking, ba->counter() ? curAction->destinationTile + shift : curAction->additionalInfo );
  1206. }
  1207. }
  1208. void CPlayerInterface::showComp(SComponent comp)
  1209. {
  1210. boost::unique_lock<boost::recursive_mutex> un(*pim);
  1211. CGI->soundh->playSoundFromSet(CGI->soundh->pickupSounds);
  1212. adventureInt->infoBar.showComp(&comp,4000);
  1213. }
  1214. void CPlayerInterface::showInfoDialog(const std::string &text, const std::vector<Component*> &components, int soundID)
  1215. {
  1216. std::vector<SComponent*> intComps;
  1217. for(int i=0;i<components.size();i++)
  1218. intComps.push_back(new SComponent(*components[i]));
  1219. showInfoDialog(text,intComps,soundID);
  1220. }
  1221. void CPlayerInterface::showInfoDialog(const std::string &text, const std::vector<SComponent*> & components, int soundID)
  1222. {
  1223. waitWhileDialog();
  1224. boost::unique_lock<boost::recursive_mutex> un(*pim);
  1225. if(stillMoveHero.get() == DURING_MOVE)//if we are in the middle of hero movement
  1226. stillMoveHero.setn(STOP_MOVE); //after showing dialog movement will be stopped
  1227. std::vector<std::pair<std::string,CFunctionList<void()> > > pom;
  1228. pom.push_back(std::pair<std::string,CFunctionList<void()> >("IOKAY.DEF",0));
  1229. CInfoWindow * temp = new CInfoWindow(text,playerID,0,components,pom,false);
  1230. if(makingTurn && listInt.size())
  1231. {
  1232. CGI->soundh->playSound(static_cast<soundBase::soundID>(soundID));
  1233. showingDialog->set(true);
  1234. pushInt(temp);
  1235. }
  1236. else
  1237. {
  1238. dialogs.push_back(temp);
  1239. }
  1240. }
  1241. void CPlayerInterface::showYesNoDialog(const std::string &text, const std::vector<SComponent*> & components, CFunctionList<void()> onYes, CFunctionList<void()> onNo, bool DelComps)
  1242. {
  1243. boost::unique_lock<boost::recursive_mutex> un(*pim);
  1244. LOCPLINT->showingDialog->setn(true);
  1245. std::vector<std::pair<std::string,CFunctionList<void()> > > pom;
  1246. pom.push_back(std::pair<std::string,CFunctionList<void()> >("IOKAY.DEF",0));
  1247. pom.push_back(std::pair<std::string,CFunctionList<void()> >("ICANCEL.DEF",0));
  1248. CInfoWindow * temp = new CInfoWindow(text,playerID,0,components,pom,DelComps);
  1249. temp->delComps = DelComps;
  1250. for(int i=0;i<onYes.funcs.size();i++)
  1251. temp->buttons[0]->callback += onYes.funcs[i];
  1252. for(int i=0;i<onNo.funcs.size();i++)
  1253. temp->buttons[1]->callback += onNo.funcs[i];
  1254. LOCPLINT->pushInt(temp);
  1255. }
  1256. void CPlayerInterface::showBlockingDialog( const std::string &text, const std::vector<Component> &components, ui32 askID, int soundID, bool selection, bool cancel )
  1257. {
  1258. waitWhileDialog();
  1259. boost::unique_lock<boost::recursive_mutex> un(*pim);
  1260. CGI->soundh->playSound(static_cast<soundBase::soundID>(soundID));
  1261. if(!selection && cancel) //simple yes/no dialog
  1262. {
  1263. std::vector<SComponent*> intComps;
  1264. for(int i=0;i<components.size();i++)
  1265. intComps.push_back(new SComponent(components[i])); //will be deleted by close in window
  1266. showYesNoDialog(text,intComps,boost::bind(&CCallback::selectionMade,cb,1,askID),boost::bind(&CCallback::selectionMade,cb,0,askID),true);
  1267. }
  1268. else if(selection)
  1269. {
  1270. std::vector<CSelectableComponent*> intComps;
  1271. for(int i=0;i<components.size();i++)
  1272. intComps.push_back(new CSelectableComponent(components[i])); //will be deleted by CSelWindow::close
  1273. std::vector<std::pair<std::string,CFunctionList<void()> > > pom;
  1274. pom.push_back(std::pair<std::string,CFunctionList<void()> >("IOKAY.DEF",0));
  1275. if(cancel)
  1276. {
  1277. pom.push_back(std::pair<std::string,CFunctionList<void()> >("ICANCEL.DEF",0));
  1278. }
  1279. CSelWindow * temp = new CSelWindow(text,playerID,35,intComps,pom,askID);
  1280. pushInt(temp);
  1281. intComps[0]->clickLeft(true);
  1282. }
  1283. }
  1284. void CPlayerInterface::tileRevealed(const std::set<int3> &pos)
  1285. {
  1286. boost::unique_lock<boost::recursive_mutex> un(*pim);
  1287. for(std::set<int3>::const_iterator i=pos.begin(); i!=pos.end();i++)
  1288. adventureInt->minimap.showTile(*i);
  1289. }
  1290. void CPlayerInterface::tileHidden(const std::set<int3> &pos)
  1291. {
  1292. boost::unique_lock<boost::recursive_mutex> un(*pim);
  1293. for(std::set<int3>::const_iterator i=pos.begin(); i!=pos.end();i++)
  1294. adventureInt->minimap.hideTile(*i);
  1295. }
  1296. void CPlayerInterface::openHeroWindow(const CGHeroInstance *hero)
  1297. {
  1298. boost::unique_lock<boost::recursive_mutex> un(*pim);
  1299. adventureInt->heroWindow->setHero(hero);
  1300. adventureInt->heroWindow->quitButton->callback = boost::bind(&CHeroWindow::quit,adventureInt->heroWindow);
  1301. pushInt(adventureInt->heroWindow);
  1302. }
  1303. void CPlayerInterface::heroArtifactSetChanged(const CGHeroInstance*hero)
  1304. {
  1305. boost::unique_lock<boost::recursive_mutex> un(*pim);
  1306. if(adventureInt->heroWindow->curHero) //hero window is opened
  1307. {
  1308. adventureInt->heroWindow->deactivate();
  1309. adventureInt->heroWindow->setHero(adventureInt->heroWindow->curHero);
  1310. adventureInt->heroWindow->activate();
  1311. return;
  1312. }
  1313. CExchangeWindow* cew = dynamic_cast<CExchangeWindow*>(listInt.front());
  1314. if(cew) //exchange window is open
  1315. {
  1316. cew->deactivate();
  1317. for(int g=0; g<ARRAY_COUNT(cew->heroInst); ++g)
  1318. {
  1319. if(cew->heroInst[g] == hero)
  1320. {
  1321. cew->artifs[g]->setHero(hero);
  1322. }
  1323. }
  1324. cew->prepareBackground();
  1325. cew->activate();
  1326. }
  1327. }
  1328. void CPlayerInterface::updateWater()
  1329. {
  1330. }
  1331. void CPlayerInterface::availableCreaturesChanged( const CGDwelling *town )
  1332. {
  1333. boost::unique_lock<boost::recursive_mutex> un(*pim);
  1334. if(castleInt && town->ID == TOWNI_TYPE)
  1335. {
  1336. CFortScreen *fs = dynamic_cast<CFortScreen*>(listInt.front());
  1337. if(fs)
  1338. fs->draw(castleInt,false);
  1339. }
  1340. else if(listInt.size() && (town->ID == 17 || town->ID == 20)) //external dwelling
  1341. {
  1342. CRecruitmentWindow *crw = dynamic_cast<CRecruitmentWindow*>(listInt.front());
  1343. if(crw)
  1344. crw->initCres();
  1345. }
  1346. }
  1347. void CPlayerInterface::heroBonusChanged( const CGHeroInstance *hero, const HeroBonus &bonus, bool gain )
  1348. {
  1349. if(bonus.type == HeroBonus::NONE) return;
  1350. boost::unique_lock<boost::recursive_mutex> un(*pim);
  1351. redrawHeroWin(hero);
  1352. }
  1353. template <typename Handler> void CPlayerInterface::serializeTempl( Handler &h, const int version )
  1354. {
  1355. h & playerID & serialID;
  1356. h & sysOpts;
  1357. h & CBattleInterface::settings;
  1358. }
  1359. void CPlayerInterface::serialize( COSer<CSaveFile> &h, const int version )
  1360. {
  1361. serializeTempl(h,version);
  1362. }
  1363. void CPlayerInterface::serialize( CISer<CLoadFile> &h, const int version )
  1364. {
  1365. serializeTempl(h,version);
  1366. sysOpts.apply();
  1367. }
  1368. void CPlayerInterface::redrawHeroWin(const CGHeroInstance * hero)
  1369. {
  1370. if(!vstd::contains(graphics->heroWins,hero->subID))
  1371. {
  1372. tlog1 << "Cannot redraw infowindow for hero with subID=" << hero->subID << " - not present in our map\n";
  1373. return;
  1374. }
  1375. SDL_FreeSurface(graphics->heroWins[hero->subID]);
  1376. graphics->heroWins[hero->subID] = infoWin(hero);
  1377. if (adventureInt->selection == hero)
  1378. adventureInt->infoBar.draw(screen);
  1379. }
  1380. bool CPlayerInterface::moveHero( const CGHeroInstance *h, CPath path )
  1381. {
  1382. if (!h)
  1383. return false; //can't find hero
  1384. bool result = false;
  1385. path.convert(0);
  1386. boost::unique_lock<boost::mutex> un(stillMoveHero.mx);
  1387. stillMoveHero.data = CONTINUE_MOVE;
  1388. enum TerrainTile::EterrainType currentTerrain = TerrainTile::border; // not init yet
  1389. enum TerrainTile::EterrainType newTerrain;
  1390. int sh = -1;
  1391. for(int i=path.nodes.size()-1; i>0 && stillMoveHero.data == CONTINUE_MOVE; i--)
  1392. {
  1393. //stop sending move requests if hero exhausted all his move points
  1394. if(!h->movement)
  1395. {
  1396. stillMoveHero.data = STOP_MOVE;
  1397. break;
  1398. }
  1399. // Start a new sound for the hero movement or let the existing one carry on.
  1400. #if 0
  1401. // TODO
  1402. if (hero is flying && sh == -1)
  1403. sh = CGI->soundh->playSound(soundBase::horseFlying, -1);
  1404. }
  1405. else if (hero is in a boat && sh = -1) {
  1406. sh = CGI->soundh->playSound(soundBase::sound_todo, -1);
  1407. } else
  1408. #endif
  1409. {
  1410. newTerrain = cb->getTileInfo(CGHeroInstance::convertPosition(path.nodes[i].coord, false))->tertype;
  1411. if (newTerrain != currentTerrain) {
  1412. CGI->soundh->stopSound(sh);
  1413. sh = CGI->soundh->playSound(CGI->soundh->horseSounds[newTerrain], -1);
  1414. currentTerrain = newTerrain;
  1415. }
  1416. }
  1417. stillMoveHero.data = WAITING_MOVE;
  1418. int3 endpos(path.nodes[i-1].coord.x, path.nodes[i-1].coord.y, h->pos.z);
  1419. cb->moveHero(h,endpos);
  1420. while(stillMoveHero.data != STOP_MOVE && stillMoveHero.data != CONTINUE_MOVE)
  1421. stillMoveHero.cond.wait(un);
  1422. }
  1423. CGI->soundh->stopSound(sh);
  1424. //stillMoveHero = false;
  1425. return result;
  1426. }
  1427. bool CPlayerInterface::shiftPressed() const
  1428. {
  1429. return SDL_GetKeyState(NULL)[SDLK_LSHIFT] || SDL_GetKeyState(NULL)[SDLK_RSHIFT];
  1430. }
  1431. void CPlayerInterface::showGarrisonDialog( const CArmedInstance *up, const CGHeroInstance *down, boost::function<void()> &onEnd )
  1432. {
  1433. {
  1434. boost::unique_lock<boost::mutex> un(showingDialog->mx);
  1435. while(showingDialog->data)
  1436. showingDialog->cond.wait(un);
  1437. }
  1438. boost::unique_lock<boost::recursive_mutex> un(*pim);
  1439. while(dialogs.size())
  1440. {
  1441. pim->unlock();
  1442. SDL_Delay(20);
  1443. pim->lock();
  1444. }
  1445. CGarrisonWindow *cgw = new CGarrisonWindow(up,down);
  1446. cgw->quit->callback += onEnd;
  1447. pushInt(cgw);
  1448. }
  1449. void CPlayerInterface::popInt( IShowActivable *top )
  1450. {
  1451. assert(listInt.front() == top);
  1452. top->deactivate();
  1453. listInt.pop_front();
  1454. objsToBlit -= top;
  1455. if(listInt.size())
  1456. listInt.front()->activate();
  1457. totalRedraw();
  1458. }
  1459. void CPlayerInterface::popIntTotally( IShowActivable *top )
  1460. {
  1461. assert(listInt.front() == top);
  1462. popInt(top);
  1463. delete top;
  1464. }
  1465. void CPlayerInterface::pushInt( IShowActivable *newInt )
  1466. {
  1467. //a new interface will be present, we'll need to use buffer surface (unless it's advmapint that will alter screenBuf on activate anyway)
  1468. screenBuf = screen2;
  1469. if(listInt.size())
  1470. listInt.front()->deactivate();
  1471. listInt.push_front(newInt);
  1472. newInt->activate();
  1473. objsToBlit += newInt;
  1474. LOCPLINT->totalRedraw();
  1475. }
  1476. void CPlayerInterface::popInts( int howMany )
  1477. {
  1478. if(!howMany) return; //senseless but who knows...
  1479. assert(listInt.size() > howMany);
  1480. listInt.front()->deactivate();
  1481. for(int i=0; i < howMany; i++)
  1482. {
  1483. objsToBlit -= listInt.front();
  1484. delete listInt.front();
  1485. listInt.pop_front();
  1486. }
  1487. listInt.front()->activate();
  1488. totalRedraw();
  1489. }
  1490. IShowActivable * CPlayerInterface::topInt()
  1491. {
  1492. if(!listInt.size())
  1493. return NULL;
  1494. else
  1495. return listInt.front();
  1496. }
  1497. void CPlayerInterface::totalRedraw()
  1498. {
  1499. for(int i=0;i<objsToBlit.size();i++)
  1500. objsToBlit[i]->showAll(screen2);
  1501. blitAt(screen2,0,0,screen);
  1502. if(objsToBlit.size())
  1503. objsToBlit.back()->showAll(screen);
  1504. }
  1505. void CPlayerInterface::requestRealized( PackageApplied *pa )
  1506. {
  1507. if(stillMoveHero.get() == DURING_MOVE)
  1508. stillMoveHero.setn(CONTINUE_MOVE);
  1509. }
  1510. void CPlayerInterface::heroExchangeStarted(si32 hero1, si32 hero2)
  1511. {
  1512. pushInt(new CExchangeWindow(hero2, hero1));
  1513. }
  1514. void CPlayerInterface::objectPropertyChanged(const SetObjectProperty * sop)
  1515. {
  1516. //redraw minimap if owner changed
  1517. if(sop->what == 1)
  1518. {
  1519. const CGObjectInstance * obj = cb->getObjectInfo(sop->id);
  1520. std::set<int3> pos = obj->getBlockedPos();
  1521. for(std::set<int3>::const_iterator it = pos.begin(); it != pos.end(); ++it)
  1522. {
  1523. if(cb->isVisible(*it))
  1524. adventureInt->minimap.showTile(*it);
  1525. }
  1526. }
  1527. }
  1528. void CPlayerInterface::recreateWanderingHeroes()
  1529. {
  1530. wanderingHeroes.clear();
  1531. std::vector<const CGHeroInstance*> heroes = cb->getHeroesInfo();
  1532. for(size_t i = 0; i < heroes.size(); i++)
  1533. if(!heroes[i]->inTownGarrison)
  1534. wanderingHeroes.push_back(heroes[i]);
  1535. }
  1536. const CGHeroInstance * CPlayerInterface::getWHero( int pos )
  1537. {
  1538. if(pos < 0 || pos >= wanderingHeroes.size())
  1539. return NULL;
  1540. return wanderingHeroes[pos];
  1541. }
  1542. void CPlayerInterface::showRecruitmentDialog(const CGDwelling *dwelling, const CArmedInstance *dst, int level)
  1543. {
  1544. waitWhileDialog();
  1545. boost::unique_lock<boost::recursive_mutex> un(*pim);
  1546. CRecruitmentWindow *cr = new CRecruitmentWindow(dwelling, level, dst, boost::bind(&CCallback::recruitCreatures, cb, dwelling, _1, _2));
  1547. pushInt(cr);
  1548. }
  1549. void CPlayerInterface::waitWhileDialog()
  1550. {
  1551. boost::unique_lock<boost::mutex> un(showingDialog->mx);
  1552. while(showingDialog->data)
  1553. showingDialog->cond.wait(un);
  1554. }
  1555. void CPlayerInterface::showShipyardDialog(const IShipyard *obj)
  1556. {
  1557. boost::unique_lock<boost::recursive_mutex> un(*pim);
  1558. int state = obj->state();
  1559. std::vector<si32> cost;
  1560. obj->getBoatCost(cost);
  1561. CShipyardWindow *csw = new CShipyardWindow(cost, state, boost::bind(&CCallback::buildBoat, cb, obj));
  1562. pushInt(csw);
  1563. }
  1564. void CPlayerInterface::newObject( const CGObjectInstance * obj )
  1565. {
  1566. boost::unique_lock<boost::recursive_mutex> un(*pim);
  1567. CGI->mh->printObject(obj);
  1568. //we might have built a boat in shipyard in opened town screen
  1569. if(obj->ID == 8
  1570. && LOCPLINT->castleInt
  1571. && obj->pos-obj->getVisitableOffset() == LOCPLINT->castleInt->town->bestLocation())
  1572. {
  1573. CGI->soundh->playSound(soundBase::newBuilding);
  1574. LOCPLINT->castleInt->recreateBuildings();
  1575. }
  1576. }
  1577. void SystemOptions::setMusicVolume( int newVolume )
  1578. {
  1579. musicVolume = newVolume;
  1580. CGI->musich->setVolume(newVolume);
  1581. settingsChanged();
  1582. }
  1583. void SystemOptions::setSoundVolume( int newVolume )
  1584. {
  1585. soundVolume = newVolume;
  1586. CGI->soundh->setVolume(newVolume);
  1587. settingsChanged();
  1588. }
  1589. void SystemOptions::setHeroMoveSpeed( int newSpeed )
  1590. {
  1591. heroMoveSpeed = newSpeed;
  1592. settingsChanged();
  1593. }
  1594. void SystemOptions::setMapScrollingSpeed( int newSpeed )
  1595. {
  1596. mapScrollingSpeed = newSpeed;
  1597. settingsChanged();
  1598. }
  1599. void SystemOptions::settingsChanged()
  1600. {
  1601. CSaveFile settings("config" PATHSEPARATOR "sysopts.bin");
  1602. if(settings.sfile)
  1603. settings << *this;
  1604. else
  1605. tlog1 << "Cannot save settings to config" PATHSEPARATOR "sysopts.bin!\n";
  1606. }
  1607. void SystemOptions::apply()
  1608. {
  1609. CGI->musich->setVolume(musicVolume);
  1610. CGI->soundh->setVolume(soundVolume);
  1611. settingsChanged();
  1612. }