~ubuntu-branches/ubuntu/precise/flightgear/precise

« back to all changes in this revision

Viewing changes to src/AIModel/performancedb.cxx

  • Committer: Bazaar Package Importer
  • Author(s): Ove Kaaven
  • Date: 2011-01-30 15:46:35 UTC
  • mfrom: (3.1.7 sid)
  • Revision ID: james.westby@ubuntu.com-20110130154635-rlynmg9n5hzxq5xe
Tags: 2.0.0-3
* Recommend fgfs-aircraft-base and fgfs-models-base.
  Closes. #610276.
* Added note about scenery SharedModels.tgz to README.Debian.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <simgear/math/SGMath.hxx>
 
2
#include <simgear/misc/sg_path.hxx>
 
3
#include <simgear/props/props.hxx>
 
4
#include <simgear/props/props_io.hxx>
 
5
#include <simgear/xml/easyxml.hxx>
 
6
 
 
7
#include <Main/globals.hxx>
 
8
#include <iostream>
 
9
#include <fstream>
 
10
 
1
11
#include "performancedb.hxx"
2
12
 
 
13
using std::string;
 
14
using std::cerr;
 
15
 
3
16
PerformanceDB::PerformanceDB()
4
17
{
5
 
    // these are the 6 classes originally defined in the PERFSTRUCT
6
 
    registerPerformanceData("light", new PerformanceData(
7
 
        2.0, 2.0,  450.0, 1000.0,  70.0, 70.0,  80.0, 100.0,  80.0,  70.0, 60.0, 15.0));
8
 
    registerPerformanceData("ww2_fighter", new PerformanceData(
9
 
        4.0, 2.0,  3000.0, 1500.0,  110.0, 110.0,  180.0, 250.0,  200.0,  130.0, 100.0, 15.0));
10
 
    registerPerformanceData("jet_fighter", new PerformanceData(
11
 
        7.0, 3.0,  4000.0, 2000.0,  120.0, 150.0,  350.0, 500.0,  350.0,  170.0, 150.0, 15.0));
12
 
    registerPerformanceData("jet_transport", new PerformanceData(
13
 
        5.0, 2.0,  3000.0, 1500.0,  100.0, 140.0,  300.0, 430.0,  300.0,  170.0, 130.0, 15.0));
14
 
    registerPerformanceData("tanker", new PerformanceData(
15
 
        5.0, 2.0,  3000.0, 1500.0,  100.0, 140.0,  300.0, 430.0,  300.0,  170.0, 130.0, 15.0));
16
 
    registerPerformanceData("ufo", new PerformanceData(
17
 
        30.0, 30.0, 6000.0, 6000.0, 150.0, 150.0, 300.0, 430.0, 300.0, 170.0, 130.0, 15.0));
 
18
    SGPath dbpath( globals->get_fg_root() );
 
19
    
18
20
 
 
21
    dbpath.append( "/AI/Aircraft/" );
 
22
    dbpath.append( "performancedb.xml"); 
 
23
    load(dbpath);
19
24
}
20
25
 
21
26
 
38
43
 
39
44
    return _db[id];
40
45
}
 
46
 
 
47
void PerformanceDB::load(SGPath filename) {
 
48
    string name;
 
49
    double acceleration;
 
50
    double deceleration;
 
51
    double climbRate;
 
52
    double descentRate;
 
53
    double vRotate;
 
54
    double vTakeOff;
 
55
    double vClimb;
 
56
    double vCruise;
 
57
    double vDescent;
 
58
    double vApproach;
 
59
    double vTouchdown;
 
60
    double vTaxi;
 
61
    SGPropertyNode root;
 
62
    try {
 
63
        readProperties(filename.str(), &root);
 
64
    } catch (const sg_exception &) {
 
65
        SG_LOG(SG_GENERAL, SG_ALERT,
 
66
            "Error reading AI aircraft performance database: " << filename.str());
 
67
        return;
 
68
    }
 
69
 
 
70
    SGPropertyNode * node = root.getNode("performancedb");
 
71
    for (int i = 0; i < node->nChildren(); i++) { 
 
72
        SGPropertyNode * db_node = node->getChild(i);
 
73
            name         = db_node->getStringValue("type", "heavy_jet");
 
74
            acceleration = db_node->getDoubleValue("acceleration-kts-hour", 4.0);
 
75
            deceleration = db_node->getDoubleValue("deceleration-kts-hour", 2.0);
 
76
            climbRate    = db_node->getDoubleValue("climbrate-fpm", 3000.0);
 
77
            descentRate  = db_node->getDoubleValue("decentrate-fpm", 1500.0);
 
78
            vRotate      = db_node->getDoubleValue("rotate-speed-kts", 150.0);
 
79
            vTakeOff     = db_node->getDoubleValue("takeoff-speed-kts", 160.0);
 
80
            vClimb       = db_node->getDoubleValue("climb-speed-kts", 300.0);
 
81
            vCruise      = db_node->getDoubleValue("cruise-speed-kts", 430.0);
 
82
            vDescent     = db_node->getDoubleValue("decent-speed-kts", 300.0);
 
83
            vApproach    = db_node->getDoubleValue("approach-speed-kts", 170.0);
 
84
            vTouchdown   = db_node->getDoubleValue("touchdown-speed-kts", 150.0);
 
85
            vTaxi        = db_node->getDoubleValue("taxi-speed-kts", 15.0);
 
86
 
 
87
            registerPerformanceData(name, new PerformanceData(
 
88
                acceleration, deceleration, climbRate, descentRate, vRotate, vTakeOff, vClimb, vCruise, vDescent, vApproach, vTouchdown, vTaxi));
 
89
    }
 
90
}
 
91