OpenXcom  1.0
Open-source clone of the original X-Com
BattlescapeGame.h
1 #pragma once
2 /*
3  * Copyright 2010-2016 OpenXcom Developers.
4  *
5  * This file is part of OpenXcom.
6  *
7  * OpenXcom is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * OpenXcom is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with OpenXcom. If not, see <http:///www.gnu.org/licenses/>.
19  */
20 #include "Position.h"
21 #include <SDL.h>
22 #include <string>
23 #include <list>
24 #include <vector>
25 
26 namespace OpenXcom
27 {
28 
29 class BattleUnit;
30 class SavedBattleGame;
31 class BattleItem;
32 class BattleState;
33 class BattlescapeState;
34 class Map;
35 class TileEngine;
36 class Pathfinding;
37 class Mod;
38 class InfoboxOKState;
39 class SoldierDiary;
40 
41 enum BattleActionType { BA_NONE, BA_TURN, BA_WALK, BA_PRIME, BA_THROW, BA_AUTOSHOT, BA_SNAPSHOT, BA_AIMEDSHOT, BA_HIT, BA_USE, BA_LAUNCH, BA_MINDCONTROL, BA_PANIC, BA_RETHINK };
42 
44 {
45  BattleActionType type;
46  BattleUnit *actor;
47  BattleItem *weapon;
48  Position target;
49  std::list<Position> waypoints;
50  int TU;
51  bool targeting;
52  int value;
53  std::string result;
54  bool strafe, run;
55  int diff;
56  int autoShotCounter;
57  Position cameraPosition;
58  bool desperate; // ignoring newly-spotted units
59  int finalFacing;
60  bool finalAction;
61  int number; // first action of turn, second, etc.?
62  BattleAction() : type(BA_NONE), actor(0), weapon(0), TU(0), targeting(false), value(0), strafe(false), run(false), diff(0), autoShotCounter(0), cameraPosition(0, 0, -1), desperate(false), finalFacing(-1), finalAction(false), number(0) { }
63 };
64 
69 {
70 private:
71  SavedBattleGame *_save;
72  BattlescapeState *_parentState;
73  std::list<BattleState*> _states, _deleted;
74  bool _playerPanicHandled;
75  int _AIActionCounter;
76  BattleAction _currentAction;
77  bool _AISecondMove, _playedAggroSound;
78  bool _endTurnRequested, _endTurnProcessed;
79 
81  void endTurn();
83  bool handlePanickingPlayer();
85  bool handlePanickingUnit(BattleUnit *unit);
87  bool noActionsPending(BattleUnit *bu);
88  std::vector<InfoboxOKState*> _infoboxQueue;
90  void showInfoBoxQueue();
91 public:
93  static bool _debugPlay;
94 
100  void think();
102  void init();
104  bool playableUnitSelected() const;
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 *origMurderer, bool hiddenExplosion = false, bool terrainExplosion = false);
122  bool checkReservedTU(BattleUnit *bu, int tu, bool justChecking = false);
124  void handleAI(BattleUnit *unit);
126  void dropItem(Position position, BattleItem *item, bool newItem = false, bool removeItem = false);
130  bool kneel(BattleUnit *bu);
132  bool cancelCurrentAction(bool bForce = false);
136  bool isBusy() const;
138  void primaryAction(Position pos);
140  void secondaryAction(Position pos);
142  void launchAction();
144  void psiButtonAction();
146  void moveUpDown(BattleUnit *unit, int dir);
148  void requestEndTurn();
150  void setTUReserved(BattleActionType tur);
152  void setupCursor();
154  Map *getMap();
162  Mod *getMod();
164  bool getPanicHandled() const { return _playerPanicHandled; }
166  void findItem(BattleAction *action);
170  bool worthTaking(BattleItem* item, BattleAction *action);
172  int takeItemFromGround(BattleItem* item, BattleAction *action);
174  bool takeItem(BattleItem* item, BattleAction *action);
176  BattleActionType getReservedAction();
178  void tallyUnits(int &liveAliens, int &liveSoldiers);
179  bool convertInfected();
181  void setKneelReserved(bool reserved);
183  bool getKneelReserved() const;
187  void cleanupDeleted();
189  int getDepth() const;
191  void missionComplete();
192  std::list<BattleState*> getStates();
194  void autoEndBattle();
195 };
196 
197 }
void autoEndBattle()
Auto end the battle if conditions are met.
Definition: BattlescapeGame.cpp:2265
A utility class that modifies tile properties on a battlescape map.
Definition: TileEngine.h:38
void setupCursor()
Sets up the cursor taking into account the action.
Definition: BattlescapeGame.cpp:863
bool worthTaking(BattleItem *item, BattleAction *action)
Evaluates if it&#39;s worthwhile to take this item.
Definition: BattlescapeGame.cpp:1887
bool playableUnitSelected() const
Determines whether a playable unit is selected.
Definition: BattlescapeGame.cpp:899
int getDepth() const
Get the depth of the saved game.
Definition: BattlescapeGame.cpp:2251
Definition: BattlescapeGame.h:43
Pathfinding * getPathfinding()
Gets the pathfinding.
Definition: BattlescapeGame.cpp:1787
void think()
Checks for units panicking or falling and so on.
Definition: BattlescapeGame.cpp:100
TileEngine * getTileEngine()
Gets the tilengine.
Definition: BattlescapeGame.cpp:1778
~BattlescapeGame()
Cleans up the BattlescapeGame state.
Definition: BattlescapeGame.cpp:88
bool checkReservedTU(BattleUnit *bu, int tu, bool justChecking=false)
Checks reserved tu.
Definition: BattlescapeGame.cpp:1154
void statePushBack(BattleState *bs)
Pushes a state to the back of the list.
Definition: BattlescapeGame.cpp:958
void cleanupDeleted()
Cleans up all the deleted states.
Definition: BattlescapeGame.cpp:2238
void popState()
Removes current state.
Definition: BattlescapeGame.cpp:988
void secondaryAction(Position pos)
Activates secondary action (right click).
Definition: BattlescapeGame.cpp:1546
static bool _debugPlay
is debug mode enabled in the battlescape?
Definition: BattlescapeGame.h:93
Contains all the game-specific static data that never changes throughout the game, like rulesets and resources.
Definition: Mod.h:87
bool takeItem(BattleItem *item, BattleAction *action)
Assigns the item to a slot (stolen from battlescapeGenerator::addItem()).
Definition: BattlescapeGame.cpp:2030
BattlescapeGame(SavedBattleGame *save, BattlescapeState *parentState)
Creates the BattlescapeGame state.
Definition: BattlescapeGame.cpp:71
void requestEndTurn()
Requests the end of the turn (wait for explosions etc to really end the turn).
Definition: BattlescapeGame.cpp:1618
SavedBattleGame * getSave()
Gets the save.
Definition: BattlescapeGame.cpp:1769
void statePushNext(BattleState *bs)
Pushes a state to second on the list.
Definition: BattlescapeGame.cpp:940
void psiButtonAction()
Handler for the psi button.
Definition: BattlescapeGame.cpp:1573
void handleAI(BattleUnit *unit)
Handles unit AI.
Definition: BattlescapeGame.cpp:168
void moveUpDown(BattleUnit *unit, int dir)
Moves a unit up or down.
Definition: BattlescapeGame.cpp:1594
void statePushFront(BattleState *bs)
Pushes a state to the front of the list.
Definition: BattlescapeGame.cpp:930
void setStateInterval(Uint32 interval)
Sets state think interval.
Definition: BattlescapeGame.cpp:1141
Represents a single item in the battlescape.
Definition: BattleItem.h:37
bool cancelCurrentAction(bool bForce=false)
Cancels the current action.
Definition: BattlescapeGame.cpp:1331
bool kneel(BattleUnit *bu)
Handles kneeling action.
Definition: BattlescapeGame.cpp:329
Interactive map of the battlescape.
Definition: Map.h:44
bool isBusy() const
Determines whether there is an action currently going on.
Definition: BattlescapeGame.cpp:1392
This class sets the battlescape in a certain sub-state.
Definition: BattleState.h:29
void primaryAction(Position pos)
Activates primary action (left click).
Definition: BattlescapeGame.cpp:1401
void handleNonTargetAction()
Handles the result of non target actions, like priming a grenade.
Definition: BattlescapeGame.cpp:816
void setTUReserved(BattleActionType tur)
Sets the TU reserved type.
Definition: BattlescapeGame.cpp:1633
Mod * getMod()
Gets the mod.
Definition: BattlescapeGame.cpp:1796
bool checkForProximityGrenades(BattleUnit *unit)
Checks for and triggers proximity grenades.
Definition: BattlescapeGame.cpp:2198
bool getPanicHandled() const
Returns whether panic has been handled.
Definition: BattlescapeGame.h:164
void checkForCasualties(BattleItem *murderweapon, BattleUnit *origMurderer, bool hiddenExplosion=false, bool terrainExplosion=false)
Checks for casualties in battle.
Definition: BattlescapeGame.cpp:535
void handleState()
Handles states timer.
Definition: BattlescapeGame.cpp:907
BattleUnit * convertUnit(BattleUnit *unit)
Converts a unit into a unit of another type.
Definition: BattlescapeGame.cpp:1697
Battlescape game - the core game engine of the battlescape game.
Definition: BattlescapeGame.h:68
void findItem(BattleAction *action)
Tries to find an item and pick it up if possible.
Definition: BattlescapeGame.cpp:1805
A utility class that calculates the shortest path between two points on the battlescape map...
Definition: Pathfinding.h:35
The battlescape data that gets written to disk when the game is saved.
Definition: SavedBattleGame.h:47
BattleActionType getReservedAction()
Returns the type of action that is reserved.
Definition: BattlescapeGame.cpp:2109
void dropItem(Position position, BattleItem *item, bool newItem=false, bool removeItem=false)
Drops an item and affects it with gravity.
Definition: BattlescapeGame.cpp:1645
void init()
Initializes the Battlescape game.
Definition: BattlescapeGame.cpp:155
Easy handling of X-Y-Z coordinates.
Definition: Position.h:28
BattleAction * getCurrentAction()
Gets a pointer to access action members directly.
Definition: BattlescapeGame.cpp:1383
void setKneelReserved(bool reserved)
Sets the kneel reservation setting.
Definition: BattlescapeGame.cpp:2177
Map * getMap()
Gets the map.
Definition: BattlescapeGame.cpp:1760
Battlescape screen which shows the tactical battle.
Definition: BattlescapeState.h:47
BattleItem * surveyItems(BattleAction *action)
Checks through all the items on the ground and picks one.
Definition: BattlescapeGame.cpp:1845
void tallyUnits(int &liveAliens, int &liveSoldiers)
Tallies the living units, converting them if necessary.
Definition: BattlescapeGame.cpp:2120
void launchAction()
Handler for the blaster launcher button.
Definition: BattlescapeGame.cpp:1558
bool getKneelReserved() const
Checks the kneel reservation setting.
Definition: BattlescapeGame.cpp:2186
void missionComplete()
Sets up a mission complete notification.
Definition: BattlescapeGame.cpp:800
Represents a moving unit in the battlescape, player controlled or AI controlled it holds info about i...
Definition: BattleUnit.h:59
Definition: BaseInfoState.cpp:40
int takeItemFromGround(BattleItem *item, BattleAction *action)
Picks the item up from the ground.
Definition: BattlescapeGame.cpp:1982