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
Friends | List of all members
World Class Reference

This class represents the game world. More...

#include <World.h>

Friends

void error1 (std::string error)
 
void error2 (std::string error)
 

Object handling

These methods provide the basic object handling for the game world. In World::initialize() the world is created. This function needs to be called each time, a new system is loaded. The other functions mainly serve to retrieve pointers to game objects. Some functions to update the world are also included. They delete objects if necessary.

void initialize ()
 Initializes the game world for one system.
 
void deinitialize ()
 Destructs the game world.
 
PlayerObjectgetPlayer ()
 Returns the current player object.
 
StargetStar ()
 Returns the star of the current system.
 
std::vector< Planet * > * getPlanets ()
 Returns a vector containing the planets of the current system.
 
SpaceStationgetStation ()
 Returns the station of the current system.
 
SpaceShipcreateNewSpaceShip (ObjectName objectType, float radius)
 Creates a new space ship.
 
ThargoncreateNewThargon (ObjectName objectType, float radius, PlayerObject *player, float maxSpeed)
 Creates a new thargon ship.
 
PiratecreateNewPirate (ObjectName objectType, float radius, PlayerObject *player, float maxSpeed)
 Creates a new police ship.
 
MerchantcreateNewMerchant (ObjectName objectType, float radius, Planet *planet, Vector3 aim)
 Creates a new merchant.
 
PoliceShipcreateNewPoliceShip (ObjectName objectType, float radius, std::vector< Vector3 > point, PlayerObject *player, float maxSpeed)
 Creates a police ship.
 
std::vector< GraphicsObject * > * getGraphicObjects ()
 Returns a list of all objects of type GraphicsObject.
 
std::vector< SpaceShip * > * getSpaceShips ()
 Returns a list of all space ships.
 
std::vector< ForeignSpaceShip * > * getForeignSpaceShips ()
 Returns a list of all space ships that can move freely.
 
std::vector< PoliceShip * > * getPoliceShips ()
 Returns a list of all police ships.
 
void deleteCrashedShips (void)
 Checks if ships have hit each other and deletes them if necessary.
 
void deleteDestroyedShips (void)
 Checks if ships were distroyed and deletes the objects if necessary.
 

Construction

The constructor and destructor for a singleton object. The function World::getWorld() is used to access the class.

static WorldgetWorld (void)
 Public access to singleton object.
 
 ~World (void)
 Destructor.
 

System information

In this group all needed information for a system is created or fetched from the Wrapper class. The graphical status is created here, such as the used textures. The functions are called from World::initialize(). The other methods mainly call their pendant in the wrapper object.

SystemInfo getSystemInfo (void)
 Returns the system information of the current system.
 
SystemInfo getSystemInfo (unsigned __int8 number)
 Returns system information to a given system.
 
std::string getSystemName (int number)
 Returns the name of a given system.
 
std::vector
< PlanetInfoGraphical > * 
getSystemPlanets (void)
 Returns a vector of planets for the current system.
 
std::vector
< PlanetInfoGraphical > * 
getSystemPlanets (unsigned __int8 number)
 Returns a vector of planets for any system.
 
std::vector< SystemInfo > * getSystems (SystemLists systemList)
 
std::vector< SystemInfo > * getSystems (int left, int right, int bottom, int top)
 
TextureName getSystemStarTexture (void)
 Gets the TextureName for the star of the current system.
 
TextureName getSystemStarTexture (unsigned __int8 number)
 Gets the TextureName for the star of any system.
 
bool isSystemReachable (int number)
 Checks if a system is reachable with current fuel.
 
bool isSystemLocal (int number)
 Checks if a system is in the near range of the current system.
 
void performJump (int number)
 Perform a jump to another system.
 

Market system

This group contains all method related to the marketplace, buying or selling things. They are to the greater part only translators that call functions of the wrapper.

void buyFuel (float amount)
 Buys fuel.
 
std::vector< Tradegood > * getAllTradegoodDescriptions (void)
 Gets a list of descriptions for all trade goods.
 
