RigsofRods
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 "IWater.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  {
113  float height = (args[1] == "default") ? App::GetGameContext()->GetTerrain()->getWaterHeight() : PARSEREAL(args[1]);
114  water->SetStaticWaterHeight(height);
115  water->UpdateWater();
116  }
117  reply << _L ("Water level set to: ") << App::GetGameContext()->GetTerrain()->getWater()->GetStaticWaterHeight();
118  }
120  }
121 };
122 
124 {
125 public:
126  TerrainheightCmd(): ConsoleCmd("terrainheight", "[]", _L("Get elevation of terrain at current position")) {}
127 
128  void Run(Ogre::StringVector const& args) override
129  {
130  if (!this->CheckAppState(AppState::SIMULATION))
131  return;
132 
133  ROR_ASSERT(App::GetGameContext()->GetTerrain());
134 
135  Str<200> reply;
136  reply << m_name << ": ";
138  Ogre::Vector3 pos;
139  ActorPtr const actor = App::GetGameContext()->GetPlayerActor();
140  if (actor)
141  {
142  pos = actor->getPosition();
143 
144  }
145  else
146  {
147  ROR_ASSERT(App::GetGameContext()->GetPlayerCharacter());
149  }
150  reply << _L("Terrain height at position: ")
151  << "x: " << pos.x << " z: " << pos.z << " = "
152  << App::GetGameContext()->GetTerrain()->getHeightAt(pos.x, pos.z);
154  }
155 };
156 
158 {
159 public:
160  SpawnobjectCmd(): ConsoleCmd("spawnobject", "<odef name>", _L("spawnobject - spawn a object at the player position")) {}
161 
162  void Run(Ogre::StringVector const& args) override
163  {
164  if (!this->CheckAppState(AppState::SIMULATION))
165  return;
166 
167  ROR_ASSERT(App::GetGameContext()->GetPlayerCharacter());
168  ROR_ASSERT(App::GetGameContext()->GetTerrain());
169 
170  Str<200> reply;
171  reply << m_name << ": ";
172  Console::MessageType reply_type;
173 
174  try
175  {
176  if (args.size() == 1)
177  {
178  reply_type = Console::CONSOLE_SYSTEM_ERROR;
179  reply << _L("Missing parameter: ") << m_usage;
180  }
181  else
182  {
183  Ogre::Vector3 pos = App::GetGameContext()->GetPlayerCharacter()->getPosition();
184  if (App::GetGameContext()->GetTerrain()->getObjectManager()->LoadTerrainObject(args[1], pos, Ogre::Vector3::ZERO, "Console", ""))
185  {
186  reply_type = Console::CONSOLE_SYSTEM_REPLY;
187  reply << _L("Spawned object at position: ") << "x: " << pos.x << " z: " << pos.z;
188  }
189  else
190  {
191  reply_type = Console::CONSOLE_SYSTEM_ERROR;
192  reply << _L("Could not spawn object");
193  }
194  }
195  }
196  catch (std::exception& e)
197  {
198  reply_type = Console::CONSOLE_SYSTEM_ERROR;
199  reply << e.what();
200  }
202  }
203 };
204 
205 class LogCmd: public ConsoleCmd
206 {
207 public:
208  LogCmd(): ConsoleCmd("log", "[]", _L("log - toggles log output on the console")) {}
209 
210  void Run(Ogre::StringVector const& args) override
211  {
212  Str<200> reply;
213  reply << m_name << ": ";
215 
216  // switch to console logging
217  bool now_logging = !App::diag_log_console_echo->getBool();
218  const char* msg = (now_logging) ? " logging to console enabled" : " logging to console disabled";
219  reply << _L(msg);
220  App::diag_log_console_echo->setVal(now_logging);
221 
223  }
224 };
225 
226 class VerCmd: public ConsoleCmd
227 {
228 public:
229  VerCmd(): ConsoleCmd("ver", "[]", _L("ver - shows the Rigs of Rods version")) {}
230 
231  void Run(Ogre::StringVector const& args) override
232  {
233  Str<200> reply;
234  reply << m_name << ": ";
236 
237  reply << "Rigs of Rods " << ROR_VERSION_STRING
238  << " (" << RORNET_VERSION << ") ["
239  << ROR_BUILD_DATE << ", " << ROR_BUILD_TIME << "]";
240 
242  }
243 };
244 
245 class PosCmd: public ConsoleCmd
246 {
247 public:
248  PosCmd(): ConsoleCmd("pos", "[]", _L("pos - outputs the current position")) {}
249 
250  void Run(Ogre::StringVector const& args) override
251  {
252  if (!this->CheckAppState(AppState::SIMULATION))
253  return;
254 
255  Str<200> reply;
256  reply << m_name << ": ";
258 
260  if (!b && App::GetGameContext()->GetPlayerCharacter())
261  {
262  Ogre::Vector3 pos = App::GetGameContext()->GetPlayerCharacter()->getPosition();
263  reply << _L("Character position: ") << "x: " << pos.x << " y: " << pos.y << " z: " << pos.z;
264  }
265  else if (b)
266  {
267  Ogre::Vector3 pos = b->getPosition();
268  reply << _L("Vehicle position: ") << "x: " << pos.x << " y: " << pos.y << " z: " << pos.z;
269  }
270 
272  }
273 };
274 
275 class GotoCmd: public ConsoleCmd
276 {
277 public:
278  GotoCmd(): ConsoleCmd("goto", "<x> <y> <z>", _L("goto <x> <y> <z> - jumps to the mentioned position")) {}
279 
280  void Run(Ogre::StringVector const& args) override
281  {
282  if (!this->CheckAppState(AppState::SIMULATION))
283  return;
284 
285  Str<200> reply;
286  reply << m_name << ": ";
287  Console::MessageType reply_type;
288 
289  if (args.size() != 4)
290  {
291  reply_type = Console::CONSOLE_HELP;
292  reply <<_L("usage: goto x y z");
293  }
294  else
295  {
296  reply_type = Console::CONSOLE_SYSTEM_REPLY;
297  Ogre::Vector3 pos(PARSEREAL(args[1]), PARSEREAL(args[2]), PARSEREAL(args[3]));
298 
300  if (!b && App::GetGameContext()->GetPlayerCharacter())
301  {
303  reply << _L("Character position set to: ") << "x: " << pos.x << " y: " << pos.y << " z: " << pos.z;
304  }
305  else if (b)
306  {
307  b->resetPosition(pos, false);
309  reply << _L("Vehicle position set to: ") << "x: " << pos.x << " y: " << pos.y << " z: " << pos.z;
310  }
311  }
312 
314  }
315 };
316 
317 
318 class AsCmd: public ConsoleCmd
319 {
320 public:
321  AsCmd(): ConsoleCmd("as", "<code>", _L("Run AngelScript code snippet")) {}
322 
323  void Run(Ogre::StringVector const& args) override
324  {
325  if (!this->CheckAppState(AppState::SIMULATION))
326  return;
327 
328  Str<200> reply;
329  reply << m_name << ": ";
330  Console::MessageType reply_type;
331 
332 #ifdef USE_ANGELSCRIPT
333  // we want to notify any running scripts that we might change something (prevent cheating)
335 
336  // Re-compose the code snippet
337  Str<1000> code;
338  for (int i = 1; i < args.size(); ++i)
339  {
340  code << " " << args[i];
341  }
342 
343  // Echo the code back to console user.
344  reply_type = Console::CONSOLE_SYSTEM_REPLY;
345  reply << " >>> " << code.ToCStr();
347 
348  // Run the code - will output script messages/AngelScript errors.
350 #else
351  reply_type = Console::CONSOLE_SYSTEM_ERROR;
352  reply << _L("Scripting disabled in this build");
354 #endif
355  }
356 };
357 
359 {
360 public:
361  SpeedOfSoundCmd(): ConsoleCmd("speedofsound", "[]", _L("speedofsound - outputs the current speed of sound")) {}
362 
363  void Run(Ogre::StringVector const& args) override
364  {
365  if (!this->CheckAppState(AppState::SIMULATION))
366  return;
367 
368  Str<200> reply;
369  reply << m_name << ": ";
371 
373  if (sound_manager == nullptr)
374  {
375  reply << _L("unable to get sound manager");
376  }
377  else
378  {
379  reply << _L("Current speed of sound: ") << sound_manager->GetSpeedOfSound();
380  }
381 
383  }
384 };
385 
386 class QuitCmd: public ConsoleCmd
387 {
388 public:
389  QuitCmd(): ConsoleCmd("quit", "[]", _L("quit - exit Rigs of Rods")) {}
390 
391  void Run(Ogre::StringVector const& args) override
392  {
394  }
395 };
396 
397 class HelpCmd: public ConsoleCmd
398 {
399 public:
400  HelpCmd(): ConsoleCmd("help", "[]", _L("help - information on commands (this)")) {}
401 
402  void Run(Ogre::StringVector const& args) override
403  {
405  Console::CONSOLE_TITLE, _L("Available commands:"));
406 
407  Str<500> line;
408  for (auto& cmd_pair: App::GetConsole()->getCommands())
409  {
410  line.Clear() << cmd_pair.second->getName() << " "
411  << cmd_pair.second->GetUsage() << " - " << cmd_pair.second->GetDoc();
412 
414  Console::CONSOLE_HELP, line.ToCStr());
415  }
416 
418  Console::CONSOLE_TITLE, _L("Tips:"));
420  Console::CONSOLE_HELP, _L("- use Arrow Up/Down Keys in the InputBox to reuse old messages"));
421  }
422 };
423 
424 class LoadScriptCmd : public ConsoleCmd
425 {
426 public:
427  LoadScriptCmd() : ConsoleCmd("loadscript", "[filename]", _L("Runs an AngelScript file")) {}
428 
429  void Run(Ogre::StringVector const& args) override
430  {
431  Str<200> reply;
432  reply << m_name << ": ";
433  Console::MessageType reply_type;
434 
435 #ifdef USE_ANGELSCRIPT
436  if (args.size() == 1)
437  {
438  reply_type = Console::CONSOLE_SYSTEM_ERROR;
439  reply << _L("Missing parameter: ") << m_usage;
440  }
441  else
442  {
444  if (id == SCRIPTUNITID_INVALID)
445  {
446  reply_type = Console::CONSOLE_SYSTEM_ERROR;
447  reply << _L("Failed to load script. See 'Angelscript.log' or use console command `log` and retry.");
448  }
449  else
450  {
451  reply_type = Console::CONSOLE_SYSTEM_REPLY;
452  reply << fmt::format(_L("Script '{}' running with ID '{}'"), args[1], id);
453  }
454  }
455 #else
456  reply_type = Console::CONSOLE_SYSTEM_ERROR;
457  reply << _L("Scripting disabled in this build");
458 #endif
459 
461  }
462 };
463 
464 // -------------------------------------------------------------------------------------
465 // CVar (builtin) console commmands
466 
467 class VarsCmd: public ConsoleCmd
468 {
469 public:
470  VarsCmd(): ConsoleCmd("vars", "[<expr> ...]", _L("Print cvars with one of <expr> in name")) {}
471 
472  void Run(Ogre::StringVector const& args) override
473  {
474  for (auto& pair: App::GetConsole()->getCVars())
475  {
476  bool match = args.size() == 1;
477  for (size_t i = 1; i < args.size(); ++i)
478  {
479  if (pair.first.find(args[i]) != std::string::npos)
480  {
481  match = true;
482  break;
483  }
484  }
485 
486  if (match)
487  {
488  Str<200> reply;
489  reply << "vars: " << pair.first << "=" << pair.second->getStr() << " (";
490 
491  if (pair.second->hasFlag(CVAR_TYPE_BOOL)) { reply << "bool"; }
492  else if (pair.second->hasFlag(CVAR_TYPE_INT)) { reply << "int"; }
493  else if (pair.second->hasFlag(CVAR_TYPE_FLOAT)) { reply << "float"; }
494  else { reply << "string"; }
495 
496  if (pair.second->hasFlag(CVAR_ARCHIVE)) { reply << ", archive"; }
497  if (pair.second->hasFlag(CVAR_NO_LOG)) { reply << ", no log"; }
498 
499  reply << ")";
501  }
502  }
503  }
504 };
505 
506 class SetCmd: public ConsoleCmd
507 {
508 public:
509  SetCmd(): ConsoleCmd("set", "<cvar> [<flags>] [<value>]", _L("Get or set value of existing CVar")) {}
510 
511  void Run(Ogre::StringVector const& args) override
512  {
513  Str<200> reply;
514  reply << m_name << ": ";
516 
517  if (args.size() == 1)
518  {
519  reply_type = Console::CONSOLE_HELP;
520  reply << this->GetUsage() << " - " << this->GetDoc();
521  }
522  else
523  {
524  CVar* cvar = App::GetConsole()->cVarFind(args[1]);
525  if (cvar)
526  {
527  if (args.size() > 2)
528  {
529  App::GetConsole()->cVarAssign(cvar, args[2]);
530  }
531  reply_type = Console::CONSOLE_SYSTEM_REPLY;
532  reply << cvar->getName() << " = " << cvar->getStr();
533  }
534  else
535  {
536  reply_type = Console::CONSOLE_SYSTEM_ERROR;
537  reply << _L("No such CVar: ") << args[1];
538  }
539  }
540 
542  }
543 };
544 
545 class SetCVarCmd: public ConsoleCmd // Generic
546 {
547 public:
548  SetCVarCmd(std::string const& name, std::string const& usage, std::string const& doc, int flag):
549  ConsoleCmd(name, usage, doc), m_cvar_flag(flag)
550  {}
551 
552  void Run(Ogre::StringVector const& args) override
553  {
554  Str<200> reply;
555  reply << m_name << ": ";
556  Console::MessageType reply_type;
557 
558  if (args.size() == 1)
559  {
560  reply_type = Console::CONSOLE_HELP;
561  reply << this->GetUsage() << " - " << this->GetDoc() << "Switches: --autoapply/--allowstore/--autostore";
562  }
563  else
564  {
565  int flags = m_cvar_flag;
566  size_t i;
567  for (i = 1; i < args.size(); ++i)
568  {
569  if (args[i] == "--archive") { flags |= CVAR_ARCHIVE; }
570  else break; // Exit loop on first non-switch arg!
571  }
572 
573  if (i == args.size()) // Only switches but no cvar?
574  {
575  reply_type = Console::CONSOLE_HELP;
576  reply << this->GetUsage() << " - " << this->GetDoc() << "Switches: --archive";
577  }
578  else
579  {
580  CVar* cvar = App::GetConsole()->cVarGet(args[i], flags);
581  if (args.size() > (i+1))
582  {
583  App::GetConsole()->cVarAssign(cvar, args[i+1]);
584  }
585  reply_type = Console::CONSOLE_SYSTEM_REPLY;
586  reply << cvar->getName() << " = " << cvar->getStr();
587  }
588  }
589 
591  }
592 private:
594 };
595 
597 {
598 public:
599  SetstringCmd(): SetCVarCmd("setstring", "<cvar> [<value>]", _L("Set or create string CVar"), /*flag=*/0) {}
600 };
601 
602 class SetboolCmd: public SetCVarCmd
603 {
604 public:
605  SetboolCmd(): SetCVarCmd("setbool", "<cvar> [<value>]", _L("Set or create boolean CVar"), CVAR_TYPE_BOOL) {}
606 };
607 
608 class SetintCmd: public SetCVarCmd
609 {
610 public:
611  SetintCmd(): SetCVarCmd("setint", "<cvar> [<value>]", _L("Set or create integer CVar"), CVAR_TYPE_INT) {}
612 };
613 
614 class SetfloatCmd: public SetCVarCmd
615 {
616 public:
617  SetfloatCmd(): SetCVarCmd("setfloat", "<cvar> [<value>]", _L("Set or create real-number CVar"), CVAR_TYPE_FLOAT) {}
618 };
619 
620 class ClearCmd: public ConsoleCmd
621 {
622 public:
623  ClearCmd(): ConsoleCmd("clear", "[<type>]", _L("Clear console history. Types: all/info/net/chat/terrn/actor/script")) {}
624 
625  void Run(Ogre::StringVector const& args) override
626  {
627  if (args.size() < 2 || args[1] == "all")
628  {
630  lock.messages.clear();
631  }
632  else
633  {
634  // Create a predicate function
635  std::function<bool(Console::Message const& m)> filter_fn;
636  if (args[1] == "chat")
637  {
638  filter_fn = [](Console::Message const& m){ return m.cm_type == Console::CONSOLE_SYSTEM_NETCHAT; };
639  }
640  else if (args[1] == "net") // Chat and user notifications
641  {
642  filter_fn = [](Console::Message const& m){ return m.cm_net_userid != 0; };
643  }
644  else
645  {
647  bool valid = false;
648  if (args[1] == "info") { area = Console::CONSOLE_MSGTYPE_INFO; valid = true; }
649  else if (args[1] == "terrn") { area = Console::CONSOLE_MSGTYPE_TERRN; valid = true; }
650  else if (args[1] == "actor") { area = Console::CONSOLE_MSGTYPE_ACTOR; valid = true; }
651  else if (args[1] == "script") { area = Console::CONSOLE_MSGTYPE_SCRIPT; valid = true; }
652 
653  if (valid)
654  {
655  filter_fn = [area](Console::Message const& m) { return m.cm_area == area; };
656  }
657  else
658  {
660  fmt::format(_L("No such message type: {}"), args[1]));
661  }
662  }
663 
665  // Shove unwanted entries to the end
666  auto erase_begin = std::remove_if(lock.messages.begin(), lock.messages.end(), filter_fn);
667  // Erase unwanted
668  lock.messages.erase(erase_begin, lock.messages.end());
669  }
670  }
671 };
672 
674 
675 // -------------------------------------------------------------------------------------
676 // Console integration
677 
679 {
680  ConsoleCmd* cmd = nullptr;
681 
682  // Classics
683  cmd = new GravityCmd(); m_commands.insert(std::make_pair(cmd->getName(), cmd));
684  cmd = new WaterlevelCmd(); m_commands.insert(std::make_pair(cmd->getName(), cmd));
685  cmd = new TerrainheightCmd(); m_commands.insert(std::make_pair(cmd->getName(), cmd));
686  cmd = new SpawnobjectCmd(); m_commands.insert(std::make_pair(cmd->getName(), cmd));
687  cmd = new LogCmd(); m_commands.insert(std::make_pair(cmd->getName(), cmd));
688  cmd = new VerCmd(); m_commands.insert(std::make_pair(cmd->getName(), cmd));
689  cmd = new PosCmd(); m_commands.insert(std::make_pair(cmd->getName(), cmd));
690  cmd = new GotoCmd(); m_commands.insert(std::make_pair(cmd->getName(), cmd));
691  cmd = new AsCmd(); m_commands.insert(std::make_pair(cmd->getName(), cmd));
692  cmd = new QuitCmd(); m_commands.insert(std::make_pair(cmd->getName(), cmd));
693  cmd = new HelpCmd(); m_commands.insert(std::make_pair(cmd->getName(), cmd));
694  // Additions
695  cmd = new ClearCmd(); m_commands.insert(std::make_pair(cmd->getName(), cmd));
696  cmd = new LoadScriptCmd(); m_commands.insert(std::make_pair(cmd->getName(), cmd));
697  cmd = new SpeedOfSoundCmd(); m_commands.insert(std::make_pair(cmd->getName(), cmd));
698  // CVars
699  cmd = new SetCmd(); m_commands.insert(std::make_pair(cmd->getName(), cmd));
700  cmd = new SetstringCmd(); m_commands.insert(std::make_pair(cmd->getName(), cmd));
701  cmd = new SetboolCmd(); m_commands.insert(std::make_pair(cmd->getName(), cmd));
702  cmd = new SetintCmd(); m_commands.insert(std::make_pair(cmd->getName(), cmd));
703  cmd = new SetfloatCmd(); m_commands.insert(std::make_pair(cmd->getName(), cmd));
704  cmd = new VarsCmd(); m_commands.insert(std::make_pair(cmd->getName(), cmd));
705 }
706 
707 void Console::doCommand(std::string msg)
708 {
709  if (msg[0] == '/' || msg[0] == '\\')
710  {
712  _L("Using slashes before commands are deprecated, you can now type command without any slashes"));
713  msg.erase(msg.begin());
714  }
715 
716  if (msg[0] == '!')
717  {
718  // Server commands - pass through to multiplayer chat
719  App::GetNetwork()->BroadcastChatMsg(msg.c_str());
720  return;
721  }
722 
723  Ogre::StringVector args = Ogre::StringUtil::split(msg, " ");
724 
725  auto found = m_commands.find(args[0]);
726  if (found != m_commands.end())
727  {
728  found->second->Run(args);
729  return;
730  }
731 
732  CVar* cvar = this->cVarFind(args[0]);
733  if (cvar)
734  {
735  Str<200> reply;
736  reply << cvar->getName() << " = " << cvar->getStr();
738  return;
739  }
740 
741  Str<200> reply;
742  reply << _L("unknown command: ") << msg;
744 }
745 
746 // -------------------------------------------------------------------------------------
747 // Helpers
748 
750 {
751  if (App::app_state->getEnum<AppState>() == state)
752  return true;
753 
754  Str<200> reply;
755  reply << m_name << ": ";
756  if (state == AppState::SIMULATION)
757  {
758  reply << _L("Only allowed when simulation is running");
759  }
760  else
761  {
762  reply << _L("Not allowed in current app state");
763  }
765  return false;
766 }
767 
768  // Currently unused: _L("Please enter a correct value. ")
769 
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::IWater::GetStaticWaterHeight
virtual float GetStaticWaterHeight()=0
Returns static water level configured in 'terrn2'.
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:1340
SpawnobjectCmd::SpawnobjectCmd
SpawnobjectCmd()
Definition: ConsoleCmd.cpp:160
RoR::App::GetNetwork
Network * GetNetwork()
Definition: Application.cpp:300
SpawnobjectCmd
Definition: ConsoleCmd.cpp:157
VarsCmd
Definition: ConsoleCmd.cpp:467
RoR::Character::setPosition
void setPosition(Ogre::Vector3 position)
Definition: Character.cpp:85
RoR::App::GetSoundScriptManager
SoundScriptManager * GetSoundScriptManager()
Definition: Application.cpp:293
SetfloatCmd
Definition: ConsoleCmd.cpp:614
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:292
SetCVarCmd
Definition: ConsoleCmd.cpp:545
ClearCmd::ClearCmd
ClearCmd()
Definition: ConsoleCmd.cpp:623
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:552
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:58
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:280
QuitCmd::QuitCmd
QuitCmd()
Definition: ConsoleCmd.cpp:389
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:323
HelpCmd
Definition: ConsoleCmd.cpp:397
RoR::SCRIPTUNITID_INVALID
static const ScriptUnitID_t SCRIPTUNITID_INVALID
Definition: ForwardDeclarations.h:42
LogCmd
Definition: ConsoleCmd.cpp:205
SetintCmd
Definition: ConsoleCmd.cpp:608
AsCmd::AsCmd
AsCmd()
Definition: ConsoleCmd.cpp:321
LogCmd::LogCmd
LogCmd()
Definition: ConsoleCmd.cpp:208
RoR::Actor::ar_instance_id
ActorInstanceID_t ar_instance_id
Static attr; session-unique ID.
Definition: Actor.h:400
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:248
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:548
SpeedOfSoundCmd::SpeedOfSoundCmd
SpeedOfSoundCmd()
Definition: ConsoleCmd.cpp:361
RoR::GameContext::GetPlayerCharacter
Character * GetPlayerCharacter()
Definition: GameContext.cpp:897
RoR::Terrain::setGravity
void setGravity(float value)
Definition: Terrain.cpp:483
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:305
RoR::SoundScriptManager::getSoundManager
SoundManager * getSoundManager()
Definition: SoundScriptManager.h:336
RoR::IWater
< TODO: Mixed gfx+physics (waves) - must be separated ~ only_a_ptr, 02/2018
Definition: IWater.h:32
RoR::Console::cVarFind
CVar * cVarFind(std::string const &input_name)
Find cvar by short/long name.
Definition: CVar.cpp:264
PosCmd::Run
void Run(Ogre::StringVector const &args) override
Definition: ConsoleCmd.cpp:250
VerCmd::Run
void Run(Ogre::StringVector const &args) override
Definition: ConsoleCmd.cpp:231
CameraManager.h
SetfloatCmd::SetfloatCmd
SetfloatCmd()
Definition: ConsoleCmd.cpp:617
SetCmd
Definition: ConsoleCmd.cpp:506
ClearCmd::Run
void Run(Ogre::StringVector const &args) override
Definition: ConsoleCmd.cpp:625
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:511
GotoCmd::GotoCmd
GotoCmd()
Definition: ConsoleCmd.cpp:278
TerrainheightCmd::TerrainheightCmd
TerrainheightCmd()
Definition: ConsoleCmd.cpp:126
Utils.h
Language.h
TerrainObjectManager.h
RefCountingObjectPtr< Actor >
LoadScriptCmd
Definition: ConsoleCmd.cpp:424
RoR::CVAR_ARCHIVE
@ CVAR_ARCHIVE
Will be written to RoR.cfg.
Definition: CVar.h:41
SetintCmd::SetintCmd
SetintCmd()
Definition: ConsoleCmd.cpp:611
RoR::Console::CONSOLE_SYSTEM_ERROR
@ CONSOLE_SYSTEM_ERROR
Definition: Console.h:52
GUIManager.h
SetboolCmd
Definition: ConsoleCmd.cpp:602
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:295
GotoCmd
Definition: ConsoleCmd.cpp:275
TerrainheightCmd::Run
void Run(Ogre::StringVector const &args) override
Definition: ConsoleCmd.cpp:128
QuitCmd
Definition: ConsoleCmd.cpp:386
RoR::IWater::UpdateWater
virtual void UpdateWater()=0
RoR::Console::Message
Definition: Console.h:67
RoR::Terrain::getWaterHeight
float getWaterHeight() const
Definition: Terrain.cpp:591
RoR::Console::MsgLockGuard
Definition: Console.h:82
VerCmd
Definition: ConsoleCmd.cpp:226
RoR::CVar::getStr
std::string const & getStr() const
Definition: CVar.h:95
RoR::Str< 200 >
TerrainheightCmd
Definition: ConsoleCmd.cpp:123
RoR::Console::cVarAssign
void cVarAssign(CVar *cvar, std::string const &value)
Parse value by cvar type.
Definition: CVar.cpp:246
RoR::Terrain::getHeightAt
float getHeightAt(float x, float z)
Definition: Terrain.cpp:505
RoR::ASMANIP_CONSOLE_SNIPPET_EXECUTED
@ ASMANIP_CONSOLE_SNIPPET_EXECUTED
Definition: ScriptEvents.h:74
PosCmd
Definition: ConsoleCmd.cpp:245
LogCmd::Run
void Run(Ogre::StringVector const &args) override
Definition: ConsoleCmd.cpp:210
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:830
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:371
GfxScene.h
Character.h
Application.h
Central state/object manager and communications hub.
RoR::App::GetConsole
Console * GetConsole()
Definition: Application.cpp:286
RoR::App::GetGameContext
GameContext * GetGameContext()
Definition: Application.cpp:296
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:707
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:781
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:593
ROR_VERSION_STRING
const char *const ROR_VERSION_STRING
VarsCmd::VarsCmd
VarsCmd()
Definition: ConsoleCmd.cpp:470
SetstringCmd
Definition: ConsoleCmd.cpp:596
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:749
RoR::Console::Message::cm_area
MessageArea cm_area
Definition: Console.h:74
SetstringCmd::SetstringCmd
SetstringCmd()
Definition: ConsoleCmd.cpp:599
AsCmd
Definition: ConsoleCmd.cpp:318
HelpCmd::HelpCmd
HelpCmd()
Definition: ConsoleCmd.cpp:400
RoR::CVar::getName
std::string const & getName() const
Definition: CVar.h:103
RoR::ConsoleCmd
Base (abstract) console command.
Definition: ConsoleCmd.h:37
IWater.h
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:358
RoR::Console::regBuiltinCommands
void regBuiltinCommands()
Register builtin commands.
Definition: ConsoleCmd.cpp:678
RoR::Console::Message::cm_type
MessageType cm_type
Definition: Console.h:75
RoR::Terrain::getGravity
float getGravity() const
Definition: Terrain.h:99
Terrain.h
VerCmd::VerCmd
VerCmd()
Definition: ConsoleCmd.cpp:229
RoR::CVAR_TYPE_INT
@ CVAR_TYPE_INT
Definition: CVar.h:39
SpeedOfSoundCmd::Run
void Run(Ogre::StringVector const &args) override
Definition: ConsoleCmd.cpp:363
QuitCmd::Run
void Run(Ogre::StringVector const &args) override
Definition: ConsoleCmd.cpp:391
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:828
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::IWater::SetStaticWaterHeight
virtual void SetStaticWaterHeight(float value)=0
RoR::ScriptEngine::executeString
ScriptRetCode_t executeString(Ogre::String command)
executes a string (useful for the console)
Definition: ScriptEngine.cpp:502
VarsCmd::Run
void Run(Ogre::StringVector const &args) override
Definition: ConsoleCmd.cpp:472
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:605
SetCmd::SetCmd
SetCmd()
Definition: ConsoleCmd.cpp:509
RoR::CVAR_TYPE_FLOAT
@ CVAR_TYPE_FLOAT
Definition: CVar.h:40
HelpCmd::Run
void Run(Ogre::StringVector const &args) override
Definition: ConsoleCmd.cpp:402
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
LoadScriptCmd::Run
void Run(Ogre::StringVector const &args) override
Definition: ConsoleCmd.cpp:429
ClearCmd
Definition: ConsoleCmd.cpp:620
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:85
RoR::Terrain::getWater
IWater * getWater()
Definition: Terrain.h:86
WaterlevelCmd::WaterlevelCmd
WaterlevelCmd()
Definition: ConsoleCmd.cpp:92
SpawnobjectCmd::Run
void Run(Ogre::StringVector const &args) override
Definition: ConsoleCmd.cpp:162
RoR::Console::MessageArea
MessageArea
Definition: Console.h:58
RoR::GameContext::GetTerrain
const TerrainPtr & GetTerrain()
Definition: GameContext.h:117
LoadScriptCmd::LoadScriptCmd
LoadScriptCmd()
Definition: ConsoleCmd.cpp:427