#include <Main/viewer.hxx>
#include <Scenery/scenery.hxx>
-#include <Scenery/tilemgr.hxx>
#include <Airports/dynamics.hxx>
#include "AIGroundVehicle.hxx"
_range_ft(0),
_relbrg (0),
_parent_speed(0),
-_dt_count(0),
-_next_run(0),
_parent_x_offset(0),
_parent_y_offset(0),
_parent_z_offset(0),
+_dt_count(0),
+_next_run(0),
_break_count(0)
{
SG_CLAMP_RANGE(_tow_angle, -limit, limit);
}
-bool FGAIGroundVehicle::getGroundElev(SGGeod inpos) {
-
- double height_m ;
-
- if (globals->get_scenery()->get_elevation_m(SGGeod::fromGeodM(inpos, 3000), height_m, &_material,0)){
- _ht_agl_ft = inpos.getElevationFt() - height_m * SG_METER_TO_FEET;
-
- if (_material) {
- const vector<string>& names = _material->get_names();
-
- _solid = _material->get_solid();
-
- if (!names.empty())
- props->setStringValue("material/name", names[0].c_str());
- else
- props->setStringValue("material/name", "");
-
- //cout << "material " << names[0].c_str()
- // << " _elevation_m " << _elevation_m
- // << " solid " << _solid
- // << " load " << _load_resistance
- // << " frictionFactor " << _frictionFactor
- // << endl;
-
- }
-
- return true;
- } else {
- return false;
- }
-
-}
-
bool FGAIGroundVehicle::getPitch() {
if (!_tunnel){
double rear_elev_m = 0;
double elev_front = 0;
double elev_rear = 0;
- double max_alt = 10000;
+ //double max_alt = 10000;
if (globals->get_scenery()->get_elevation_m(SGGeod::fromGeodM(geodFront, 3000),
elev_front, &_material, 0)){
} else {
- if (prev->altitude == 0 || curr->altitude == 0) return false;
+ if (prev->getAltitude() == 0 || curr->getAltitude() == 0) return false;
static double distance;
static double d_alt;
if (_new_waypoint){
//cout << "new waypoint, calculating pitch " << endl;
- curr_alt = curr->altitude;
- prev_alt = prev->altitude;
+ curr_alt = curr->getAltitude();
+ prev_alt = prev->getAltitude();
//cout << "prev_alt" <<prev_alt << endl;
d_alt = (curr_alt - prev_alt) * SG_METER_TO_FEET;
//_elevation = prev->altitude;
- distance = SGGeodesy::distanceM(SGGeod::fromDeg(prev->longitude, prev->latitude),
- SGGeod::fromDeg(curr->longitude, curr->latitude));
+ distance = SGGeodesy::distanceM(SGGeod::fromDeg(prev->getLongitude(), prev->getLatitude()),
+ SGGeod::fromDeg(curr->getLongitude(), curr->getLatitude()));
_pitch = atan2(d_alt, distance * SG_METER_TO_FEET) * SG_RADIANS_TO_DEGREES;
//cout << "new waypoint, calculating pitch " << _pitch <<
// " " << _pitch_offset << " " << _elevation <<endl;
}
double distance_to_go = SGGeodesy::distanceM(SGGeod::fromDeg(pos.getLongitudeDeg(), pos.getLatitudeDeg()),
- SGGeod::fromDeg(curr->longitude, curr->latitude));
+ SGGeod::fromDeg(curr->getLongitude(), curr->getLatitude()));
/*cout << "tunnel " << _tunnel
<< " distance prev & curr " << prev->name << " " << curr->name << " " << distance * SG_METER_TO_FEET
}
- //getGroundElev(pos);
-
return true;
}
-//void FGAIGroundVehicle::setParentNode() {
-//
-// if(_parent == "")
-// return;
-//
-// const SGPropertyNode_ptr ai = fgGetNode("/ai/models", true);
-//
-// for (int i = ai->nChildren() - 1; i >= -1; i--) {
-// SGPropertyNode_ptr model;
-//
-// if (i < 0) { // last iteration: selected model
-// model = _selected_ac;
-// } else {
-// model = ai->getChild(i);
-// string path = ai->getPath();
-// const string name = model->getStringValue("name");
-//
-// if (!model->nChildren()){
-// continue;
-// }
-// if (name == _parent) {
-// _selected_ac = model; // save selected model for last iteration
-// break;
-// }
-//
-// }
-// if (!model)
-// continue;
-//
-// }// end for loop
-//
-// if (_selected_ac != 0){
-// const string name = _selected_ac->getStringValue("name");
-// //_parent_x_offset = _selected_ac->getDoubleValue("hitch/x-offset-ft");
-// //_parent_y_offset = _selected_ac->getDoubleValue("hitch/y-offset-ft");
-// //_parent_z_offset = _selected_ac->getDoubleValue("hitch/z-offset-ft");
-// //_hitch_x_offset_m = _selected_ac->getDoubleValue("hitch/x-offset-ft")
-// // * SG_FEET_TO_METER;
-// //_hitch_y_offset_m = _selected_ac->getDoubleValue("hitch/y-offset-ft")
-// // * SG_FEET_TO_METER;
-// //_hitch_z_offset_m = _selected_ac->getDoubleValue("hitch/z-offset-ft")
-// // * SG_FEET_TO_METER;
-// //setParent();
-// } else {
-// SG_LOG(SG_GENERAL, SG_ALERT, "AIGroundVeh1cle: " << _name
-// << " parent not found: dying ");
-// setDie(true);
-// }
-//
-//}
-
void FGAIGroundVehicle::setParent(){
double lat = _selected_ac->getDoubleValue("position/latitude-deg");
range = distance * SG_METER_TO_NM;
}
-double FGAIGroundVehicle::calcRelBearingDeg(double bearing, double heading)
-{
- double angle = bearing - heading;
- SG_NORMALIZE_RANGE(angle, -180.0, 180.0);
- return angle;
-}
SGVec3d FGAIGroundVehicle::getCartHitchPosAt(const SGVec3d& _off) const {
double hdg = _selected_ac->getDoubleValue("orientation/true-heading-deg");
double count = 0;
string parent_next_name =_selected_ac->getStringValue("waypoint/name-next");
- while(fp->getNextWaypoint() != 0 && fp->getNextWaypoint()->name != "END" && count < 5){
+ while(fp->getNextWaypoint() != 0 && fp->getNextWaypoint()->getName() != "END" && count < 5){
SG_LOG(SG_GENERAL, SG_DEBUG, "AIGroundVeh1cle: " << _name
<<" advancing waypoint to: " << parent_next_name);
- if (fp->getNextWaypoint()->name == parent_next_name){
+ if (fp->getNextWaypoint()->getName() == parent_next_name){
SG_LOG(SG_GENERAL, SG_DEBUG, "AIGroundVeh1cle: " << _name
- << " not setting waypoint already at: " << fp->getNextWaypoint()->name);
+ << " not setting waypoint already at: " << fp->getNextWaypoint()->getName());
return;
}
curr = fp->getCurrentWaypoint();
next = fp->getNextWaypoint();
- if (fp->getNextWaypoint()->name == parent_next_name){
+ if (fp->getNextWaypoint()->getName() == parent_next_name){
SG_LOG(SG_GENERAL, SG_DEBUG, "AIGroundVeh1cle: " << _name
- << " waypoint set to: " << fp->getNextWaypoint()->name);
+ << " waypoint set to: " << fp->getNextWaypoint()->getName());
return;
}
}// end while loop
- while(fp->getPreviousWaypoint() != 0 && fp->getPreviousWaypoint()->name != "END"
+ while(fp->getPreviousWaypoint() != 0 && fp->getPreviousWaypoint()->getName() != "END"
&& count > -10){
SG_LOG(SG_GENERAL, SG_DEBUG, "AIGroundVeh1cle: " << _name
<< " retreating waypoint to: " << parent_next_name
- << " at: " << fp->getNextWaypoint()->name);
+ << " at: " << fp->getNextWaypoint()->getName());
- if (fp->getNextWaypoint()->name == parent_next_name){
+ if (fp->getNextWaypoint()->getName() == parent_next_name){
SG_LOG(SG_GENERAL, SG_DEBUG, "AIGroundVeh1cle: " << _name
- << " not setting waypoint already at:" << fp->getNextWaypoint()->name );
+ << " not setting waypoint already at:" << fp->getNextWaypoint()->getName() );
return;
}
curr = fp->getCurrentWaypoint();
next = fp->getNextWaypoint();
- if (fp->getNextWaypoint()->name == parent_next_name){
+ if (fp->getNextWaypoint()->getName() == parent_next_name){
SG_LOG(SG_GENERAL, SG_DEBUG, "AIGroundVeh1cle: " << _name
- << " waypoint set to: " << fp->getNextWaypoint()->name);
+ << " waypoint set to: " << fp->getNextWaypoint()->getName());
return;
}
void FGAIGroundVehicle::setTowSpeed(){
- double diff = _range_ft - _x_offset;
+ //double diff = _range_ft - _x_offset;
double x = 0;
if (_range_ft > _x_offset * 3) x = 50;
}
if(_parent == ""){
- AccelTo(prev->speed);
+ AccelTo(prev->getSpeed());
_dt_count = 0;
return;
}
string parent_next_name = _selected_ac->getStringValue("waypoint/name-next");
bool parent_waiting = _selected_ac->getBoolValue("waypoint/waiting");
- bool parent_restart = _selected_ac->getBoolValue("controls/restart");
+ //bool parent_restart = _selected_ac->getBoolValue("controls/restart");
- if (parent_next_name == "END" && fp->getNextWaypoint()->name != "END" ){
+ if (parent_next_name == "END" && fp->getNextWaypoint()->getName() != "END" ){
SG_LOG(SG_GENERAL, SG_DEBUG, "AIGroundVeh1cle: " << _name
<< " setting END: getting new waypoints ");
AdvanceFP();
AdvanceFP();
setWPNames();
_waiting = true;
- } else if (parent_next_name != "WAIT" && fp->getNextWaypoint()->name == "WAIT"){
+ } else if (parent_next_name != "WAIT" && fp->getNextWaypoint()->getName() == "WAIT"){
SG_LOG(SG_GENERAL, SG_DEBUG, "AIGroundVeh1cle: " << _name
<< " wait done: getting new waypoints ");
_waiting = false;
fp->IncrementWaypoint(false);
next = fp->getNextWaypoint();
- if (next->name == "WAITUNTIL" || next->name == "WAIT"
- || next->name == "END"){
+ if (next->getName() == "WAITUNTIL" || next->getName() == "WAIT"
+ || next->getName() == "END"){
} else {
prev = curr;
fp->IncrementWaypoint(false);