unsigned int getCargoBaySize (void)
 Gets the size of the cargo bay.
 
float getCurrentCash (void)
 Gets the amount of cash of the player.
 
std::vector< int > * getCurrentCargo (void)
 Gets a list of trade goods that is currently in the cargo bay of the player's ship.
 
std::vector< MarketplaceItem > * getCurrentMarketplace (void)
 Gets the items in the current market place.
 
unsigned int getFreeHoldspace (void)
 Gets the free space in the players ship.
 
int getNumberOfTradegoods (void)
 Gets the number of different trade goods.
 
Tradegood getTradegoodDescription (int)
 Gets the description for a good.
 
std::string performPurchase (int number, int amount)
 Buys an amount of some trade good.
 
std::string performSale (int number, int amount)
 Sells an amount of some trade good.
 
float getFuelCost ()
 Gets the cost of fuel.
 
float getFuelAmount ()
 Gets the amount of fuel in the player's ship.
 
float getMaxFuel ()
 Gets the maximal amount of fuel the player's ship can hold.
 
bool tradegoodIsInTons (int number)
 Decides whether a trade good is measured in tons.
 

Player

Controls the current player status.

PlayerStatusgetPlayerStatus (void)
 Returns the current player status as an pointer to a PlayerStatus structure.
 

Helper

Some additional functions.

std::string getEconomyString (econTypes economy)
 Returns the name of an economy given as econTypes.
 
std::string getGovernmentString (govTypes government)
 Returns the name of an government given as govTypes.
 

Detailed Description

This class represents the game world.

All information that are needed are hold by this class. Therefore it is designed as a singleton. It creates all graphical information, e.g. the planets textures, randomized. The access to the Elite data provided by Textelite is given through a wrapper object.

Definition at line 37 of file World.h.

Constructor & Destructor Documentation

World::~World ( void  )

Destructor.

Clean up all created objects, that means all system data and the wrapper and player data created in the constructor are destroyed. Also all ship information is destroyed.

Definition at line 693 of file World.cpp.

Member Function Documentation

void World::buyFuel ( float  amount)

Buys fuel.

This buys a given amount of fuel without any error checking. If an error occurs, it is sent to the error handling functions.

Parameters
amountthe amount of fuel that is to be bought

Definition at line 1182 of file World.cpp.

Merchant * World::createNewMerchant ( ObjectName  objectType,
float  radius,
Planet planet,
Vector3  aim 
)

Creates a new merchant.

Parameters
objectTypeThe type of the merchant (as 3d model).
radiusThe size of the merchant.
planetThe planet the merchant is flying to.
aimThe direction of the merchant.

Definition at line 519 of file World.cpp.

Pirate * World::createNewPirate ( ObjectName  objectType,
float  radius,
PlayerObject player,
float  maxSpeed 
)

Creates a new police ship.

Parameters
objectTypeThe type of the pirate (as 3d model).
radiusThe size of the pirate.
playerThe player.
maxSpeedThe maximum speed of the new pirate.

Definition at line 503 of file World.cpp.

PoliceShip * World::createNewPoliceShip ( ObjectName  objectType,
float  radius,
std::vector< Vector3 point,
PlayerObject player,
float  maxSpeed 
)

Creates a police ship.

Parameters
objectTypeThe type of the police ship (as 3d model).
radiusThe size of the police ship.
pointThe start position of the police ship.
playerThe player.
maxSpeedThe maximum speed of the new police ship.

Definition at line 536 of file World.cpp.

SpaceShip * World::createNewSpaceShip ( ObjectName  objectType,
float  radius 
)

Creates a new space ship.

Creates a new space ship with a given type. The type has to be passed as variable of the type ObjectName. With this name the correct display list can be loaded to display the ship. The loading of the model is automatically done by the ModelObject class. A radius to perform collision detection and view frustum culling has also to be permitted.

Parameters
objectTypethe type of the ship
radiusthe radius of the ship
Returns
a pointer to the new created ship

Definition at line 472 of file World.cpp.

