]> git.mxchange.org Git - flightgear.git/commitdiff
Add the ability to specify an initial state (on/off) for a connector switch.
authorcurt <curt>
Mon, 3 Feb 2003 22:15:36 +0000 (22:15 +0000)
committercurt <curt>
Mon, 3 Feb 2003 22:15:36 +0000 (22:15 +0000)
If nothing is specifed the switch defaults to on, but this is a problem for
the starter switch.

src/Systems/electrical.cxx
src/Systems/electrical.hxx

index 75a1a4fbcda8a8441063f19c58c644d486d3ee5f..2559874cace44b644658ab9f3e962a829e44c01f 100644 (file)
@@ -180,9 +180,33 @@ FGElectricalConnector::FGElectricalConnector ( SGPropertyNode *node,
             add_switch( fgGetNode( child->getStringValue(), true ) );
         }
     }
+
+    // do a 2nd pass to pick up starting switch value if specified
+    for ( i = 0; i < node->nChildren(); ++i ) {
+        SGPropertyNode *child = node->getChild(i);
+        string cname = child->getName();
+        string cval = child->getStringValue();
+        // cout << "  " << cname << " = " << cval << endl;
+        if ( cname == "initial-state" ) {
+            if ( cval == "off" ) {
+                set_switches( false );
+            } else {
+                set_switches( true );
+            }
+        }
+    }
 }  
 
 
+// set all switches to the specified state
+void FGElectricalConnector::set_switches( bool state ) {
+    cout << "setting switch state to " << state << endl;
+    for ( unsigned int i = 0; i < switches.size(); ++i ) {
+        switches[i]->setBoolValue( state );
+    }
+}
+
+
 // return true if all switches are true, false otherwise.  A connector
 // could have multiple switches, but they all need to be true(closed)
 // for current to get through.
index da29db5467b219941459d99cbb3f3e5502c4e8fa..30c3cc33ce753436900491d3757793f73b591ee4 100644 (file)
@@ -170,6 +170,9 @@ public:
         switches.push_back( node );
     }
 
+    // set all switches to the specified state
+    void set_switches( bool state );
+
     bool get_state();
 };