OpenXcom  1.0
Open-source clone of the original X-Com
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Public Member Functions | List of all members
OpenXcom::BattlescapeGame Class Reference

Battlescape game - the core game engine of the battlescape game. More...

#include <BattlescapeGame.h>

Public Member Functions

 BattlescapeGame (SavedBattleGame *save, BattlescapeState *parentState)
 Creates the BattlescapeGame state. More...
 
 ~BattlescapeGame ()
 Cleans up the BattlescapeGame state. More...
 
void think ()
 Checks for units panicking or falling and so on.
 
void init ()
 Initializes the Battlescape game.
 
bool playableUnitSelected ()
 Determines whether a playable unit is selected. More...
 
void handleState ()
 Handles states timer. More...
 
void statePushFront (BattleState *bs)
 Pushes a state to the front of the list. More...
 
void statePushNext (BattleState *bs)
 Pushes a state to second on the list. More...
 
void statePushBack (BattleState *bs)
 Pushes a state to the back of the list. More...
 
void handleNonTargetAction ()
 Handles the result of non target actions, like priming a grenade.
 
void popState ()
 Removes current state. More...
 
void setStateInterval (Uint32 interval)
 Sets state think interval. More...
 
void checkForCasualties (BattleItem *murderweapon, BattleUnit *murderer, bool hiddenExplosion=false, bool terrainExplosion=false)
 Checks for casualties in battle. More...
 
void checkForPanic (BattleUnit *unit)
 Checks if a unit panics.
 
bool checkReservedTU (BattleUnit *bu, int tu, bool justChecking=false)
 Checks reserved tu. More...
 
void handleAI (BattleUnit *unit)
 Handles unit AI. More...
 
void dropItem (const Position &position, BattleItem *item, bool newItem=false, bool removeItem=false)
 Drops an item and affects it with gravity. More...
 
BattleUnitconvertUnit (BattleUnit *unit, std::string newType)
 Converts a unit into a unit of another type. More...
 
bool kneel (BattleUnit *bu)
 Handles kneeling action. More...
 
bool cancelCurrentAction (bool bForce=false)
 Cancels the current action. More...
 
BattleActiongetCurrentAction ()
 Gets a pointer to access action members directly. More...
 
bool isBusy ()
 Determines whether there is an action currently going on. More...
 
void primaryAction (const Position &pos)
 Activates primary action (left click). More...
 
void secondaryAction (const Position &pos)
 Activates secondary action (right click). More...
 
void launchAction ()
 Handler for the blaster launcher button.
 
void psiButtonAction ()
 Handler for the psi button.
 
void moveUpDown (BattleUnit *unit, int dir)
 Moves a unit up or down. More...
 
void requestEndTurn ()
 Requests the end of the turn (wait for explosions etc to really end the turn). More...
 
void setTUReserved (BattleActionType tur, bool player)
 Sets the TU reserved type. More...
 
void setupCursor ()
 Sets up the cursor taking into account the action. More...
 
MapgetMap ()
 Gets the map. More...
 
SavedBattleGamegetSave ()
 Gets the save. More...
 
TileEnginegetTileEngine ()
 Gets the tilengine. More...
 
PathfindinggetPathfinding ()
 Gets the pathfinding. More...
 
ResourcePackgetResourcePack ()
 Gets the resourcepack. More...
 
const RulesetgetRuleset () const
 Gets the ruleset. More...
 
bool getPanicHandled ()
 Returns whether panic has been handled.
 
void findItem (BattleAction *action)
 Tries to find an item and pick it up if possible.
 
BattleItemsurveyItems (BattleAction *action)
 Checks through all the items on the ground and picks one. More...
 
bool worthTaking (BattleItem *item, BattleAction *action)
 Evaluates if it's worthwhile to take this item. More...
 
int takeItemFromGround (BattleItem *item, BattleAction *action)
 Picks the item up from the ground. More...
 
bool takeItem (BattleItem *item, BattleAction *action)
 Assigns the item to a slot (stolen from battlescapeGenerator::addItem()). More...
 
BattleActionType getReservedAction ()
 Returns the type of action that is reserved. More...
 
void tallyUnits (int &liveAliens, int &liveSoldiers, bool convert)
 Tallies the living units, converting them if necessary. More...
 
void setKneelReserved (bool reserved)
 Sets the kneel reservation setting. More...
 
bool getKneelReserved ()
 Checks the kneel reservation setting. More...
 
bool checkForProximityGrenades (BattleUnit *unit)
 Checks for and triggers proximity grenades. More...
 

Detailed Description

Battlescape game - the core game engine of the battlescape game.

Constructor & Destructor Documentation

