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 
98  ~BattlescapeGame();
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);
128  BattleUnit *convertUnit(BattleUnit *unit);
130  bool kneel(BattleUnit *bu);
132  bool cancelCurrentAction(bool bForce = false);
134  BattleAction *getCurrentAction();
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();
156  SavedBattleGame *getSave();
158  TileEngine *getTileEngine();
160  Pathfinding *getPathfinding();
162  Mod *getMod();
164  bool getPanicHandled() const { return _playerPanicHandled; }
166  void findItem(BattleAction *action);
168  BattleItem *surveyItems(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;
185  bool checkForProximityGrenades(BattleUnit *unit);
187  void cleanupDeleted();
189  int getDepth() const;
191  void missionComplete();
192  std::list<BattleState*> getStates();
194  void autoEndBattle();
195 };
196 
197 }
A utility class that modifies tile properties on a battlescape map.
Definition: TileEngine.h:37
Definition: BattlescapeGame.h:43
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
Represents a single item in the battlescape.
Definition: BattleItem.h:36
Interactive map of the battlescape.
Definition: Map.h:43
This class sets the battlescape in a certain sub-state.
Definition: BattleState.h:29
bool getPanicHandled() const
Returns whether panic has been handled.
Definition: BattlescapeGame.h:164
Battlescape game - the core game engine of the battlescape game.
Definition: BattlescapeGame.h:68
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
Easy handling of X-Y-Z coordinates.
Definition: Position.h:28
Battlescape screen which shows the tactical battle.
Definition: BattlescapeState.h:47
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