]> git.mxchange.org Git - flightgear.git/blob - src/AIModel/AIBallistic.cxx
Initials sound support for AI models.
[flightgear.git] / src / AIModel / AIBallistic.cxx
1 // FGAIBallistic - FGAIBase-derived class creates a ballistic object
2 //
3 // Written by David Culp, started November 2003.
4 // - davidculp2@comcast.net
5 //
6 // With major additions by Mathias Froehlich & Vivian Meazza 2004-2008
7 //
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License as
10 // published by the Free Software Foundation; either version 2 of the
11 // License, or (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful, but
14 // WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 // General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21
22 #ifdef HAVE_CONFIG_H
23 #  include <config.h>
24 #endif
25
26 #include <simgear/math/sg_random.h>
27 #include <simgear/math/sg_geodesy.hxx>
28 #include <simgear/scene/model/modellib.hxx>
29
30 #include <Scenery/scenery.hxx>
31
32 #include "AIBallistic.hxx"
33
34 #include <Main/util.hxx>
35 #include <Environment/gravity.hxx>
36
37 using namespace simgear;
38
39 const double FGAIBallistic::slugs_to_kgs = 14.5939029372;
40 const double FGAIBallistic::slugs_to_lbs = 32.1740485564;
41
42 FGAIBallistic::FGAIBallistic(object_type ot) :
43 FGAIBase(ot, false),
44 _height(0.0),
45 _speed(0),
46 _ht_agl_ft(0.0),
47 _azimuth(0.0),
48 _elevation(0.0),
49 _rotation(0.0),
50 hs(0),
51 _elapsed_time(0),
52 _aero_stabilised(false),
53 _drag_area(0.007),
54 _life_timer(0.0),
55 _buoyancy(0),
56 _wind(true),
57 _mass(0),
58 _random(false),
59 _load_resistance(0),
60 _solid(false),
61 _force_stabilised(false),
62 _slave_to_ac(false),
63 _slave_load_to_ac(false),
64 _contents_lb(0),
65 _report_collision(false),
66 _report_impact(false),
67 _external_force(false),
68 _report_expiry(false),
69 _impact_report_node(fgGetNode("/ai/models/model-impact", true)),
70 _old_height(0)
71
72 {
73     no_roll = false;
74 }
75
76 FGAIBallistic::~FGAIBallistic() {
77 }
78
79 void FGAIBallistic::readFromScenario(SGPropertyNode* scFileNode) {
80     if (!scFileNode){
81         return;
82     }
83
84     FGAIBase::readFromScenario(scFileNode);
85
86     //setPath(scFileNode->getStringValue("model", "Models/Geometry/rocket.ac")); 
87     setRandom(scFileNode->getBoolValue("random", false));
88     setAzimuth(scFileNode->getDoubleValue("azimuth", 0.0));
89     setElevation(scFileNode->getDoubleValue("elevation", 0));
90     setDragArea(scFileNode->getDoubleValue("eda", 0.007));
91     setLife(scFileNode->getDoubleValue("life", 900.0));
92     setBuoyancy(scFileNode->getDoubleValue("buoyancy", 0));
93     //setWind_from_east(scFileNode->getDoubleValue("wind_from_east", 0));
94     //setWind_from_north(scFileNode->getDoubleValue("wind_from_north", 0));
95     setWind(scFileNode->getBoolValue("wind", false));
96     setRoll(scFileNode->getDoubleValue("roll", 0.0));
97     setCd(scFileNode->getDoubleValue("cd", 0.029));
98     //setMass(scFileNode->getDoubleValue("mass", 0.007));
99     setWeight(scFileNode->getDoubleValue("weight", 0.25));
100     setStabilisation(scFileNode->getBoolValue("aero-stabilised", false));
101     setNoRoll(scFileNode->getBoolValue("no-roll", false));
102     setImpact(scFileNode->getBoolValue("impact", false));
103     setExpiry(scFileNode->getBoolValue("expiry", false));
104     setCollision(scFileNode->getBoolValue("collision", false));
105     setImpactReportNode(scFileNode->getStringValue("impact-reports"));
106     setName(scFileNode->getStringValue("name", "Rocket"));
107     setFuseRange(scFileNode->getDoubleValue("fuse-range", 0.0));
108     setSMPath(scFileNode->getStringValue("submodel-path", ""));
109     setSubID(scFileNode->getIntValue("SubID", 0));
110     setExternalForce(scFileNode->getBoolValue("external-force", false));
111     setForcePath(scFileNode->getStringValue("force-path", ""));
112     setForceStabilisation(scFileNode->getBoolValue("force-stabilised", false));
113     setXoffset(scFileNode->getDoubleValue("x-offset", 0.0));
114     setYoffset(scFileNode->getDoubleValue("y-offset", 0.0));
115     setZoffset(scFileNode->getDoubleValue("z-offset", 0.0));
116     setPitchoffset(scFileNode->getDoubleValue("pitch-offset", 0.0));
117     setRolloffset(scFileNode->getDoubleValue("roll-offset", 0.0));
118     setYawoffset(scFileNode->getDoubleValue("yaw-offset", 0.0));
119     setGroundOffset(scFileNode->getDoubleValue("ground-offset", 0.0));
120     setLoadOffset(scFileNode->getDoubleValue("load-offset", 0.0));
121     setSlaved(scFileNode->getBoolValue("slaved", false));
122     setSlavedLoad(scFileNode->getBoolValue("slaved-load", false));
123     setContentsPath(scFileNode->getStringValue("contents"));
124     setParentName(scFileNode->getStringValue("parent"));
125 }
126
127 bool FGAIBallistic::init(bool search_in_AI_path) {
128     FGAIBase::init(search_in_AI_path);
129
130     _impact_reported = false;
131     _collision_reported = false;
132     _expiry_reported = false;
133
134     _impact_lat = 0;
135     _impact_lon = 0;
136     _impact_elev = 0;
137     _impact_hdg = 0;
138     _impact_pitch = 0;
139     _impact_roll = 0;
140     _impact_speed = 0;
141
142     invisible = false;
143
144     _elapsed_time += (sg_random() * 100);
145
146     _life_timer = 0;
147
148     props->setStringValue("material/name", "");
149     props->setStringValue("name", _name.c_str());
150     props->setStringValue("submodels/path", _path.c_str());
151
152     if (_slave_to_ac){
153         props->setStringValue("force/path", _force_path.c_str());
154         props->setStringValue("contents/path", _contents_path.c_str());
155     }
156
157     //cout << "init: name " << _name.c_str() << " _life_timer " << _life_timer 
158     //    << endl;
159
160     //if(_parent != ""){
161     //    setParentNode();
162     //}
163
164     //setParentNodes(_selected_ac);
165
166     //props->setStringValue("vector/path", _vector_path.c_str());
167
168     // start with high value so that animations don't trigger yet
169     _ht_agl_ft = 1e10;
170     hdg = _azimuth;
171     pitch = _elevation;
172     roll = _rotation;
173
174     Transform();
175
176     if(_parent != ""){
177         setParentNode();
178     }
179
180     setParentNodes(_selected_ac);
181
182     return true;
183 }
184
185 void FGAIBallistic::bind() {
186     //    FGAIBase::bind();
187
188     props->tie("sim/time/elapsed-sec",
189         SGRawValueMethods<FGAIBallistic,double>(*this,
190         &FGAIBallistic::_getTime, &FGAIBallistic::setTime));
191     //props->tie("mass-slug",
192     //    SGRawValueMethods<FGAIBallistic,double>(*this,
193     //    &FGAIBallistic::getMass));
194
195     props->tie("material/solid",
196         SGRawValuePointer<bool>(&_solid));
197     props->tie("altitude-agl-ft",
198         SGRawValuePointer<double>(&_ht_agl_ft));
199     props->tie("controls/slave-to-ac",
200         SGRawValueMethods<FGAIBallistic,bool>
201         (*this, &FGAIBallistic::getSlaved, &FGAIBallistic::setSlaved));
202     props->tie("controls/invisible",
203         SGRawValuePointer<bool>(&invisible));
204
205     if(_external_force || _slave_to_ac){
206         props->tie("controls/force_stabilized",
207             SGRawValuePointer<bool>(&_force_stabilised));
208         props->tie("position/global-x", 
209             SGRawValueMethods<FGAIBase,double>(*this, &FGAIBase::_getCartPosX, 0));
210         props->tie("position/global-y",
211             SGRawValueMethods<FGAIBase,double>(*this, &FGAIBase::_getCartPosY, 0));
212         props->tie("position/global-z",
213             SGRawValueMethods<FGAIBase,double>(*this, &FGAIBase::_getCartPosZ, 0));
214         props->tie("velocities/vertical-speed-fps",
215             SGRawValuePointer<double>(&vs));
216         props->tie("velocities/true-airspeed-kt",
217             SGRawValuePointer<double>(&speed));
218         props->tie("velocities/horizontal-speed-fps",
219             SGRawValuePointer<double>(&hs));
220         props->tie("position/altitude-ft",
221             SGRawValueMethods<FGAIBase,double>(*this, &FGAIBase::_getElevationFt, &FGAIBase::_setAltitude));
222         props->tie("position/latitude-deg", 
223             SGRawValueMethods<FGAIBase,double>(*this, &FGAIBase::_getLatitude, &FGAIBase::_setLatitude));
224         props->tie("position/longitude-deg",
225             SGRawValueMethods<FGAIBase,double>(*this, &FGAIBase::_getLongitude, &FGAIBase::_setLongitude));
226         props->tie("orientation/hdg-deg",
227             SGRawValuePointer<double>(&hdg));
228         props->tie("orientation/pitch-deg",
229             SGRawValuePointer<double>(&pitch));
230         props->tie("orientation/roll-deg",
231             SGRawValuePointer<double>(&roll));
232         props->tie("controls/slave-load-to-ac",
233             SGRawValueMethods<FGAIBallistic,bool>
234             (*this, &FGAIBallistic::getSlavedLoad, &FGAIBallistic::setSlavedLoad));
235         props->tie("position/load-offset",
236             SGRawValueMethods<FGAIBallistic,double>
237             (*this, &FGAIBallistic::getLoadOffset, &FGAIBallistic::setLoadOffset));
238         props->tie("load/distance-to-hitch-ft",
239             SGRawValueMethods<FGAIBallistic,double>
240             (*this, &FGAIBallistic::getDistanceToHitch));
241         props->tie("load/elevation-to-hitch-deg",
242             SGRawValueMethods<FGAIBallistic,double>
243             (*this, &FGAIBallistic::getElevToHitch));
244         props->tie("load/bearing-to-hitch-deg",
245             SGRawValueMethods<FGAIBallistic,double>
246             (*this, &FGAIBallistic::getBearingToHitch));
247         props->tie("material/load-resistance",
248         SGRawValuePointer<double>(&_load_resistance));
249     }
250
251 }
252
253 void FGAIBallistic::unbind() {
254 //    FGAIBase::unbind();
255
256     props->untie("sim/time/elapsed-sec");
257     props->untie("mass-slug");
258     props->untie("material/solid");
259     props->untie("altitude-agl-ft");
260     props->untie("controls/slave-to-ac");
261     props->untie("controls/invisible");
262
263     if(_external_force || _slave_to_ac){
264         props->untie("position/global-y");
265         props->untie("position/global-x");
266         props->untie("position/global-z");
267         props->untie("velocities/vertical-speed-fps");
268         props->untie("velocities/true-airspeed-kt");
269         props->untie("velocities/horizontal-speed-fps");
270         props->untie("position/altitude-ft");
271         props->untie("position/latitude-deg");
272         props->untie("position/longitude-deg");
273         props->untie("position/ht-agl-ft");
274         props->untie("orientation/hdg-deg");
275         props->untie("orientation/pitch-deg");
276         props->untie("orientation/roll-deg");
277         props->untie("controls/force_stabilized");
278         props->untie("position/load-offset");
279         props->untie("load/distance-to-hitch-ft");
280         props->untie("load/elevation-to-hitch-deg");
281         props->untie("load/bearing-to-hitch-deg");
282         props->untie("material/load-resistance");
283     }
284 }
285
286 void FGAIBallistic::update(double dt) {
287     FGAIBase::update(dt);
288     _setUserPos();
289
290     if (_slave_to_ac){
291         slaveToAC(dt);
292         Transform();
293     } else if (!invisible){
294         Run(dt);
295         Transform();
296     }
297
298 }
299
300 void FGAIBallistic::setAzimuth(double az) {
301
302     if (_random)
303         hdg = _azimuth = (az - 5 ) + (10 * sg_random());
304     else 
305         hdg = _azimuth = az;
306
307     //cout << _name << " init hdg " << hdg << " random " << _random << endl;
308 }
309
310 void FGAIBallistic::setElevation(double el) {
311     pitch = _elevation = el;
312 }
313
314 void FGAIBallistic::setRoll(double rl) {
315     roll = _rotation = rl;
316 }
317
318 void FGAIBallistic::setStabilisation(bool val) {
319     _aero_stabilised = val;
320 }
321
322 void FGAIBallistic::setForceStabilisation(bool val) {
323     _force_stabilised = val;
324 }
325
326 void FGAIBallistic::setNoRoll(bool nr) {
327     no_roll = nr;
328 }
329
330 void FGAIBallistic::setDragArea(double a) {
331     _drag_area = a;
332 }
333
334 void FGAIBallistic::setLife(double seconds) {
335
336     if (_random){
337         life = seconds * _randomness + (seconds * (1 -_randomness) * sg_random());
338         //cout << " set life " << life << endl;
339     } else
340         life = seconds;
341 }
342
343 void FGAIBallistic::setBuoyancy(double fpss) {
344     _buoyancy = fpss;
345 }
346
347 void FGAIBallistic::setWind_from_east(double fps) {
348     _wind_from_east = fps;
349 }
350
351 void FGAIBallistic::setWind_from_north(double fps) {
352     _wind_from_north = fps;
353 }
354
355 void FGAIBallistic::setWind(bool val) {
356     _wind = val;
357 }
358
359 void FGAIBallistic::setCd(double c) {
360     _Cd = c;
361 }
362
363 void FGAIBallistic::setMass(double m) {
364     _mass = m;
365 }
366
367 void FGAIBallistic::setWeight(double w) {
368     _weight_lb = w;
369 }
370
371 void FGAIBallistic::setRandomness(double r) {
372     _randomness = r;
373 }
374
375 void FGAIBallistic::setRandom(bool r) {
376     _random = r;
377 }
378
379 void FGAIBallistic::setImpact(bool i) {
380     _report_impact = i;
381 }
382
383 void FGAIBallistic::setCollision(bool c) {
384     _report_collision = c;
385 }
386
387 void FGAIBallistic::setExpiry(bool e) {
388     _report_expiry = e;
389 }
390
391 void FGAIBallistic::setExternalForce(bool f) {
392     _external_force = f;
393 }
394
395 void FGAIBallistic::setImpactReportNode(const string& path) {
396
397     if (!path.empty())
398         _impact_report_node = fgGetNode(path.c_str(), true);
399 }
400
401 void FGAIBallistic::setSMPath(const string& s) {
402     _path = s;
403     //cout << "submodel path " << _path << endl;
404 }
405
406 void FGAIBallistic::setFuseRange(double f) {
407     _fuse_range = f;
408 }
409
410 void FGAIBallistic::setSubID(int i) {
411     _subID = i;
412 }
413
414 void FGAIBallistic::setSubmodel(const string& s) {
415     _submodel = s;
416 }
417
418 void FGAIBallistic::setGroundOffset(double g) {
419     _ground_offset = g;
420 }
421
422 void FGAIBallistic::setLoadOffset(double l) {
423     _load_offset = l;
424 }
425
426 double FGAIBallistic::getLoadOffset() const {
427     return _load_offset;
428 }
429
430 void FGAIBallistic::setSlaved(bool s) {
431     _slave_to_ac = s;
432 }
433
434 void FGAIBallistic::setContentsPath(const string& path) {
435
436     _contents_path = path;
437
438     if (!path.empty()) {
439         _contents_node = fgGetNode(path.c_str(), true);
440     }
441 }
442
443 void FGAIBallistic::setContentsNode(SGPropertyNode_ptr node) {
444
445     if (node != 0) {
446         _contents_node = node;
447         _contents_path = _contents_node->getDisplayName();
448     }
449 }
450
451 void FGAIBallistic::setParentNodes(SGPropertyNode_ptr node) {
452
453     if (node != 0) {
454         _pnode = node;
455         _p_pos_node = _pnode->getChild("position", 0, true);
456         _p_lat_node = _p_pos_node->getChild("latitude-deg", 0, true);
457         _p_lon_node = _p_pos_node->getChild("longitude-deg", 0, true);
458         _p_alt_node = _p_pos_node->getChild("altitude-ft", 0, true);
459         _p_agl_node = _p_pos_node->getChild("altitude-agl-ft", 0, true);
460
461
462         _p_ori_node = _pnode->getChild("orientation", 0, true);
463         _p_pch_node = _p_ori_node->getChild("pitch-deg", 0, true);
464         _p_rll_node = _p_ori_node->getChild("roll-deg", 0, true);
465         _p_hdg_node = _p_ori_node->getChild("true-heading-deg",0, true);
466
467         _p_vel_node = _pnode->getChild("velocities", 0, true);
468         _p_spd_node = _p_vel_node->getChild("true-airspeed-kt", 0, true);
469     }
470
471 }
472
473 void FGAIBallistic::setParentPos() {
474
475     if (_pnode != 0) { 
476         //cout << "set parent pos" << endl;
477
478         double lat = _p_lat_node->getDoubleValue();
479         double lon = _p_lon_node->getDoubleValue();
480         double alt = _p_alt_node->getDoubleValue();
481
482         _parentpos.setLongitudeDeg(lon);
483         _parentpos.setLatitudeDeg(lat);
484         _parentpos.setElevationFt(alt);
485
486     }
487
488 }
489
490 bool FGAIBallistic::getSlaved() const {
491     return _slave_to_ac;
492 }
493
494 double FGAIBallistic::getMass() const {
495     return _mass;
496 }
497
498 double FGAIBallistic::getContents() {
499     if(_contents_node){
500         _contents_lb = _contents_node->getChild("level-lbs",0,1)->getDoubleValue();
501     }
502     return _contents_lb;
503 }
504
505 void FGAIBallistic::setContents(double c) {
506     if(_contents_node) 
507         _contents_lb = _contents_node->getChild("level-gal_us",0,1)->setDoubleValue(c);
508 }
509
510 void FGAIBallistic::setSlavedLoad(bool l) {
511     _slave_load_to_ac = l;
512 }
513
514 bool FGAIBallistic::getSlavedLoad() const {
515     return _slave_load_to_ac;
516 }
517
518 void FGAIBallistic::setForcePath(const string& p) {
519     _force_path = p;
520     if (!_force_path.empty()) {
521         SGPropertyNode *fnode = fgGetNode(_force_path.c_str(), 0, true );
522         _force_node = fnode->getChild("force-lb", 0, true);
523         _force_azimuth_node = fnode->getChild("force-azimuth-deg", 0, true);
524         _force_elevation_node = fnode->getChild("force-elevation-deg", 0, true);
525     }
526 }
527
528 bool FGAIBallistic::getHtAGL(double start){
529
530     if (getGroundElevationM(SGGeod::fromGeodM(pos, start),
531         _elevation_m, &_material)) {
532             _ht_agl_ft = pos.getElevationFt() - _elevation_m * SG_METER_TO_FEET;
533
534             if (_material) {
535                 const vector<string>& names = _material->get_names();
536                 _solid = _material->get_solid();
537                 _load_resistance = _material->get_load_resistance();
538                 _frictionFactor =_material->get_friction_factor();
539
540                 if (!names.empty())
541                     props->setStringValue("material/name", names[0].c_str());
542                 else
543                     props->setStringValue("material/name", "");
544
545                 _mat_name = names[0];
546
547                 //cout << "material " << _mat_name 
548                 //<< " solid " << _solid 
549                 //<< " load " << _load_resistance
550                 //<< " frictionFactor " << _frictionFactor
551                 //<< endl;
552
553             }
554
555             return true;
556     } else {
557         return false;
558     }
559
560 }
561
562 double FGAIBallistic::getRecip(double az){
563     // calculate the reciprocal of the input azimuth 
564     if(az - 180 < 0){
565         return az + 180;
566     } else {
567         return az - 180; 
568     }
569 }
570
571 void FGAIBallistic::setPch(double e, double dt, double coeff){
572     double c = dt / (coeff + dt);
573     pitch = (e * c) + (pitch * (1 - c));
574 }
575
576 void FGAIBallistic::setBnk(double r, double dt, double coeff){
577     double c = dt / (coeff + dt);
578     roll = (r * c) + (roll * (1 - c));
579 }
580
581 void FGAIBallistic::setSpd(double s, double dt, double coeff){
582     double c = dt / (coeff + dt);
583     _speed = (s * c) + (_speed * (1 - c));
584 }
585
586 void FGAIBallistic::setHt(double h, double dt, double coeff){
587     double c = dt / (coeff + dt);
588     _height = (h * c) + (_height * (1 - c));
589 }
590
591 int FGAIBallistic::setHdg(double tgt_hdg, double dt, double coeff){
592     double recip = getRecip(hdg);
593     double c = dt / (coeff + dt);
594     //cout << "set heading " << tgt_hdg << endl;
595     //we need to ensure that we turn the short way to the new hdg
596     if (tgt_hdg < recip && tgt_hdg < hdg && hdg > 180) {
597         hdg = ((tgt_hdg + 360) * c) + (hdg * (1 - c));
598 //        cout << "case 1: right turn" << endl;
599     } else if (tgt_hdg > recip && tgt_hdg > hdg && hdg <= 180){
600         hdg = ((tgt_hdg - 360) * c) + (hdg * (1 - c));
601 //        cout << "case 2: left turn" << endl;
602     } else {
603         hdg = (tgt_hdg * c) + (hdg * (1 - c));
604 //        cout << "case 4: left turn" << endl;
605     }
606     return -1;
607 }
608
609 double  FGAIBallistic::getTgtXOffset() const {
610     return _tgt_x_offset;
611 }
612
613 double  FGAIBallistic::getTgtYOffset() const {
614     return _tgt_y_offset;
615
616
617 double  FGAIBallistic::getTgtZOffset() const {
618     return _tgt_z_offset;
619 }
620
621 void FGAIBallistic::setTgtXOffset(double x){
622     _tgt_x_offset = x;
623 }
624
625 void FGAIBallistic::setTgtYOffset(double y){
626     _tgt_y_offset = y;
627 }
628
629 void FGAIBallistic::setTgtZOffset(double z){
630     _tgt_z_offset = z;
631 }
632
633 void FGAIBallistic::slaveToAC(double dt){
634
635     if (invisible)
636         return;
637
638     double hdg, pch, rll, agl = 0;
639
640     if (_pnode != 0) {
641         setParentPos();
642         hdg = _p_hdg_node->getDoubleValue();
643         pch = _p_pch_node->getDoubleValue();
644         rll = _p_rll_node->getDoubleValue();
645         agl = _p_agl_node->getDoubleValue();
646         setOffsetPos(_parentpos, hdg, pch, rll);
647         setSpeed(_p_spd_node->getDoubleValue());
648     }else {
649         hdg = manager->get_user_heading();
650         pch = manager->get_user_pitch();
651         rll = manager->get_user_roll();
652         agl = manager->get_user_agl();
653         setOffsetPos(userpos, hdg, pch, rll);
654         setSpeed(manager->get_user_speed());
655     }
656
657     pos.setLatitudeDeg(_offsetpos.getLatitudeDeg());
658     pos.setLongitudeDeg(_offsetpos.getLongitudeDeg());
659     pos.setElevationFt(_offsetpos.getElevationFt());
660     setHeading(hdg);
661     setPitch(pch + _pitch_offset);
662     setBank(rll + _roll_offset);
663     setOffsetVelocity(dt, pos);
664     setTime(0);
665
666     //update the mass (slugs)
667     _mass = (_weight_lb + getContents()) / slugs_to_lbs;
668
669     _impact_reported = false;
670
671     //cout << _name << " _mass "<<_mass <<" " << getContents() 
672     //<< " " << getContents() / slugs_to_lbs << " weight " << _weight_lb << endl;
673     //    cout << _name << " update hs " << hs << " vs " << vs << endl;
674 }
675
676 void FGAIBallistic::Run(double dt) {
677     _life_timer += dt;
678     
679     //_pass += 1;
680     //cout<<"AIBallistic run: name " << _name.c_str() 
681     //    << " dt " << dt <<  " _life_timer " << _life_timer << " pass " << _pass << endl;
682
683     // if life = -1 the object does not die
684     if (_life_timer > life && life != -1){
685
686         if (_report_expiry && !_expiry_reported && !_impact_reported && !_collision_reported){
687             //cout<<"AIBallistic run: name " << _name.c_str() << " expiry " 
688                 //<< " _life_timer " << _life_timer<< endl;
689             handle_expiry();
690         } else{
691             //cout<<"AIBallistic run: name " << _name.c_str() 
692             //    << " die " <<  " _life_timer " << _life_timer << endl;
693             setDie(true);
694         }
695
696         setTime(0);
697     }
698
699     //set the contents in the appropriate tank or other property in the parent to zero
700     setContents(0);
701
702     //randomise Cd by +- 10%
703     if (_random)
704         _Cd = _Cd * 0.90 + (0.10 * sg_random());
705
706     // Adjust Cd by Mach number. The equations are based on curves
707     // for a conventional shell/bullet (no boat-tail).
708     double Cdm;
709
710     if (Mach < 0.7)
711         Cdm = 0.0125 * Mach + _Cd;
712     else if (Mach < 1.2 )
713         Cdm = 0.3742 * pow(Mach, 2) - 0.252 * Mach + 0.0021 + _Cd;
714     else
715         Cdm = 0.2965 * pow(Mach, -1.1506) + _Cd;
716
717     //cout <<_name << " Mach " << Mach << " Cdm " << Cdm 
718     //    << " ballistic speed kts "<< speed <<  endl;
719
720     // drag = Cd * 0.5 * rho * speed * speed * drag_area;
721     // rho is adjusted for altitude in void FGAIBase::update,
722     // using Standard Atmosphere (sealevel temperature 15C)
723     // acceleration = drag/mass;
724     // adjust speed by drag
725     speed -= (Cdm * 0.5 * rho * speed * speed * _drag_area/_mass) * dt;
726
727     // don't let speed become negative
728     if ( speed < 0.0 )
729         speed = 0.0;
730
731 //    double speed_fps = speed * SG_KT_TO_FPS;
732
733     // calculate vertical and horizontal speed components
734     calcVSHS();
735
736     //resolve horizontal speed into north and east components:
737     //and convert horizontal speed (fps) to degrees per second
738     calcNE();
739
740     // if wind not required, set to zero
741     if (!_wind) {
742         _wind_from_north = 0;
743         _wind_from_east = 0;
744     } else {
745         _wind_from_north = manager->get_wind_from_north();
746         _wind_from_east = manager->get_wind_from_east();
747     }
748
749     //calculate velocity due to external force
750     double force_speed_north_deg_sec = 0;
751     double force_speed_east_deg_sec = 0;
752 //    double vs_force_fps = 0;
753     double hs_force_fps = 0;
754     double v_force_acc_fpss = 0;
755     double force_speed_north_fps = 0;
756     double force_speed_east_fps = 0;
757     double h_force_lbs = 0;
758     double normal_force_lbs = 0;
759     double normal_force_fpss = 0;
760     double static_friction_force_lbs = 0;
761     double dynamic_friction_force_lbs = 0;
762     double friction_force_speed_north_fps = 0;
763     double friction_force_speed_east_fps = 0;
764     double friction_force_speed_north_deg_sec = 0;
765     double friction_force_speed_east_deg_sec = 0;
766     double force_elevation_deg = 0;
767     double force_azimuth_deg  = 0;
768     double force_lbs = 0;
769
770     if (_external_force) {
771         //cout << _name << " external force " <<  hdg << " az " << _azimuth << endl;
772
773         SGPropertyNode *n = fgGetNode(_force_path.c_str(), true);
774         force_lbs            = n->getChild("force-lb", 0, true)->getDoubleValue();
775         force_elevation_deg  = n->getChild("force-elevation-deg", 0, true)->getDoubleValue();
776         force_azimuth_deg    = n->getChild("force-azimuth-deg", 0, true)->getDoubleValue();
777         
778         //resolve force into vertical and horizontal components:
779         double v_force_lbs = force_lbs * sin( force_elevation_deg * SG_DEGREES_TO_RADIANS );
780         h_force_lbs = force_lbs * cos( force_elevation_deg * SG_DEGREES_TO_RADIANS );
781
782         //ground interaction 
783         //we don't do this if impacts are calculated
784         if(!_report_impact){
785
786             if (getHtAGL(10000)){
787                 double deadzone = 0.1;
788
789                 if (_ht_agl_ft <= (0 + _ground_offset + deadzone) && _solid){
790                     normal_force_lbs = (_mass * slugs_to_lbs) - v_force_lbs;
791
792                     if ( normal_force_lbs < 0 )
793                         normal_force_lbs = 0;
794
795                     pos.setElevationFt(0 + _ground_offset);
796                     if (vs < 0) 
797                         vs = -vs * 0.5;
798
799                     // calculate friction
800                     // we assume a static Coefficient of Friction (mu) of 0.62 (wood on concrete)
801                     double mu = 0.62;
802
803                     static_friction_force_lbs = mu * normal_force_lbs * _frictionFactor;
804
805                     //adjust horizontal force. We assume that a speed of <= 5 fps is static 
806                     if (h_force_lbs <= static_friction_force_lbs && hs <= 5){
807                         h_force_lbs = hs = 0;
808                         _speed_north_fps = _speed_east_fps = 0;
809                     } else
810                         dynamic_friction_force_lbs = (static_friction_force_lbs * 0.95);
811
812                     //ignore wind when on the ground for now
813                     //TODO fix this
814                     _wind_from_north = 0;
815                     _wind_from_east = 0;
816
817                 }
818
819             }
820
821         } //endif
822
823         //acceleration = (force(lbsf)/mass(slugs))
824         v_force_acc_fpss = v_force_lbs/_mass;
825         normal_force_fpss = normal_force_lbs/_mass;
826         double h_force_acc_fpss = h_force_lbs/_mass;
827         double dynamic_friction_acc_fpss = dynamic_friction_force_lbs/_mass;
828
829         // velocity = acceleration * dt
830         hs_force_fps = h_force_acc_fpss * dt;
831         double friction_force_fps = dynamic_friction_acc_fpss * dt;
832
833         //resolve horizontal speeds into north and east components:
834         force_speed_north_fps   = cos(force_azimuth_deg * SG_DEGREES_TO_RADIANS) * hs_force_fps;
835         force_speed_east_fps    = sin(force_azimuth_deg * SG_DEGREES_TO_RADIANS) * hs_force_fps;
836
837         friction_force_speed_north_fps = cos(getRecip(hdg) * SG_DEGREES_TO_RADIANS) * friction_force_fps;
838         friction_force_speed_east_fps  = sin(getRecip(hdg) * SG_DEGREES_TO_RADIANS) * friction_force_fps;
839
840         // convert horizontal speed (fps) to degrees per second
841         force_speed_north_deg_sec = force_speed_north_fps / ft_per_deg_lat;
842         force_speed_east_deg_sec  = force_speed_east_fps / ft_per_deg_lon;
843
844         friction_force_speed_north_deg_sec = friction_force_speed_north_fps / ft_per_deg_lat;
845         friction_force_speed_east_deg_sec  = friction_force_speed_east_fps / ft_per_deg_lon;
846     }
847
848     // convert wind speed (fps) to degrees lat/lon per second
849     double wind_speed_from_north_deg_sec = _wind_from_north / ft_per_deg_lat;
850     double wind_speed_from_east_deg_sec  = _wind_from_east / ft_per_deg_lon;
851
852     //recombine the horizontal velocity components
853     hs = sqrt(((_speed_north_fps + force_speed_north_fps + friction_force_speed_north_fps) 
854         * (_speed_north_fps + force_speed_north_fps + friction_force_speed_north_fps))
855         + ((_speed_east_fps + force_speed_east_fps + friction_force_speed_east_fps) 
856         * (_speed_east_fps + force_speed_east_fps + friction_force_speed_east_fps)));
857
858     if (hs <= 0.00001)
859         hs = 0;
860
861     // adjust vertical speed for acceleration of gravity, buoyancy, and vertical force
862     double gravity = SG_METER_TO_FEET * (Environment::Gravity::instance()->getGravity(pos));
863     vs -= (gravity - _buoyancy - v_force_acc_fpss - normal_force_fpss) * dt;
864
865     if (vs <= 0.00001 && vs >= -0.00001)
866         vs = 0;
867
868     // set new position
869     if(_slave_load_to_ac) {
870         setOffsetPos(pos, 
871             manager->get_user_heading(),
872             manager->get_user_pitch(), 
873             manager->get_user_roll()
874             );
875         pos.setLatitudeDeg(_offsetpos.getLatitudeDeg());
876         pos.setLongitudeDeg(_offsetpos.getLongitudeDeg());
877         pos.setElevationFt(_offsetpos.getElevationFt());
878
879         if (getHtAGL(10000)){
880             double deadzone = 0.1;
881
882             if (_ht_agl_ft <= (0 + _ground_offset + deadzone) && _solid){
883                 pos.setElevationFt(0 + _ground_offset);
884             } else {
885                 pos.setElevationFt(_offsetpos.getElevationFt() + _load_offset);
886             }
887
888         }
889     } else {
890         pos.setLatitudeDeg( pos.getLatitudeDeg()
891             + (speed_north_deg_sec - wind_speed_from_north_deg_sec 
892             + force_speed_north_deg_sec + friction_force_speed_north_deg_sec) * dt );
893         pos.setLongitudeDeg( pos.getLongitudeDeg()
894             + (speed_east_deg_sec - wind_speed_from_east_deg_sec 
895             + force_speed_east_deg_sec + friction_force_speed_east_deg_sec) * dt );
896         pos.setElevationFt(pos.getElevationFt() + vs * dt);
897     }
898
899 //    cout << _name << " run hs " << hs << " vs " << vs << endl;
900
901     // recalculate total speed
902     if ( vs == 0 && hs == 0)
903         speed = 0;
904     else
905         speed = sqrt( vs * vs + hs * hs) / SG_KT_TO_FPS;
906
907     // recalculate elevation and azimuth (velocity vectors)
908     _elevation = atan2( vs, hs ) * SG_RADIANS_TO_DEGREES;
909     _azimuth =  atan2((_speed_east_fps + force_speed_east_fps + friction_force_speed_east_fps), 
910         (_speed_north_fps + force_speed_north_fps + friction_force_speed_north_fps))
911         * SG_RADIANS_TO_DEGREES;
912
913     // rationalise azimuth
914     if (_azimuth < 0)
915         _azimuth += 360;
916
917     if (_aero_stabilised) { // we simulate rotational moment of inertia by using a filter
918         //cout<< "_aero_stabilised " << hdg << " az " << _azimuth << endl;
919         const double coeff = 0.9;
920
921         // we assume a symetrical MI about the pitch and yaw axis
922         setPch(_elevation, dt, coeff);
923         setHdg(_azimuth, dt, coeff);
924     } else if (_force_stabilised) { // we simulate rotational moment of inertia by using a filter
925         //cout<< "_force_stabilised "<< endl;
926         
927         const double coeff = 0.9;
928         double ratio = h_force_lbs/(_mass * slugs_to_lbs);
929
930         if (ratio >  1) ratio =  1;
931         if (ratio < -1) ratio = -1;
932
933         double force_pitch = acos(ratio) * SG_RADIANS_TO_DEGREES;
934
935         if (force_pitch <= force_elevation_deg)
936             force_pitch = force_elevation_deg;
937
938         // we assume a symetrical MI about the pitch and yaw axis
939         setPch(force_pitch,dt, coeff);
940         setHdg(_azimuth, dt, coeff);
941     }
942
943     //do impacts and collisions
944     if (_report_impact && !_impact_reported)
945         handle_impact();
946
947     if (_report_collision && !_collision_reported)
948         handle_collision();
949
950     // set destruction flag if altitude less than sea level -1000
951     if (altitude_ft < -1000.0 && life != -1)
952         setDie(true);
953
954 }  // end Run
955
956 double FGAIBallistic::_getTime() const {
957     return _life_timer;
958 }
959
960 void FGAIBallistic::setTime(double s){
961     _life_timer = s;
962 }
963
964 void FGAIBallistic::handle_impact() {
965
966     // try terrain intersection
967     double start = pos.getElevationM() + 100;
968
969     if(!getHtAGL(start)) 
970         return;
971
972     if (_ht_agl_ft <= 0) {
973         SG_LOG(SG_AI, SG_DEBUG, "AIBallistic: terrain impact material" << _mat_name);
974         report_impact(_elevation_m);
975         _impact_reported = true;
976
977         if (life == -1){
978             invisible = true;
979         } else if (_subID == 0)  // kill the AIObject if there is no subsubmodel
980             setDie(true);
981     } 
982 }
983
984 void FGAIBallistic::handle_expiry() {
985
986     //SG_LOG(SG_AI, SG_DEBUG, "AIBallistic: handle_expiry " << pos.getElevationM());
987
988     report_impact(pos.getElevationM());
989     _expiry_reported = true;
990
991     if (life == -1){
992         invisible = true;
993     } else if (_subID == 0){  // kill the AIObject if there is no subsubmodel
994         setDie(true);
995     }
996
997 }
998
999 void FGAIBallistic::handle_collision()
1000 {
1001     const FGAIBase *object = manager->calcCollision(pos.getElevationFt(),
1002         pos.getLatitudeDeg(),pos.getLongitudeDeg(), _fuse_range);
1003
1004     if (object) {
1005         report_impact(pos.getElevationM(), object);
1006         _collision_reported = true;
1007     }
1008 }
1009
1010 void FGAIBallistic::report_impact(double elevation, const FGAIBase *object)
1011 {
1012     _impact_lat    = pos.getLatitudeDeg();
1013     _impact_lon    = pos.getLongitudeDeg();
1014     _impact_elev   = elevation;
1015     _impact_speed  = speed * SG_KT_TO_MPS;
1016     _impact_hdg    = hdg;
1017     _impact_pitch  = pitch;
1018     _impact_roll   = roll;
1019
1020     SGPropertyNode *n = props->getNode("impact", true);
1021
1022     if (object)
1023         n->setStringValue("type", object->getTypeString());
1024     else
1025         n->setStringValue("type", "terrain");
1026
1027     SG_LOG(SG_AI, SG_DEBUG, "AIBallistic: object impact " << _name 
1028         << " lon " <<_impact_lon << " lat " <<_impact_lat << " sec " << _life_timer);
1029
1030     n->setDoubleValue("longitude-deg", _impact_lon);
1031     n->setDoubleValue("latitude-deg", _impact_lat);
1032     n->setDoubleValue("elevation-m", _impact_elev);
1033     n->setDoubleValue("heading-deg", _impact_hdg);
1034     n->setDoubleValue("pitch-deg", _impact_pitch);
1035     n->setDoubleValue("roll-deg", _impact_roll);
1036     n->setDoubleValue("speed-mps", _impact_speed);
1037
1038     _impact_report_node->setStringValue(props->getPath());
1039 }
1040
1041 SGVec3d FGAIBallistic::getCartUserPos() const {
1042     SGVec3d cartUserPos = SGVec3d::fromGeod(userpos);
1043     return cartUserPos;
1044 }
1045
1046 SGVec3d FGAIBallistic::getCartHitchPos() const{
1047
1048     // convert geodetic positions to geocentered
1049     SGVec3d cartuserPos = SGVec3d::fromGeod(userpos);
1050     //SGVec3d cartPos = getCartPos();
1051
1052     // Transform to the right coordinate frame, configuration is done in
1053     // the x-forward, y-right, z-up coordinates (feet), computation
1054     // in the simulation usual body x-forward, y-right, z-down coordinates
1055     // (meters) )
1056     SGVec3d _off(_x_offset * SG_FEET_TO_METER,
1057             _y_offset * SG_FEET_TO_METER,
1058             -_z_offset * SG_FEET_TO_METER);
1059
1060     // Transform the user position to the horizontal local coordinate system.
1061     SGQuatd hlTrans = SGQuatd::fromLonLat(userpos);
1062
1063     // and postrotate the orientation of the user model wrt the horizontal
1064     // local frame
1065     hlTrans *= SGQuatd::fromYawPitchRollDeg(
1066         manager->get_user_heading(),
1067         manager->get_user_pitch(),
1068         manager->get_user_roll());
1069
1070     // The offset converted to the usual body fixed coordinate system
1071     // rotated to the earth-fixed coordinates axis
1072     SGVec3d off = hlTrans.backTransform(_off);
1073
1074     // Add the position offset of the user model to get the geocentered position
1075     SGVec3d offsetPos = cartuserPos + off;
1076
1077     return offsetPos;
1078 }
1079
1080 void FGAIBallistic::setOffsetPos(SGGeod inpos, double heading, double pitch, double roll){
1081     // convert the hitch geocentered position to geodetic
1082
1083     SGVec3d cartoffsetPos = getCartOffsetPos(inpos, heading, pitch, roll);
1084
1085     //SGVec3d cartoffsetPos = getCartHitchPos();
1086
1087     //SGGeodesy::SGCartToGeod(cartoffsetPos, hitchpos);
1088     SGGeodesy::SGCartToGeod(cartoffsetPos, _offsetpos);
1089
1090 }
1091
1092 double FGAIBallistic::getDistanceToHitch() const {
1093     //calculate the distance load to hitch 
1094     SGVec3d carthitchPos = getCartHitchPos();
1095     SGVec3d cartPos = getCartPos();
1096
1097     SGVec3d diff = carthitchPos - cartPos;
1098     double distance = norm(diff);
1099     return distance * SG_METER_TO_FEET;
1100 }
1101
1102 double FGAIBallistic::getElevToHitch() const {
1103     // now the angle, positive angles are upwards
1104     double distance = getDistanceToHitch() * SG_FEET_TO_METER;
1105     double angle = 0;
1106     double daltM = _offsetpos.getElevationM() - pos.getElevationM();
1107
1108     if (fabs(distance) < SGLimits<float>::min()) {
1109         angle = 0;
1110     } else {
1111         double sAngle = daltM/distance;
1112         sAngle = SGMiscd::min(1, SGMiscd::max(-1, sAngle));
1113         angle = SGMiscd::rad2deg(asin(sAngle));
1114     }
1115
1116     return angle;
1117 }
1118
1119 double FGAIBallistic::getBearingToHitch() const {
1120     //calculate the bearing and range of the second pos from the first
1121     double distance = getDistanceToHitch() * SG_FEET_TO_METER;
1122     double az1, az2;
1123
1124     geo_inverse_wgs_84(pos, _offsetpos, &az1, &az2, &distance);
1125
1126     return az1;
1127 }
1128
1129 double FGAIBallistic::getRelBrgHitchToUser() const {
1130     //calculate the relative bearing 
1131     double az1, az2, distance;
1132
1133     geo_inverse_wgs_84(_offsetpos, userpos, &az1, &az2, &distance);
1134
1135     double rel_brg = az1 - hdg;
1136
1137     SG_NORMALIZE_RANGE(rel_brg, -180.0, 180.0);
1138
1139     return rel_brg;
1140 }
1141
1142 double FGAIBallistic::getElevHitchToUser() const {
1143
1144     //calculate the distance from the user position
1145     SGVec3d carthitchPos = getCartHitchPos();
1146     SGVec3d cartuserPos = getCartUserPos();
1147
1148     SGVec3d diff = cartuserPos - carthitchPos;
1149
1150     double distance = norm(diff);
1151     double angle = 0;
1152
1153     double daltM = userpos.getElevationM() - _offsetpos.getElevationM();
1154
1155     // now the angle, positive angles are upwards
1156     if (fabs(distance) < SGLimits<float>::min()) {
1157         angle = 0;
1158     } else {
1159         double sAngle = daltM/distance;
1160         sAngle = SGMiscd::min(1, SGMiscd::max(-1, sAngle));
1161         angle = SGMiscd::rad2deg(asin(sAngle));
1162     }
1163
1164     return angle;
1165 }
1166
1167 void FGAIBallistic::setTgtOffsets(double dt, double coeff){
1168     double c = dt / (coeff + dt);
1169
1170     _x_offset = (_tgt_x_offset * c) + (_x_offset * (1 - c));
1171     _y_offset = (_tgt_y_offset * c) + (_y_offset * (1 - c));
1172     _z_offset = (_tgt_z_offset * c) + (_z_offset * (1 - c));
1173 }
1174
1175
1176 void FGAIBallistic::calcVSHS(){
1177     // calculate vertical and horizontal speed components
1178     double speed_fps = speed * SG_KT_TO_FPS;
1179
1180     if (speed == 0.0) {
1181         hs = vs = 0.0;
1182     } else {
1183         vs = sin( _elevation * SG_DEGREES_TO_RADIANS ) * speed_fps;
1184         hs = cos( _elevation * SG_DEGREES_TO_RADIANS ) * speed_fps;
1185     }
1186 }
1187
1188 void FGAIBallistic::calcNE(){
1189     //resolve horizontal speed into north and east components:
1190     _speed_north_fps = cos(_azimuth / SG_RADIANS_TO_DEGREES) * hs;
1191     _speed_east_fps = sin(_azimuth / SG_RADIANS_TO_DEGREES) * hs;
1192
1193     // convert horizontal speed (fps) to degrees per second
1194     speed_north_deg_sec = _speed_north_fps / ft_per_deg_lat;
1195     speed_east_deg_sec  = _speed_east_fps / ft_per_deg_lon;
1196
1197 }
1198
1199 SGVec3d FGAIBallistic::getCartOffsetPos(SGGeod inpos, double user_heading, 
1200                                         double user_pitch, double user_roll
1201                                         ) const{
1202
1203     // convert geodetic positions to geocentered
1204      SGVec3d cartuserPos = SGVec3d::fromGeod(inpos);
1205     //SGVec3d cartuserPos = getCartUserPos();
1206     //SGVec3d cartPos = getCartPos();
1207
1208     // Transform to the right coordinate frame, configuration is done in
1209     // the x-forward, y-right, z-up coordinates (feet), computation
1210     // in the simulation usual body x-forward, y-right, z-down coordinates
1211     // (meters) )
1212     SGVec3d _off(_x_offset * SG_FEET_TO_METER,
1213             _y_offset * SG_FEET_TO_METER,
1214             -_z_offset * SG_FEET_TO_METER);
1215
1216     // Transform the user position to the horizontal local coordinate system.
1217     SGQuatd hlTrans = SGQuatd::fromLonLat(inpos);
1218
1219     // and postrotate the orientation of the user model wrt the horizontal
1220     // local frame
1221     hlTrans *= SGQuatd::fromYawPitchRollDeg(
1222         user_heading,
1223         user_pitch,
1224         user_roll);
1225
1226     // The offset converted to the usual body fixed coordinate system
1227     // rotated to the earth-fixed coordinates axis
1228     SGVec3d off = hlTrans.backTransform(_off);
1229
1230     // Add the position offset of the user model to get the geocentered position
1231     SGVec3d offsetPos = cartuserPos + off;
1232
1233     return offsetPos;
1234 }
1235
1236 void FGAIBallistic::setOffsetVelocity(double dt, SGGeod offsetpos) {
1237     //calculate the distance from the previous offset position
1238     SGVec3d cartoffsetPos = SGVec3d::fromGeod(offsetpos);
1239     SGVec3d diff = cartoffsetPos - _oldcartoffsetPos;
1240
1241     double distance = norm(diff);
1242     //calculate speed knots
1243     speed = (distance/dt) * SG_MPS_TO_KT;
1244
1245     //now calulate the angle between the old and current postion positions (degrees)
1246     double angle = 0;
1247     double daltM = offsetpos.getElevationM() - _oldoffsetpos.getElevationM();
1248
1249     if (fabs(distance) < SGLimits<float>::min()) {
1250         angle = 0;
1251     } else {
1252         double sAngle = daltM/distance;
1253         sAngle = SGMiscd::min(1, SGMiscd::max(-1, sAngle));
1254         angle = SGMiscd::rad2deg(asin(sAngle));
1255     }
1256
1257     _elevation = angle;
1258
1259     //calculate vertical and horizontal speed components
1260     calcVSHS();
1261
1262     //calculate the bearing of the new offset position from the old
1263     //don't do this if speed is low
1264     //cout << "speed " << speed << endl;
1265     if (speed > 0.1){
1266         double az1, az2, dist;
1267         geo_inverse_wgs_84(_oldoffsetpos, offsetpos, &az1, &az2, &dist);
1268         _azimuth = az1;
1269         //cout << "offset az " << _azimuth << endl;
1270     } else {
1271         _azimuth = hdg;
1272         //cout << " slow offset az " << _azimuth << endl;
1273     }
1274
1275     //resolve horizontal speed into north and east components:
1276     calcNE();
1277
1278     // and finally store the new values
1279     _oldcartoffsetPos = cartoffsetPos;
1280     _oldoffsetpos = offsetpos;
1281 }
1282
1283 // end AIBallistic