Open Source Tomb Raider Engine
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

Command.cpp 24KB

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