OpenXcom  1.0
Open-source clone of the original X-Com
Map.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 "../Engine/InteractiveSurface.h"
21 #include "../Engine/Options.h"
22 #include "Position.h"
23 #include <vector>
24 
25 namespace OpenXcom
26 {
27 
28 class SavedBattleGame;
29 class Surface;
30 class SurfaceSet;
31 class BattleUnit;
32 class Projectile;
33 class Explosion;
34 class BattlescapeMessage;
35 class Camera;
36 class Timer;
37 class Text;
38 class Tile;
39 
40 enum CursorType { CT_NONE, CT_NORMAL, CT_AIM, CT_PSI, CT_WAYPOINT, CT_THROW };
44 class Map : public InteractiveSurface
45 {
46 private:
47  static const int SCROLL_INTERVAL = 15;
48  static const int BULLET_SPRITES = 35;
49  Timer *_scrollMouseTimer, *_scrollKeyTimer, *_obstacleTimer;
50  Game *_game;
51  SavedBattleGame *_save;
52  Surface *_arrow;
53  int _spriteWidth, _spriteHeight;
54  int _selectorX, _selectorY;
55  int _mouseX, _mouseY;
56  CursorType _cursorType;
57  int _cursorSize;
58  int _animFrame;
59  Projectile *_projectile;
60  bool _projectileInFOV;
61  std::list<Explosion *> _explosions;
62  bool _explosionInFOV, _launch;
63  BattlescapeMessage *_message;
64  Camera *_camera;
65  int _visibleMapHeight;
66  std::vector<Position> _waypoints;
67  bool _unitDying, _smoothCamera, _smoothingEngaged, _flashScreen;
68  PathPreview _previewSetting;
69  Text *_txtAccuracy;
70  SurfaceSet *_projectileSet;
71 
72  void drawUnit(Surface *surface, Tile *unitTile, Tile *currTile, Position tileScreenPosition, int shade, int obstacleShade, bool topLayer);
73  void drawTerrain(Surface *surface);
74  int getTerrainLevel(const Position& pos, int size) const;
75  int _iconHeight, _iconWidth, _messageColor;
76  const std::vector<Uint8> *_transparencies;
77  bool _showObstacles;
78 public:
80  Map(Game* game, int width, int height, int x, int y, int visibleMapHeight);
82  ~Map();
84  void init();
86  void think();
88  void draw();
90  void setPalette(SDL_Color *colors, int firstcolor = 0, int ncolors = 256);
92  void mousePress(Action *action, State *state);
94  void mouseRelease(Action *action, State *state);
96  void mouseOver(Action *action, State *state);
98  void keyboardPress(Action *action, State *state);
100  void keyboardRelease(Action *action, State *state);
102  void animate(bool redraw);
104  void setSelectorPosition(int mx, int my);
106  void getSelectorPosition(Position *pos) const;
108  void calculateWalkingOffset(BattleUnit *unit, Position *offset, int *shadeOffset = 0);
110  void setCursorType(CursorType type, int size = 1);
112  CursorType getCursorType() const;
114  void cacheUnits();
116  void cacheUnit(BattleUnit *unit);
118  void setProjectile(Projectile *projectile);
120  Projectile *getProjectile() const;
122  std::list<Explosion*> *getExplosions();
124  Camera *getCamera();
126  void scrollMouse();
128  void scrollKey();
130  std::vector<Position> *getWaypoints();
132  void setButtonsPressed(Uint8 button, bool pressed);
134  void setUnitDying(bool flag);
138  void setHeight(int height);
140  void setWidth(int width);
142  int getMessageY() const;
144  int getIconHeight() const;
146  int getIconWidth() const;
148  int getSoundAngle(const Position& pos) const;
150  void resetCameraSmoothing();
152  void setBlastFlash(bool flash);
154  bool getBlastFlash() const;
156  void resetObstacles();
158  void enableObstacles();
160  void disableObstacles();
161 };
162 
163 }
void keyboardPress(Action *action, State *state)
Special handling for key presses.
Definition: Map.cpp:1276
Container for all the information associated with a given user action, like mouse clicks...
Definition: Action.h:32
Map(Game *game, int width, int height, int x, int y, int visibleMapHeight)
Creates a new map at the specified position and size.
Definition: Map.cpp:77
void setSelectorPosition(int mx, int my)
Sets the battlescape selector position relative to mouseposition.
Definition: Map.cpp:1313
A game state that receives user input and reacts accordingly.
Definition: State.h:44
CursorType getCursorType() const
Gets the 3D cursor type.
Definition: Map.cpp:1523
void setProjectile(Projectile *projectile)
Sets projectile.
Definition: Map.cpp:1580
A class that represents a projectile.
Definition: Projectile.h:37
Timer used to run code in fixed intervals.
Definition: Timer.h:35
Surface that the user can interact with.
Definition: InteractiveSurface.h:37
bool getBlastFlash() const
Check if the screen is flashing this.
Definition: Map.cpp:1760
void animate(bool redraw)
Rotates the tileframes 0-7.
Definition: Map.cpp:1329
void draw()
Draws the surface.
Definition: Map.cpp:183
Text string displayed on screen.
Definition: Text.h:40
void scrollMouse()
Mouse-scrolls the camera.
Definition: Map.cpp:1619
~Map()
Cleans up the map.
Definition: Map.cpp:122
Class handling camera movement, either by mouse or by events on the battlescape.
Definition: Camera.h:33
void resetCameraSmoothing()
Reset the camera smoothing bool.
Definition: Map.cpp:1742
void resetObstacles()
Resets obstacle markers.
Definition: Map.cpp:1768
void setButtonsPressed(Uint8 button, bool pressed)
Set mouse-buttons&#39; pressed state.
Definition: Map.cpp:1646
void scrollKey()
Keyboard-scrolls the camera.
Definition: Map.cpp:1627
std::list< Explosion * > * getExplosions()
Gets explosion set.
Definition: Map.cpp:1602
void setWidth(int width)
Special handling for updating map width.
Definition: Map.cpp:1684
void mouseOver(Action *action, State *state)
Special handling for mouse over.
Definition: Map.cpp:1298
void refreshSelectorPosition()
Refreshes the battlescape selector after scrolling.
Definition: Map.cpp:1663
int getSoundAngle(const Position &pos) const
Convert a map position to a sound angle.
Definition: Map.cpp:1722
Container of a set of surfaces.
Definition: SurfaceSet.h:35
void mousePress(Action *action, State *state)
Special handling for mouse press.
Definition: Map.cpp:1254
void cacheUnit(BattleUnit *unit)
Caches the unit.
Definition: Map.cpp:1543
Interactive map of the battlescape.
Definition: Map.h:44
void getSelectorPosition(Position *pos) const
Gets the currently selected position.
Definition: Map.cpp:1364
void think()
Handles timers.
Definition: Map.cpp:173
std::vector< Position > * getWaypoints()
Get waypoints vector.
Definition: Map.cpp:1636
void enableObstacles()
Enables obstacle markers.
Definition: Map.cpp:1783
Basic element of which a battle map is build.
Definition: Tile.h:42
Element that is blit (rendered) onto the screen.
Definition: Surface.h:38
void mouseRelease(Action *action, State *state)
Special handling for mouse release.
Definition: Map.cpp:1265
Camera * getCamera()
Gets the pointer to the camera.
Definition: Map.cpp:1611
void setBlastFlash(bool flash)
Set whether the screen should "flash" or not.
Definition: Map.cpp:1751
void disableObstacles()
Disables obstacle markers.
Definition: Map.cpp:1796
void cacheUnits()
Caches units.
Definition: Map.cpp:1531
Generic window used to display messages over the Battlescape map.
Definition: BattlescapeMessage.h:34
The battlescape data that gets written to disk when the game is saved.
Definition: SavedBattleGame.h:47
int getMessageY() const
Get the vertical position of the hidden movement screen.
Definition: Map.cpp:1695
void setPalette(SDL_Color *colors, int firstcolor=0, int ncolors=256)
Sets the palette.
Definition: Map.cpp:237
The core of the game engine, manages the game&#39;s entire contents and structure.
Definition: Game.h:41
void init()
Initializes the map.
Definition: Map.cpp:136
void setCursorType(CursorType type, int size=1)
Sets the 3D cursor type.
Definition: Map.cpp:1510
Projectile * getProjectile() const
Gets projectile.
Definition: Map.cpp:1593
Easy handling of X-Y-Z coordinates.
Definition: Position.h:28
void calculateWalkingOffset(BattleUnit *unit, Position *offset, int *shadeOffset=0)
Calculates the offset of a soldier, when it is walking in the middle of 2 tiles.
Definition: Map.cpp:1376
void setUnitDying(bool flag)
Sets the unitDying flag.
Definition: Map.cpp:1655
int getIconHeight() const
Get the icon height.
Definition: Map.cpp:1703
void keyboardRelease(Action *action, State *state)
Special handling for key releases.
Definition: Map.cpp:1287
Represents a moving unit in the battlescape, player controlled or AI controlled it holds info about i...
Definition: BattleUnit.h:59
int getIconWidth() const
Get the icon width.
Definition: Map.cpp:1711
Definition: BaseInfoState.cpp:40
void offset(int off, int min=-1, int max=-1, int mul=1)
Offsets the surface&#39;s colors by a set amount.
Definition: Surface.cpp:492
void setHeight(int height)
Special handling for updating map height.
Definition: Map.cpp:1672