CPlayerInterface.cpp 64 KB

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