10 #include "gfx/cockpit_generic.h"
11 #include "cmd/unit_generic.h"
14 #include "cmd/script/mission.h"
17 #include "cmd/unit_util.h"
20 #include "cmd/role_bitmask.h"
22 using namespace GalaxyXML;
28 while ( star_system.size() ) {
29 star_system.back()->RemoveStarsystemFromUniverse();
30 delete star_system.back();
31 star_system.pop_back();
33 active_star_system.clear();
39 Cockpit *cp =
new Cockpit(
"", NULL, player );
40 cockpit.push_back( cp );
49 if ( !plr || !plr->getStarSystem() ) {
50 safevec = QVector( 0, 0, 0 );
56 Unit *closestUnit = NULL;
60 QVector dock_position( plr->curr_physical_state.position );
61 for (un_iter iter = plr->getStarSystem()->getUnitList().createIterator(); (un = *iter); ++iter)
62 if (un->name == str || un->getFullname() == str) {
63 dist = UnitUtil::getSignificantDistance( plr, un );
64 if (closestUnit == NULL || dist < lastdist) {
70 if (UnitUtil::getSignificantDistance( plr, closestUnit ) > 0 && closestUnit->isUnit() != PLANETPTR)
71 dock_position = closestUnit->Position();
73 plr->SetPosAndCumPos( dock_position );
75 vector< DockingPorts >dprt = closestUnit->pImage->dockingports;
78 if ( i >= dprt.size() ) {
79 safevec = QVector( 0, 0, 0 );
82 if (!dprt[i].IsOccupied())
85 plr->ForceDock( closestUnit, i );
86 closestUnit->pImage->clearedunits.push_back( plr );
87 closestUnit->RequestPhysics();
94 safevec = dock_position;
95 return ( closestUnit && closestUnit->isDocked( plr ) ) ? closestUnit : NULL;
102 if (!doNotDereference)
104 for (std::vector< Cockpit* >::iterator iter = cockpit.begin(); iter < cockpit.end(); iter++)
105 if ( doNotDereference == ( *(iter) )->GetParent() )
112 if (!doNotDereference)
114 for (
unsigned int i = 0; i < cockpit.size(); i++)
115 if ( doNotDereference == cockpit[i]->GetParent() )
123 if ( i < 0 || i >= cockpit.size() )
131 for (
unsigned int i = 0; i < cockpit.size(); i++)
132 if (cockpit[i] == cp) {
133 SetActiveCockpit( i );
140 for (
unsigned int i = 0; i < playerNames.size(); i++)
141 cockpit.push_back(
new Cockpit(
"", NULL, playerNames[i] ) );
146 if ( ( *ss.begin() ) == drawn )
148 vector< StarSystem* >::iterator drw = std::find( ss.begin(), ss.end(), drawn );
149 if ( drw != ss.end() ) {
151 vector< StarSystem* >::iterator i = ss.begin();
163 ROLES::getAllRolePriorities();
166 static bool firsttime =
false;
168 LoadFactionXML(
"factions.xml" );
171 script_system = NULL;
175 : current_cockpit( 0 )
176 , script_system( NULL )
178 this->
Init( galaxy_str );
184 : current_cockpit( 0 )
185 , script_system( NULL )
198 std::cerr<<
"Loading a starsystem"<<std::endl;
227 string fullname = systemfile+
".system";
233 vector< StarSystem* >::iterator iter;
244 using namespace VSFileSystem;
246 static void ss_generating(
bool enable )
248 static bool ss_generating_active =
false;
251 static const std::string empty;
253 ss_generating_active =
true;
255 }
else if (ss_generating_active) {
257 ss_generating_active =
false;
266 ss_generating(
true );
273 string filestr( file );
280 static bool firsttime =
true;
281 LoadStarSystem( ss );
282 pushActiveStarSystem( ss );
283 static int num_times_to_simulate_new_star_system =
285 for (
unsigned int tume = 0; tume <= num_times_to_simulate_new_star_system*
SIM_QUEUE_SIZE+1; ++tume)
288 StarSystem *old_script_system = script_system;
291 const vector< std::string > &adjacent = getAdjacentStarSystems( ss->
getFileName() );
292 for (
unsigned int i = 0; i < adjacent.size(); i++) {
295 static bool first =
true;
297 mission->DirectorStartStarSystem( ss );
299 script_system = old_script_system;
300 popActiveStarSystem();
301 if ( active_star_system.empty() ) {
302 pushActiveStarSystem( ss );
305 activeStarSystem()->SwapIn();
310 ss_generating(
false );
318 this->Generate1( file, jumpback );
320 this->Generate2( ss );
327 float systime = nonactivesystemtime;
328 for (
unsigned int i = 0; i < star_system.size(); ++i)
330 star_system[i]->
Update( (i == 0) ? 1 : systime/i );
335 for (
unsigned int i = 0; i < star_system.size(); i++)
336 if (star_system[i] == ss)
346 while (unitdata.length() != 0) {
347 string::size_type where = unitdata.find(
" " ), where2 = where;
348 if (where == string::npos)
349 where = unitdata.length();
350 string tmp = unitdata.substr( 0, where );
353 unitTables.push_back(
new CSVTable( allUnits, allUnits.
GetRoot() ) );
356 if (where2 == string::npos)
break;
357 unitdata = unitdata.substr( where+1, unitdata.length() );
362 unitTables.push_back(
new CSVTable( allUnits, allUnits.
GetRoot() ) );
369 for (std::vector<CSVTable*>::iterator it = unitTables.begin(); it != unitTables.end(); ++it)