mElite
1.0
An Elite clone based on TextElite by Jan-Philipp Kappmeier and Melanie Schmidt.
|
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. | |
PlayerObject * | getPlayer () |
Returns the current player object. | |
Star * | getStar () |
Returns the star of the current system. | |
std::vector< Planet * > * | getPlanets () |
Returns a vector containing the planets of the current system. | |
SpaceStation * | getStation () |
Returns the station of the current system. | |
SpaceShip * | createNewSpaceShip (ObjectName objectType, float radius) |
Creates a new space ship. | |
Thargon * | createNewThargon (ObjectName objectType, float radius, PlayerObject *player, float maxSpeed) |
Creates a new thargon ship. | |
Pirate * | createNewPirate (ObjectName objectType, float radius, PlayerObject *player, float maxSpeed) |
Creates a new police ship. | |
Merchant * | createNewMerchant (ObjectName objectType, float radius, Planet *planet, Vector3 aim) |
Creates a new merchant. | |
PoliceShip * | createNewPoliceShip (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 World * | getWorld (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 | |
PlayerStatus * | getPlayerStatus (void) |
Returns the current player status as an pointer to a PlayerStatus structure. | |
Helper | |
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. | |
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.
World::~World | ( | void | ) |
void World::buyFuel | ( | float | amount | ) |
Merchant * World::createNewMerchant | ( | ObjectName | objectType, |
float | radius, | ||
Planet * | planet, | ||
Vector3 | aim | ||
) |
Pirate * World::createNewPirate | ( | ObjectName | objectType, |
float | radius, | ||
PlayerObject * | player, | ||
float | maxSpeed | ||
) |
PoliceShip * World::createNewPoliceShip | ( | ObjectName | objectType, |
float | radius, | ||
std::vector< Vector3 > | point, | ||
PlayerObject * | player, | ||
float | maxSpeed | ||
) |
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.
objectType | the type of the ship |
radius | the radius of the ship |
Thargon * World::createNewThargon | ( | ObjectName | objectType, |
float | radius, | ||
PlayerObject * | player, | ||
float | maxSpeed | ||
) |
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().
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.
void World::deleteDestroyedShips | ( | void | ) |
vector< Tradegood > * World::getAllTradegoodDescriptions | ( | void | ) |
unsigned int World::getCargoBaySize | ( | void | ) |
vector< int > * World::getCurrentCargo | ( | void | ) |
float World::getCurrentCash | ( | void | ) |
vector< MarketplaceItem > * World::getCurrentMarketplace | ( | void | ) |
string World::getEconomyString | ( | econTypes | economy | ) |
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.
unsigned int World::getFreeHoldspace | ( | void | ) |
float World::getFuelAmount | ( | ) |
float World::getFuelCost | ( | ) |
string World::getGovernmentString | ( | govTypes | government | ) |
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.
float World::getMaxFuel | ( | ) |
int World::getNumberOfTradegoods | ( | void | ) |
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.
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.
PlayerStatus * World::getPlayerStatus | ( | void | ) |
Returns the current player status as an pointer to a PlayerStatus structure.
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.
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().
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.
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.
SystemInfo World::getSystemInfo | ( | void | ) |
Returns the system information of the current system.
The information is taken from the Wrapper::getCurrentSystem() function.
SystemInfo World::getSystemInfo | ( | unsigned __int8 | number | ) |
Returns system information to a given system.
The information are taken from Textelite via the Wrapper.
number | internal number of the system which is asked for |
string World::getSystemName | ( | int | number | ) |
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.
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.
number | the system number of the system whose planets are asked for |
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.
systemList | specifies the systems that should be returned |
std::vector< SystemInfo > * World::getSystems | ( | int | left, |
int | right, | ||
int | bottom, | ||
int | top | ||
) |
TextureName World::getSystemStarTexture | ( | void | ) |
TextureName World::getSystemStarTexture | ( | unsigned __int8 | number | ) |
Tradegood World::getTradegoodDescription | ( | int | number | ) |
|
static |
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.
bool World::isSystemLocal | ( | int | systemNumber | ) |
bool World::isSystemReachable | ( | int | systemNumber | ) |
void World::performJump | ( | int | number | ) |
string World::performPurchase | ( | int | number, |
int | amount | ||
) |
string World::performSale | ( | int | number, |
int | amount | ||
) |
bool World::tradegoodIsInTons | ( | int | number | ) |
|
friend |
|
friend |