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 23KB

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