OpenXcom  1.0
Open-source clone of the original X-Com
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
BattlescapeGame.h
1 /*
2  * Copyright 2010-2014 OpenXcom Developers.
3  *
4  * This file is part of OpenXcom.
5  *
6  * OpenXcom is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * OpenXcom is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with OpenXcom. If not, see <http:///www.gnu.org/licenses/>.
18  */
19 #ifndef OPENXCOM_BATTLESCAPEGAME_H
20 #define OPENXCOM_BATTLESCAPEGAME_H
21 
22 #include "Position.h"
23 #include <SDL.h>
24 #include <string>
25 #include <list>
26 #include <vector>
27 
28 namespace OpenXcom
29 {
30 
31 class BattleUnit;
32 class SavedBattleGame;
33 class BattleItem;
34 class BattleState;
35 class BattlescapeState;
36 class ResourcePack;
37 class Map;
38 class TileEngine;
39 class Pathfinding;
40 class Ruleset;
41 class InfoboxOKState;
42 
43 enum BattleActionType { BA_NONE, BA_TURN, BA_WALK, BA_PRIME, BA_THROW, BA_AUTOSHOT, BA_SNAPSHOT, BA_AIMEDSHOT, BA_STUN, BA_HIT, BA_USE, BA_LAUNCH, BA_MINDCONTROL, BA_PANIC, BA_RETHINK };
44 
46 {
47  BattleActionType type;
48  BattleUnit *actor;
49  BattleItem *weapon;
50  Position target;
51  std::list<Position> waypoints;
52  int TU;
53  bool targeting;
54  int value;
55  std::string result;
56  bool strafe, run;
57  int diff;
58  int autoShotCounter;
59  Position cameraPosition;
60  bool desperate; // ignoring newly-spotted units
61  int finalFacing;
62  bool finalAction;
63  int number; // first action of turn, second, etc.?
64  BattleAction() : type(BA_NONE), actor(0), weapon(0), TU(0), targeting(false), value(0), result(""), strafe(false), run(false), diff(0), autoShotCounter(0), cameraPosition(0, 0, -1), desperate(false), finalFacing(-1), finalAction(false), number(0) { }
65 };
66 
71 {
72 private:
73  SavedBattleGame *_save;
74  BattlescapeState *_parentState;
75  std::list<BattleState*> _states, _deleted;
76  BattleActionType _tuReserved, _playerTUReserved;
77  bool _playerPanicHandled;
78  int _AIActionCounter;
79  BattleAction _currentAction;
80  bool _AISecondMove;
81 
83  void endTurn();
85  bool handlePanickingPlayer();
87  bool handlePanickingUnit(BattleUnit *unit);
89  bool noActionsPending(BattleUnit *bu);
90  std::vector<InfoboxOKState*> _infoboxQueue;
92  void showInfoBoxQueue();
93  bool _playedAggroSound, _endTurnRequested, _kneelReserved;
94 public:
100  void think();
102  void init();
104  bool playableUnitSelected();
106  void handleState();
108  void statePushFront(BattleState *bs);
110  void statePushNext(BattleState *bs);
112  void statePushBack(BattleState *bs);
114  void handleNonTargetAction();
116  void popState();
118  void setStateInterval(Uint32 interval);
120  void checkForCasualties(BattleItem *murderweapon, BattleUnit *murderer, bool hiddenExplosion = false, bool terrainExplosion = false);
122  void checkForPanic(BattleUnit *unit);
124  bool checkReservedTU(BattleUnit *bu, int tu, bool justChecking = false);
126  void handleAI(BattleUnit *unit);
128  void dropItem(const Position &position, BattleItem *item, bool newItem = false, bool removeItem = false);
130  BattleUnit *convertUnit(BattleUnit *unit, std::string newType);
132  bool kneel(BattleUnit *bu);
134  bool cancelCurrentAction(bool bForce = false);
138  bool isBusy();
140  void primaryAction(const Position &pos);
142  void secondaryAction(const Position &pos);
144  void launchAction();
146  void psiButtonAction();
148  void moveUpDown(BattleUnit *unit, int dir);
150  void requestEndTurn();
152  void setTUReserved(BattleActionType tur, bool player);
154  void setupCursor();
156  Map *getMap();
166  const Ruleset *getRuleset() const;
167  static bool _debugPlay;
169  bool getPanicHandled() { return _playerPanicHandled; }
171  void findItem(BattleAction *action);
175  bool worthTaking(BattleItem* item, BattleAction *action);
177  int takeItemFromGround(BattleItem* item, BattleAction *action);
179  bool takeItem(BattleItem* item, BattleAction *action);
181  BattleActionType getReservedAction();
183  void tallyUnits(int &liveAliens, int &liveSoldiers, bool convert);
185  void setKneelReserved(bool reserved);
187  bool getKneelReserved();
190  void cleanupDeleted();
191 };
192 
193 }
194 
195 #endif
A utility class that modifies tile properties on a battlescape map.
Definition: TileEngine.h:40
void tallyUnits(int &liveAliens, int &liveSoldiers, bool convert)
Tallies the living units, converting them if necessary.
Definition: BattlescapeGame.cpp:1949
void primaryAction(const Position &pos)
Activates primary action (left click).
Definition: BattlescapeGame.cpp:1211
void setupCursor()
Sets up the cursor taking into account the action.
Definition: BattlescapeGame.cpp:663
bool worthTaking(BattleItem *item, BattleAction *action)
Evaluates if it's worthwhile to take this item.
Definition: BattlescapeGame.cpp:1713
Definition: BattlescapeGame.h:45
Pathfinding * getPathfinding()
Gets the pathfinding.
Definition: BattlescapeGame.cpp:1606
void think()
Checks for units panicking or falling and so on.
Definition: BattlescapeGame.cpp:104
TileEngine * getTileEngine()
Gets the tilengine.
Definition: BattlescapeGame.cpp:1598
~BattlescapeGame()
Cleans up the BattlescapeGame state.
Definition: BattlescapeGame.cpp:92
ResourcePack * getResourcePack()
Gets the resourcepack.
Definition: BattlescapeGame.cpp:1614
bool checkReservedTU(BattleUnit *bu, int tu, bool justChecking=false)
Checks reserved tu.
Definition: BattlescapeGame.cpp:950
void statePushBack(BattleState *bs)
Pushes a state to the back of the list.
Definition: BattlescapeGame.cpp:758
void popState()
Removes current state.
Definition: BattlescapeGame.cpp:788
bool playableUnitSelected()
Determines whether a playable unit is selected.
Definition: BattlescapeGame.cpp:699
void checkForCasualties(BattleItem *murderweapon, BattleUnit *murderer, bool hiddenExplosion=false, bool terrainExplosion=false)
Checks for casualties in battle.
Definition: BattlescapeGame.cpp:487
bool isBusy()
Determines whether there is an action currently going on.
Definition: BattlescapeGame.cpp:1202
bool takeItem(BattleItem *item, BattleAction *action)
Assigns the item to a slot (stolen from battlescapeGenerator::addItem()).
Definition: BattlescapeGame.cpp:1859
BattlescapeGame(SavedBattleGame *save, BattlescapeState *parentState)
Creates the BattlescapeGame state.
Definition: BattlescapeGame.cpp:72
void setTUReserved(BattleActionType tur, bool player)
Sets the TU reserved type.
Definition: BattlescapeGame.cpp:1450
void requestEndTurn()
Requests the end of the turn (wait for explosions etc to really end the turn).
Definition: BattlescapeGame.cpp:1435
BattleUnit * convertUnit(BattleUnit *unit, std::string newType)
Converts a unit into a unit of another type.
Definition: BattlescapeGame.cpp:1520
SavedBattleGame * getSave()
Gets the save.
Definition: BattlescapeGame.cpp:1590
void statePushNext(BattleState *bs)
Pushes a state to second on the list.
Definition: BattlescapeGame.cpp:740
void psiButtonAction()
Handler for the psi button.
Definition: BattlescapeGame.cpp:1396
void handleAI(BattleUnit *unit)
Handles unit AI.
Definition: BattlescapeGame.cpp:170
void moveUpDown(BattleUnit *unit, int dir)
Moves a unit up or down.
Definition: BattlescapeGame.cpp:1411
void statePushFront(BattleState *bs)
Pushes a state to the front of the list.
Definition: BattlescapeGame.cpp:730
void setStateInterval(Uint32 interval)
Sets state think interval.
Definition: BattlescapeGame.cpp:937
Represents a single item in the battlescape.
Definition: BattleItem.h:39
Set of rules and stats for a game.
Definition: Ruleset.h:69
bool cancelCurrentAction(bool bForce=false)
Cancels the current action.
Definition: BattlescapeGame.cpp:1142
bool kneel(BattleUnit *bu)
Handles kneeling action.
Definition: BattlescapeGame.cpp:342
Interactive map of the battlescape.
Definition: Map.h:46
This class sets the battlescape in a certain sub-state.
Definition: BattleState.h:34
void handleNonTargetAction()
Handles the result of non target actions, like priming a grenade.
Definition: BattlescapeGame.cpp:607
bool checkForProximityGrenades(BattleUnit *unit)
Checks for and triggers proximity grenades.
Definition: BattlescapeGame.cpp:2023
void checkForPanic(BattleUnit *unit)
Checks if a unit panics.
Packs of external game media.
Definition: ResourcePack.h:50
void handleState()
Handles states timer.
Definition: BattlescapeGame.cpp:707
Battlescape game - the core game engine of the battlescape game.
Definition: BattlescapeGame.h:70
void findItem(BattleAction *action)
Tries to find an item and pick it up if possible.
Definition: BattlescapeGame.cpp:1631
A utility class that calculates the shortest path between two points on the battlescape map...
Definition: Pathfinding.h:37
The battlescape data that gets written to disk when the game is saved.
Definition: SavedBattleGame.h:50
bool getPanicHandled()
Returns whether panic has been handled.
Definition: BattlescapeGame.h:169
BattleActionType getReservedAction()
Returns the type of action that is reserved.
Definition: BattlescapeGame.cpp:1938
void init()
Initializes the Battlescape game.
Definition: BattlescapeGame.cpp:157
const Ruleset * getRuleset() const
Gets the ruleset.
Definition: BattlescapeGame.cpp:1622
Easy handling of X-Y-Z coordinates.
Definition: Position.h:30
BattleAction * getCurrentAction()
Gets a pointer to access action members directly.
Definition: BattlescapeGame.cpp:1193
void setKneelReserved(bool reserved)
Sets the kneel reservation setting.
Definition: BattlescapeGame.cpp:1997
void dropItem(const Position &position, BattleItem *item, bool newItem=false, bool removeItem=false)
Drops an item and affects it with gravity.
Definition: BattlescapeGame.cpp:1467
bool getKneelReserved()
Checks the kneel reservation setting.
Definition: BattlescapeGame.cpp:2007
Map * getMap()
Gets the map.
Definition: BattlescapeGame.cpp:1582
Battlescape screen which shows the tactical battle.
Definition: BattlescapeState.h:48
BattleItem * surveyItems(BattleAction *action)
Checks through all the items on the ground and picks one.
Definition: BattlescapeGame.cpp:1671
void launchAction()
Handler for the blaster launcher button.
Definition: BattlescapeGame.cpp:1381
Represents a moving unit in the battlescape, player controlled or AI controlled it holds info about i...
Definition: BattleUnit.h:58
int takeItemFromGround(BattleItem *item, BattleAction *action)
Picks the item up from the ground.
Definition: BattlescapeGame.cpp:1808
void secondaryAction(const Position &pos)
Activates secondary action (right click).
Definition: BattlescapeGame.cpp:1369