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