mElite  1.0
An Elite clone based on TextElite by Jan-Philipp Kappmeier and Melanie Schmidt.
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
World.cpp
Go to the documentation of this file.
1 
6 #include "World.h"
7 #include "SpaceShip.h"
8 #include "GlobalParameters.h"
9 #include "Textures.h"
10 #include "Wrapper.h"
11 #include "Objects.h"
12 #include "FileAccess.h"
13 #include "MovingObject.h"
14 #include "Planet.h"
15 #include "Wrapper.h"
16 #include "SpaceShip.h"
17 #include "ForeignSpaceShip.h"
18 #include "Thargon.h"
19 #include "Pirate.h"
20 #include "Merchant.h"
21 #include "PoliceShip.h"
22 #include "GraphicsObject.h"
23 #include "PlayerObject.h"
24 #include "GameObject.h"
25 #include "Star.h"
26 #include "Planet.h"
27 #include "SpaceStation.h"
28 
29 using namespace std;
30 
38 
39 
46  // init the data structure
47  GameObjects.clear();
48 
49  float lightspeed = 0.00815;
50 
51  // create player
52  PlayerObject *player = new PlayerObject( 0, 0, 4100, 0 , 0);
53  player->setView( Vector3( 0, 0, -1 ) );
54  player->setMaxSpeed( lightspeed );
55  player->setMinSpeed( -lightspeed*0.5 );
56  player->setStep( lightspeed/20.0 * 0.2 ); // 0.2 is a calibration value ;) greater value increases speed faster
57  player->setMoveSpeed( player->getMaxSpeed()*0.5 );
58 
59  GameObjects.push_back( player );
60 
61  list<GameObject*>::iterator it = GameObjects.begin();
62  playerPosition = it;
63 
64  // create the star(s)
65  Star *sun = new Star( 0, 0, 0, 1000, star );
66  //sun->setLightColor( 0, 1, 0);
67  sun->setAxis( 0, 1, 0 );
68  sun->setSpeed( -0.006);
69  sun->setRotateAngle( 0 );
70  sun->setRotateSpeed( 0 );
71 
72  GameObjects.push_back( sun );
73  starPosition = ++it;
74 
75  // get planets info
76  vector<PlanetInfoGraphical> planets = *World::getWorld()->getSystemPlanets();
77 
78  // get a planet for placing coriolis station later
79 
80  unsigned int coriolisPlanetNr = nrForCoriolis[wrapper->getCurrentSystem()];
81  Planet * coriolisPlanet;
82 
83  // create planets
84  PlanetInfoGraphical planet = planets[0];
85  float scaleFactor = (4155.0*0.5) / (planet.distance); // this sets the distance of the first planet to 4155/2
86  for( unsigned int i=0; i < planets.size(); i++ ) {
87  PlanetInfoGraphical planetInfo = planets[i];
88  Planet *planet = new Planet( 0, 0, scaleFactor*planetInfo.distance, planetInfo.radius*10, planet1+i );
89  planet->setAxis( 0, 1, 0 );
90  planet->setColor( 0, 0, 0 );
91  planet->setSpeed( planetInfo.spinningSpeed );
92  // set rotate angle randomly, but in [-30,30] intervall
93  // set corolis planet rotate angle randomly, but in [-15,15] intervall
94  planet->setRotateAngle((rand()%61-30));
95  //planet->setRotateAngle( 0 );
96  planet->setRotateSpeed( 0 );
97  GameObjects.push_back( planet );
98  if (i == coriolisPlanetNr)
99  coriolisPlanet = planet;
100  it++;
101  }
102 
103  // set corolis planet rotate angle randomly, but in [-15,15] intervall
104  // coriolisPlanet->setRotateAngle((rand()%31-15));
105  coriolisPlanet->setRotateAngle(0);
106 
107  // create coriolis station
108  SpaceStation *station = new SpaceStation( 1, Objects::getObjects()->getDisplayList( coriolis ) );
109  // calculate random position in orbit
110  float sx, sy, sz;
111  sx = coriolisPlanet->getPos().x;
112  sy = coriolisPlanet->getPos().y;
113  sz = coriolisPlanet->getPos().z;
114  Vector3 a = Vector3( rand()%100, rand()%100, rand()%100);
115  a.normalize();
116  a = a * coriolisPlanet->getCollisionRadius()*2.0f;//4150 );
117  station->setPos( sx+a.x, sy+a.y, sz+a.z );
118  //station->setPos(sx,sy,sz);
119  station->setSpeed( 0.006 );
120  station->setAxis( a ); // Vector3( 0, 0, 1 ) );
121  GameObjects.push_back( station );
122  stationPosition = ++it;
123 
124  playerStartDistance = 1000;
125 
126  player->setPos(station->getPos().x,station->getPos().y,station->getPos().z+playerStartDistance);
127 
128  // create 5 up to 10 pirates
129  unsigned int numOfPirates = rand()%6+5;
130  //numOfPirates = 0;
131 
132  for (unsigned i = 0; i < numOfPirates; i++)
133  {
134  Pirate* ship;
135  ship = World::getWorld()->createNewPirate( anaconda, 1, player, lightspeed*0.75 );
136 
137  // pirates are between player and station, but not at station (there is the police)
138  int rangeStart = (int)((playerStartDistance) * 0.50); //-(int)playerStartDistance* 0.5;
139  int rangeEnd = (int)((playerStartDistance) * 0.90);
140  int range = rangeEnd-rangeStart;
141 
142  Vector3 offset;
143  offset.x = (rand()%101)-50;
144  offset.y = (rand()%101)-50;
145  offset.z = (rand()%range)+rangeStart;
146 
147  Vector3 stationPos = station->getPos();
148 
149  ship->setPos (stationPos+offset);
150  }
151 
152  // create thargoids; maximal 5, but less if there are already more than 5 pirates
153  unsigned int maxNumberOfThargoids = max((int)0,(int)(11-numOfPirates));
154  unsigned int numOfThargoids = rand()%(maxNumberOfThargoids+1);
155 
156  //numOfThargoids = 0;
157 
158  int thargoidPositionRangeStart = (int)((playerStartDistance) * 0.20);
159  int thargoidPositionRangeEnd = (int)((playerStartDistance) * 0.45);
160  int thargoidPositionRange = thargoidPositionRangeEnd-thargoidPositionRangeStart;
161 
162  int thargoidPosition = rand()%thargoidPositionRange+thargoidPositionRangeStart;
163 
164  int thargoidRange = 100;
165 
166  for (unsigned i = 0; i < numOfThargoids; i++)
167  {
168  Thargon* ship;
169  ship = World::getWorld()->createNewThargon( ball, 1, player, lightspeed/2 );
170 
171  // thargoids are all in a certain field
172 
173  Vector3 offset;
174  offset.x = (rand()%101)-50;
175  offset.y = (rand()%101)-50;
176  offset.z = (thargoidPosition+rand()%thargoidRange-thargoidRange/2);
177 
178  Vector3 stationPos = station->getPos();
179  ship->setPos( stationPos + offset);
180 
181  }
182 
183  // create PoliceShips
184  unsigned int numOfPoliceShips = 3 + rand()%3;
185 
186  int shipsPositionRangeStart = (int)((playerStartDistance) * 0.01);
187  int shipsPositionRangeEnd = (int)((playerStartDistance) * 0.15);
188  int shipsPositionRange = shipsPositionRangeEnd-shipsPositionRangeStart;
189 
190  for (unsigned int i = 0; i < numOfPoliceShips; i++)
191  {
192  std::vector<Vector3> pointList;
193  Vector3 offset;
194 
195  Vector3 stationPos = station->getPos();
196 
197  unsigned int shipPosition= rand()%shipsPositionRange+shipsPositionRangeStart;
198 
199  for (unsigned int j = 0; j < 3; j++)
200  {
201  offset.x = (rand()%51)-25;
202  offset.y = (rand()%51)-25;
203  offset.z = shipPosition;
204  pointList.push_back(offset+stationPos);
205  }
206 
207  PoliceShip* ship;
208  ship = World::getWorld()->createNewPoliceShip( adder, 1, pointList,player, lightspeed*0.75 );
209  }
210 
211  // create a merchant
212 
213  int shipPositionRangeStart = (int)((playerStartDistance) * 0.01);
214  int shipPositionRangeEnd = (int)((playerStartDistance) * 0.05);
215  int shipPositionRange = shipsPositionRangeEnd-shipsPositionRangeStart;
216 
217  Vector3 offset;
218  offset.x = (rand()%41)-20;
219  offset.y = (rand()%41)-20;
220  offset.z = rand()%shipsPositionRange+shipsPositionRangeStart;
221 
222  Merchant* ship;
223  ship = World::getWorld()->createNewMerchant( thargoid, 1, coriolisPlanet, player->getPos()+offset);
224 
225  Vector3 stationPos = station->getPos();
226  ship->setPos( stationPos + offset);
227  Vector3 viewVector = player->getPos()+offset - stationPos + offset;
228  viewVector.normalize();
229  ship->setView( viewVector );
230  ship->setSpeed( lightspeed/3 );
231 }
232 
234 
240  list<GameObject*>::iterator it = GameObjects.begin();
241  while( it !=GameObjects.end() ) {
242  PlayerObject * pl = dynamic_cast<PlayerObject*>(*it);
243  Star * st = dynamic_cast<Star*>(*it);
244  Planet * pln = dynamic_cast<Planet*>(*it);
245  PoliceShip * pol = dynamic_cast<PoliceShip*>(*it);
246  Pirate * pir = dynamic_cast<Pirate*>(*it);
247  Thargon * tha = dynamic_cast<Thargon*>(*it);
248  Merchant * mer = dynamic_cast<Merchant*>(*it);
249  SpaceShip * sh = dynamic_cast<SpaceShip*>(*it);
250  SpaceStation * sta = dynamic_cast<SpaceStation*>(*it);
251  if( pl ) {
252  delete pl;
253  it++;
254  continue;
255  }
256  if( st ) {
257  delete st;
258  it++;
259  continue;
260  }
261  if( pln ) {
262  delete pln;
263  it++;
264  continue;
265  }
266  if( pol ) {
267  delete pol;
268  it++;
269  continue;
270  }
271  if( pir ) {
272  delete pir;
273  it++;
274  continue;
275  }
276  if( tha ) {
277  delete tha;
278  it++;
279  continue;
280  }
281  if( mer ) {
282  delete mer;
283  it++;
284  continue;
285  }
286  if( sh ) {
287  delete sh;
288  it++;
289  continue;
290  }
291  if( sta ) {
292  delete sta;
293  it++;
294  continue;
295  }
296  MessageBox(0, "Unknown Type!", "World::deinitialize()", 0 );
297  it++;
298  }
299  GameObjects.clear();
300 }
301 
303 
310  PlayerObject * pl = dynamic_cast<PlayerObject*>(*playerPosition);
311  return pl;
312 }
313 
315 
322  Star * st = dynamic_cast<Star*>(*starPosition);
323  return st;
324 }
325 
327 
336 vector<Planet*> * World::getPlanets() {
337  vector<Planet*> * planets = new vector<Planet*>;
338 
339  if( starPosition == GameObjects.end() )
340  return planets;
341 
342  list<GameObject*>::iterator it = starPosition;
343  it++;
344 
345  Planet * pl;
346  while( it != GameObjects.end() && (pl = dynamic_cast<Planet*>(*it++)) != 0 )
347  planets->push_back( pl );
348 
349  return planets;
350 }
351 
353 
360  SpaceStation * st = dynamic_cast<SpaceStation*>(*stationPosition);
361  return st;
362 }
363 
365 
372 vector<GraphicsObject*> *World::getGraphicObjects() {
373  vector<GraphicsObject*> * retObjects = new vector<GraphicsObject*>;
374 
375  list<GameObject*>::iterator it = starPosition;
376 
377  GraphicsObject * obj;
378  while( it!= GameObjects.end() && (obj = dynamic_cast<GraphicsObject*>(*it++)) != 0 )
379  retObjects->push_back( obj );
380 
381  return retObjects;
382 }
383 
384 
386 
394 vector<SpaceShip*> * World::getSpaceShips() {
395  vector<SpaceShip*> * retObjects = new vector<SpaceShip*>;
396 
397  list<GameObject*>::iterator it = stationPosition;
398 
399  if (it==GameObjects.end()) return retObjects;
400 
401  it++;
402 
403  SpaceShip * obj;
404  while( it!= GameObjects.end() && (obj = dynamic_cast<SpaceShip*>(*it++)) != 0 )
405  retObjects->push_back( obj );
406 
407  return retObjects;
408 }
409 
411 
419 vector<ForeignSpaceShip*> * World::getForeignSpaceShips() {
420  vector<ForeignSpaceShip*> * retObjects = new vector<ForeignSpaceShip*>;
421 
422  list<GameObject*>::iterator it = stationPosition;
423 
424  if (it==GameObjects.end()) return retObjects;
425 
426  it++;
427 
428  ForeignSpaceShip * obj;
429  while( it!= GameObjects.end() && (obj = dynamic_cast<ForeignSpaceShip*>(*it++)) != 0 )
430  retObjects->push_back( obj );
431 
432  return retObjects;
433 }
434 
436 vector <PoliceShip*> * World::getPoliceShips() {
443  vector<PoliceShip*> * retObjects = new vector<PoliceShip*>;
444 
445  list<GameObject*>::iterator it = stationPosition;
446 
447  if (it==GameObjects.end()) return retObjects;
448 
449  it++;
450 
451  PoliceShip * obj;
452  while( it!= GameObjects.end() )
453  {
454  obj = dynamic_cast<PoliceShip*>(*it++);
455  if ( obj != 0)
456  retObjects->push_back( obj );
457  }
458 
459  return retObjects;
460 }
461 
463 
472 SpaceShip * World::createNewSpaceShip( ObjectName objectType, float radius ) {
473  SpaceShip *ship = new SpaceShip( radius, Objects::getObjects()->getDisplayList( objectType ) );
474  ship->setView( FileAccess::getObjectView( objectType ) );
475  GameObjects.push_back( ship );
476 
477  return ship;
478 }
479 
481 
487 Thargon * World::createNewThargon( ObjectName objectType, float radius, PlayerObject *player, float maxSpeed ) {
488  Thargon *ship = new Thargon( radius, Objects::getObjects()->getDisplayList( objectType ), player, maxSpeed );
489  ship->setView( FileAccess::getObjectView( objectType ) );
490 
491  GameObjects.push_back( ship );
492 
493  return ship;
494 }
495 
497 
503 Pirate* World::createNewPirate( ObjectName objectType, float radius, PlayerObject *player, float maxSpeed ) {
504  Pirate *ship = new Pirate( radius, Objects::getObjects()->getDisplayList( objectType ), player, maxSpeed );
505  ship->setView( FileAccess::getObjectView( objectType ) );
506 
507  GameObjects.push_back( ship );
508 
509  return ship;
510 }
511 
513 
519 Merchant * World::createNewMerchant( ObjectName objectType, float radius, Planet * planet, Vector3 aim ) {
520  Merchant *ship = new Merchant( radius, Objects::getObjects()->getDisplayList( objectType ), planet, aim );
521  ship->setView( FileAccess::getObjectView( objectType ) );
522 
523  GameObjects.push_back( ship );
524 
525  return ship;
526 }
527 
529 
536 PoliceShip * World::createNewPoliceShip( ObjectName objectType, float radius, std::vector<Vector3> point, PlayerObject * player, float maxSpeed ) {
537  PoliceShip *ship = new PoliceShip( radius, Objects::getObjects()->getDisplayList( objectType ), point, player, maxSpeed );
538  ship->setView( FileAccess::getObjectView( objectType ) );
539 
540  GameObjects.push_back( ship );
541 
542  return ship;
543 }
544 
546 
556  list<GameObject*>::iterator iti = stationPosition;
557  list<GameObject*>::iterator itj = stationPosition;
558 
559  if( itj == GameObjects.end() )
560  return;
561  //itj++;
562 
563  GraphicsObject* goi;
564  GraphicsObject* goj;
565  while( iti != GameObjects.end() ) {
566  itj = iti;
567  itj++;
568  while( itj != GameObjects.end() ) {
569  // check if iti and itj have a collision
570  goi = dynamic_cast<GraphicsObject*>(*iti);
571  goj = dynamic_cast<GraphicsObject*>(*itj);
572 
573  Vector3 distVector = goi->getPos() - goj->getPos();
574  float dist = distVector.length();
575 
576  if( dist - goi->getCollisionRadius() - goj->getCollisionRadius() <= 0 ) {
577  // collision occured
578  list<GameObject*>::iterator pred = iti;
579  pred--;
580  // check for coriolis
581  SpaceStation* st = getStation();
582  if( *iti != st )
583  GameObjects.erase( iti );
584  else
585  pred = iti;
586  //if( *itj != st ) // this can't happen if the station is always in front of the other ships
587  // Objects::getObjects().erase( itj );
588  //else
589  // pred = iti;
590  // delete both objects if
591  GameObjects.erase( itj );
592 
593  iti = pred;
594  itj = pred;
595  //if( itj != Objects::getObjects().end() )
596  itj++;
597  } else {
598  itj++;
599  }
600  }
601  iti++;
602  }
603 }
604 
606 
611  list<GameObject*>::iterator it = stationPosition;
612 
613  if( it ==GameObjects.end() )
614  return;
615  it++;
616 
617  SpaceShip* go;
618  while( it != GameObjects.end() ) {
619  go = dynamic_cast<SpaceShip*>(*it);
620  if( go->isDestroyed() ) {
621  list<GameObject*>::iterator pred = it;
622  pred--;
623  GameObjects.erase( it );
624  it = pred;
625  }
626  it++;
627  }
628 }
630 
636 
637 
641 World *World::m_world = 0;
642 
644 
649  if( m_world == 0 )
650  m_world = new World;
651  return m_world;
652 }
653 
655 
662 World::World() {
663 
664  wrapper = new Wrapper( &error1, &error2 );
665 
666  srand(351);
667  for( unsigned int i=0; i < 256; i++ )
668  systemPlanets[i] = getSystemPlanetsR();
669 
670  systemStars.reserve( 256 );
671  for( unsigned int i=0; i < 256; i++ )
672  systemStars.push_back( this->getStarTextureR() );
673 
674  m_playerStatus = new PlayerStatus();
675  m_playerStatus->fuel = wrapper->getFuelAmount();
676 
677  for (int i = 0; i < 256; i++ )
678  {
679  vector<PlanetInfoGraphical> planets = *getSystemPlanets(i);
680  unsigned possiblePlanets = min((float)planets.size(),5.0f);
681  unsigned coriolisPlanetNr = (rand()%possiblePlanets);
682  nrForCoriolis[i] = coriolisPlanetNr;
683  }
684 
685 }
686 
688 
693 World::~World( void ) {
694  // delete ship info
695  // missing cuz ship-handling is not very well now
696 
697  delete m_playerStatus;
698 
699  systemStars.clear();
700 
701  for( unsigned int i=0; i < 256; i++ ) {
702  systemPlanets[i]->clear();
703  delete systemPlanets[i];
704  }
705 
706  delete wrapper;
707 }
709 
716 
717 
725 TextureName World::getPlanetTexture( unsigned __int8 number ) {
726  switch( number ) {
727 case 0:
728  return planet_ss_earth;
729  break;
730 case 1:
731  return planet_ss_jupiter;
732  break;
733 case 2:
734  return planet_ss_mars;
735  break;
736 case 3:
737  return planet_ss_mercury;
738  break;
739 case 4:
740  return planet_ss_moon;
741  break;
742 case 5:
743  return planet_ss_neptune;
744  break;
745 case 6:
746  return planet_ss_pluto;
747  break;
748 case 7:
749  return planet_ss_saturn;
750  break;
751 case 8:
752  return planet_ss_uranus;
753  break;
754 case 9:
755  return planet_ss_venus;
756  break;
757 case 10:
758  return planet_red;
759  break;
760 case 11:
761  return planet_01;
762  break;
763 case 12:
764  return planet_02;
765  break;
766 case 13:
767  return planet_03;
768  break;
769 case 14:
770  return planet_04;
771  break;
772 case 15:
773  return planet_05;
774  break;
775 case 16:
776  return planet_06;
777  break;
778 case 17:
779  return planet_07;
780  break;
781 case 18:
782  return planet_08;
783  break;
784 case 19:
785  return planet_09;
786  break;
787  }
788  return planet_ss_earth; // should not happen
789 }
790 
792 
801 TextureName World::getPlanetTextureR( bool reset ) {
802  static vector<TextureName> usedTextures;
803  if( reset )
804  usedTextures.clear();
805 
806  unsigned __int8 num;
807  bool newTexture;
808  do {
809  newTexture = false;
810  num = rand()%20;
811  for( unsigned int i=0; i < usedTextures.size(); i++ )
812  if( usedTextures[i] == getPlanetTexture( num ) )
813  newTexture = true;
814  } while ( newTexture );
815 
816  usedTextures.push_back( getPlanetTexture( num ) );
817  return getPlanetTexture( num );
818 }
819 
821 
828 TextureName World::getStarTexture( unsigned __int8 number ) {
829  switch( number ) {
830 case 0:
831  return star_sun;
832  break;
833 case 1:
834  return star_001;
835  break;
836 case 2:
837  return star_002;
838  break;
839 case 3:
840  return star_003;
841  break;
842 case 4:
843  return star_004;
844  break;
845 case 5:
846  return star_005;
847  break;
848 case 6:
849  return star_006;
850  break;
851 case 7:
852  return star_010;
853  break;
854 case 8:
855  return star_011;
856  break;
857 case 9:
858  return star_012;
859  break;
860 case 10:
861  return star_013;
862  break;
863 case 11:
864  return star_014;
865  break;
866  }
867  return star_sun; // should not happen
868 }
869 
871 
876 TextureName World::getStarTextureR( ) {
877  unsigned __int8 num = rand()%11;
878  return getStarTexture( num );
879 }
880 
882 
887  return getSystemInfo( wrapper->getCurrentSystem() );
888 }
889 
891 
896 SystemInfo World::getSystemInfo( unsigned __int8 number ) {
897  // TODO: size is not correct, number of planets shall be calculated and
898  //graphical information can be submitted directly?
899  SystemInfo sysinfo;
900 
901  System system = wrapper->getSystemInfo( number );
902 
903  sysinfo.name = system.name;
904  sysinfo.pos.x = system.posx;
905  sysinfo.pos.y = system.posy;
906  sysinfo.size = 591352 * (4155.0 / 149600);
907  sysinfo.government = system.government;
908  sysinfo.description = system.description;
909  sysinfo.population = system.population;
910  sysinfo.productivity = system.productivity;
911  sysinfo.radius = system.radius;
912  sysinfo.techLevel = system.techLevel;
913  sysinfo.economy = system.economy;
914  sysinfo.systemNumber = system.systemnumber;
915  return sysinfo;
916 }
917 
919 
923 string World::getSystemName( int number ) {
924  return wrapper->getSystemInfo( number ).name;
925 }
926 
928 
932 vector<PlanetInfoGraphical> * World::getSystemPlanets() {
933  return systemPlanets[wrapper->getCurrentSystem()];
934 }
935 
937 
942 vector<PlanetInfoGraphical> * World::getSystemPlanets( unsigned __int8 number ) {
943  return systemPlanets[number];
944 }
945 
947 
959 vector<PlanetInfoGraphical> * World::getSystemPlanetsR() {
960  vector<PlanetInfoGraphical> *solarSystem = new vector<PlanetInfoGraphical>;
961 
962  int planetCount = (rand()%5 + 1) + (rand()%5 + 1); // minimal 2 and maximal 10 planets
963 
964  int maxDistance;
965  int minPlanetPosition = 0;
966 
967  // create some factors. the planet which is furthest away from the sun should? have the distance 800000
968  float c1 = (float)800000 / pow((float)2, (float) planetCount-1);
969  float c2 = (pow((float)2, (float)(planetCount*0.75)) * c1) / pow((float)(planetCount*0.75), (float)2);
970  float rotateSpeed = -1;
971  bool reset = true; // used to reset the no-double-textures-filter in getPlanetTexturesR function
972 
973  for(int i = 0; i < planetCount; i++) {
975 
976  // dist1 and dist2 are two functions that should set the maximal possible distance for planet i.
977  // dist1 increases polynomial and dist2 super polynomial. the constants c1 and c2 calculated above
978  // should assure that the values of the functions are the same when i is equal to the half of the
979  // planets. that means that the distances for the first half of the planet increase approximately
980  // polynomial and the distances for the second half of planets increases approximately exponential.
981  // because this values will set the maximal distance they are only hints as the distance is calculated
982  // randomly and the minimal distance must only increase by 20000!
983  int dist1 = c2*(i+1)*(i+1) + 20000;
984  int dist2 = pow((float)2, (float)i) * c1;
985  maxDistance = max( dist1, dist2 );
986 
987  // only create random number if maximal position is greater than minimal position
988  int planetDistance = maxDistance;
989  if( minPlanetPosition != 0 && minPlanetPosition < maxDistance )
990  planetDistance = getRandNumber( minPlanetPosition, maxDistance );
991  planet.distance = planetDistance;
992 
993  // calculate rotate speed. the speed of the first planet should be fixed to 1.
994  if(rotateSpeed < 0)
995  rotateSpeed = 1 * planetDistance;
996  planet.rotateSpeed =(rotateSpeed / planetDistance);
997 
998  // set up the other information
999  planet.radius = 10;
1000  planet.rotateAngle = rand()%360;
1001  planet.spinningSpeed = -0.012;
1002  planet.texture = getPlanetTextureR( reset );
1003  reset = false;
1004  solarSystem->push_back( planet );
1005 
1006  // set the minimal position for the next planet. it is increased by 20000 in every step. if the planets
1007  // shouldn't be very near together, the length of stride should be increased. if the stride is big enough
1008  // the distance will increase continously.
1009  minPlanetPosition = planetDistance + 20000;
1010  }
1011  return solarSystem;
1012 }
1013 
1022 vector<SystemInfo> *World::getSystems( SystemLists systemList ) {
1023  // TODO: return all systems and reachable
1024  vector<SystemInfo> *systems;
1025  switch( systemList ) {
1026 case allSystems:
1027  break;
1028 case nearSystems:
1029  {
1030  // this creates a list in an square around the reachable systems!
1031  // find out maximal/minimal x and y positions
1032  vector<int> *localSystems = wrapper->getLocalSystems();
1033  Position maxPos, minPos; // positions are unsigned integers in textelite --> 0 is minimal
1034  maxPos.x = wrapper->getSystemInfo(localSystems->at(0)).posx;
1035  maxPos.y = wrapper->getSystemInfo(localSystems->at(0)).posy;
1036  minPos = maxPos;
1037  for(unsigned int i = 0; i < localSystems->size(); i++) {
1038  System reachableSystem = wrapper->getSystemInfo(localSystems->at(i));
1039  if( reachableSystem.posx < minPos.x )
1040  minPos.x = reachableSystem.posx;
1041  if( reachableSystem.posy < minPos.y )
1042  minPos.y = reachableSystem.posy;
1043  if( reachableSystem.posx > maxPos.x )
1044  maxPos.x = reachableSystem.posx;
1045  if( reachableSystem.posy > maxPos.y )
1046  maxPos.y = reachableSystem.posy;
1047  }
1048  localSystems->clear();
1049  delete localSystems;
1050  systems = getSystems( minPos.x, maxPos.x, minPos.y, maxPos.y );
1051  }
1052  break;
1053 case maximalReachable:
1054  {
1055  systems = new vector<SystemInfo>;
1056  vector<int> *localSystems = wrapper->getLocalSystems();
1057  for(unsigned int i = 0; i < localSystems->size(); i++) {
1058  SystemInfo sysinfo;
1059  System wsystem = wrapper->getSystemInfo(localSystems->at(i));
1060  sysinfo.name = wsystem.name;
1061  sysinfo.pos.x = wsystem.posx;
1062  sysinfo.pos.y = wsystem.posy;
1063  sysinfo.size = i; // wtf is this?
1064  sysinfo.government = wsystem.government;
1065  sysinfo.description = wsystem.description;
1066  sysinfo.population = wsystem.population;
1067  sysinfo.productivity = wsystem.productivity;
1068  sysinfo.radius = wsystem.radius;
1069  sysinfo.techLevel = wsystem.techLevel;
1070  sysinfo.economy = wsystem.economy;
1071  sysinfo.systemNumber = wsystem.systemnumber;
1072  systems->push_back( sysinfo );
1073  }
1074  localSystems->clear();
1075  delete localSystems;
1076  }
1077  break;
1078 case reachable:
1079  break;
1080  }
1081 
1082  return systems;
1083 }
1084 
1093 std::vector<SystemInfo> *World::getSystems( int left, int right, int bottom, int top ) {
1094  vector<SystemInfo> *systems = new vector<SystemInfo>;
1095 
1096  vector<int> *localSystems = wrapper->getSystemsInRectangle( left, right, bottom, top );
1097 
1098  for(unsigned int i = 0; i < localSystems->size(); i++) {
1099  SystemInfo sysinfo;
1100  System wsystem = wrapper->getSystemInfo(localSystems->at(i));
1101  sysinfo.name = wsystem.name;
1102  sysinfo.pos.x = wsystem.posx;
1103  sysinfo.pos.y = wsystem.posy;
1104  sysinfo.size = i; // wtf is this?
1105  sysinfo.government = wsystem.government;
1106  sysinfo.description = wsystem.description;
1107  sysinfo.population = wsystem.population;
1108  sysinfo.productivity = wsystem.productivity;
1109  sysinfo.radius = wsystem.radius;
1110  sysinfo.techLevel = wsystem.techLevel;
1111  sysinfo.economy = wsystem.economy;
1112  sysinfo.systemNumber = wsystem.systemnumber;
1113  systems->push_back( sysinfo );
1114  }
1115  localSystems->clear();
1116  delete localSystems;
1117 
1118  return systems;
1119 }
1120 
1122 
1126  return this->systemStars.at( wrapper->getCurrentSystem() );
1127 }
1128 
1130 
1134 TextureName World::getSystemStarTexture( unsigned __int8 number ) {
1135  return systemStars.at( number );
1136 }
1137 
1139 
1142 bool World::isSystemReachable( int systemNumber ) {
1143  return wrapper->systemIsReachable( systemNumber );
1144 }
1145 
1147 
1151 bool World::isSystemLocal( int systemNumber ) {
1152  return wrapper->systemIsInLocalRange( systemNumber );
1153 }
1154 
1156 
1161 void World::performJump( int number ) {
1162  wrapper->performJump( number );
1163  m_playerStatus->fuel = wrapper->getFuelAmount();
1164  // new initialization for new level, textures are not loaded here, however
1165  deinitialize();
1166  initialize();
1167 }
1169 
1170 
1176 
1177 
1182 void World::buyFuel(float amount) {
1183  wrapper->buyFuel(amount);
1184  m_playerStatus->fuel = wrapper->getFuelAmount();
1185 }
1186 
1188 vector<Tradegood> * World::getAllTradegoodDescriptions() {
1189  return wrapper->getAllTradegoodDescriptions();
1190 }
1191 
1193 unsigned int World::getCargoBaySize() {
1194  return wrapper->getCargoBaySize();
1195 }
1196 
1199  return wrapper->getCurrentCash();
1200 }
1201 
1203 vector<int> * World::getCurrentCargo() {
1204  return wrapper->getCurrentCargo();
1205 }
1206 
1208 vector<MarketplaceItem> * World::getCurrentMarketplace() {
1209  return wrapper->getCurrentMarketplace();
1210 }
1211 
1213 unsigned int World::getFreeHoldspace() {
1214  return wrapper->getFreeHoldspace();
1215 }
1216 
1219  return wrapper->getNumberOfTradegoods();
1220 }
1221 
1223 
1228  return wrapper->getTradegoodDescription(number);
1229 }
1230 
1232 
1236 string World::performPurchase(int number, int amount) {
1237  return wrapper->performPurchase(number,amount);
1238 }
1239 
1241 
1245 string World::performSale(int number, int amount) {
1246  return wrapper->performSale(number,amount);
1247 }
1248 
1250 
1254 {
1255  return wrapper->getFuelCost();
1256 }
1257 
1259 
1263 {
1264  return wrapper->getFuelAmount();
1265 }
1266 
1268 
1272 {
1273  return wrapper->getMaxFuel();
1274 }
1275 
1277 
1281 {
1282  return wrapper->tradegoodIsInTons(number);
1283 }
1285 
1286 
1296  return m_playerStatus;
1297 }
1299 
1310  switch( economy ) {
1311 case AverageAgri:
1312  return "Average agricultural";
1313 case AverageInd:
1314  return "Average industrial";
1315 case MainlyAgri:
1316  return "Mainly agricultural";
1317 case MainlyInd:
1318  return "Mainly industrial";
1319 case PoorAgri:
1320  return "Poor agricultural";
1321 case PoorInd:
1322  return "Poor industrial";
1323 case RichAgri:
1324  return "Rich agricultural";
1325 case RichInd:
1326  return "Rich industrial";
1327  }
1328  return "";// does not happen under normal circumstances
1329 }
1330 
1336 string World::getGovernmentString( govTypes government ) {
1337  switch(government) {
1338 case Anarchy:
1339  return "Anarchy";
1340 case Communist:
1341  return "Communism";
1342 case Confederacy:
1343  return "Confederacy";
1344 case CorporateState:
1345  return "Corporate State";
1346 case Democracy:
1347  return "Democracy";
1348 case Dictatorship:
1349  return "Dictatorship";
1350 case Feudal:
1351  return "Feudalism";
1352 case MultiGov:
1353  return "Multiple Governments";
1354  }
1355  return ""; // does not happen under normal circumstances
1356 }
1357 
1359 
1373 unsigned int World::getRandNumber( unsigned int min, unsigned int max ) {
1374  if( min > max )
1375  return 0;
1376 
1377  unsigned int returnVal;
1378 
1379  do {
1380  unsigned int upperBound = max - min;
1381  unsigned int factor = upperBound / 32767;
1382  if( factor == 0)
1383  factor = 1;
1384  unsigned int randomFactor = rand()%factor; // creates random number from 0 to factor
1385  unsigned int randomOffset = rand(); // create offset
1386  returnVal = (randomFactor * 32767 + randomOffset) + min; // create value to upperBound and add min to get a value in range
1387  } while( returnVal > max );
1388 
1389  return returnVal;
1390 }
1391 
1392 
1393 void error1( string error ) {
1394 
1395 }
1396 
1397 void error2( string error ) {
1398 
1399 }