Thargon * World::createNewThargon ( ObjectName  objectType,
float  radius,
PlayerObject player,
float  maxSpeed 
)

Creates a new thargon ship.

Parameters
objectTypeThe type of the thargon ship (as 3d model).
radiusThe size of the Thargon.
playerThe player.
maxSpeedThe maximum speed of the new Thargon.

Definition at line 487 of file World.cpp.

void World::deinitialize ( void  )

Destructs the game world.

Deletes all objects that have been inserted into the object list. As the list contains generic pointers to objects of the type Objects::getObjects(), all object have to be casted into their original type. At last the list is cleared itself. The next level can be initialized through World::initialize().

Definition at line 239 of file World.cpp.

void World::deleteCrashedShips ( void  )

Checks if ships have hit each other and deletes them if necessary.

The list of objects is iterated by two iterators starting at the position of the station. The second iterator always starts one position on as the first. This procedure avoids testing a pair of ships two times. For each pair the distance between the centers is calculated and it is checked if they hit ech other using the collision radius. If that happens, both ships are deleted from the list. As the deleting invalidates the iterators a iterator which leads to last previous ship in the list is saved. If one of the two ships (in fact, it could ouly be the first one) is the coriolis station, it is not deleted because it is indestructible.

Definition at line 555 of file World.cpp.

void World::deleteDestroyedShips ( void  )

Checks if ships were distroyed and deletes the objects if necessary.

The list of objects is iterated by an iterator. The objects are casted to ships and it is checked if they are destroyed.

Definition at line 610 of file World.cpp.

vector< Tradegood > * World::getAllTradegoodDescriptions ( void  )

Gets a list of descriptions for all trade goods.

Definition at line 1188 of file World.cpp.

unsigned int World::getCargoBaySize ( void  )

Gets the size of the cargo bay.

Definition at line 1193 of file World.cpp.

vector< int > * World::getCurrentCargo ( void  )

Gets a list of trade goods that is currently in the cargo bay of the player's ship.

Definition at line 1203 of file World.cpp.

float World::getCurrentCash ( void  )

Gets the amount of cash of the player.

Definition at line 1198 of file World.cpp.

vector< MarketplaceItem > * World::getCurrentMarketplace ( void  )

Gets the items in the current market place.

Definition at line 1208 of file World.cpp.

string World::getEconomyString ( econTypes  economy)

Returns the name of an economy given as econTypes.

Parameters
economythe economy
Returns
a string describing the economy

Definition at line 1309 of file World.cpp.

vector< ForeignSpaceShip * > * World::getForeignSpaceShips ( )

Returns a list of all space ships that can move freely.

Uses the saved iterator to the station to find all space ship objects in the list of objects. The found objects are casted to ForeignSpaceShip and pushed into a vector. The whole list started at the station position and is iterated until the first object that can't be casted into ForeignSpaceShip is found. This list can be used to update the positions and status of self acting ships.

Returns
a pointer to a vector containing pointers to the objects. it is created in this function and has to be deleted from the caller.

Definition at line 419 of file World.cpp.

unsigned int World::getFreeHoldspace ( void  )

Gets the free space in the players ship.

Definition at line 1213 of file World.cpp.

float World::getFuelAmount ( )

Gets the amount of fuel in the player's ship.

Returns
the amount of fuel in the tank

Definition at line 1262 of file World.cpp.

float World::getFuelCost ( )

Gets the cost of fuel.

Returns
the cost of fuel

Definition at line 1253 of file World.cpp.

string World::getGovernmentString ( govTypes  government)

Returns the name of an government given as govTypes.

Parameters
governmentthe government
Returns
a string describing the government

Definition at line 1336 of file World.cpp.

vector< GraphicsObject * > * World::getGraphicObjects ( )

Returns a list of all objects of type GraphicsObject.

Uses the saved iterator to the star to find all drawable objects in the list of objects. The found objects are casted to GraphicsObject and pushed into a vector. The whole list started at the star position is iterated until the first object that can't be casted into GraphicsObject is found.

