]> git.mxchange.org Git - flightgear.git/commitdiff
Add new property-randomize command.
authordavid <david>
Fri, 4 Apr 2003 22:38:35 +0000 (22:38 +0000)
committerdavid <david>
Fri, 4 Apr 2003 22:38:35 +0000 (22:38 +0000)
Set a random value for a numeric property

Params:

  <property> - the name of the property to randomize
  <min> - the minimum allowed value
  <max> - the maximum allowed value

src/Main/fg_commands.cxx

index 8218dfa3d31f61476852f13d45799e9595282378..cda99467a80d063a1d7117195e6674500fae41f8 100644 (file)
@@ -9,6 +9,7 @@
 #include STL_FSTREAM
 
 #include <simgear/debug/logstream.hxx>
+#include <simgear/math/sg_random.h>
 #include <simgear/misc/commands.hxx>
 #include <simgear/misc/props.hxx>
 #include <simgear/sg_inlines.h>
@@ -684,6 +685,24 @@ do_property_cycle (const SGPropertyNode * arg)
 }
 
 
+/**
+ * Built-in command: randomize a numeric property value.
+ *
+ * property: the name of the property value to randomize.
+ * min: the minimum allowed value.
+ * max: the maximum allowed value.
+ */
+static bool
+do_property_randomize (const SGPropertyNode * arg)
+{
+    SGPropertyNode * prop = get_prop(arg);
+    double min = arg->getDoubleValue("min", DBL_MIN);
+    double max = arg->getDoubleValue("max", DBL_MAX);
+    prop->setDoubleValue(sg_random() * (max - min) + min);
+    std::cerr << "Random value is " << prop->getDoubleValue() << std::endl;
+}
+
+
 /**
  * Built-in command: Show an XML-configured dialog.
  *
@@ -840,6 +859,7 @@ static struct {
     { "property-swap", do_property_swap },
     { "property-scale", do_property_scale },
     { "property-cycle", do_property_cycle },
+    { "property-randomize", do_property_randomize },
     { "dialog-show", do_dialog_show },
     { "dialog-close", do_dialog_close },
     { "dialog-show", do_dialog_show },