Open Source Tomb Raider Engine
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Command.cpp 26KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718
  1. /*!
  2. * \file src/Command.cpp
  3. * \brief OpenRaider command implementation
  4. *
  5. * \author xythobuz
  6. */
  7. #include <fstream>
  8. #include "WindowSDL.h"
  9. #include "global.h"
  10. #include "Console.h"
  11. #include "Entity.h"
  12. #include "Font.h"
  13. #include "Game.h"
  14. #include "math/math.h"
  15. #include "Menu.h"
  16. #include "Sound.h"
  17. #include "TombRaider.h"
  18. #include "utils/strings.h"
  19. #include "utils/time.h"
  20. #include "OpenRaider.h"
  21. int OpenRaider::loadConfig(const char *config) {
  22. assert(config != NULL);
  23. assert(config[0] != '\0');
  24. char *configFile = fullPath(config, 0);
  25. getConsole().print("Loading config from \"%s\"...", configFile);
  26. std::ifstream file(configFile);
  27. if (!file) {
  28. getConsole().print("Could not open file!");
  29. return -1;
  30. }
  31. for (std::string line; std::getline(file, line);) {
  32. if (line.length() == 0)
  33. continue;
  34. int error = command(line);
  35. if (error != 0)
  36. getConsole().print("Error Code: %d", error);
  37. }
  38. file.close();
  39. return 0;
  40. }
  41. int OpenRaider::command(const char *command) {
  42. std::string tmp(command);
  43. return this->command(tmp);
  44. }
  45. int OpenRaider::command(std::string &c) {
  46. // Remove comment, if any
  47. size_t comment = c.find_first_of('#');
  48. if (comment != std::string::npos)
  49. c.erase(comment);
  50. // Execute command
  51. std::stringstream command(c);
  52. std::string cmd;
  53. command >> cmd;
  54. if (cmd.length() == 0)
  55. return 0;
  56. if (cmd.compare("set") == 0) {
  57. return set(command);
  58. } else if (cmd.compare("bind") == 0) {
  59. std::string a, b;
  60. if (!(command >> a >> b)) {
  61. getConsole().print("Invalid use of bind-command");
  62. return -1;
  63. } else {
  64. return bind(a.c_str(), b.c_str());
  65. }
  66. } else if (cmd.compare("quit") == 0) {
  67. exit(0);
  68. } else if (cmd.compare("load") == 0) {
  69. if (!mRunning) {
  70. getConsole().print("Use load command interactively!");
  71. return -999;
  72. }
  73. std::string temp;
  74. command >> temp;
  75. char *tmp = bufferString("%s/%s", mPakDir, temp.c_str());
  76. int error = getGame().loadLevel(tmp);
  77. delete [] tmp;
  78. return error;
  79. } else if (cmd.compare("help") == 0) {
  80. std::string tmp;
  81. if (!(command >> tmp)) {
  82. getConsole().print("Available commands:");
  83. getConsole().print(" load - load a level");
  84. getConsole().print(" set - set a parameter");
  85. getConsole().print(" bind - bind a keyboard/mouse action");
  86. /*
  87. getConsole().print(" sshot - make a screenshot");
  88. getConsole().print(" move - [walk|fly|noclip]");
  89. getConsole().print(" sound - INT - Test play sound");
  90. getConsole().print(" mode - MODE - Render mode");
  91. getConsole().print(" animate - [BOOL|n|p] - Animate models");
  92. getConsole().print(" light - BOOL - GL Lights");
  93. getConsole().print(" fog - BOOL - GL Fog");
  94. getConsole().print(" viewmodel - INT - Change Laras model");
  95. getConsole().print(" pos - Print position info");
  96. getConsole().print(" vmodel - BOOL - View Model");
  97. getConsole().print(" ralpha - BOOL - Room Alpha");
  98. getConsole().print(" vis - BOOL - Use Portals");
  99. getConsole().print(" upf - BOOL - Update Room List Per Frame");
  100. getConsole().print(" entmodel - BOOL");
  101. getConsole().print(" oneroom - BOOL");
  102. getConsole().print(" allrooms - BOOL");
  103. getConsole().print(" ponytail - BOOL");
  104. getConsole().print(" pigtail - BOOL");
  105. getConsole().print(" ponypos - FLOAT FLOAT FLOAT FLOAT - x y z angle");
  106. */
  107. getConsole().print(" help - print command help");
  108. getConsole().print(" quit - exit OpenRaider");
  109. getConsole().print("Use help COMMAND to get additional info");
  110. } else {
  111. return help(tmp);
  112. }
  113. /*
  114. } else if (cmd.compare("mode") == 0) {
  115. std::string mode;
  116. command >> mode;
  117. if (!getGame().isLoaded()) {
  118. getConsole().print("Load a level to set the mode!");
  119. return -1;
  120. }
  121. if (mode.compare("wireframe") == 0) {
  122. getRender().setMode(Render::modeWireframe);
  123. getConsole().print("Wireframe mode");
  124. } else if (mode.compare("solid") == 0) {
  125. getRender().setMode(Render::modeSolid);
  126. getConsole().print("Solid mode");
  127. } else if (mode.compare("texture") == 0) {
  128. getRender().setMode(Render::modeTexture);
  129. getConsole().print("Texture mode");
  130. } else if (mode.compare("vertexlight") == 0) {
  131. getRender().setMode(Render::modeVertexLight);
  132. getConsole().print("Vertexlight mode");
  133. } else if (mode.compare("titlescreen") == 0) {
  134. getRender().setMode(Render::modeLoadScreen);
  135. getConsole().print("Titlescreen mode");
  136. } else {
  137. getConsole().print("Invalid use of mode command (%s)!", mode.c_str());
  138. return -1;
  139. }
  140. } else if (cmd.compare("light") == 0) {
  141. if (args->size() > 0) {
  142. bool b;
  143. if (readBool(args->at(0), &b) < 0) {
  144. getConsole().print("Pass BOOL to light command!");
  145. return -15;
  146. }
  147. if (b)
  148. getRender().setFlags(Render::fGL_Lights);
  149. else
  150. getRender().clearFlags(Render::fGL_Lights);
  151. getConsole().print("GL-Lights are now %s", b ? "on" : "off");
  152. } else {
  153. getConsole().print("Invalid use of light-command!");
  154. return -16;
  155. }
  156. } else if (cmd.compare("fog") == 0) {
  157. if (args->size() > 0) {
  158. bool b;
  159. if (readBool(args->at(0), &b) < 0) {
  160. getConsole().print("Pass BOOL to fog command!");
  161. return -17;
  162. }
  163. if (b)
  164. getRender().setFlags(Render::fFog);
  165. else
  166. getRender().clearFlags(Render::fFog);
  167. getConsole().print("Fog is now %s", b ? "on" : "off");
  168. } else {
  169. getConsole().print("Invalid use of fog-command!");
  170. return -18;
  171. }
  172. } else if (cmd.compare("vmodel") == 0) {
  173. if (args->size() > 0) {
  174. bool b;
  175. if (readBool(args->at(0), &b) < 0) {
  176. getConsole().print("Pass BOOL to vmodel command!");
  177. return -22;
  178. }
  179. if (b)
  180. getRender().setFlags(Render::fViewModel);
  181. else
  182. getRender().clearFlags(Render::fViewModel);
  183. getConsole().print("Viewmodel is now %s", b ? "on" : "off");
  184. } else {
  185. getConsole().print("Invalid use of vmodel-command!");
  186. return -23;
  187. }
  188. } else if (cmd.compare("ralpha") == 0) {
  189. if (args->size() > 0) {
  190. bool b;
  191. if (readBool(args->at(0), &b) < 0) {
  192. getConsole().print("Pass BOOL to ralpha command!");
  193. return -24;
  194. }
  195. if (b)
  196. getRender().setFlags(Render::fRoomAlpha);
  197. else
  198. getRender().clearFlags(Render::fRoomAlpha);
  199. getConsole().print("Room Alpha is now %s", b ? "on" : "off");
  200. } else {
  201. getConsole().print("Invalid use of ralpha-command!");
  202. return -25;
  203. }
  204. } else if (cmd.compare("vis") == 0) {
  205. if (args->size() > 0) {
  206. bool b;
  207. if (readBool(args->at(0), &b) < 0) {
  208. getConsole().print("Pass BOOL to vis command!");
  209. return -28;
  210. }
  211. if (b)
  212. getRender().setFlags(Render::fUsePortals);
  213. else
  214. getRender().clearFlags(Render::fUsePortals);
  215. getConsole().print("Portals are now %s", b ? "on" : "off");
  216. } else {
  217. getConsole().print("Invalid use of vis-command!");
  218. return -29;
  219. }
  220. } else if (cmd.compare("upf") == 0) {
  221. if (args->size() > 0) {
  222. bool b;
  223. if (readBool(args->at(0), &b) < 0) {
  224. getConsole().print("Pass BOOL to upf command!");
  225. return -30;
  226. }
  227. if (b)
  228. getRender().setFlags(Render::fUpdateRoomListPerFrame);
  229. else
  230. getRender().clearFlags(Render::fUpdateRoomListPerFrame);
  231. getConsole().print("URLPF is now %s", b ? "on" : "off");
  232. } else {
  233. getConsole().print("Invalid use of upf-command!");
  234. return -31;
  235. }
  236. } else if (cmd.compare("entmodel") == 0) {
  237. if (args->size() > 0) {
  238. bool b;
  239. if (readBool(args->at(0), &b) < 0) {
  240. getConsole().print("Pass BOOL to entmodel command!");
  241. return -38;
  242. }
  243. if (b)
  244. getRender().setFlags(Render::fEntityModels);
  245. else
  246. getRender().clearFlags(Render::fEntityModels);
  247. getConsole().print("Entmodels are now %s", b ? "on" : "off");
  248. } else {
  249. getConsole().print("Invalid use of entmodel-command!");
  250. return -39;
  251. }
  252. } else if (cmd.compare("oneroom") == 0) {
  253. if (args->size() > 0) {
  254. bool b;
  255. if (readBool(args->at(0), &b) < 0) {
  256. getConsole().print("Pass BOOL to oneroom command!");
  257. return -40;
  258. }
  259. if (b)
  260. getRender().setFlags(Render::fOneRoom);
  261. else
  262. getRender().clearFlags(Render::fOneRoom);
  263. getConsole().print("Rendering one room is now %s", b ? "on" : "off");
  264. } else {
  265. getConsole().print("Invalid use of oneroom-command!");
  266. return -41;
  267. }
  268. } else if (cmd.compare("allrooms") == 0) {
  269. if (args->size() > 0) {
  270. bool b;
  271. if (readBool(args->at(0), &b) < 0) {
  272. getConsole().print("Pass BOOL to allrooms command!");
  273. return -42;
  274. }
  275. if (b)
  276. getRender().setFlags(Render::fAllRooms);
  277. else
  278. getRender().clearFlags(Render::fAllRooms);
  279. getConsole().print("Rendering all rooms is now %s", b ? "on" : "off");
  280. } else {
  281. getConsole().print("Invalid use of allrooms-command!");
  282. return -43;
  283. }
  284. } else if (cmd.compare("ponytail") == 0) {
  285. if (args->size() > 0) {
  286. bool b;
  287. if (readBool(args->at(0), &b) < 0) {
  288. getConsole().print("Pass BOOL to ponytail command!");
  289. return -44;
  290. }
  291. if (b)
  292. getRender().setFlags(Render::fRenderPonytail);
  293. else
  294. getRender().clearFlags(Render::fRenderPonytail);
  295. getConsole().print("Ponytail is now %s", b ? "on" : "off");
  296. } else {
  297. getConsole().print("Invalid use of ponytail-command!");
  298. return -45;
  299. }
  300. } else if (cmd.compare("sshot") == 0) {
  301. if (!mRunning) {
  302. getConsole().print("Use sshot command interactively!");
  303. return -999;
  304. }
  305. char *filename = bufferString("%s/sshots/%s", mBaseDir, VERSION);
  306. bool console = (args->size() > 0) && (strcmp(args->at(0), "console") == 0);
  307. bool menu = (args->size() > 0) && (strcmp(args->at(0), "menu") == 0);
  308. if (!console) {
  309. getConsole().setVisible(false);
  310. if (menu)
  311. getMenu().setVisible(true);
  312. frame();
  313. frame(); // Double buffered
  314. }
  315. getRender().screenShot(filename);
  316. if (!console) {
  317. getConsole().setVisible(true);
  318. if (menu)
  319. getMenu().setVisible(false);
  320. }
  321. getConsole().print("Screenshot stored...");
  322. delete filename;
  323. } else if (cmd.compare("move") == 0) {
  324. if (!mRunning) {
  325. getConsole().print("Use move command interactively!");
  326. return -999;
  327. }
  328. if (args->size() > 0) {
  329. if (getGame().isLoaded()) {
  330. char *move = args->at(0);
  331. if (strcmp(move, "walk") == 0) {
  332. getGame().getLara().setMoveType(Entity::MoveTypeWalk);
  333. getConsole().print("Lara is walking...");
  334. } else if (strcmp(move, "fly") == 0) {
  335. getGame().getLara().setMoveType(Entity::MoveTypeFly);
  336. getConsole().print("Lara is flying...");
  337. } else if (strcmp(move, "noclip") == 0) {
  338. getGame().getLara().setMoveType(Entity::MoveTypeNoClipping);
  339. getConsole().print("Lara is noclipping...");
  340. } else {
  341. getConsole().print("Invalid use of move command (%s)!", move);
  342. return -9;
  343. }
  344. } else {
  345. getConsole().print("Load a level to change the movement type!");
  346. return -10;
  347. }
  348. } else {
  349. getConsole().print("Invalid use of move command!");
  350. return -11;
  351. }
  352. } else if (cmd.compare("sound") == 0) {
  353. if ((!mRunning) || (!getGame().isLoaded())) {
  354. getConsole().print("Use sound command interactively!");
  355. return -999;
  356. }
  357. if (args->size() > 0) {
  358. getSound().play(atoi(args->at(0)));
  359. } else {
  360. getConsole().print("Invalid use of sound command!");
  361. return -12;
  362. }
  363. } else if (cmd.compare("animate") == 0) {
  364. if ((!mRunning) || (!getGame().isLoaded())) {
  365. getConsole().print("Use animate command interactively!");
  366. return -999;
  367. }
  368. if (args->size() > 0) {
  369. char c = args->at(0)[0];
  370. if (c == 'n') {
  371. // Step all skeletal models to their next animation
  372. if (getRender().getFlags() & Render::fAnimateAllModels) {
  373. for (unsigned int i = 0; i < getWorld().sizeEntity(); i++) {
  374. Entity &e = getWorld().getEntity(i);
  375. SkeletalModel &m = e.getModel();
  376. if (e.getAnimation() < (m.size() - 1))
  377. e.setAnimation(e.getAnimation() + 1);
  378. else
  379. e.setAnimation(0);
  380. }
  381. } else {
  382. getConsole().print("Animations need to be enabled!");
  383. }
  384. } else if (c == 'p') {
  385. // Step all skeletal models to their previous animation
  386. if (getRender().getFlags() & Render::fAnimateAllModels) {
  387. for (unsigned int i = 0; i < getWorld().sizeEntity(); i++) {
  388. Entity &e = getWorld().getEntity(i);
  389. SkeletalModel &m = e.getModel();
  390. if (e.getAnimation() > 0)
  391. e.setAnimation(e.getAnimation() - 1);
  392. else
  393. if (m.size() > 0)
  394. e.setAnimation(m.size() - 1);
  395. }
  396. } else {
  397. getConsole().print("Animations need to be enabled!");
  398. }
  399. } else {
  400. // Enable or disable animating all skeletal models
  401. bool b;
  402. if (readBool(args->at(0), &b) < 0) {
  403. getConsole().print("Pass BOOL to animate command!");
  404. return -13;
  405. }
  406. if (b)
  407. getRender().setFlags(Render::fAnimateAllModels);
  408. else
  409. getRender().clearFlags(Render::fAnimateAllModels);
  410. getConsole().print(b ? "Animating all models" : "No longer animating all models");
  411. }
  412. } else {
  413. getConsole().print("Invalid use of animate command!");
  414. return -14;
  415. }
  416. } else if (cmd.compare("viewmodel") == 0) {
  417. if ((!mRunning) || (!getGame().isLoaded())) {
  418. getConsole().print("Use viewmodel command interactively!");
  419. return -999;
  420. }
  421. unsigned int n = atoi(args->at(0));
  422. if (n < getWorld().sizeSkeletalModel())
  423. getGame().getLara().setSkeletalModel(n);
  424. else {
  425. getConsole().print("Invalid SkeletalModel index!");
  426. return -66;
  427. }
  428. } else if (cmd.compare("pos") == 0) {
  429. if ((!mRunning) || (!getGame().isLoaded())) {
  430. getConsole().print("Use pos command interactively!");
  431. return -21;
  432. }
  433. getGame().getLara().print();
  434. } else if (cmd.compare("pigtail") == 0) {
  435. if ((!mRunning) || (!getGame().isLoaded())) {
  436. getConsole().print("Use pigtail command interactively!");
  437. return -999;
  438. }
  439. if (args->size() > 0) {
  440. bool b;
  441. if (readBool(args->at(0), &b) < 0) {
  442. getConsole().print("Pass BOOL to pigtail command!");
  443. return -46;
  444. }
  445. SkeletalModel &tmp = getGame().getLara().getModel();
  446. tmp.setPigTail(b);
  447. getConsole().print("Pigtail is now %s", b ? "on" : "off");
  448. } else {
  449. getConsole().print("Invalid use of pigtail-command!");
  450. return -47;
  451. }
  452. } else if (cmd.compare("ponypos") == 0) {
  453. if ((!mRunning) || (!getGame().isLoaded())) {
  454. getConsole().print("Use ponypos command interactively!");
  455. return -999;
  456. }
  457. if (args->size() > 3) {
  458. SkeletalModel &tmp = getGame().getLara().getModel();
  459. tmp.setPonyPos((float)atof(args->at(0)), (float)atof(args->at(1)),
  460. (float)atof(args->at(2)), (float)atof(args->at(3)));
  461. } else {
  462. getConsole().print("Invalid use of ponypos-command!");
  463. return -48;
  464. }
  465. */
  466. } else {
  467. getConsole().print("Unknown command: %s", cmd.c_str());
  468. return -50;
  469. }
  470. return 0;
  471. }
  472. int OpenRaider::help(std::string &cmd) {
  473. if (cmd.compare("set") == 0) {
  474. getConsole().print("set-Command Usage:");
  475. getConsole().print(" set VAR VAL");
  476. getConsole().print("Available Variables:");
  477. getConsole().print(" basedir STRING");
  478. getConsole().print(" pakdir STRING");
  479. getConsole().print(" audiodir STRING");
  480. getConsole().print(" datadir STRING");
  481. getConsole().print(" font STRING");
  482. getConsole().print(" gldriver STRING");
  483. getConsole().print(" size INT INT");
  484. getConsole().print(" fullscreen BOOL");
  485. getConsole().print(" audio BOOL");
  486. getConsole().print(" volume BOOL");
  487. getConsole().print(" mouse_x FLOAT");
  488. getConsole().print(" mouse_y FLOAT");
  489. getConsole().print(" fps BOOL");
  490. getConsole().print("Enclose STRINGs with \"\"!");
  491. } else if (cmd.compare("bind") == 0) {
  492. getConsole().print("bind-Command Usage:");
  493. getConsole().print(" bind ACTION KEY");
  494. getConsole().print("Available Actions:");
  495. getConsole().print(" menu");
  496. getConsole().print(" console");
  497. getConsole().print(" forward");
  498. getConsole().print(" backward");
  499. getConsole().print(" left");
  500. getConsole().print(" right");
  501. getConsole().print(" jump");
  502. getConsole().print(" crouch");
  503. getConsole().print(" use");
  504. getConsole().print(" holster");
  505. getConsole().print("Key-Format:");
  506. getConsole().print(" 'a' or '1' for character/number keys");
  507. getConsole().print(" \"leftctrl\" for symbols and special keys");
  508. } else if (cmd.compare("load") == 0) {
  509. getConsole().print("load-Command Usage:");
  510. getConsole().print(" load levelfile.name");
  511. /*
  512. } else if (cmd.compare("game") == 0) {
  513. getConsole().print("Use \"game help\" for more info");
  514. } else if (cmd.compare("sshot") == 0) {
  515. getConsole().print("sshot-Command Usage:");
  516. getConsole().print(" sshot [console|menu]");
  517. getConsole().print("Add console/menu to capture them too");
  518. } else if (cmd.compare("sound") == 0) {
  519. getConsole().print("sound-Command Usage:");
  520. getConsole().print(" sound INT");
  521. getConsole().print("Where INT is a valid sound ID integer");
  522. } else if (cmd.compare("move") == 0) {
  523. getConsole().print("move-Command Usage:");
  524. getConsole().print(" move COMMAND");
  525. getConsole().print("Where COMMAND is one of the following:");
  526. getConsole().print(" walk");
  527. getConsole().print(" fly");
  528. getConsole().print(" noclip");
  529. } else if (cmd.compare("mode") == 0) {
  530. getConsole().print("mode-Command Usage:");
  531. getConsole().print(" mode MODE");
  532. getConsole().print("Where MODE is one of the following:");
  533. getConsole().print(" wireframe");
  534. getConsole().print(" solid");
  535. getConsole().print(" texture");
  536. getConsole().print(" vertexlight");
  537. getConsole().print(" titlescreen");
  538. } else if (cmd.compare("animate") == 0) {
  539. getConsole().print("animate-Command Usage:");
  540. getConsole().print(" animate [n|p|BOOL]");
  541. getConsole().print("Where the commands have the following meaning:");
  542. getConsole().print(" BOOL to (de)activate animating all models");
  543. getConsole().print(" n to step all models to their next animation");
  544. getConsole().print(" p to step all models to their previous animation");
  545. */
  546. } else {
  547. getConsole().print("No help available for %s", cmd.c_str());
  548. return -1;
  549. }
  550. return 0;
  551. }
  552. char *OpenRaider::expandDirectoryNames(const char *s) {
  553. assert(s != NULL);
  554. assert(s[0] != '\0');
  555. char *result = bufferString("%s", s);
  556. if (mPakDir != NULL) {
  557. char *tmp = stringReplace(s, "$(pakdir)", mPakDir);
  558. delete [] result;
  559. result = tmp;
  560. }
  561. if (mAudioDir != NULL) {
  562. char *tmp = stringReplace(s, "$(audiodir)", mAudioDir);
  563. delete [] result;
  564. result = tmp;
  565. }
  566. if (mDataDir != NULL) {
  567. char *tmp = stringReplace(s, "$(datadir)", mDataDir);
  568. delete [] result;
  569. result = tmp;
  570. }
  571. if (mBaseDir != NULL) {
  572. char *tmp = stringReplace(result, "$(basedir)", mBaseDir);
  573. delete [] result;
  574. result = tmp;
  575. }
  576. return result;
  577. }
  578. #define CHANGE_DIR_WITH_EXPANSION(a) do { \
  579. std::string temp; \
  580. command >> temp; \
  581. const char *value = temp.c_str(); \
  582. char *quotes = stringRemoveQuotes(value); \
  583. char *tmp = expandDirectoryNames(quotes); \
  584. a = fullPath(tmp, 0); \
  585. delete [] tmp; \
  586. delete [] quotes; \
  587. } while(false)
  588. int OpenRaider::set(std::istream &command) {
  589. std::string var;
  590. command >> var >> std::boolalpha;
  591. if (var.compare("size") == 0) {
  592. unsigned int w = DEFAULT_WIDTH, h = DEFAULT_HEIGHT;
  593. if (!(command >> w >> h)) {
  594. getConsole().print("set-size-Error: Invalid value(s)");
  595. return -2;
  596. }
  597. getWindow().setSize(w, h);
  598. } else if (var.compare("fullscreen") == 0) {
  599. bool fullscreen = false;
  600. if (!(command >> fullscreen)) {
  601. getConsole().print("set-fullscreen-Error: Invalid value");
  602. return -3;
  603. }
  604. getWindow().setFullscreen(fullscreen);
  605. } else if (var.compare("gldriver") == 0) {
  606. std::string driver;
  607. command >> driver;
  608. getWindow().setDriver(driver.c_str());
  609. } else if (var.compare("audio") == 0) {
  610. bool audio = false;
  611. if (!(command >> audio)) {
  612. getConsole().print("set-audio-Error: Invalid value");
  613. return -4;
  614. }
  615. getSound().setEnabled(audio);
  616. } else if (var.compare("volume") == 0) {
  617. float vol = 1.0f;
  618. if (!(command >> vol)) {
  619. getConsole().print("set-volume-Error: Invalid value");
  620. return -5;
  621. }
  622. getSound().setVolume(vol);
  623. } else if (var.compare("mouse_x") == 0) {
  624. float sense = 1.0f;
  625. if (!(command >> sense)) {
  626. getConsole().print("set-mouse_x-Error: Invalid value");
  627. return -6;
  628. }
  629. getCamera().setSensitivityX(OR_DEG_TO_RAD(sense));
  630. } else if (var.compare("mouse_y") == 0) {
  631. float sense = 1.0f;
  632. if (!(command >> sense)) {
  633. getConsole().print("set-mouse_y-Error: Invalid value");
  634. return -7;
  635. }
  636. getCamera().setSensitivityY(OR_DEG_TO_RAD(sense));
  637. } else if (var.compare("fps") == 0) {
  638. bool fps = false;
  639. if (!(command >> fps)) {
  640. getConsole().print("set-fps-Error: Invalid value");
  641. return -8;
  642. }
  643. mFPS = fps;
  644. } else if (var.compare("basedir") == 0) {
  645. CHANGE_DIR_WITH_EXPANSION(mBaseDir);
  646. } else if (var.compare("pakdir") == 0) {
  647. CHANGE_DIR_WITH_EXPANSION(mPakDir);
  648. } else if (var.compare("audiodir") == 0) {
  649. CHANGE_DIR_WITH_EXPANSION(mAudioDir);
  650. } else if (var.compare("datadir") == 0) {
  651. CHANGE_DIR_WITH_EXPANSION(mDataDir);
  652. } else if (var.compare("font") == 0) {
  653. std::string temp;
  654. command >> temp;
  655. const char *value = temp.c_str();
  656. char *quotes = stringReplace(value, "\"", "");
  657. char *tmp = expandDirectoryNames(quotes);
  658. getFont().setFont(tmp);
  659. delete [] tmp;
  660. delete [] quotes;
  661. } else {
  662. getConsole().print("set-Error: Unknown variable (%s)", var.c_str());
  663. return -1;
  664. }
  665. return 0;
  666. }
  667. int OpenRaider::bind(const char *action, const char *key) {
  668. assert(action != NULL);
  669. assert(action[0] != '\0');
  670. assert(key != NULL);
  671. assert(key[0] != '\0');
  672. ActionEvents e = stringToActionEvent(action);
  673. if (e == ActionEventCount) {
  674. getConsole().print("bind-Error: Unknown action (%s --> %s)", key, action);
  675. return -1;
  676. }
  677. KeyboardButton c = stringToKeyboardButton(key);
  678. if (c == unknownKey) {
  679. getConsole().print("bind-Error: Unknown key (%s)", key);
  680. return -2;
  681. }
  682. keyBindings[e] = c;
  683. return 0;
  684. }