]> git.mxchange.org Git - flightgear.git/blob - src/Systems/submodel.cxx
David Culp:
[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     _serviceable_node->setBoolValue(true);
30     _trigger_node = fgGetNode("/systems/submodel/trigger", true);
31     _trigger_node->setBoolValue(false);
32     _amount_node = fgGetNode("/systems/submodel/amount", true);
33     _amount_node->setIntValue(60);
34
35     _user_lat_node = fgGetNode("/position/latitude-deg", true);
36     _user_lon_node = fgGetNode("/position/longitude-deg", true);
37     _user_alt_node = fgGetNode("/position/altitude-ft", true);
38
39     _user_heading_node = fgGetNode("/orientation/heading-deg", true);
40     _user_pitch_node =   fgGetNode("/orientation/pitch-deg", true);
41     _user_roll_node =    fgGetNode("/orientation/roll-deg", true);
42     _user_yaw_node =     fgGetNode("/orientation/yaw-deg", true);
43
44     _user_speed_node = fgGetNode("/velocities/uBody-fps", true);
45
46     elapsed_time = 0.0;
47     initial_velocity = 2750.0;  // feet per second, .50 caliber
48
49     ai = (FGAIManager*)globals->get_subsystem("ai_model");
50 }
51
52 void
53 SubmodelSystem::bind ()
54 {
55 }
56
57 void
58 SubmodelSystem::unbind ()
59 {
60 }
61
62 void
63 SubmodelSystem::update (double dt)
64 {
65   if (_trigger_node->getBoolValue()) {
66     if (_serviceable_node->getBoolValue()) {
67       if (_amount_node->getIntValue() > 0) {
68         firing = true;
69         release(dt);
70       } 
71     }
72   } else {
73     if (firing){
74       firing = false;
75       elapsed_time = 0.0;
76     }
77   }
78 }
79
80 bool
81 SubmodelSystem::release (double dt)
82 {
83   // releases a submodel every 0.25 seconds
84   elapsed_time += dt;
85   if (elapsed_time < 0.25) return false;
86   elapsed_time = 0.0;
87
88   int rval = ai->createBallistic( "Models/Geometry/tracer.ac",
89         _user_lat_node->getDoubleValue(),
90         _user_lon_node->getDoubleValue(),
91         _user_alt_node->getDoubleValue() + z_offset,
92         _user_heading_node->getDoubleValue() + yaw_offset,
93         _user_pitch_node->getDoubleValue() + pitch_offset,
94         _user_speed_node->getDoubleValue() + initial_velocity );
95
96   _amount_node->setIntValue( _amount_node->getIntValue() - 1); 
97   return true;                    
98 }
99
100 // end of submodel.cxx