OpenXcom::BattlescapeGame::BattlescapeGame ( SavedBattleGame save,
BattlescapeState parentState 
)

Creates the BattlescapeGame state.

Initializes all the elements in the Battlescape screen.

Parameters
savePointer to the save game.
parentStatePointer to the parent battlescape state.
OpenXcom::BattlescapeGame::~BattlescapeGame ( )

Cleans up the BattlescapeGame state.

Delete BattlescapeGame.

Member Function Documentation

bool OpenXcom::BattlescapeGame::cancelCurrentAction ( bool  bForce = false)

Cancels the current action.

Cancels the current action the user had selected (firing, throwing,..)

Parameters
bForceForce the action to be cancelled.
Returns
Whether an action was cancelled or not.
void OpenXcom::BattlescapeGame::checkForCasualties ( BattleItem murderweapon,
BattleUnit murderer,
bool  hiddenExplosion = false,
bool  terrainExplosion = false 
)

Checks for casualties in battle.

Checks for casualties and adjusts morale accordingly.

Parameters
murderweaponNeed to know this, for a HE explosion there is an instant death.
murdererThis is needed for credits for the kill.
hiddenExplosionSet to true for the explosions of UFO Power sources at start of battlescape.
terrainExplosionSet to true for the explosions of terrain.
bool OpenXcom::BattlescapeGame::checkForProximityGrenades ( BattleUnit unit)

Checks for and triggers proximity grenades.

Checks if a unit has moved next to a proximity grenade.

Checks one tile around the unit in every direction. For a large unit we check every tile it occupies.

Parameters
unitPointer to a unit.
Returns
True if a proximity grenade was triggered.
bool OpenXcom::BattlescapeGame::checkReservedTU ( BattleUnit bu,
int  tu,
bool  justChecking = false 
)

Checks reserved tu.

Checks against reserved time units.

Parameters
buPointer to the unit.
tuNumber of time units to check.
justCheckingTrue to suppress error messages, false otherwise.
Returns
bool Whether or not we got enough time units.
BattleUnit * OpenXcom::BattlescapeGame::convertUnit ( BattleUnit unit,
std::string  newType 
)

Converts a unit into a unit of another type.

Parameters
unitThe unit to convert.
newTypeThe type of unit to convert to.
Returns
Pointer to the new unit.
void OpenXcom::BattlescapeGame::dropItem ( const Position position,
BattleItem item,
bool  newItem = false,
bool  removeItem = false 
)

Drops an item and affects it with gravity.

Drops an item to the floor and affects it with gravity.

Parameters
positionPosition to spawn the item.
itemPointer to the item.
newItemBool whether this is a new item.
removeItemBool whether to remove the item from the owner.
BattleAction * OpenXcom::BattlescapeGame::getCurrentAction ( )

Gets a pointer to access action members directly.

Returns
Pointer to action.
bool OpenXcom::BattlescapeGame::getKneelReserved ( )

Checks the kneel reservation setting.

Gets the kneel reservation setting.

Returns
Kneel reservation setting.
Map * OpenXcom::BattlescapeGame::getMap ( )

Gets the map.

Returns
map.
Pathfinding * OpenXcom::BattlescapeGame::getPathfinding ( )

Gets the pathfinding.

Returns
pathfinding.
BattleActionType OpenXcom::BattlescapeGame::getReservedAction ( )

Returns the type of action that is reserved.

Returns the action type that is reserved.

Returns
The type of action that is reserved.
ResourcePack * OpenXcom::BattlescapeGame::getResourcePack ( )

Gets the resourcepack.

Returns
resourcepack.
const Ruleset * OpenXcom::BattlescapeGame::getRuleset ( ) const

Gets the ruleset.

Returns
ruleset.
SavedBattleGame * OpenXcom::BattlescapeGame::getSave ( )

Gets the save.

Returns
save.
TileEngine * OpenXcom::BattlescapeGame::getTileEngine ( )

Gets the tilengine.

Returns
tilengine.
void OpenXcom::BattlescapeGame::handleAI ( BattleUnit unit)

Handles unit AI.

Handles the processing of the AI states of a unit.

Parameters
unitPointer to a unit.
void OpenXcom::BattlescapeGame::handleState ( )

Handles states timer.

Gives time slice to the front state.

bool OpenXcom::BattlescapeGame::isBusy ( )

Determines whether there is an action currently going on.

Determines whether an action is currently going on?

Returns
true or false.
bool OpenXcom::BattlescapeGame::kneel ( BattleUnit bu)

Handles kneeling action.

Toggles the Kneel/Standup status of the unit.

Parameters
buPointer to a unit.
Returns
If the action succeeded.
void OpenXcom::BattlescapeGame::moveUpDown ( BattleUnit unit,
int  dir 
)

