~ubuntu-branches/ubuntu/oneiric/flightgear/oneiric

« back to all changes in this revision

Viewing changes to src/Traffic/TrafficMgr.cxx

  • Committer: Bazaar Package Importer
  • Author(s): Daniel T Chen
  • Date: 2006-01-05 12:48:11 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20060105124811-xsr6rtcrb88w19c8
Tags: 0.9.9-1ubuntu1
Resynchronise with Debian.

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
 
42
42
#include <string>
43
43
#include <vector>
 
44
#include <algorithm>
44
45
 
45
46
#include <plib/sg.h>
46
47
 
53
54
#include <simgear/structure/subsystem_mgr.hxx>
54
55
#include <simgear/xml/easyxml.hxx>
55
56
 
 
57
#include <AIModel/AIAircraft.hxx>
56
58
#include <AIModel/AIFlightPlan.hxx>
57
59
#include <AIModel/AIBase.hxx>
58
60
#include <Airports/simple.hxx>
62
64
 
63
65
#include "TrafficMgr.hxx"
64
66
 
 
67
SG_USING_STD(sort);
65
68
 
66
69
/******************************************************************************
67
70
 * TrafficManager
72
75
 
73
76
 
74
77
void FGTrafficManager::init()
75
 
{
76
 
  currAircraft = scheduledAircraft.begin();
 
78
 
79
  //cerr << "Initializing Schedules" << endl;
 
80
  time_t now = time(NULL) + fgGetLong("/sim/time/warp");
 
81
  currAircraft = scheduledAircraft.begin();
 
82
  while (currAircraft != scheduledAircraft.end())
 
83
    {
 
84
      if (!(currAircraft->init()))
 
85
        {
 
86
          currAircraft=scheduledAircraft.erase(currAircraft);
 
87
          //cerr << "Erasing " << currAircraft->getRegistration() << endl;
 
88
          currAircraft--;
 
89
        }
 
90
      else 
 
91
        {
 
92
          currAircraft++;
 
93
        }
 
94
    }
 
95
  //cerr << "Sorting by distance " << endl;
 
96
  sort(scheduledAircraft.begin(), scheduledAircraft.end());
 
97
  currAircraft = scheduledAircraft.begin();
 
98
  currAircraftClosest = scheduledAircraft.begin();
 
99
  //cerr << "Done initializing schedules" << endl;
77
100
}
78
101
 
79
102
void FGTrafficManager::update(double something)
80
103
{
81
 
 
82
 
  //static const SGPropertyNode *warp = globals->get_props()->getNode("/sim/time/warp");
83
 
  
84
 
  //time_t now = time(NULL) + globals->get_warp();
85
104
  time_t now = time(NULL) + fgGetLong("/sim/time/warp");
86
 
  //  cerr << "TrafficManager update" << globals->get_warp() << endl;
87
 
    if(currAircraft == scheduledAircraft.end())
 
105
  if(currAircraft == scheduledAircraft.end())
 
106
    {
 
107
      //cerr << "resetting schedule " << endl;
88
108
      currAircraft = scheduledAircraft.begin();
89
 
    currAircraft->update(now);
90
 
    currAircraft++;
 
109
    }
 
110
  if (!(currAircraft->update(now)))
 
111
    {
 
112
      // after proper initialization, we shouldnt get here.
 
113
      // But let's make sure
 
114
      cerr << "Failed to update aircraft schedule in traffic manager" << endl;
 
115
    }
 
116
  currAircraft++;
91
117
}
92
118
 
93
 
void FGTrafficManager::release(void *id)
 
119
void FGTrafficManager::release(int id)
94
120
{
95
121
  releaseList.push_back(id);
96
122
}
97
123
 
98
 
bool FGTrafficManager::isReleased(void *id)
 
124
bool FGTrafficManager::isReleased(int id)
99
125
{
100
126
  IdListIterator i = releaseList.begin();
101
127
  while (i != releaseList.end())
146
172
    livery = value;
147
173
  else if (element == string("registration"))
148
174
    registration = value;
 
175
  else if (element == string("airline"))
 
176
    airline = value;
 
177
  else if (element == string("actype"))
 
178
    acType = value;
 
179
  else if (element == string("flighttype"))
 
180
    flighttype = value;
 
181
  else if (element == string("radius"))
 
182
    radius = atoi(value.c_str());
 
183
  else if (element == string("offset"))
 
184
    offset = atoi(value.c_str());
 
185
  else if (element == string("performance-class"))
 
186
    m_class = value;
149
187
  else if (element == string("heavy"))
150
188
    {
151
189
      if(value == string("true"))
195
233
    {
196
234
      //cerr << "Pushing back aircraft " << registration << endl;
197
235
      scheduledAircraft.push_back(FGAISchedule(mdl, 
198
 
                                                livery, 
199
 
                                                registration, 
200
 
                                                heavy, 
201
 
                                                flights));
 
236
                                               livery, 
 
237
                                               registration, 
 
238
                                               heavy,
 
239
                                               acType, 
 
240
                                               airline, 
 
241
                                               m_class, 
 
242
                                               flighttype,
 
243
                                               radius,
 
244
                                               offset,
 
245
                                               flights));
202
246
      while(flights.begin() != flights.end())
203
247
        flights.pop_back();
204
248
    }