RigsofRods  2023.09
Soft-body Physics Simulation
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ConsoleCmd.cpp
Go to the documentation of this file.
1 /*
2  This source file is part of Rigs of Rods
3  Copyright 2005-2012 Pierre-Michel Ricordel
4  Copyright 2007-2012 Thomas Fischer
5  Copyright 2013-2020 Petr Ohlidal
6 
7  For more information, see http://www.rigsofrods.org/
8 
9  Rigs of Rods is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License version 3, as
11  published by the Free Software Foundation.
12 
13  Rigs of Rods is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with Rigs of Rods. If not, see <http://www.gnu.org/licenses/>.
20 */
21 
22 #include "Application.h"
23 #include "Actor.h"
24 #include "ActorManager.h"
25 #include "CameraManager.h"
26 #include "Character.h"
27 #include "Console.h"
28 #include "GameContext.h"
29 #include "GfxScene.h"
30 #include "GUIManager.h"
31 #include "IGfxWater.h"
32 #include "Language.h"
33 #include "Network.h"
34 #include "OverlayWrapper.h"
35 #include "RoRnet.h"
36 #include "RoRVersion.h"
37 #include "ScriptEngine.h"
38 #include "Terrain.h"
39 #include "TerrainObjectManager.h"
40 #include "Utils.h"
41 
42 #include <algorithm>
43 #include <Ogre.h>
44 #include <fmt/core.h>
45 
47 
48 using namespace RoR;
49 
52 
53 // -------------------------------------------------------------------------------------
54 // Builtin console commands.
55 
58 
59 class GravityCmd: public ConsoleCmd
60 {
61 public:
62  GravityCmd(): ConsoleCmd("gravity", "[<number> or <constant>]", _L("Get or set terrain gravity. Constants: earth/moon/mars/jupiter.")) {}
63 
64  void Run(Ogre::StringVector const& args) override
65  {
66  if (!this->CheckAppState(AppState::SIMULATION))
67  return;
68 
69  Str<200> reply;
70  if (args.size() == 1)
71  {
72  reply << _L("Current gravity is: ") << App::GetGameContext()->GetTerrain()->getGravity();
73  }
74  else
75  {
76  if (args[1] == "earth") { App::GetGameContext()->GetTerrain()->setGravity(DEFAULT_GRAVITY); }
77  else if (args[1] == "moon") { App::GetGameContext()->GetTerrain()->setGravity(-1.62f); }
78  else if (args[1] == "mars") { App::GetGameContext()->GetTerrain()->setGravity(-3.711f); }
79  else if (args[1] == "jupiter") { App::GetGameContext()->GetTerrain()->setGravity(-24.8f); }
80  else { App::GetGameContext()->GetTerrain()->setGravity(PARSEREAL(args[1])); }
81 
82  reply << _L("Gravity set to: ") << App::GetGameContext()->GetTerrain()->getGravity();
83  }
84 
86  }
87 };
88 
90 {
91 public:
92  WaterlevelCmd(): ConsoleCmd("waterlevel", "[<number>]", _L("Get or set water level.")) {}
93 
94  void Run(Ogre::StringVector const& args) override
95  {
96  if (!this->CheckAppState(AppState::SIMULATION))
97  return;
98 
99  Str<200> reply;
100  Console::MessageType reply_type;
101  reply << m_name << ": ";
102  if (!App::GetGameContext()->GetTerrain()->getWater())
103  {
104  reply_type = Console::CONSOLE_SYSTEM_ERROR;
105  reply << _L("This terrain does not have water.");
106  }
107  else
108  {
109  reply_type = Console::CONSOLE_SYSTEM_REPLY;
110  if (args.size() > 1)
111  {
112  auto water = App::GetGameContext()->GetTerrain()->getWater();
113  float height = (args[1] == "default") ? App::GetGameContext()->GetTerrain()->getWaterHeight() : PARSEREAL(args[1]);
114  water->SetStaticWaterHeight(height);
115  }
116  reply << _L ("Water level set to: ") << App::GetGameContext()->GetTerrain()->getWater()->GetStaticWaterHeight();
117  }
119  }
120 };
121 
123 {
124 public:
125  TerrainheightCmd(): ConsoleCmd("terrainheight", "[]", _L("Get elevation of terrain at current position")) {}
126 
127  void Run(Ogre::StringVector const& args) override
128  {
129  if (!this->CheckAppState(AppState::SIMULATION))
130  return;
131 
132  ROR_ASSERT(App::GetGameContext()->GetTerrain());
133 
134  Str<200> reply;
135  reply << m_name << ": ";
137  Ogre::Vector3 pos;
138  ActorPtr const actor = App::GetGameContext()->GetPlayerActor();
139  if (actor)
140  {
141  pos = actor->getPosition();
142 
143  }
144  else
145  {
146  ROR_ASSERT(App::GetGameContext()->GetPlayerCharacter());
148  }
149  reply << _L("Terrain height at position: ")
150  << "x: " << pos.x << " z: " << pos.z << " = "
151  << App::GetGameContext()->GetTerrain()->getHeightAt(pos.x, pos.z);
153  }
154 };
155 
157 {
158 public:
159  SpawnobjectCmd(): ConsoleCmd("spawnobject", "<odef name>", _L("spawnobject - spawn a object at the player position")) {}
160 
161  void Run(Ogre::StringVector const& args) override
162  {
163  if (!this->CheckAppState(AppState::SIMULATION))
164  return;
165 
166  ROR_ASSERT(App::GetGameContext()->GetPlayerCharacter());
167  ROR_ASSERT(App::GetGameContext()->GetTerrain());
168 
169  Str<200> reply;
170  reply << m_name << ": ";
171  Console::MessageType reply_type;
172 
173  try
174  {
175  if (args.size() == 1)
176  {
177  reply_type = Console::CONSOLE_SYSTEM_ERROR;
178  reply << _L("Missing parameter: ") << m_usage;
179  }
180  else
181  {
182  Ogre::Vector3 pos = App::GetGameContext()->GetPlayerCharacter()->getPosition();
183  if (App::GetGameContext()->GetTerrain()->getObjectManager()->LoadTerrainObject(args[1], pos, Ogre::Vector3::ZERO, "Console", ""))
184  {
185  reply_type = Console::CONSOLE_SYSTEM_REPLY;
186  reply << _L("Spawned object at position: ") << "x: " << pos.x << " z: " << pos.z;
187  }
188  else
189  {
190  reply_type = Console::CONSOLE_SYSTEM_ERROR;
191  reply << _L("Could not spawn object");
192  }
193  }
194  }
195  catch (std::exception& e)
196  {
197  reply_type = Console::CONSOLE_SYSTEM_ERROR;
198  reply << e.what();
199  }
201  }
202 };
203 
204 class LogCmd: public ConsoleCmd
205 {
206 public:
207  LogCmd(): ConsoleCmd("log", "[]", _L("log - toggles log output on the console")) {}
208 
209  void Run(Ogre::StringVector const& args) override
210  {
211  Str<200> reply;
212  reply << m_name << ": ";
214 
215  // switch to console logging
216  bool now_logging = !App::diag_log_console_echo->getBool();
217  const char* msg = (now_logging) ? " logging to console enabled" : " logging to console disabled";
218  reply << _L(msg);
219  App::diag_log_console_echo->setVal(now_logging);
220 
222  }
223 };
224 
225 class VerCmd: public ConsoleCmd
226 {
227 public:
228  VerCmd(): ConsoleCmd("ver", "[]", _L("ver - shows the Rigs of Rods version")) {}
229 
230  void Run(Ogre::StringVector const& args) override
231  {
232  Str<200> reply;
233  reply << m_name << ": ";
235 
236  reply << "Rigs of Rods " << ROR_VERSION_STRING
237  << " (" << RORNET_VERSION << ") ["
238  << ROR_BUILD_DATE << ", " << ROR_BUILD_TIME << "]";
239 
241  }
242 };
243 
244 class PosCmd: public ConsoleCmd
245 {
246 public:
247  PosCmd(): ConsoleCmd("pos", "[]", _L("pos - outputs the current position")) {}
248 
249  void Run(Ogre::StringVector const& args) override
250  {
251  if (!this->CheckAppState(AppState::SIMULATION))
252  return;
253 
254  Str<200> reply;
255  reply << m_name << ": ";
257 
259  if (!b && App::GetGameContext()->GetPlayerCharacter())
260  {
261  Ogre::Vector3 pos = App::GetGameContext()->GetPlayerCharacter()->getPosition();
262  reply << _L("Character position: ") << "x: " << pos.x << " y: " << pos.y << " z: " << pos.z;
263  }
264  else if (b)
265  {
266  Ogre::Vector3 pos = b->getPosition();
267  reply << _L("Vehicle position: ") << "x: " << pos.x << " y: " << pos.y << " z: " << pos.z;
268  }
269 
271  }
272 };
273 
274 class GotoCmd: public ConsoleCmd
275 {
276 public:
277  GotoCmd(): ConsoleCmd("goto", "<x> <y> <z>", _L("goto <x> <y> <z> - jumps to the mentioned position")) {}
278 
279  void Run(Ogre::StringVector const& args) override
280  {
281  if (!this->CheckAppState(AppState::SIMULATION))
282  return;
283 
284  Str<200> reply;
285  reply << m_name << ": ";
286  Console::MessageType reply_type;
287 
288  if (args.size() != 4)
289  {
290  reply_type = Console::CONSOLE_HELP;
291  reply <<_L("usage: goto x y z");
292  }
293  else
294  {
295  reply_type = Console::CONSOLE_SYSTEM_REPLY;
296  Ogre::Vector3 pos(PARSEREAL(args[1]), PARSEREAL(args[2]), PARSEREAL(args[3]));
297 
299  if (!b && App::GetGameContext()->GetPlayerCharacter())
300  {
302  reply << _L("Character position set to: ") << "x: " << pos.x << " y: " << pos.y << " z: " << pos.z;
303  }
304  else if (b)
305  {
306  b->resetPosition(pos, false);
308  reply << _L("Vehicle position set to: ") << "x: " << pos.x << " y: " << pos.y << " z: " << pos.z;
309  }
310  }
311 
313  }
314 };
315 
316 
317 class AsCmd: public ConsoleCmd
318 {
319 public:
320  AsCmd(): ConsoleCmd("as", "<code>", _L("Run AngelScript code snippet")) {}
321 
322  void Run(Ogre::StringVector const& args) override
323  {
324  if (!this->CheckAppState(AppState::SIMULATION))
325  return;
326 
327  Str<200> reply;
328  reply << m_name << ": ";
329  Console::MessageType reply_type;
330 
331 #ifdef USE_ANGELSCRIPT
332  // we want to notify any running scripts that we might change something (prevent cheating)
334 
335  // Re-compose the code snippet
336  Str<1000> code;
337  for (int i = 1; i < args.size(); ++i)
338  {
339  code << " " << args[i];
340  }
341 
342  // Echo the code back to console user.
343  reply_type = Console::CONSOLE_SYSTEM_REPLY;
344  reply << " >>> " << code.ToCStr();
346 
347  // Run the code - will output script messages/AngelScript errors.
349 #else
350  reply_type = Console::CONSOLE_SYSTEM_ERROR;
351  reply << _L("Scripting disabled in this build");
353 #endif
354  }
355 };
356 
358 {
359 public:
360  SpeedOfSoundCmd(): ConsoleCmd("speedofsound", "[]", _L("speedofsound - outputs the current speed of sound")) {}
361 
362  void Run(Ogre::StringVector const& args) override
363  {
364  if (!this->CheckAppState(AppState::SIMULATION))
365  return;
366 
367  Str<200> reply;
368  reply << m_name << ": ";
370 
372  if (sound_manager == nullptr)
373  {
374  reply << _L("unable to get sound manager");
375  }
376  else
377  {
378  reply << _L("Current speed of sound: ") << sound_manager->GetSpeedOfSound();
379  }
380 
382  }
383 };
384 
385 class QuitCmd: public ConsoleCmd
386 {
387 public:
388  QuitCmd(): ConsoleCmd("quit", "[]", _L("quit - exit Rigs of Rods")) {}
389 
390  void Run(Ogre::StringVector const& args) override
391  {
393  }
394 };
395 
396 class HelpCmd: public ConsoleCmd
397 {
398 public:
399  HelpCmd(): ConsoleCmd("help", "[]", _L("help - information on commands (this)")) {}
400 
401  void Run(Ogre::StringVector const& args) override
402  {
404  Console::CONSOLE_TITLE, _L("Available commands:"));
405 
406  Str<500> line;
407  for (auto& cmd_pair: App::GetConsole()->getCommands())
408  {
409  line.Clear() << cmd_pair.second->getName() << " "
410  << cmd_pair.second->GetUsage() << " - " << cmd_pair.second->GetDoc();
411 
413  Console::CONSOLE_HELP, line.ToCStr());
414  }
415 
417  Console::CONSOLE_TITLE, _L("Tips:"));
419  Console::CONSOLE_HELP, _L("- use Arrow Up/Down Keys in the InputBox to reuse old messages"));
420  }
421 };
422 
423 class LoadScriptCmd : public ConsoleCmd
424 {
425 public:
426  LoadScriptCmd() : ConsoleCmd("loadscript", "[filename]", _L("Runs an AngelScript file")) {}
427 
428  void Run(Ogre::StringVector const& args) override
429  {
430  Str<200> reply;
431  reply << m_name << ": ";
432  Console::MessageType reply_type;
433 
434 #ifdef USE_ANGELSCRIPT
435  if (args.size() == 1)
436  {
437  reply_type = Console::CONSOLE_SYSTEM_ERROR;
438  reply << _L("Missing parameter: ") << m_usage;
439  }
440  else
441  {
443  if (id == SCRIPTUNITID_INVALID)
444  {
445  reply_type = Console::CONSOLE_SYSTEM_ERROR;
446  reply << _L("Failed to load script. See 'Angelscript.log' or use console command `log` and retry.");
447  }
448  else
449  {
450  reply_type = Console::CONSOLE_SYSTEM_REPLY;
451  reply << fmt::format(_L("Script '{}' running with ID '{}'"), args[1], id);
452  }
453  }
454 #else
455  reply_type = Console::CONSOLE_SYSTEM_ERROR;
456  reply << _L("Scripting disabled in this build");
457 #endif
458 
460  }
461 };
462 
463 // -------------------------------------------------------------------------------------
464 // CVar (builtin) console commmands
465 
466 class VarsCmd: public ConsoleCmd
467 {
468 public:
469  VarsCmd(): ConsoleCmd("vars", "[<expr> ...]", _L("Print cvars with one of <expr> in name")) {}
470 
471  void Run(Ogre::StringVector const& args) override
472  {
473  for (auto& pair: App::GetConsole()->getCVars())
474  {
475  bool match = args.size() == 1;
476  for (size_t i = 1; i < args.size(); ++i)
477  {
478  if (pair.first.find(args[i]) != std::string::npos)
479  {
480  match = true;
481  break;
482  }
483  }
484 
485  if (match)
486  {
487  Str<200> reply;
488  reply << "vars: " << pair.first << "=" << pair.second->getStr() << " (";
489 
490  if (pair.second->hasFlag(CVAR_TYPE_BOOL)) { reply << "bool"; }
491  else if (pair.second->hasFlag(CVAR_TYPE_INT)) { reply << "int"; }
492  else if (pair.second->hasFlag(CVAR_TYPE_FLOAT)) { reply << "float"; }
493  else { reply << "string"; }
494 
495  if (pair.second->hasFlag(CVAR_ARCHIVE)) { reply << ", archive"; }
496  if (pair.second->hasFlag(CVAR_NO_LOG)) { reply << ", no log"; }
497 
498  reply << ")";
500  }
501  }
502  }
503 };
504 
505 class SetCmd: public ConsoleCmd
506 {
507 public:
508  SetCmd(): ConsoleCmd("set", "<cvar> [<flags>] [<value>]", _L("Get or set value of existing CVar")) {}
509 
510  void Run(Ogre::StringVector const& args) override
511  {
512  Str<200> reply;
513  reply << m_name << ": ";
515 
516  if (args.size() == 1)
517  {
518  reply_type = Console::CONSOLE_HELP;
519  reply << this->GetUsage() << " - " << this->GetDoc();
520  }
521  else
522  {
523  CVar* cvar = App::GetConsole()->cVarFind(args[1]);
524  if (cvar)
525  {
526  if (args.size() > 2)
527  {
528  App::GetConsole()->cVarAssign(cvar, args[2]);
529  }
530  reply_type = Console::CONSOLE_SYSTEM_REPLY;
531  reply << cvar->getName() << " = " << cvar->getStr();
532  }
533  else
534  {
535  reply_type = Console::CONSOLE_SYSTEM_ERROR;
536  reply << _L("No such CVar: ") << args[1];
537  }
538  }
539 
541  }
542 };
543 
544 class SetCVarCmd: public ConsoleCmd // Generic
545 {
546 public:
547  SetCVarCmd(std::string const& name, std::string const& usage, std::string const& doc, int flag):
548  ConsoleCmd(name, usage, doc), m_cvar_flag(flag)
549  {}
550 
551  void Run(Ogre::StringVector const& args) override
552  {
553  Str<200> reply;
554  reply << m_name << ": ";
555  Console::MessageType reply_type;
556 
557  if (args.size() == 1)
558  {
559  reply_type = Console::CONSOLE_HELP;
560  reply << this->GetUsage() << " - " << this->GetDoc() << "Switches: --autoapply/--allowstore/--autostore";
561  }
562  else
563  {
564  int flags = m_cvar_flag;
565  size_t i;
566  for (i = 1; i < args.size(); ++i)
567  {
568  if (args[i] == "--archive") { flags |= CVAR_ARCHIVE; }
569  else break; // Exit loop on first non-switch arg!
570  }
571 
572  if (i == args.size()) // Only switches but no cvar?
573  {
574  reply_type = Console::CONSOLE_HELP;
575  reply << this->GetUsage() << " - " << this->GetDoc() << "Switches: --archive";
576  }
577  else
578  {
579  CVar* cvar = App::GetConsole()->cVarGet(args[i], flags);
580  if (args.size() > (i+1))
581  {
582  App::GetConsole()->cVarAssign(cvar, args[i+1]);
583  }
584  reply_type = Console::CONSOLE_SYSTEM_REPLY;
585  reply << cvar->getName() << " = " << cvar->getStr();
586  }
587  }
588 
590  }
591 private:
593 };
594 
596 {
597 public:
598  SetstringCmd(): SetCVarCmd("setstring", "<cvar> [<value>]", _L("Set or create string CVar"), /*flag=*/0) {}
599 };
600 
601 class SetboolCmd: public SetCVarCmd
602 {
603 public:
604  SetboolCmd(): SetCVarCmd("setbool", "<cvar> [<value>]", _L("Set or create boolean CVar"), CVAR_TYPE_BOOL) {}
605 };
606 
607 class SetintCmd: public SetCVarCmd
608 {
609 public:
610  SetintCmd(): SetCVarCmd("setint", "<cvar> [<value>]", _L("Set or create integer CVar"), CVAR_TYPE_INT) {}
611 };
612 
613 class SetfloatCmd: public SetCVarCmd
614 {
615 public:
616  SetfloatCmd(): SetCVarCmd("setfloat", "<cvar> [<value>]", _L("Set or create real-number CVar"), CVAR_TYPE_FLOAT) {}
617 };
618 
619 class ClearCmd: public ConsoleCmd
620 {
621 public:
622  ClearCmd(): ConsoleCmd("clear", "[<type>]", _L("Clear console history. Types: all/info/net/chat/terrn/actor/script")) {}
623 
624  void Run(Ogre::StringVector const& args) override
625  {
626  if (args.size() < 2 || args[1] == "all")
627  {
629  lock.messages.clear();
630  }
631  else
632  {
633  // Create a predicate function
634  std::function<bool(Console::Message const& m)> filter_fn;
635  if (args[1] == "chat")
636  {
637  filter_fn = [](Console::Message const& m){ return m.cm_type == Console::CONSOLE_SYSTEM_NETCHAT; };
638  }
639  else if (args[1] == "net") // Chat and user notifications
640  {
641  filter_fn = [](Console::Message const& m){ return m.cm_net_userid != 0; };
642  }
643  else
644  {
646  bool valid = false;
647  if (args[1] == "info") { area = Console::CONSOLE_MSGTYPE_INFO; valid = true; }
648  else if (args[1] == "terrn") { area = Console::CONSOLE_MSGTYPE_TERRN; valid = true; }
649  else if (args[1] == "actor") { area = Console::CONSOLE_MSGTYPE_ACTOR; valid = true; }
650  else if (args[1] == "script") { area = Console::CONSOLE_MSGTYPE_SCRIPT; valid = true; }
651 
652  if (valid)
653  {
654  filter_fn = [area](Console::Message const& m) { return m.cm_area == area; };
655  }
656  else
657  {
659  fmt::format(_L("No such message type: {}"), args[1]));
660  }
661  }
662 
664  // Shove unwanted entries to the end
665  auto erase_begin = std::remove_if(lock.messages.begin(), lock.messages.end(), filter_fn);
666  // Erase unwanted
667  lock.messages.erase(erase_begin, lock.messages.end());
668  }
669  }
670 };
671 
673 
674 // -------------------------------------------------------------------------------------
675 // Console integration
676 
678 {
679  ConsoleCmd* cmd = nullptr;
680 
681  // Classics
682  cmd = new GravityCmd(); m_commands.insert(std::make_pair(cmd->getName(), cmd));
683  cmd = new WaterlevelCmd(); m_commands.insert(std::make_pair(cmd->getName(), cmd));
684  cmd = new TerrainheightCmd(); m_commands.insert(std::make_pair(cmd->getName(), cmd));
685  cmd = new SpawnobjectCmd(); m_commands.insert(std::make_pair(cmd->getName(), cmd));
686  cmd = new LogCmd(); m_commands.insert(std::make_pair(cmd->getName(), cmd));
687  cmd = new VerCmd(); m_commands.insert(std::make_pair(cmd->getName(), cmd));
688  cmd = new PosCmd(); m_commands.insert(std::make_pair(cmd->getName(), cmd));
689  cmd = new GotoCmd(); m_commands.insert(std::make_pair(cmd->getName(), cmd));
690  cmd = new AsCmd(); m_commands.insert(std::make_pair(cmd->getName(), cmd));
691  cmd = new QuitCmd(); m_commands.insert(std::make_pair(cmd->getName(), cmd));
692  cmd = new HelpCmd(); m_commands.insert(std::make_pair(cmd->getName(), cmd));
693  // Additions
694  cmd = new ClearCmd(); m_commands.insert(std::make_pair(cmd->getName(), cmd));
695  cmd = new LoadScriptCmd(); m_commands.insert(std::make_pair(cmd->getName(), cmd));
696  cmd = new SpeedOfSoundCmd(); m_commands.insert(std::make_pair(cmd->getName(), cmd));
697  // CVars
698  cmd = new SetCmd(); m_commands.insert(std::make_pair(cmd->getName(), cmd));
699  cmd = new SetstringCmd(); m_commands.insert(std::make_pair(cmd->getName(), cmd));
700  cmd = new SetboolCmd(); m_commands.insert(std::make_pair(cmd->getName(), cmd));
701  cmd = new SetintCmd(); m_commands.insert(std::make_pair(cmd->getName(), cmd));
702  cmd = new SetfloatCmd(); m_commands.insert(std::make_pair(cmd->getName(), cmd));
703  cmd = new VarsCmd(); m_commands.insert(std::make_pair(cmd->getName(), cmd));
704 }
705 
706 void Console::doCommand(std::string msg)
707 {
708  if (msg[0] == '/' || msg[0] == '\\')
709  {
711  _L("Using slashes before commands are deprecated, you can now type command without any slashes"));
712  msg.erase(msg.begin());
713  }
714 
715  if (msg[0] == '!')
716  {
717  // Server commands - pass through to multiplayer chat
718  App::GetNetwork()->BroadcastChatMsg(msg.c_str());
719  return;
720  }
721 
722  Ogre::StringVector args = Ogre::StringUtil::split(msg, " ");
723 
724  auto found = m_commands.find(args[0]);
725  if (found != m_commands.end())
726  {
727  found->second->Run(args);
728  return;
729  }
730 
731  CVar* cvar = this->cVarFind(args[0]);
732  if (cvar)
733  {
734  Str<200> reply;
735  reply << cvar->getName() << " = " << cvar->getStr();
737  return;
738  }
739 
740  Str<200> reply;
741  reply << _L("unknown command: ") << msg;
743 }
744 
745 // -------------------------------------------------------------------------------------
746 // Helpers
747 
749 {
750  if (App::app_state->getEnum<AppState>() == state)
751  return true;
752 
753  Str<200> reply;
754  reply << m_name << ": ";
755  if (state == AppState::SIMULATION)
756  {
757  reply << _L("Only allowed when simulation is running");
758  }
759  else
760  {
761  reply << _L("Not allowed in current app state");
762  }
764  return false;
765 }
766 
767  // Currently unused: _L("Please enter a correct value. ")
768 
ROR_ASSERT
#define ROR_ASSERT(_EXPR)
Definition: Application.h:40
GameContext.h
Game state manager and message-queue provider.
RoR::CVAR_NO_LOG
@ CVAR_NO_LOG
Will not be written to RoR.log.
Definition: CVar.h:42
RoR::Actor::resetPosition
void resetPosition(Ogre::Vector3 translation, bool setInitPosition)
Moves the actor to given world coords (pivot point is node 0).
Definition: Actor.cpp:1349
SpawnobjectCmd::SpawnobjectCmd
SpawnobjectCmd()
Definition: ConsoleCmd.cpp:159
RoR::App::GetNetwork
Network * GetNetwork()
Definition: Application.cpp:303
SpawnobjectCmd
Definition: ConsoleCmd.cpp:156
VarsCmd
Definition: ConsoleCmd.cpp:466
RoR::Character::setPosition
void setPosition(Ogre::Vector3 position)
Definition: Character.cpp:85
RoR::App::GetSoundScriptManager
SoundScriptManager * GetSoundScriptManager()
Definition: Application.cpp:296
SetfloatCmd
Definition: ConsoleCmd.cpp:613
RoR::Console::cVarGet
CVar * cVarGet(std::string const &input_name, int flags)
Get cvar by short/long name, or create new one using input as short name.
Definition: CVar.cpp:295
SetCVarCmd
Definition: ConsoleCmd.cpp:544
ClearCmd::ClearCmd
ClearCmd()
Definition: ConsoleCmd.cpp:622
RoR::SoundManager
Definition: SoundManager.h:53
RoR::Console::Message::cm_net_userid
uint32_t cm_net_userid
Definition: Console.h:77
SetCVarCmd::Run
void Run(Ogre::StringVector const &args) override
Definition: ConsoleCmd.cpp:551
RoR::SE_ANGELSCRIPT_MANIPULATIONS
@ SE_ANGELSCRIPT_MANIPULATIONS
triggered when the user tries to dynamically use the scripting capabilities (prevent cheating) args: ...
Definition: ScriptEvents.h:54
PARSEREAL
#define PARSEREAL(x)
Definition: Application.h:59
GravityCmd
Definition: ConsoleCmd.cpp:59
RoR::ConsoleCmd::m_name
std::string m_name
Definition: ConsoleCmd.h:54
OverlayWrapper.h
GotoCmd::Run
void Run(Ogre::StringVector const &args) override
Definition: ConsoleCmd.cpp:279
QuitCmd::QuitCmd
QuitCmd()
Definition: ConsoleCmd.cpp:388
RoR::SoundManager::GetSpeedOfSound
float GetSpeedOfSound() const
Definition: SoundManager.h:137
RoR::Console::CONSOLE_MSGTYPE_TERRN
@ CONSOLE_MSGTYPE_TERRN
Parsing/spawn/simulation messages for terrain.
Definition: Console.h:64
AsCmd::Run
void Run(Ogre::StringVector const &args) override
Definition: ConsoleCmd.cpp:322
HelpCmd
Definition: ConsoleCmd.cpp:396
RoR::SCRIPTUNITID_INVALID
static const ScriptUnitID_t SCRIPTUNITID_INVALID
Definition: ForwardDeclarations.h:42
LogCmd
Definition: ConsoleCmd.cpp:204
SetintCmd
Definition: ConsoleCmd.cpp:607
AsCmd::AsCmd
AsCmd()
Definition: ConsoleCmd.cpp:320
LogCmd::LogCmd
LogCmd()
Definition: ConsoleCmd.cpp:207
RoR::Actor::ar_instance_id
ActorInstanceID_t ar_instance_id
Static attr; session-unique ID.
Definition: Actor.h:427
RoR::ConsoleCmd::getName
std::string const & getName() const
Definition: ConsoleCmd.h:47
RORNET_VERSION
#define RORNET_VERSION
Definition: RoRnet.h:35
PosCmd::PosCmd
PosCmd()
Definition: ConsoleCmd.cpp:247
format
Truck file format(technical spec)
SetCVarCmd::SetCVarCmd
SetCVarCmd(std::string const &name, std::string const &usage, std::string const &doc, int flag)
Definition: ConsoleCmd.cpp:547
SpeedOfSoundCmd::SpeedOfSoundCmd
SpeedOfSoundCmd()
Definition: ConsoleCmd.cpp:360
RoR::GameContext::GetPlayerCharacter
Character * GetPlayerCharacter()
Definition: GameContext.cpp:897
RoR::Terrain::setGravity
void setGravity(float value)
Definition: Terrain.cpp:490
RoR::CVar::getBool
bool getBool() const
Definition: CVar.h:98
RoR::TRIGGER_EVENT_ASYNC
void TRIGGER_EVENT_ASYNC(scriptEvents type, int arg1, int arg2ex=0, int arg3ex=0, int arg4ex=0, std::string arg5ex="", std::string arg6ex="", std::string arg7ex="", std::string arg8ex="")
Asynchronously (via MSG_SIM_SCRIPT_EVENT_TRIGGERED) invoke script function eventCallbackEx(),...
Definition: ScriptEngine.h:51
RoR::AppState
AppState
Definition: Application.h:309
RoR::SoundScriptManager::getSoundManager
SoundManager * getSoundManager()
Definition: SoundScriptManager.h:336
RoR::Console::cVarFind
CVar * cVarFind(std::string const &input_name)
Find cvar by short/long name.
Definition: CVar.cpp:267
PosCmd::Run
void Run(Ogre::StringVector const &args) override
Definition: ConsoleCmd.cpp:249
VerCmd::Run
void Run(Ogre::StringVector const &args) override
Definition: ConsoleCmd.cpp:230
CameraManager.h
SetfloatCmd::SetfloatCmd
SetfloatCmd()
Definition: ConsoleCmd.cpp:616
SetCmd
Definition: ConsoleCmd.cpp:505
ClearCmd::Run
void Run(Ogre::StringVector const &args) override
Definition: ConsoleCmd.cpp:624
WaterlevelCmd
Definition: ConsoleCmd.cpp:89
Console.h
RoR::Console::putMessage
void putMessage(MessageArea area, MessageType type, std::string const &msg, std::string icon="")
Definition: Console.cpp:103
RoR::Console::CONSOLE_TITLE
@ CONSOLE_TITLE
Definition: Console.h:49
RoR::Console::CONSOLE_SYSTEM_NETCHAT
@ CONSOLE_SYSTEM_NETCHAT
Definition: Console.h:55
SetCmd::Run
void Run(Ogre::StringVector const &args) override
Definition: ConsoleCmd.cpp:510
GotoCmd::GotoCmd
GotoCmd()
Definition: ConsoleCmd.cpp:277
TerrainheightCmd::TerrainheightCmd
TerrainheightCmd()
Definition: ConsoleCmd.cpp:125
Utils.h
Language.h
TerrainObjectManager.h
RefCountingObjectPtr< Actor >
LoadScriptCmd
Definition: ConsoleCmd.cpp:423
RoR::CVAR_ARCHIVE
@ CVAR_ARCHIVE
Will be written to RoR.cfg.
Definition: CVar.h:41
SetintCmd::SetintCmd
SetintCmd()
Definition: ConsoleCmd.cpp:610
RoR::Console::CONSOLE_SYSTEM_ERROR
@ CONSOLE_SYSTEM_ERROR
Definition: Console.h:52
GUIManager.h
SetboolCmd
Definition: ConsoleCmd.cpp:601
ActorManager.h
Actor.h
RoR::Console::MsgLockGuard::messages
std::vector< Message > & messages
Definition: Console.h:91
GravityCmd::GravityCmd
GravityCmd()
Definition: ConsoleCmd.cpp:62
RoR::App::GetScriptEngine
ScriptEngine * GetScriptEngine()
Definition: Application.cpp:298
GotoCmd
Definition: ConsoleCmd.cpp:274
TerrainheightCmd::Run
void Run(Ogre::StringVector const &args) override
Definition: ConsoleCmd.cpp:127
QuitCmd
Definition: ConsoleCmd.cpp:385
RoR::Console::Message
Definition: Console.h:67
RoR::Terrain::getWaterHeight
float getWaterHeight() const
Definition: Terrain.cpp:598
RoR::Console::MsgLockGuard
Definition: Console.h:82
VerCmd
Definition: ConsoleCmd.cpp:225
RoR::CVar::getStr
std::string const & getStr() const
Definition: CVar.h:95
RoR::Str< 200 >
TerrainheightCmd
Definition: ConsoleCmd.cpp:122
RoR::Console::cVarAssign
void cVarAssign(CVar *cvar, std::string const &value)
Parse value by cvar type.
Definition: CVar.cpp:249
RoR::Terrain::getHeightAt
float getHeightAt(float x, float z)
Definition: Terrain.cpp:512
RoR::ASMANIP_CONSOLE_SNIPPET_EXECUTED
@ ASMANIP_CONSOLE_SNIPPET_EXECUTED
Definition: ScriptEvents.h:74
PosCmd
Definition: ConsoleCmd.cpp:244
LogCmd::Run
void Run(Ogre::StringVector const &args) override
Definition: ConsoleCmd.cpp:209
ScriptEngine.h
WaterlevelCmd::Run
void Run(Ogre::StringVector const &args) override
Definition: ConsoleCmd.cpp:94
RoR::GameContext::PushMessage
void PushMessage(Message m)
Doesn't guarantee order! Use ChainMessage() if order matters.
Definition: GameContext.cpp:66
RoR::App::app_state
CVar * app_state
Definition: Application.cpp:79
RoR::Network::BroadcastChatMsg
void BroadcastChatMsg(const char *msg)
Definition: Network.cpp:838
RoR::Str::ToCStr
const char * ToCStr() const
Definition: Str.h:46
RoR::Console::MessageType
MessageType
Definition: Console.h:46
RoR::Actor::getPosition
Ogre::Vector3 getPosition()
Definition: Actor.cpp:370
GfxScene.h
Character.h
Application.h
Central state/object manager and communications hub.
RoR::App::GetConsole
Console * GetConsole()
Definition: Application.cpp:289
RoR::App::GetGameContext
GameContext * GetGameContext()
Definition: Application.cpp:299
GravityCmd::Run
void Run(Ogre::StringVector const &args) override
Definition: ConsoleCmd.cpp:64
RoR::Console::doCommand
void doCommand(std::string msg)
Identify and execute any console line.
Definition: ConsoleCmd.cpp:706
RoR::Character::getPosition
Ogre::Vector3 getPosition()
Definition: Character.cpp:92
RoR::AppState::SIMULATION
@ SIMULATION
RoR::ScriptEngine::triggerEvent
void triggerEvent(scriptEvents eventnum, int arg1=0, int arg2ex=0, int arg3ex=0, int arg4ex=0, std::string arg5ex="", std::string arg6ex="", std::string arg7ex="", std::string arg8ex="")
triggers an event; Not to be used by the end-user.
Definition: ScriptEngine.cpp:787
RoRVersion.h
RoR::Console::CONSOLE_SYSTEM_REPLY
@ CONSOLE_SYSTEM_REPLY
Success.
Definition: Console.h:54
SetCVarCmd::m_cvar_flag
int m_cvar_flag
Definition: ConsoleCmd.cpp:592
ROR_VERSION_STRING
const char *const ROR_VERSION_STRING
VarsCmd::VarsCmd
VarsCmd()
Definition: ConsoleCmd.cpp:469
SetstringCmd
Definition: ConsoleCmd.cpp:595
RoR::CVar
Quake-style console variable, defined in RoR.cfg or crated via Console UI and scripts.
Definition: CVar.h:52
RoR::App::diag_log_console_echo
CVar * diag_log_console_echo
Definition: Application.cpp:146
RoR::ConsoleCmd::CheckAppState
bool CheckAppState(AppState state)
Definition: ConsoleCmd.cpp:748
RoR::Console::Message::cm_area
MessageArea cm_area
Definition: Console.h:74
SetstringCmd::SetstringCmd
SetstringCmd()
Definition: ConsoleCmd.cpp:598
AsCmd
Definition: ConsoleCmd.cpp:317
HelpCmd::HelpCmd
HelpCmd()
Definition: ConsoleCmd.cpp:399
RoR::CVar::getName
std::string const & getName() const
Definition: CVar.h:103
RoR::ConsoleCmd
Base (abstract) console command.
Definition: ConsoleCmd.h:37
RoR::Message
Unified game event system - all requests and state changes are reported using a message.
Definition: GameContext.h:51
RoR::SE_TRUCK_TELEPORT
@ SE_TRUCK_TELEPORT
triggered when the user teleports the truck, the argument refers to the actor ID of the vehicle
Definition: ScriptEvents.h:51
RoR::CVar::setVal
void setVal(T val)
Definition: CVar.h:72
_L
#define _L
Definition: ErrorUtils.cpp:35
RoR::CVAR_TYPE_BOOL
@ CVAR_TYPE_BOOL
Definition: CVar.h:38
SpeedOfSoundCmd
Definition: ConsoleCmd.cpp:357
RoR::Console::regBuiltinCommands
void regBuiltinCommands()
Register builtin commands.
Definition: ConsoleCmd.cpp:677
RoR::Console::Message::cm_type
MessageType cm_type
Definition: Console.h:75
RoR::Wavefield::GetStaticWaterHeight
float GetStaticWaterHeight()
Returns static water level configured in 'terrn2'.
Definition: Wavefield.cpp:75
RoR::Terrain::getGravity
float getGravity() const
Definition: Terrain.h:101
RoR::Terrain::getWater
Wavefield * getWater()
Definition: Terrain.h:87
Terrain.h
VerCmd::VerCmd
VerCmd()
Definition: ConsoleCmd.cpp:228
RoR::CVAR_TYPE_INT
@ CVAR_TYPE_INT
Definition: CVar.h:39
SpeedOfSoundCmd::Run
void Run(Ogre::StringVector const &args) override
Definition: ConsoleCmd.cpp:362
QuitCmd::Run
void Run(Ogre::StringVector const &args) override
Definition: ConsoleCmd.cpp:390
RoR::Console::CONSOLE_MSGTYPE_ACTOR
@ CONSOLE_MSGTYPE_ACTOR
Parsing/spawn/simulation messages for actors.
Definition: Console.h:63
DEFAULT_GRAVITY
static const float DEFAULT_GRAVITY
earth gravity
Definition: SimConstants.h:50
RoR::Console::m_commands
CommandPtrMap m_commands
Definition: Console.h:162
RoR::ScriptEngine::loadScript
ScriptUnitID_t loadScript(Ogre::String filename, ScriptCategory category=ScriptCategory::TERRAIN, ActorPtr associatedActor=nullptr, std::string buffer="")
Loads a script.
Definition: ScriptEngine.cpp:834
RoR::ScriptUnitID_t
int ScriptUnitID_t
Unique sequentially generated ID of a loaded and running scriptin session. Use ScriptEngine::getScrip...
Definition: ForwardDeclarations.h:41
RoR::Console::CONSOLE_MSGTYPE_INFO
@ CONSOLE_MSGTYPE_INFO
Generic message.
Definition: Console.h:60
RoR::Console::CONSOLE_MSGTYPE_SCRIPT
@ CONSOLE_MSGTYPE_SCRIPT
Messages sent from scripts.
Definition: Console.h:62
RoR::ScriptEngine::executeString
ScriptRetCode_t executeString(Ogre::String command)
executes a string (useful for the console)
Definition: ScriptEngine.cpp:508
VarsCmd::Run
void Run(Ogre::StringVector const &args) override
Definition: ConsoleCmd.cpp:471
ROR_BUILD_DATE
const char *const ROR_BUILD_DATE
RoR::Console::CONSOLE_HELP
@ CONSOLE_HELP
Definition: Console.h:48
RoR::GameContext::GetPlayerActor
const ActorPtr & GetPlayerActor()
Definition: GameContext.h:134
SetboolCmd::SetboolCmd
SetboolCmd()
Definition: ConsoleCmd.cpp:604
SetCmd::SetCmd
SetCmd()
Definition: ConsoleCmd.cpp:508
RoR::CVAR_TYPE_FLOAT
@ CVAR_TYPE_FLOAT
Definition: CVar.h:40
HelpCmd::Run
void Run(Ogre::StringVector const &args) override
Definition: ConsoleCmd.cpp:401
RoR
Definition: AppContext.h:36
Network.h
RoR::Str::Clear
Str & Clear()
Definition: Str.h:54
ROR_BUILD_TIME
const char *const ROR_BUILD_TIME
IGfxWater.h
LoadScriptCmd::Run
void Run(Ogre::StringVector const &args) override
Definition: ConsoleCmd.cpp:428
ClearCmd
Definition: ConsoleCmd.cpp:619
RoR::ScriptCategory::CUSTOM
@ CUSTOM
Loaded by user via either: A) ingame console 'loadscript'; B) RoR.cfg 'app_custom_scripts'; C) comman...
RoR::MSG_APP_SHUTDOWN_REQUESTED
@ MSG_APP_SHUTDOWN_REQUESTED
Definition: Application.h:86
WaterlevelCmd::WaterlevelCmd
WaterlevelCmd()
Definition: ConsoleCmd.cpp:92
SpawnobjectCmd::Run
void Run(Ogre::StringVector const &args) override
Definition: ConsoleCmd.cpp:161
RoR::Console::MessageArea
MessageArea
Definition: Console.h:58
RoR::GameContext::GetTerrain
const TerrainPtr & GetTerrain()
Definition: GameContext.h:117
LoadScriptCmd::LoadScriptCmd
LoadScriptCmd()
Definition: ConsoleCmd.cpp:426