OpenXcom
1.0
Open-source clone of the original X-Com
|
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... | |
BattleUnit * | convertUnit (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... | |
BattleAction * | getCurrentAction () |
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... | |
Map * | getMap () |
Gets the map. More... | |
SavedBattleGame * | getSave () |
Gets the save. More... | |
TileEngine * | getTileEngine () |
Gets the tilengine. More... | |
Pathfinding * | getPathfinding () |
Gets the pathfinding. More... | |
ResourcePack * | getResourcePack () |
Gets the resourcepack. More... | |
const Ruleset * | getRuleset () 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. | |
BattleItem * | surveyItems (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... | |
Battlescape game - the core game engine of the battlescape game.
OpenXcom::BattlescapeGame::BattlescapeGame | ( | SavedBattleGame * | save, |
BattlescapeState * | parentState | ||
) |
Creates the BattlescapeGame state.
Initializes all the elements in the Battlescape screen.
save | Pointer to the save game. |
parentState | Pointer to the parent battlescape state. |
OpenXcom::BattlescapeGame::~BattlescapeGame | ( | ) |
Cleans up the BattlescapeGame state.
Delete BattlescapeGame.
bool OpenXcom::BattlescapeGame::cancelCurrentAction | ( | bool | bForce = false | ) |
Cancels the current action.
Cancels the current action the user had selected (firing, throwing,..)
bForce | Force the action to be cancelled. |
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.
murderweapon | Need to know this, for a HE explosion there is an instant death. |
murderer | This is needed for credits for the kill. |
hiddenExplosion | Set to true for the explosions of UFO Power sources at start of battlescape. |
terrainExplosion | Set 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.
unit | Pointer to a unit. |
bool OpenXcom::BattlescapeGame::checkReservedTU | ( | BattleUnit * | bu, |
int | tu, | ||
bool | justChecking = false |
||
) |
Checks reserved tu.
Checks against reserved time units.
bu | Pointer to the unit. |
tu | Number of time units to check. |
justChecking | True to suppress error messages, false otherwise. |
BattleUnit * OpenXcom::BattlescapeGame::convertUnit | ( | BattleUnit * | unit, |
std::string | newType | ||
) |
Converts a unit into a unit of another type.
unit | The unit to convert. |
newType | The type of unit to convert to. |
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.
position | Position to spawn the item. |
item | Pointer to the item. |
newItem | Bool whether this is a new item. |
removeItem | Bool whether to remove the item from the owner. |
BattleAction * OpenXcom::BattlescapeGame::getCurrentAction | ( | ) |
Gets a pointer to access action members directly.
bool OpenXcom::BattlescapeGame::getKneelReserved | ( | ) |
Checks the kneel reservation setting.
Gets the kneel reservation setting.
Map * OpenXcom::BattlescapeGame::getMap | ( | ) |
Gets the map.
Pathfinding * OpenXcom::BattlescapeGame::getPathfinding | ( | ) |
Gets the pathfinding.
BattleActionType OpenXcom::BattlescapeGame::getReservedAction | ( | ) |
Returns the type of action that is reserved.
Returns the action type that is reserved.
ResourcePack * OpenXcom::BattlescapeGame::getResourcePack | ( | ) |
Gets the resourcepack.
const Ruleset * OpenXcom::BattlescapeGame::getRuleset | ( | ) | const |
Gets the ruleset.
SavedBattleGame * OpenXcom::BattlescapeGame::getSave | ( | ) |
Gets the save.
TileEngine * OpenXcom::BattlescapeGame::getTileEngine | ( | ) |
Gets the tilengine.
void OpenXcom::BattlescapeGame::handleAI | ( | BattleUnit * | unit | ) |
Handles unit AI.
Handles the processing of the AI states of a unit.
unit | Pointer 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?
bool OpenXcom::BattlescapeGame::kneel | ( | BattleUnit * | bu | ) |
Handles kneeling action.
Toggles the Kneel/Standup status of the unit.
bu | Pointer to a unit. |
void OpenXcom::BattlescapeGame::moveUpDown | ( | BattleUnit * | unit, |
int | dir | ||
) |
Moves a unit up or down.
unit | The unit. |
dir | Direction 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.
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).
pos | Position 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).
pos | Position on the map. |
void OpenXcom::BattlescapeGame::setKneelReserved | ( | bool | reserved | ) |
Sets the kneel reservation setting.
reserved | Should 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.
interval | An interval in ms. |
void OpenXcom::BattlescapeGame::setTUReserved | ( | BattleActionType | tur, |
bool | player | ||
) |
Sets the TU reserved type.
tur | A battleactiontype. |
player | is 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.
bs | Battlestate. |
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.
bs | Battlestate. |
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.
bs | Battlestate. |
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.
action | A pointer to the action being performed. |
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.
item | The item to attempt to take. |
action | A pointer to the action being performed. |
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.
item | The item to attempt to take. |
action | A pointer to the action being performed. |
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.
&liveAliens | The integer in which to store the live alien tally. |
&liveSoldiers | The integer in which to store the live XCom tally. |
convert | Should 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.
item | The item to attempt to take. |
action | A pointer to the action being performed. |