Returns
a pointer to a vector containing pointers to the objects. it is created in this function and has to be deleted from the caller.

Definition at line 372 of file World.cpp.

float World::getMaxFuel ( )

Gets the maximal amount of fuel the player's ship can hold.

Returns
the maximal amount of fuel in the tnak

Definition at line 1271 of file World.cpp.

int World::getNumberOfTradegoods ( void  )

Gets the number of different trade goods.

Definition at line 1218 of file World.cpp.

vector< Planet * > * World::getPlanets ( )

Returns a vector containing the planets of the current system.

Uses an iterator that has been saved during initialization to find the first planet object in the list of objects. It iterates through the list beginning at the position of the first planet to find all the planets. The iteration stops when the first non-planet object is found. It is assumed that all planets are inserted one after another. The objects are casted to Planet and put into a vector. The pointers became invalid if a new system is loaded, that means World::deinitialize() and World::initialize() have been called.

Returns
a pointer to a vector containing pointers to the planets. it is created in this function and has to be deleted from the caller.

Definition at line 336 of file World.cpp.

PlayerObject * World::getPlayer ( )

Returns the current player object.

Uses an iterator that has been saved during initialization to find the player object in the list of objects. The object is casted to PlayerObject and returned. The pointer can be saved but gets invalid if a new system is loaded, that means World::deinitialize() and World::initialize() have been called.

Returns
a pointer to the current player object.

Definition at line 309 of file World.cpp.

PlayerStatus * World::getPlayerStatus ( void  )

Returns the current player status as an pointer to a PlayerStatus structure.

Returns
a pointer to a PlayerStatus structure

Definition at line 1295 of file World.cpp.

vector< PoliceShip * > * World::getPoliceShips ( )

Returns a list of all police ships.

Uses the saved iterator to the station to find all space ship objects in the list of objects. The found objects are casted to PoliceShop and pushed into a vector if the cast was successful. We check all objects up to the end of the list.

Returns
a pointer to a vector containing pointers to the objects. it is created in this function and has to be deleted from the caller.

Definition at line 442 of file World.cpp.

vector< SpaceShip * > * World::getSpaceShips ( )

Returns a list of all space ships.

Uses the saved iterator to the station to find all space ship objects in the list of objects. The found objects are casted to SpaceShip and pushed into a vector. The whole list started at the station position and is iterated until the first object that can't be casted into SpaceShip is found. This list can be used to update all ships and is used to perform the collision detection in World::deleteCrashedShips().

Returns
a pointer to a vector containing pointers to the objects. it is created in this function and has to be deleted from the caller.

Definition at line 394 of file World.cpp.

Star * World::getStar ( )

Returns the star of the current system.

Uses an iterator that has been saved during initialization to find the star object in the list of objects. The found object is casted to Star and returned. The pointer can be saved but gets invalid if a new system is loaded, that means World::deinitialize() and World::initialize() have been called.

Returns
a pointer to the current systems star.

Definition at line 321 of file World.cpp.

SpaceStation * World::getStation ( )

Returns the station of the current system.

Uses an iterator that has been saved during initialization to find the station object in the list of objects. The found object is casted to SpaceStation and returned. The pointer can be saved but gets invalid if a new system is loaded, that means World::deinitialize() and World::initialize() have been called.

Returns
a pointer to the current systems station.

Definition at line 359 of file World.cpp.

SystemInfo World::getSystemInfo ( void  )

Returns the system information of the current system.

The information is taken from the Wrapper::getCurrentSystem() function.

Returns
a SystemInfo object containing the information

Definition at line 886 of file World.cpp.

SystemInfo World::getSystemInfo ( unsigned __int8  number)

Returns system information to a given system.

The information are taken from Textelite via the Wrapper.

Parameters
numberinternal number of the system which is asked for
Returns
a SystemInfo object containing the information

Definition at line 896 of file World.cpp.

string World::getSystemName ( int  number)

Returns the name of a given system.

The name is taken from the function Wrapper::getSysteminfo( int )

