]> git.mxchange.org Git - flightgear.git/blob - src/Systems/submodel.cxx
Fix a mistake and make it possible to activate the submodel subsystem again.
[flightgear.git] / src / Systems / submodel.cxx
1 // submodel.cxx - models a releasable submodel.
2 // Written by Dave Culp, started Aug 2004
3 //
4 // This file is in the Public Domain and comes with no warranty.
5
6 #include "submodel.hxx"
7 #include <Main/fg_props.hxx>
8 #include <Main/util.hxx>
9 #include <AIModel/AIManager.hxx>
10
11
12 SubmodelSystem::SubmodelSystem ()
13 {
14   firing = false;
15   x_offset = y_offset = 0.0;
16   z_offset = -4.0;
17   pitch_offset = 2.0;
18   yaw_offset = 0.0;
19 }
20
21 SubmodelSystem::~SubmodelSystem ()
22 {
23 }
24
25 void
26 SubmodelSystem::init ()
27 {
28     _serviceable_node = fgGetNode("/systems/submodel/serviceable", true);
29         
30     _trigger_node = fgGetNode("/systems/submodel/trigger", true);
31     _trigger_node->setBoolValue(false);
32         
33     _amount_node = fgGetNode("/systems/submodel/amount", true);
34     _amount_node->setIntValue(0);
35          
36     _user_lat_node = fgGetNode("/position/latitude-deg", true);
37     _user_lon_node = fgGetNode("/position/longitude-deg", true);
38     _user_alt_node = fgGetNode("/position/altitude-ft", true);
39
40     _user_heading_node = fgGetNode("/orientation/heading-deg", true);
41     _user_pitch_node =   fgGetNode("/orientation/pitch-deg", true);
42     _user_roll_node =    fgGetNode("/orientation/roll-deg", true);
43     _user_yaw_node =     fgGetNode("/orientation/yaw-deg", true);
44
45     _user_speed_node = fgGetNode("/velocities/uBody-fps", true);
46
47     elapsed_time = 0.0;
48     initial_velocity = 2750.0;  // feet per second, .50 caliber
49
50     ai = (FGAIManager*)globals->get_subsystem("ai_model");
51 }
52
53 void
54 SubmodelSystem::bind ()
55 {
56 }
57
58 void
59 SubmodelSystem::unbind ()
60 {
61 }
62
63 void
64 SubmodelSystem::update (double dt)
65 {
66   if (_trigger_node->getBoolValue()) {
67     if (_serviceable_node->getBoolValue()) {
68       if (_amount_node->getIntValue() > 0) {
69         firing = true;
70         release(dt);
71       } 
72     }
73   } else {
74     if (firing){
75       firing = false;
76       elapsed_time = 0.0;
77     }
78   }
79 }
80
81 bool
82 SubmodelSystem::release (double dt)
83 {
84   // releases a submodel every 0.25 seconds
85   elapsed_time += dt;
86   if (elapsed_time < 0.25) return false;
87   elapsed_time = 0.0;
88
89   int rval = ai->createBallistic( "Models/Geometry/tracer.ac",
90         _user_lat_node->getDoubleValue(),
91         _user_lon_node->getDoubleValue(),
92         _user_alt_node->getDoubleValue() + z_offset,
93         _user_heading_node->getDoubleValue() + yaw_offset,
94         _user_pitch_node->getDoubleValue() + pitch_offset,
95         _user_speed_node->getDoubleValue() + initial_velocity );
96
97   _amount_node->setIntValue( _amount_node->getIntValue() - 1); 
98   return true;                    
99 }
100
101 // end of submodel.cxx