Moves a unit up or down.

Parameters
unitThe unit.
dirDirection DIR_UP or DIR_DOWN.
bool OpenXcom::BattlescapeGame::playableUnitSelected ( )

Determines whether a playable unit is selected.

Normally only player side units can be selected, but in debug mode one can play with aliens too :) Is used to see if stats can be displayed and action buttons will work.

Returns
Whether a playable unit is selected.
void OpenXcom::BattlescapeGame::popState ( )

Removes current state.

Removes the current state.

This is a very important function. It is called by a BattleState (walking, projectile is flying, explosions,...) at the moment this state has finished its action. Here we check the result of that action and do all the aftermath. The state is popped off the list.

void OpenXcom::BattlescapeGame::primaryAction ( const Position pos)

Activates primary action (left click).

Parameters
posPosition on the map.
void OpenXcom::BattlescapeGame::requestEndTurn ( )

Requests the end of the turn (wait for explosions etc to really end the turn).

Requests the end of the turn (waits for explosions etc to really end the turn).

void OpenXcom::BattlescapeGame::secondaryAction ( const Position pos)

Activates secondary action (right click).

Parameters
posPosition on the map.
void OpenXcom::BattlescapeGame::setKneelReserved ( bool  reserved)

Sets the kneel reservation setting.

Parameters
reservedShould we reserve an extra 4 TUs to kneel?
void OpenXcom::BattlescapeGame::setStateInterval ( Uint32  interval)

Sets state think interval.

Sets the timer interval for think() calls of the state.

Parameters
intervalAn interval in ms.
void OpenXcom::BattlescapeGame::setTUReserved ( BattleActionType  tur,
bool  player 
)

Sets the TU reserved type.

Parameters
turA battleactiontype.
playeris this requested by the player?
void OpenXcom::BattlescapeGame::setupCursor ( )

Sets up the cursor taking into account the action.

Sets the cursor according to the selected action.

void OpenXcom::BattlescapeGame::statePushBack ( BattleState bs)

Pushes a state to the back of the list.

Pushes a state to the back.

Parameters
bsBattlestate.
void OpenXcom::BattlescapeGame::statePushFront ( BattleState bs)

Pushes a state to the front of the list.

Pushes a state to the front of the queue and starts it.

Parameters
bsBattlestate.
void OpenXcom::BattlescapeGame::statePushNext ( BattleState bs)

Pushes a state to second on the list.

Pushes a state as the next state after the current one.

Parameters
bsBattlestate.
BattleItem * OpenXcom::BattlescapeGame::surveyItems ( BattleAction action)

Checks through all the items on the ground and picks one.

Searches through items on the map that were dropped on an alien turn, then picks the most "attractive" one.

Parameters
actionA pointer to the action being performed.
Returns
The item to attempt to take.
bool OpenXcom::BattlescapeGame::takeItem ( BattleItem item,
BattleAction action 
)

Assigns the item to a slot (stolen from battlescapeGenerator::addItem()).

Tries to fit an item into the unit's inventory, return false if you can't.

Parameters
itemThe item to attempt to take.
actionA pointer to the action being performed.
Returns
Whether or not the item was successfully retrieved.
int OpenXcom::BattlescapeGame::takeItemFromGround ( BattleItem item,
BattleAction action 
)

Picks the item up from the ground.

At this point we've decided it's worth our while to grab this item, so we try to do just that. First we check to make sure we have time units, then that we have space (using horrifying logic) then we attempt to actually recover the item.

Parameters
itemThe item to attempt to take.
actionA pointer to the action being performed.
Returns
0 if successful, 1 for no TUs, 2 for not enough room, 3 for "won't fit" and -1 for "something went horribly wrong".
void OpenXcom::BattlescapeGame::tallyUnits ( int &  liveAliens,
int &  liveSoldiers,
bool  convert 
)

Tallies the living units, converting them if necessary.

Tallies the living units in the game and, if required, converts units into their spawn unit.

Parameters
&liveAliensThe integer in which to store the live alien tally.
&liveSoldiersThe integer in which to store the live XCom tally.
convertShould we convert infected units?
bool OpenXcom::BattlescapeGame::worthTaking ( BattleItem item,
BattleAction action 
)

Evaluates if it's worthwhile to take this item.

Assesses whether this item is worth trying to pick up, taking into account how many units we see, whether or not the Weapon has ammo, and if we have ammo FOR it, or, if it's ammo, checks if we have the weapon to go with it, assesses the attraction value of the item and compares it with the distance to the object, then returns false anyway.

Parameters
itemThe item to attempt to take.
actionA pointer to the action being performed.
Returns
false.

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