Parameters
numberinternal number of the system whose name is asked for

Definition at line 923 of file World.cpp.

vector< PlanetInfoGraphical > * World::getSystemPlanets ( void  )

Returns a vector of planets for the current system.

The delivered information may be used to draw the planets on the screen.

Returns
a pointer to a vector containing PlanetInfoGraphical objects.

Definition at line 932 of file World.cpp.

vector< PlanetInfoGraphical > * World::getSystemPlanets ( unsigned __int8  number)

Returns a vector of planets for any system.

The delivered information may be used to draw the planets on the screen.

Parameters
numberthe system number of the system whose planets are asked for
Returns
a pointer to a vector containing PlanetInfoGraphical objects

Definition at line 942 of file World.cpp.

vector< SystemInfo > * World::getSystems ( SystemLists  systemList)

Returns a vector of systems. The systems that should be in the list can be chosen in different ways. All systems can be chosen, the systems in the near range of the current system, the systems that could be reached with full fuel amount and the systems which are reachable with the current fuel amount.

Parameters
systemListspecifies the systems that should be returned

Definition at line 1022 of file World.cpp.

std::vector< SystemInfo > * World::getSystems ( int  left,
int  right,
int  bottom,
int  top 
)

Returns a vector of systems. All systems whose positions are in a given range are returned.

Parameters
leftspecifies the leftmost coordinate
rightspecifies the rightmost coordinate
bottomspecifies the lowest coordinate
topspecifies the highest coordinate

Definition at line 1093 of file World.cpp.

TextureName World::getSystemStarTexture ( void  )

Gets the TextureName for the star of the current system.

Returns
the TextureName for the star of the current system

Definition at line 1125 of file World.cpp.

TextureName World::getSystemStarTexture ( unsigned __int8  number)

Gets the TextureName for the star of any system.

Returns
the TextureName for the star of any system.
Parameters
numberspecifies the system

Definition at line 1134 of file World.cpp.

Tradegood World::getTradegoodDescription ( int  number)

Gets the description for a good.

/return the description for a good /param number the number of the trade good

Definition at line 1227 of file World.cpp.

World * World::getWorld ( void  )
static

Public access to singleton object.

The public access for the singleton object. If accessed the first time a new instance is created, otherwise the old instance is returned.

Definition at line 648 of file World.cpp.

void World::initialize ( void  )

Initializes the game world for one system.

Creates all objects for one system that can be considered as a level. The first created object is the player itself. After that the star and the planets and at last the coriolis station of the current system are created. All objects are initialized with correct values and pushed into a list holding all game objects.

Definition at line 45 of file World.cpp.

bool World::isSystemLocal ( int  systemNumber)

Checks if a system is in the near range of the current system.

A system near in range is reachable with the maximum amount of fuel.

Parameters
systemNumberspecifies the system

Definition at line 1151 of file World.cpp.

bool World::isSystemReachable ( int  systemNumber)

Checks if a system is reachable with current fuel.

Parameters
systemNumberspecifies the system

Definition at line 1142 of file World.cpp.

void World::performJump ( int  number)

Perform a jump to another system.

Tries to perform a jump to a system without any error checking. If an error occurs, it is sent to the error handling functions.

Parameters
numberspecifies the system

Definition at line 1161 of file World.cpp.

string World::performPurchase ( int  number,
int  amount 
)

Buys an amount of some trade good.

Parameters
numberthe id of the trade good
amountthe amount

Definition at line 1236 of file World.cpp.

string World::performSale ( int  number,
int  amount 
)

Sells an amount of some trade good.

Parameters
numberthe id of the trade good
amountthe amount

Definition at line 1245 of file World.cpp.

bool World::tradegoodIsInTons ( int  number)

Decides whether a trade good is measured in tons.

Returns
true, if a good is measured in tons

Definition at line 1280 of file World.cpp.

Friends And Related Function Documentation

void error1 ( std::string  error)
friend
void error2 ( std::string  error)
friend

The documentation for this class was generated from the following files: