Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/commandbuffer.cc')
-rw-r--r--src/core/commandbuffer.cc73
1 files changed, 66 insertions, 7 deletions
diff --git a/src/core/commandbuffer.cc b/src/core/commandbuffer.cc
index 80e7e36..c111e17 100644
--- a/src/core/commandbuffer.cc
+++ b/src/core/commandbuffer.cc
@@ -17,6 +17,7 @@
#include "core/gameconnection.h"
#include "core/func.h"
#include "core/cvar.h"
+#include "core/zone.h"
namespace core
{
@@ -51,31 +52,83 @@ void func_list_ent(std::string const &args)
Entity::list();
}
+void func_list_zone(std::string const &args)
+{
+ std::istringstream argstream(args);
+ std::string zonelabel;
+ if (argstream >> zonelabel) {
+ aux::lowercase(zonelabel);
+ Zone::list_zone(zonelabel);
+ } else {
+ Zone::list();
+ }
+}
+
void func_set(std::string const &args)
{
std::istringstream argstream(args);
std::string varname;
- if (!(argstream >> varname))
+ if (!(argstream >> varname)) {
+ con_print << "Variable name expected!" << std::endl;
return;
+ }
aux::to_lowercase(varname);
std::string value;
if (!(argstream >> value)) {
+ Cvar *cvar = Cvar::find(varname);
+ if (cvar) {
+ con_print << " " << varname << " " << cvar->str() << " ^N" << cvar->info() << "\n";
+ }
return;
}
char c;
while (argstream.get(c))
value += c;
+
Cvar *cvar = Cvar::set(varname.c_str(), value.c_str(), Cvar::Archive);
+ if (cvar->flags() && Cvar::Info) {
+ localplayer()->player_dirty = true;
+ }
+
+ con_debug << " " << cvar->name() << " " << cvar->str() << "\n";
+}
+
+void func_toggle(std::string const &args)
+{
+ std::istringstream argstream(args);
+ std::string varname;
+ if (!(argstream >> varname)) {
+ con_print << "Variable name expected!" << std::endl;
+ return;
+ }
- con_print << " " << cvar->name() << " " << cvar->str() << "\n";
+ aux::to_lowercase(varname);
+
+ Cvar *cvar = Cvar::find(varname);
+ if (!cvar) {
+ con_print << "Unknown variable '" << varname << "'\n";
+ return;
+ }
+
+ float valueone = 1.0f;
+ if (!(argstream >> valueone)) {
+ valueone = 1.0f;
+ }
+
+ if (cvar->value()) {
+ (*cvar) = 0.0f;
+ } else {
+ (*cvar) = valueone;
+ }
if (cvar->flags() && Cvar::Info) {
localplayer()->player_dirty = true;
}
- return;
+
+ con_debug << " " << cvar->name() << " " << cvar->str() << "\n";
}
void func_exec(std::string const &args)
@@ -104,9 +157,15 @@ void CommandBuffer::init()
func = Func::add("list_var", (FuncPtr)func_list_var);
func->set_info("list variables");
+ func = Func::add("list_zone", (FuncPtr)func_list_zone);
+ func->set_info("list zones");
+
func = Func::add("set", (FuncPtr)func_set);
func->set_info("[variable] [str] set variable value");
+ func = Func::add("toggle", (FuncPtr)func_toggle);
+ func->set_info("[variable] toggle a variable");
+
func = Func::add("print", func_print);
func->set_info("[str] print a message on the console");
@@ -122,9 +181,11 @@ void CommandBuffer::shutdown()
//con_debug << "Shutting down command buffer...\n";
Func::remove("set");
+ Func::remove("toggle");
Func::remove("list_var");
Func::remove("list_func");
Func::remove("list_ent");
+ Func::remove("list_zone");
Func::remove("print");
Func::remove("print_file");
Func::remove("exec");
@@ -220,8 +281,7 @@ void CommandBuffer::complete(std::string &input, size_t &pos)
aux::to_lowercase(partial);
// search function registry for matches
- std::map<std::string, Func *>::iterator f;
- for (f = Func::registry.begin(); f != Func::registry.end(); f++) {
+ for (Func::Registry::iterator f = Func::registry().begin(); f != Func::registry().end(); f++) {
if (partial == (*f).first.substr(0, partial.size())) {
match.push_back((*f).first);
//con_print << " " << (*f).first << "\n";
@@ -229,8 +289,7 @@ void CommandBuffer::complete(std::string &input, size_t &pos)
}
// search cvar registry for matches
- std::map<std::string, Cvar *>::iterator c;
- for (c = Cvar::registry.begin(); c != Cvar::registry.end(); c++) {
+ for (Cvar::Registry::iterator c = Cvar::registry().begin(); c != Cvar::registry().end(); c++) {
if (partial == (*c).first.substr(0, partial.size())) {
match.push_back((*c).first);
//con_print << " " << (*c).first << "\n";