CMT.cpp 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285
  1. // CMT.cpp : Defines the entry point for the console application.
  2. //
  3. #include "StdInc.h"
  4. #include <SDL_mixer.h>
  5. #include "gui/SDL_Extensions.h"
  6. #include "CGameInfo.h"
  7. #include "mapHandler.h"
  8. #include "../lib/filesystem/Filesystem.h"
  9. #include "../lib/filesystem/FileStream.h"
  10. #include "CPreGame.h"
  11. #include "windows/CCastleInterface.h"
  12. #include "../lib/CConsoleHandler.h"
  13. #include "gui/CCursorHandler.h"
  14. #include "../lib/CGameState.h"
  15. #include "../CCallback.h"
  16. #include "CPlayerInterface.h"
  17. #include "windows/CAdvmapInterface.h"
  18. #include "../lib/CBuildingHandler.h"
  19. #include "CVideoHandler.h"
  20. #include "../lib/CHeroHandler.h"
  21. #include "../lib/CCreatureHandler.h"
  22. #include "../lib/spells/CSpellHandler.h"
  23. #include "CMusicHandler.h"
  24. #include "CVideoHandler.h"
  25. #include "CDefHandler.h"
  26. #include "../lib/CGeneralTextHandler.h"
  27. #include "Graphics.h"
  28. #include "Client.h"
  29. #include "../lib/CConfigHandler.h"
  30. #include "../lib/Connection.h"
  31. #include "../lib/VCMI_Lib.h"
  32. #include "../lib/VCMIDirs.h"
  33. #include "../lib/NetPacks.h"
  34. #include "CMessage.h"
  35. #include "../lib/CModHandler.h"
  36. #include "../lib/CTownHandler.h"
  37. #include "../lib/CArtHandler.h"
  38. #include "../lib/CScriptingModule.h"
  39. #include "../lib/GameConstants.h"
  40. #include "gui/CGuiHandler.h"
  41. #include "../lib/logging/CBasicLogConfigurator.h"
  42. #include "../lib/CondSh.h"
  43. #include "../lib/StringConstants.h"
  44. #include "../lib/CPlayerState.h"
  45. #ifdef VCMI_WINDOWS
  46. #include "SDL_syswm.h"
  47. #endif
  48. #include "../lib/UnlockGuard.h"
  49. #include "CMT.h"
  50. #if __MINGW32__
  51. #undef main
  52. #endif
  53. namespace po = boost::program_options;
  54. namespace bfs = boost::filesystem;
  55. /*
  56. * CMT.cpp, part of VCMI engine
  57. *
  58. * Authors: listed in file AUTHORS in main folder
  59. *
  60. * License: GNU General Public License v2.0 or later
  61. * Full text of license available in license.txt file, in main folder
  62. *
  63. */
  64. std::string NAME_AFFIX = "client";
  65. std::string NAME = GameConstants::VCMI_VERSION + std::string(" (") + NAME_AFFIX + ')'; //application name
  66. CGuiHandler GH;
  67. static CClient *client=nullptr;
  68. int preferredDriverIndex = -1;
  69. SDL_Window * mainWindow = nullptr;
  70. SDL_Renderer * mainRenderer = nullptr;
  71. SDL_Texture * screenTexture = nullptr;
  72. extern boost::thread_specific_ptr<bool> inGuiThread;
  73. SDL_Surface *screen = nullptr, //main screen surface
  74. *screen2 = nullptr, //and hlp surface (used to store not-active interfaces layer)
  75. *screenBuf = screen; //points to screen (if only advmapint is present) or screen2 (else) - should be used when updating controls which are not regularly redrawed
  76. std::queue<SDL_Event> events;
  77. boost::mutex eventsM;
  78. bool gNoGUI = false;
  79. static po::variables_map vm;
  80. //static bool setResolution = false; //set by event handling thread after resolution is adjusted
  81. static bool ermInteractiveMode = false; //structurize when time is right
  82. void processCommand(const std::string &message);
  83. static void setScreenRes(int w, int h, int bpp, bool fullscreen, bool resetVideo=true);
  84. void dispose();
  85. void playIntro();
  86. static void mainLoop();
  87. //void requestChangingResolution();
  88. void startGame(StartInfo * options, CConnection *serv = nullptr);
  89. void endGame();
  90. #ifndef VCMI_WINDOWS
  91. #ifndef _GNU_SOURCE
  92. #define _GNU_SOURCE
  93. #endif
  94. #include <getopt.h>
  95. #endif
  96. void startGameFromFile(const bfs::path &fname)
  97. {
  98. StartInfo si;
  99. try //attempt retrieving start info from given file
  100. {
  101. if(fname.empty() || !bfs::exists(fname))
  102. throw std::runtime_error("Startfile \"" + fname.string() + "\" does not exist!");
  103. CLoadFile out(fname);
  104. if (!out.sfile || !*out.sfile)
  105. throw std::runtime_error("Cannot read from startfile \"" + fname.string() +"\"!");
  106. out >> si;
  107. }
  108. catch(std::exception &e)
  109. {
  110. logGlobal->errorStream() << "Failed to start from the file: " << fname << ". Error: " << e.what()
  111. << " Falling back to main menu.";
  112. GH.curInt = CGPreGame::create();
  113. return;
  114. }
  115. while(GH.topInt())
  116. GH.popIntTotally(GH.topInt());
  117. startGame(&si);
  118. }
  119. void init()
  120. {
  121. CStopWatch tmh, pomtime;
  122. loadDLLClasses();
  123. const_cast<CGameInfo*>(CGI)->setFromLib();
  124. logGlobal->infoStream()<<"Initializing VCMI_Lib: "<<tmh.getDiff();
  125. if(!gNoGUI)
  126. {
  127. pomtime.getDiff();
  128. CCS->curh = new CCursorHandler;
  129. graphics = new Graphics(); // should be before curh->init()
  130. CCS->curh->initCursor();
  131. CCS->curh->show();
  132. logGlobal->infoStream()<<"Screen handler: "<<pomtime.getDiff();
  133. pomtime.getDiff();
  134. graphics->loadHeroAnims();
  135. logGlobal->infoStream()<<"\tMain graphics: "<<pomtime.getDiff();
  136. logGlobal->infoStream()<<"Initializing game graphics: "<<tmh.getDiff();
  137. CMessage::init();
  138. logGlobal->infoStream()<<"Message handler: "<<tmh.getDiff();
  139. }
  140. }
  141. static void prog_version(void)
  142. {
  143. printf("%s\n", GameConstants::VCMI_VERSION.c_str());
  144. std::cout << VCMIDirs::get().genHelpString();
  145. }
  146. static void prog_help(const po::options_description &opts)
  147. {
  148. printf("%s - A Heroes of Might and Magic 3 clone\n", GameConstants::VCMI_VERSION.c_str());
  149. printf("Copyright (C) 2007-2016 VCMI dev team - see AUTHORS file\n");
  150. printf("This is free software; see the source for copying conditions. There is NO\n");
  151. printf("warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n");
  152. printf("\n");
  153. printf("Usage:\n");
  154. std::cout << opts;
  155. // printf(" -h, --help display this help and exit\n");
  156. // printf(" -v, --version display version information and exit\n");
  157. }
  158. static void SDLLogCallback(void* userdata,
  159. int category,
  160. SDL_LogPriority priority,
  161. const char* message)
  162. {
  163. //todo: convert SDL log priority to vcmi log priority
  164. //todo: make separate log domain for SDL
  165. logGlobal->debugStream() << "SDL(category " << category << "; priority " <<priority <<") "<<message;
  166. }
  167. #ifdef VCMI_APPLE
  168. void OSX_checkForUpdates();
  169. #endif
  170. #if defined(VCMI_WINDOWS) && !defined (__GNUC__)
  171. int wmain(int argc, wchar_t* argv[])
  172. #elif defined(VCMI_APPLE)
  173. int SDL_main(int argc, char *argv[])
  174. #else
  175. int main(int argc, char** argv)
  176. #endif
  177. {
  178. #ifdef VCMI_ANDROID
  179. // boost will crash without this
  180. setenv("LANG", "C", 1);
  181. #endif
  182. #ifdef VCMI_APPLE
  183. // Correct working dir executable folder (not bundle folder) so we can use executable relative paths
  184. std::string executablePath = argv[0];
  185. std::string workDir = executablePath.substr(0, executablePath.rfind('/'));
  186. chdir(workDir.c_str());
  187. // Check for updates
  188. OSX_checkForUpdates();
  189. // Check that game data is prepared. Otherwise run vcmibuilder helper application
  190. FILE* check = fopen((VCMIDirs::get().userDataPath() / "game_data_prepared").string().c_str(), "r");
  191. if (check == nullptr) {
  192. system("open ./vcmibuilder.app");
  193. return 0;
  194. }
  195. fclose(check);
  196. #endif
  197. std::cout << "Starting... " << std::endl;
  198. po::options_description opts("Allowed options");
  199. opts.add_options()
  200. ("help,h", "display help and exit")
  201. ("version,v", "display version information and exit")
  202. ("battle,b", po::value<std::string>(), "runs game in duel mode (battle-only")
  203. ("start", po::value<bfs::path>(), "starts game from saved StartInfo file")
  204. ("onlyAI", "runs without human player, all players will be default AI")
  205. ("noGUI", "runs without GUI, implies --onlyAI")
  206. ("ai", po::value<std::vector<std::string>>(), "AI to be used for the player, can be specified several times for the consecutive players")
  207. ("oneGoodAI", "puts one default AI and the rest will be EmptyAI")
  208. ("autoSkip", "automatically skip turns in GUI")
  209. ("disable-video", "disable video player")
  210. ("nointro,i", "skips intro movies")
  211. ("loadserver","specifies we are the multiplayer server for loaded games")
  212. ("loadnumplayers",po::value<int>(),"specifies the number of players connecting to a multiplayer game")
  213. ("loadhumanplayerindices",po::value<std::vector<int>>(),"Indexes of human players (0=Red, etc.)")
  214. ("loadplayer", po::value<int>(),"specifies which player we are in multiplayer loaded games (0=Red, etc.)")
  215. ("loadserverip",po::value<std::string>(),"IP for loaded game server")
  216. ("loadserverport",po::value<std::string>(),"port for loaded game server")
  217. ("testingport",po::value<std::string>(),"port for testing, override specified in config file")
  218. ("testingfileprefix",po::value<std::string>(),"prefix for auto save files");
  219. if(argc > 1)
  220. {
  221. try
  222. {
  223. po::store(po::parse_command_line(argc, argv, opts), vm);
  224. }
  225. catch(std::exception &e)
  226. {
  227. std::cerr << "Failure during parsing command-line options:\n" << e.what() << std::endl;
  228. }
  229. }
  230. po::notify(vm);
  231. if(vm.count("help"))
  232. {
  233. prog_help(opts);
  234. return 0;
  235. }
  236. if(vm.count("version"))
  237. {
  238. prog_version();
  239. return 0;
  240. }
  241. if(vm.count("noGUI"))
  242. {
  243. gNoGUI = true;
  244. vm.insert(std::pair<std::string, po::variable_value>("onlyAI", po::variable_value()));
  245. }
  246. // Have effect on X11 system only (Linux).
  247. // For whatever reason in fullscreen mode SDL takes "raw" mouse input from DGA X11 extension
  248. // (DGA = Direct graphics access). Because this is raw input (before any speed\acceleration proceesing)
  249. // it may result in very small \ very fast mouse when game in fullscreen mode
  250. putenv((char*)"SDL_VIDEO_X11_DGAMOUSE=0");
  251. // Init old logging system and new (temporary) logging system
  252. CStopWatch total, pomtime;
  253. std::cout.flags(std::ios::unitbuf);
  254. console = new CConsoleHandler;
  255. *console->cb = processCommand;
  256. console->start();
  257. atexit(dispose);
  258. const bfs::path logPath = VCMIDirs::get().userCachePath() / "VCMI_Client_log.txt";
  259. CBasicLogConfigurator logConfig(logPath, console);
  260. logConfig.configureDefault();
  261. logGlobal->infoStream() << "Creating console and configuring logger: " << pomtime.getDiff();
  262. logGlobal->infoStream() << "The log file will be saved to " << logPath;
  263. // Init filesystem and settings
  264. preinitDLL(::console);
  265. settings.init();
  266. // Init special testing settings
  267. Settings testingSettings = settings.write["testing"];
  268. if(vm.count("testingport") && vm.count("testingfileprefix"))
  269. {
  270. testingSettings["enabled"].Bool() = true;
  271. testingSettings["port"].String() = vm["testingport"].as<std::string>();
  272. testingSettings["prefix"].String() = vm["testingfileprefix"].as<std::string>();
  273. }
  274. // Initialize logging based on settings
  275. logConfig.configure();
  276. // Some basic data validation to produce better error messages in cases of incorrect install
  277. auto testFile = [](std::string filename, std::string message) -> bool
  278. {
  279. if (CResourceHandler::get()->existsResource(ResourceID(filename)))
  280. return true;
  281. logGlobal->errorStream() << "Error: " << message << " was not found!";
  282. return false;
  283. };
  284. if (!testFile("DATA/HELP.TXT", "Heroes III data") ||
  285. !testFile("MODS/VCMI/MOD.JSON", "VCMI data"))
  286. {
  287. exit(1); // These are unrecoverable errors
  288. }
  289. // these two are optional + some installs have them on CD and not in data directory
  290. testFile("VIDEO/GOOD1A.SMK", "campaign movies");
  291. testFile("SOUNDS/G1A.WAV", "campaign music"); //technically not a music but voiced intro sounds
  292. conf.init();
  293. logGlobal->infoStream() << "Loading settings: " << pomtime.getDiff();
  294. logGlobal->infoStream() << NAME;
  295. srand ( time(nullptr) );
  296. const JsonNode& video = settings["video"];
  297. const JsonNode& res = video["screenRes"];
  298. //something is really wrong...
  299. if (res["width"].Float() < 100 || res["height"].Float() < 100)
  300. {
  301. logGlobal->errorStream() << "Fatal error: failed to load settings!";
  302. logGlobal->errorStream() << "Possible reasons:";
  303. logGlobal->errorStream() << "\tCorrupted local configuration file at " << VCMIDirs::get().userConfigPath() << "/settings.json";
  304. logGlobal->errorStream() << "\tMissing or corrupted global configuration file at " << VCMIDirs::get().userConfigPath() << "/schemas/settings.json";
  305. logGlobal->errorStream() << "VCMI will now exit...";
  306. exit(EXIT_FAILURE);
  307. }
  308. if(!gNoGUI)
  309. {
  310. if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_AUDIO|SDL_INIT_NOPARACHUTE))
  311. {
  312. logGlobal->errorStream()<<"Something was wrong: "<< SDL_GetError();
  313. exit(-1);
  314. }
  315. GH.mainFPSmng->init(); //(!)init here AFTER SDL_Init() while using SDL for FPS management
  316. atexit(SDL_Quit);
  317. SDL_LogSetOutputFunction(&SDLLogCallback, nullptr);
  318. int driversCount = SDL_GetNumRenderDrivers();
  319. std::string preferredDriverName = video["driver"].String();
  320. logGlobal->infoStream() << "Found " << driversCount << " render drivers";
  321. for(int it = 0; it < driversCount; it++)
  322. {
  323. SDL_RendererInfo info;
  324. SDL_GetRenderDriverInfo(it,&info);
  325. std::string driverName(info.name);
  326. if(!preferredDriverName.empty() && driverName == preferredDriverName)
  327. {
  328. preferredDriverIndex = it;
  329. logGlobal->infoStream() << "\t" << driverName << " (active)";
  330. }
  331. else
  332. logGlobal->infoStream() << "\t" << driverName;
  333. }
  334. config::CConfigHandler::GuiOptionsMap::key_type resPair(res["width"].Float(), res["height"].Float());
  335. if (conf.guiOptions.count(resPair) == 0)
  336. {
  337. // selected resolution was not found - complain & fallback to something that we do have.
  338. logGlobal->errorStream() << "Selected resolution " << resPair.first << "x" << resPair.second << " was not found!";
  339. if (conf.guiOptions.empty())
  340. {
  341. logGlobal->errorStream() << "Unable to continue - no valid resolutions found! Please reinstall VCMI to fix this";
  342. exit(1);
  343. }
  344. else
  345. {
  346. Settings newRes = settings.write["video"]["screenRes"];
  347. newRes["width"].Float() = conf.guiOptions.begin()->first.first;
  348. newRes["height"].Float() = conf.guiOptions.begin()->first.second;
  349. conf.SetResolution(newRes["width"].Float(), newRes["height"].Float());
  350. logGlobal->errorStream() << "Falling back to " << newRes["width"].Float() << "x" << newRes["height"].Float();
  351. }
  352. }
  353. setScreenRes(res["width"].Float(), res["height"].Float(), video["bitsPerPixel"].Float(), video["fullscreen"].Bool());
  354. logGlobal->infoStream() <<"\tInitializing screen: "<<pomtime.getDiff();
  355. }
  356. CCS = new CClientState;
  357. CGI = new CGameInfo; //contains all global informations about game (texts, lodHandlers, map handler etc.)
  358. // Initialize video
  359. #ifdef DISABLE_VIDEO
  360. CCS->videoh = new CEmptyVideoPlayer;
  361. #else
  362. if (!gNoGUI && !vm.count("disable-video"))
  363. CCS->videoh = new CVideoPlayer;
  364. else
  365. CCS->videoh = new CEmptyVideoPlayer;
  366. #endif
  367. logGlobal->infoStream()<<"\tInitializing video: "<<pomtime.getDiff();
  368. #if defined(VCMI_ANDROID)
  369. //on Android threaded init is broken
  370. #define VCMI_NO_THREADED_LOAD
  371. #endif // defined
  372. //initializing audio
  373. CCS->soundh = new CSoundHandler;
  374. CCS->soundh->init();
  375. CCS->soundh->setVolume(settings["general"]["sound"].Float());
  376. CCS->musich = new CMusicHandler;
  377. CCS->musich->init();
  378. CCS->musich->setVolume(settings["general"]["music"].Float());
  379. logGlobal->infoStream()<<"Initializing screen and sound handling: "<<pomtime.getDiff();
  380. #ifdef __APPLE__
  381. // Ctrl+click should be treated as a right click on Mac OS X
  382. SDL_SetHint(SDL_HINT_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK, "1");
  383. #endif
  384. #ifndef VCMI_NO_THREADED_LOAD
  385. //we can properly play intro only in the main thread, so we have to move loading to the separate thread
  386. boost::thread loading(init);
  387. #else
  388. init();
  389. #endif
  390. if(!gNoGUI )
  391. {
  392. if(!vm.count("battle") && !vm.count("nointro") && settings["video"]["showIntro"].Bool())
  393. playIntro();
  394. SDL_FillRect(screen,nullptr,0);
  395. }
  396. CSDL_Ext::update(screen);
  397. #ifndef VCMI_NO_THREADED_LOAD
  398. loading.join();
  399. #endif
  400. logGlobal->infoStream()<<"Initialization of VCMI (together): "<<total.getDiff();
  401. if(!vm.count("battle"))
  402. {
  403. Settings session = settings.write["session"];
  404. session["autoSkip"].Bool() = vm.count("autoSkip");
  405. session["oneGoodAI"].Bool() = vm.count("oneGoodAI");
  406. session["aiSolo"].Bool() = false;
  407. bfs::path fileToStartFrom; //none by default
  408. if(vm.count("start"))
  409. fileToStartFrom = vm["start"].as<bfs::path>();
  410. if(!fileToStartFrom.empty() && bfs::exists(fileToStartFrom))
  411. startGameFromFile(fileToStartFrom); //ommit pregame and start the game using settings from file
  412. else
  413. {
  414. if(!fileToStartFrom.empty())
  415. {
  416. logGlobal->warnStream() << "Warning: cannot find given file to start from (" << fileToStartFrom
  417. << "). Falling back to main menu.";
  418. }
  419. GH.curInt = CGPreGame::create(); //will set CGP pointer to itself
  420. }
  421. }
  422. else
  423. {
  424. auto si = new StartInfo();
  425. si->mode = StartInfo::DUEL;
  426. si->mapname = vm["battle"].as<std::string>();
  427. si->playerInfos[PlayerColor(0)].color = PlayerColor(0);
  428. si->playerInfos[PlayerColor(1)].color = PlayerColor(1);
  429. startGame(si);
  430. }
  431. if(!gNoGUI)
  432. {
  433. mainLoop();
  434. }
  435. else
  436. {
  437. while(true)
  438. boost::this_thread::sleep(boost::posix_time::milliseconds(1000));
  439. }
  440. return 0;
  441. }
  442. void printInfoAboutIntObject(const CIntObject *obj, int level)
  443. {
  444. std::stringstream sbuffer;
  445. sbuffer << std::string(level, '\t');
  446. sbuffer << typeid(*obj).name() << " *** ";
  447. if (obj->active)
  448. {
  449. #define PRINT(check, text) if (obj->active & CIntObject::check) sbuffer << text
  450. PRINT(LCLICK, 'L');
  451. PRINT(RCLICK, 'R');
  452. PRINT(HOVER, 'H');
  453. PRINT(MOVE, 'M');
  454. PRINT(KEYBOARD, 'K');
  455. PRINT(TIME, 'T');
  456. PRINT(GENERAL, 'A');
  457. PRINT(WHEEL, 'W');
  458. PRINT(DOUBLECLICK, 'D');
  459. #undef PRINT
  460. }
  461. else
  462. sbuffer << "inactive";
  463. sbuffer << " at " << obj->pos.x <<"x"<< obj->pos.y;
  464. sbuffer << " (" << obj->pos.w <<"x"<< obj->pos.h << ")";
  465. logGlobal->infoStream() << sbuffer.str();
  466. for(const CIntObject *child : obj->children)
  467. printInfoAboutIntObject(child, level+1);
  468. }
  469. void processCommand(const std::string &message)
  470. {
  471. std::istringstream readed;
  472. readed.str(message);
  473. std::string cn; //command name
  474. readed >> cn;
  475. // Check mantis issue 2292 for details
  476. // if(LOCPLINT && LOCPLINT->cingconsole)
  477. // LOCPLINT->cingconsole->print(message);
  478. if(ermInteractiveMode)
  479. {
  480. if(cn == "exit")
  481. {
  482. ermInteractiveMode = false;
  483. return;
  484. }
  485. else
  486. {
  487. if(client && client->erm)
  488. client->erm->executeUserCommand(message);
  489. std::cout << "erm>";
  490. }
  491. }
  492. else if(message==std::string("die, fool"))
  493. {
  494. exit(EXIT_SUCCESS);
  495. }
  496. else if(cn == "erm")
  497. {
  498. ermInteractiveMode = true;
  499. std::cout << "erm>";
  500. }
  501. else if(cn==std::string("activate"))
  502. {
  503. int what;
  504. readed >> what;
  505. switch (what)
  506. {
  507. case 0:
  508. GH.topInt()->activate();
  509. break;
  510. case 1:
  511. adventureInt->activate();
  512. break;
  513. case 2:
  514. LOCPLINT->castleInt->activate();
  515. break;
  516. }
  517. }
  518. else if(cn=="redraw")
  519. {
  520. GH.totalRedraw();
  521. }
  522. else if(cn=="screen")
  523. {
  524. std::cout << "Screenbuf points to ";
  525. if(screenBuf == screen)
  526. logGlobal->errorStream() << "screen";
  527. else if(screenBuf == screen2)
  528. logGlobal->errorStream() << "screen2";
  529. else
  530. logGlobal->errorStream() << "?!?";
  531. SDL_SaveBMP(screen, "Screen_c.bmp");
  532. SDL_SaveBMP(screen2, "Screen2_c.bmp");
  533. }
  534. else if(cn=="save")
  535. {
  536. std::string fname;
  537. readed >> fname;
  538. client->save(fname);
  539. }
  540. else if(cn=="load")
  541. {
  542. // TODO: this code should end the running game and manage to call startGame instead
  543. std::string fname;
  544. readed >> fname;
  545. client->loadGame(fname);
  546. }
  547. else if(message=="get txt")
  548. {
  549. std::cout << "Command accepted.\t";
  550. const bfs::path outPath =
  551. VCMIDirs::get().userCachePath() / "extracted";
  552. auto list = CResourceHandler::get()->getFilteredFiles([](const ResourceID & ident)
  553. {
  554. return ident.getType() == EResType::TEXT && boost::algorithm::starts_with(ident.getName(), "DATA/");
  555. });
  556. for (auto & filename : list)
  557. {
  558. const bfs::path filePath = outPath / (filename.getName() + ".TXT");
  559. bfs::create_directories(filePath.parent_path());
  560. bfs::ofstream file(filePath);
  561. auto text = CResourceHandler::get()->load(filename)->readAll();
  562. file.write((char*)text.first.get(), text.second);
  563. }
  564. std::cout << "\rExtracting done :)\n";
  565. std::cout << " Extracted files can be found in " << outPath << " directory\n";
  566. }
  567. else if(cn=="crash")
  568. {
  569. int *ptr = nullptr;
  570. *ptr = 666;
  571. //disaster!
  572. }
  573. else if(cn == "onlyai")
  574. {
  575. vm.insert(std::pair<std::string, po::variable_value>("onlyAI", po::variable_value()));
  576. }
  577. else if (cn == "ai")
  578. {
  579. VLC->IS_AI_ENABLED = !VLC->IS_AI_ENABLED;
  580. std::cout << "Current AI status: " << (VLC->IS_AI_ENABLED ? "enabled" : "disabled") << std::endl;
  581. }
  582. else if(cn == "mp" && adventureInt)
  583. {
  584. if(const CGHeroInstance *h = dynamic_cast<const CGHeroInstance *>(adventureInt->selection))
  585. std::cout << h->movement << "; max: " << h->maxMovePoints(true) << "/" << h->maxMovePoints(false) << std::endl;
  586. }
  587. else if(cn == "bonuses")
  588. {
  589. std::cout << "Bonuses of " << adventureInt->selection->getObjectName() << std::endl
  590. << adventureInt->selection->getBonusList() << std::endl;
  591. std::cout << "\nInherited bonuses:\n";
  592. TCNodes parents;
  593. adventureInt->selection->getParents(parents);
  594. for(const CBonusSystemNode *parent : parents)
  595. {
  596. std::cout << "\nBonuses from " << typeid(*parent).name() << std::endl << parent->getBonusList() << std::endl;
  597. }
  598. }
  599. else if(cn == "not dialog")
  600. {
  601. LOCPLINT->showingDialog->setn(false);
  602. }
  603. else if(cn == "gui")
  604. {
  605. for(const IShowActivatable *child : GH.listInt)
  606. {
  607. if(const CIntObject *obj = dynamic_cast<const CIntObject *>(child))
  608. printInfoAboutIntObject(obj, 0);
  609. else
  610. std::cout << typeid(*obj).name() << std::endl;
  611. }
  612. }
  613. else if(cn=="tell")
  614. {
  615. std::string what;
  616. int id1, id2;
  617. readed >> what >> id1 >> id2;
  618. if(what == "hs")
  619. {
  620. for(const CGHeroInstance *h : LOCPLINT->cb->getHeroesInfo())
  621. if(h->type->ID.getNum() == id1)
  622. if(const CArtifactInstance *a = h->getArt(ArtifactPosition(id2)))
  623. std::cout << a->nodeName();
  624. }
  625. }
  626. else if (cn == "set")
  627. {
  628. std::string what, value;
  629. readed >> what;
  630. Settings conf = settings.write["session"][what];
  631. readed >> value;
  632. if (value == "on")
  633. conf->Bool() = true;
  634. else if (value == "off")
  635. conf->Bool() = false;
  636. }
  637. else if(cn == "sinfo")
  638. {
  639. std::string fname;
  640. readed >> fname;
  641. if(fname.size() && SEL)
  642. {
  643. CSaveFile out(fname);
  644. out << SEL->sInfo;
  645. }
  646. }
  647. else if(cn == "start")
  648. {
  649. std::string fname;
  650. readed >> fname;
  651. startGameFromFile(fname);
  652. }
  653. else if(cn == "unlock")
  654. {
  655. std::string mxname;
  656. readed >> mxname;
  657. if(mxname == "pim" && LOCPLINT)
  658. LOCPLINT->pim->unlock();
  659. }
  660. else if(cn == "def2bmp")
  661. {
  662. std::string URI;
  663. readed >> URI;
  664. if (CResourceHandler::get()->existsResource(ResourceID("SPRITES/" + URI)))
  665. {
  666. CDefEssential * cde = CDefHandler::giveDefEss(URI);
  667. const bfs::path outPath = VCMIDirs::get().userCachePath() / "extracted" / URI;
  668. bfs::create_directories(outPath);
  669. for (size_t i = 0; i < cde->ourImages.size(); ++i)
  670. {
  671. const bfs::path filePath = outPath / (boost::lexical_cast<std::string>(i)+".bmp");
  672. SDL_SaveBMP(cde->ourImages[i].bitmap, filePath.string().c_str());
  673. }
  674. }
  675. else
  676. logGlobal->errorStream() << "File not found!";
  677. }
  678. else if(cn == "extract")
  679. {
  680. std::string URI;
  681. readed >> URI;
  682. if (CResourceHandler::get()->existsResource(ResourceID(URI)))
  683. {
  684. const bfs::path outPath = VCMIDirs::get().userCachePath() / "extracted" / URI;
  685. auto data = CResourceHandler::get()->load(ResourceID(URI))->readAll();
  686. bfs::create_directories(outPath.parent_path());
  687. bfs::ofstream outFile(outPath, bfs::ofstream::binary);
  688. outFile.write((char*)data.first.get(), data.second);
  689. }
  690. else
  691. logGlobal->errorStream() << "File not found!";
  692. }
  693. else if(cn == "setBattleAI")
  694. {
  695. std::string fname;
  696. readed >> fname;
  697. std::cout << "Will try loading that AI to see if it is correct name...\n";
  698. try
  699. {
  700. if(auto ai = CDynLibHandler::getNewBattleAI(fname)) //test that given AI is indeed available... heavy but it is easy to make a typo and break the game
  701. {
  702. Settings neutralAI = settings.write["server"]["neutralAI"];
  703. neutralAI->String() = fname;
  704. std::cout << "Setting changed, from now the battle ai will be " << fname << "!\n";
  705. }
  706. }
  707. catch(std::exception &e)
  708. {
  709. logGlobal->warnStream() << "Failed opening " << fname << ": " << e.what();
  710. logGlobal->warnStream() << "Setting not changes, AI not found or invalid!";
  711. }
  712. }
  713. auto removeGUI = [&]()
  714. {
  715. // CClient::endGame
  716. GH.curInt = nullptr;
  717. if(GH.topInt())
  718. GH.topInt()->deactivate();
  719. GH.listInt.clear();
  720. GH.objsToBlit.clear();
  721. GH.statusbar = nullptr;
  722. logNetwork->infoStream() << "Removed GUI.";
  723. LOCPLINT = nullptr;
  724. };
  725. auto giveTurn = [&](PlayerColor player)
  726. {
  727. YourTurn yt;
  728. yt.player = player;
  729. yt.daysWithoutCastle = client->getPlayer(player)->daysWithoutCastle;
  730. yt.applyCl(client);
  731. };
  732. Settings session = settings.write["session"];
  733. if(cn == "autoskip")
  734. {
  735. session["autoSkip"].Bool() = !session["autoSkip"].Bool();
  736. }
  737. else if(cn == "gosolo")
  738. {
  739. boost::unique_lock<boost::recursive_mutex> un(*LOCPLINT->pim);
  740. PlayerColor color;
  741. if(session["aiSolo"].Bool())
  742. {
  743. for(auto & elem : client->gameState()->players)
  744. {
  745. if(elem.second.human)
  746. client->installNewPlayerInterface(std::make_shared<CPlayerInterface>(elem.first), elem.first);
  747. }
  748. }
  749. else
  750. {
  751. color = LOCPLINT->playerID;
  752. removeGUI();
  753. for(auto & elem : client->gameState()->players)
  754. {
  755. if(elem.second.human)
  756. {
  757. auto AiToGive = client->aiNameForPlayer(*client->getPlayerSettings(elem.first), false);
  758. logNetwork->infoStream() << boost::format("Player %s will be lead by %s") % elem.first % AiToGive;
  759. client->installNewPlayerInterface(CDynLibHandler::getNewAI(AiToGive), elem.first);
  760. }
  761. }
  762. GH.totalRedraw();
  763. giveTurn(color);
  764. }
  765. session["aiSolo"].Bool() = !session["aiSolo"].Bool();
  766. }
  767. else if(cn == "controlai")
  768. {
  769. std::string colorName;
  770. readed >> colorName;
  771. boost::to_lower(colorName);
  772. boost::unique_lock<boost::recursive_mutex> un(*LOCPLINT->pim);
  773. PlayerColor color;
  774. if(LOCPLINT)
  775. color = LOCPLINT->playerID;
  776. for(auto & elem : client->gameState()->players)
  777. {
  778. if(elem.second.human || (colorName.length() &&
  779. elem.first.getNum() != vstd::find_pos(GameConstants::PLAYER_COLOR_NAMES, colorName)))
  780. {
  781. continue;
  782. }
  783. removeGUI();
  784. client->installNewPlayerInterface(std::make_shared<CPlayerInterface>(elem.first), elem.first);
  785. }
  786. GH.totalRedraw();
  787. if(color != PlayerColor::NEUTRAL)
  788. giveTurn(color);
  789. }
  790. // Check mantis issue 2292 for details
  791. /* else if(client && client->serv && client->serv->connected && LOCPLINT) //send to server
  792. {
  793. boost::unique_lock<boost::recursive_mutex> un(*LOCPLINT->pim);
  794. LOCPLINT->cb->sendMessage(message);
  795. }*/
  796. }
  797. //plays intro, ends when intro is over or button has been pressed (handles events)
  798. void playIntro()
  799. {
  800. if(CCS->videoh->openAndPlayVideo("3DOLOGO.SMK", 60, 40, screen, true, true))
  801. {
  802. CCS->videoh->openAndPlayVideo("AZVS.SMK", 60, 80, screen, true, true);
  803. }
  804. }
  805. void dispose()
  806. {
  807. if (console)
  808. delete console;
  809. // cleanup, mostly to remove false leaks from analyzer
  810. CResourceHandler::clear();
  811. if (CCS)
  812. {
  813. CCS->musich->release();
  814. CCS->soundh->release();
  815. }
  816. CMessage::dispose();
  817. }
  818. static bool checkVideoMode(int monitorIndex, int w, int h, int& bpp, bool fullscreen)
  819. {
  820. SDL_DisplayMode mode;
  821. const int modeCount = SDL_GetNumDisplayModes(monitorIndex);
  822. for (int i = 0; i < modeCount; i++) {
  823. SDL_GetDisplayMode(0, i, &mode);
  824. if (!mode.w || !mode.h || (w >= mode.w && h >= mode.h)) {
  825. return true;
  826. }
  827. }
  828. return false;
  829. }
  830. static bool recreateWindow(int w, int h, int bpp, bool fullscreen)
  831. {
  832. // VCMI will only work with 2 or 4 bytes per pixel
  833. vstd::amax(bpp, 16);
  834. vstd::amin(bpp, 32);
  835. if(bpp>16)
  836. bpp = 32;
  837. int suggestedBpp = bpp;
  838. if(!checkVideoMode(0,w,h,suggestedBpp,fullscreen))
  839. {
  840. logGlobal->errorStream() << "Error: SDL says that " << w << "x" << h << " resolution is not available!";
  841. return false;
  842. }
  843. bool bufOnScreen = (screenBuf == screen);
  844. screenBuf = nullptr; //it`s a link - just nullify
  845. if(nullptr != screen2)
  846. {
  847. SDL_FreeSurface(screen2);
  848. screen2 = nullptr;
  849. }
  850. if(nullptr != screen)
  851. {
  852. SDL_FreeSurface(screen);
  853. screen = nullptr;
  854. }
  855. if(nullptr != screenTexture)
  856. {
  857. SDL_DestroyTexture(screenTexture);
  858. screenTexture = nullptr;
  859. }
  860. if(nullptr != mainRenderer)
  861. {
  862. SDL_DestroyRenderer(mainRenderer);
  863. mainRenderer = nullptr;
  864. }
  865. if(nullptr != mainWindow)
  866. {
  867. SDL_DestroyWindow(mainWindow);
  868. mainWindow = nullptr;
  869. }
  870. if(fullscreen)
  871. {
  872. //in full-screen mode always use desktop resolution
  873. mainWindow = SDL_CreateWindow(NAME.c_str(), SDL_WINDOWPOS_UNDEFINED,SDL_WINDOWPOS_UNDEFINED, 0, 0, SDL_WINDOW_FULLSCREEN_DESKTOP);
  874. SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear");
  875. }
  876. else
  877. {
  878. mainWindow = SDL_CreateWindow(NAME.c_str(), SDL_WINDOWPOS_CENTERED,SDL_WINDOWPOS_CENTERED, w, h, 0);
  879. }
  880. if(nullptr == mainWindow)
  881. {
  882. throw std::runtime_error("Unable to create window\n");
  883. }
  884. //create first available renderer if preferred not set. Use no flags, so HW accelerated will be preferred but SW renderer also will possible
  885. mainRenderer = SDL_CreateRenderer(mainWindow,preferredDriverIndex,0);
  886. if(nullptr == mainRenderer)
  887. {
  888. throw std::runtime_error("Unable to create renderer\n");
  889. }
  890. SDL_RendererInfo info;
  891. SDL_GetRendererInfo(mainRenderer,&info);
  892. logGlobal->infoStream() << "Created renderer " << info.name;
  893. SDL_RenderSetLogicalSize(mainRenderer, w, h);
  894. SDL_RenderSetViewport(mainRenderer, nullptr);
  895. #if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
  896. int bmask = 0xff000000;
  897. int gmask = 0x00ff0000;
  898. int rmask = 0x0000ff00;
  899. int amask = 0x000000ff;
  900. #else
  901. int bmask = 0x000000ff;
  902. int gmask = 0x0000ff00;
  903. int rmask = 0x00ff0000;
  904. int amask = 0xFF000000;
  905. #endif
  906. screen = SDL_CreateRGBSurface(0,w,h,bpp,rmask,gmask,bmask,amask);
  907. if(nullptr == screen)
  908. {
  909. logGlobal->errorStream() << "Unable to create surface";
  910. logGlobal->errorStream() << w << " "<< h << " "<< bpp;
  911. logGlobal->errorStream() << SDL_GetError();
  912. throw std::runtime_error("Unable to create surface");
  913. }
  914. //No blending for screen itself. Required for proper cursor rendering.
  915. SDL_SetSurfaceBlendMode(screen, SDL_BLENDMODE_NONE);
  916. screenTexture = SDL_CreateTexture(mainRenderer,
  917. SDL_PIXELFORMAT_ARGB8888,
  918. SDL_TEXTUREACCESS_STREAMING,
  919. w, h);
  920. if(nullptr == screenTexture)
  921. {
  922. logGlobal->errorStream() << "Unable to create screen texture";
  923. logGlobal->errorStream() << SDL_GetError();
  924. throw std::runtime_error("Unable to create screen texture");
  925. }
  926. screen2 = CSDL_Ext::copySurface(screen);
  927. if(nullptr == screen2)
  928. {
  929. throw std::runtime_error("Unable to copy surface\n");
  930. }
  931. screenBuf = bufOnScreen ? screen : screen2;
  932. SDL_SetRenderDrawColor(mainRenderer, 0, 0, 0, 0);
  933. SDL_RenderClear(mainRenderer);
  934. SDL_RenderPresent(mainRenderer);
  935. return true;
  936. }
  937. //used only once during initialization
  938. static void setScreenRes(int w, int h, int bpp, bool fullscreen, bool resetVideo)
  939. {
  940. if(!recreateWindow(w,h,bpp,fullscreen))
  941. {
  942. throw std::runtime_error("Requested screen resolution is not available\n");
  943. }
  944. }
  945. static void fullScreenChanged()
  946. {
  947. boost::unique_lock<boost::recursive_mutex> lock(*LOCPLINT->pim);
  948. Settings full = settings.write["video"]["fullscreen"];
  949. const bool toFullscreen = full->Bool();
  950. auto bitsPerPixel = screen->format->BitsPerPixel;
  951. auto w = screen->w;
  952. auto h = screen->h;
  953. if(!recreateWindow(w,h,bitsPerPixel,toFullscreen))
  954. {
  955. //will return false and report error if video mode is not supported
  956. return;
  957. }
  958. GH.totalRedraw();
  959. }
  960. static void handleEvent(SDL_Event & ev)
  961. {
  962. if((ev.type==SDL_QUIT) ||(ev.type == SDL_KEYDOWN && ev.key.keysym.sym==SDLK_F4 && (ev.key.keysym.mod & KMOD_ALT)))
  963. {
  964. handleQuit();
  965. return;
  966. }
  967. else if(ev.type == SDL_KEYDOWN && ev.key.keysym.sym==SDLK_F4)
  968. {
  969. Settings full = settings.write["video"]["fullscreen"];
  970. full->Bool() = !full->Bool();
  971. return;
  972. }
  973. else if(ev.type == SDL_USEREVENT)
  974. {
  975. switch(ev.user.code)
  976. {
  977. case FORCE_QUIT:
  978. {
  979. handleQuit(false);
  980. return;
  981. }
  982. break;
  983. case RETURN_TO_MAIN_MENU:
  984. {
  985. endGame();
  986. GH.curInt = CGPreGame::create();;
  987. GH.defActionsDef = 63;
  988. }
  989. break;
  990. case STOP_CLIENT:
  991. client->endGame(false);
  992. break;
  993. case RESTART_GAME:
  994. {
  995. StartInfo si = *client->getStartInfo(true);
  996. endGame();
  997. startGame(&si);
  998. }
  999. break;
  1000. case PREPARE_RESTART_CAMPAIGN:
  1001. {
  1002. auto si = reinterpret_cast<StartInfo *>(ev.user.data1);
  1003. endGame();
  1004. startGame(si);
  1005. }
  1006. break;
  1007. case RETURN_TO_MENU_LOAD:
  1008. endGame();
  1009. CGPreGame::create();
  1010. GH.defActionsDef = 63;
  1011. CGP->update();
  1012. CGP->menu->switchToTab(vstd::find_pos(CGP->menu->menuNameToEntry, "load"));
  1013. GH.curInt = CGP;
  1014. break;
  1015. case FULLSCREEN_TOGGLED:
  1016. fullScreenChanged();
  1017. break;
  1018. default:
  1019. logGlobal->errorStream() << "Unknown user event. Code " << ev.user.code;
  1020. break;
  1021. }
  1022. return;
  1023. }
  1024. else if(ev.type == SDL_WINDOWEVENT)
  1025. {
  1026. switch (ev.window.event) {
  1027. case SDL_WINDOWEVENT_RESTORED:
  1028. fullScreenChanged();
  1029. break;
  1030. }
  1031. return;
  1032. }
  1033. {
  1034. boost::unique_lock<boost::mutex> lock(eventsM);
  1035. events.push(ev);
  1036. }
  1037. }
  1038. static void mainLoop()
  1039. {
  1040. SettingsListener resChanged = settings.listen["video"]["fullscreen"];
  1041. resChanged([](const JsonNode &newState){ CGuiHandler::pushSDLEvent(SDL_USEREVENT, FULLSCREEN_TOGGLED); });
  1042. inGuiThread.reset(new bool(true));
  1043. GH.mainFPSmng->init();
  1044. while(1) //main SDL events loop
  1045. {
  1046. SDL_Event ev;
  1047. while(1 == SDL_PollEvent(&ev))
  1048. {
  1049. handleEvent(ev);
  1050. }
  1051. GH.renderFrame();
  1052. }
  1053. }
  1054. void startGame(StartInfo * options, CConnection *serv/* = nullptr*/)
  1055. {
  1056. if(vm.count("onlyAI"))
  1057. {
  1058. auto ais = vm.count("ai") ? vm["ai"].as<std::vector<std::string>>() : std::vector<std::string>();
  1059. int i = 0;
  1060. for(auto & elem : options->playerInfos)
  1061. {
  1062. elem.second.playerID = PlayerSettings::PLAYER_AI;
  1063. if(i < ais.size())
  1064. elem.second.name = ais[i++];
  1065. }
  1066. }
  1067. client = new CClient;
  1068. CPlayerInterface::howManyPeople = 0;
  1069. switch(options->mode) //new game
  1070. {
  1071. case StartInfo::NEW_GAME:
  1072. case StartInfo::CAMPAIGN:
  1073. case StartInfo::DUEL:
  1074. client->newGame(serv, options);
  1075. break;
  1076. case StartInfo::LOAD_GAME:
  1077. std::string fname = options->mapname;
  1078. boost::algorithm::erase_last(fname,".vlgm1");
  1079. if(!vm.count("loadplayer"))
  1080. client->loadGame(fname);
  1081. else
  1082. client->loadGame(fname,vm.count("loadserver"),vm.count("loadhumanplayerindices") ? vm["loadhumanplayerindices"].as<std::vector<int>>() : std::vector<int>(),vm.count("loadnumplayers") ? vm["loadnumplayers"].as<int>() : 1,vm["loadplayer"].as<int>(),vm.count("loadserverip") ? vm["loadserverip"].as<std::string>() : "", vm.count("loadserverport") ? vm["loadserverport"].as<std::string>() : "3030");
  1083. break;
  1084. }
  1085. client->connectionHandler = new boost::thread(&CClient::run, client);
  1086. }
  1087. void endGame()
  1088. {
  1089. client->endGame();
  1090. vstd::clear_pointer(client);
  1091. }
  1092. void handleQuit(bool ask/* = true*/)
  1093. {
  1094. auto quitApplication = []()
  1095. {
  1096. if(client)
  1097. endGame();
  1098. delete console;
  1099. console = nullptr;
  1100. boost::this_thread::sleep(boost::posix_time::milliseconds(750));
  1101. if(!gNoGUI)
  1102. SDL_Quit();
  1103. std::cout << "Ending...\n";
  1104. exit(0);
  1105. };
  1106. if(client && LOCPLINT && ask)
  1107. {
  1108. CCS->curh->changeGraphic(ECursor::ADVENTURE, 0);
  1109. LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[69], quitApplication, 0);
  1110. }
  1111. else
  1112. {
  1113. quitApplication();
  1114. }
  1115. }