OpenXcom  1.0
Open-source clone of the original X-Com
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Map.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_MAP_H
20 #define OPENXCOM_MAP_H
21 
22 #include "../Engine/InteractiveSurface.h"
23 #include "../Engine/Options.h"
24 #include "Position.h"
25 #include <set>
26 #include <vector>
27 
28 namespace OpenXcom
29 {
30 
31 class ResourcePack;
32 class SavedBattleGame;
33 class Surface;
34 class BattleUnit;
35 class Projectile;
36 class Explosion;
37 class BattlescapeMessage;
38 class Camera;
39 class Timer;
40 class Text;
41 
42 enum CursorType { CT_NONE, CT_NORMAL, CT_AIM, CT_PSI, CT_WAYPOINT, CT_THROW };
46 class Map : public InteractiveSurface
47 {
48 private:
49  static const int SCROLL_INTERVAL = 15;
50  static const int BULLET_SPRITES = 35;
51  Timer *_scrollMouseTimer, *_scrollKeyTimer;
52  Game *_game;
53  SavedBattleGame *_save;
54  ResourcePack *_res;
55  Surface *_arrow;
56  int _spriteWidth, _spriteHeight;
57  int _selectorX, _selectorY;
58  int _mouseX, _mouseY;
59  CursorType _cursorType;
60  int _cursorSize;
61  int _animFrame;
62  Projectile *_projectile;
63  bool _projectileInFOV;
64  std::list<Explosion *> _explosions;
65  bool _explosionInFOV, _launch;
66  BattlescapeMessage *_message;
67  Camera *_camera;
68  int _visibleMapHeight;
69  std::vector<Position> _waypoints;
70  bool _unitDying, _smoothCamera, _smoothingEngaged;
71  PathPreview _previewSetting;
72  Text *_txtAccuracy;
73 
74  void drawTerrain(Surface *surface);
75  int getTerrainLevel(Position pos, int size);
76 public:
77  static const int ICON_HEIGHT = 56;
78  static const int ICON_WIDTH = 320;
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;
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();
143 };
144 
145 }
146 
147 #endif
void keyboardPress(Action *action, State *state)
Special handling for key presses.
Definition: Map.cpp:1141
Container for all the information associated with a given user action, like mouse clicks...
Definition: Action.h:34
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:80
void setSelectorPosition(int mx, int my)
Sets the battlescape selector position relative to mouseposition.
Definition: Map.cpp:1178
A game state that receives user input and reacts accordingly.
Definition: State.h:44
void setProjectile(Projectile *projectile)
Sets projectile.
Definition: Map.cpp:1434
A class that represents a projectile.
Definition: Projectile.h:39
Timer used to run code in fixed intervals.
Definition: Timer.h:37
Surface that the user can interact with.
Definition: InteractiveSurface.h:39
void animate(bool redraw)
Rotates the tileframes 0-7.
Definition: Map.cpp:1194
Projectile * getProjectile() const
Gets projectile.
Definition: Map.cpp:1447
void draw()
Draws the surface.
Definition: Map.cpp:164
Text string displayed on screen.
Definition: Text.h:41
void scrollMouse()
Mouse-scrolls the camera.
Definition: Map.cpp:1473
~Map()
Cleans up the map.
Definition: Map.cpp:113
Class handling camera movement, either by mouse or by events on the battlescape.
Definition: Camera.h:35
void setButtonsPressed(Uint8 button, bool pressed)
Set mouse-buttons' pressed state.
Definition: Map.cpp:1500
void scrollKey()
Keyboard-scrolls the camera.
Definition: Map.cpp:1481
std::list< Explosion * > * getExplosions()
Gets explosion set.
Definition: Map.cpp:1456
void setWidth(int width)
Special handling for updating map width.
Definition: Map.cpp:1537
PathPreview
Path preview modes (can be OR'd together).
Definition: Options.h:41
void mouseOver(Action *action, State *state)
Special handling for mouse over.
Definition: Map.cpp:1163
void refreshSelectorPosition()
Refreshes the battlescape selector after scrolling.
Definition: Map.cpp:1517
void mousePress(Action *action, State *state)
Special handling for mouse press.
Definition: Map.cpp:1119
void cacheUnit(BattleUnit *unit)
Caches the unit.
Definition: Map.cpp:1382
Interactive map of the battlescape.
Definition: Map.h:46
void think()
Handles timers.
Definition: Map.cpp:155
std::vector< Position > * getWaypoints()
Get waypoints vector.
Definition: Map.cpp:1490
Element that is blit (rendered) onto the screen.
Definition: Surface.h:39
void mouseRelease(Action *action, State *state)
Special handling for mouse release.
Definition: Map.cpp:1130
Camera * getCamera()
Gets the pointer to the camera.
Definition: Map.cpp:1465
Packs of external game media.
Definition: ResourcePack.h:50
void cacheUnits()
Caches units.
Definition: Map.cpp:1370
Generic window used to display messages over the Battlescape map.
Definition: BattlescapeMessage.h:36
The battlescape data that gets written to disk when the game is saved.
Definition: SavedBattleGame.h:50
CursorType getCursorType() const
Gets the 3D cursor type.
Definition: Map.cpp:1362
void setPalette(SDL_Color *colors, int firstcolor=0, int ncolors=256)
Sets the palette.
Definition: Map.cpp:212
The core of the game engine, manages the game's entire contents and structure.
Definition: Game.h:44
void init()
Initializes the map.
Definition: Map.cpp:126
void getSelectorPosition(Position *pos) const
Gets the currently selected position.
Definition: Map.cpp:1224
void setCursorType(CursorType type, int size=1)
Sets the 3D cursor type.
Definition: Map.cpp:1349
Easy handling of X-Y-Z coordinates.
Definition: Position.h:30
void calculateWalkingOffset(BattleUnit *unit, Position *offset)
Calculates the offset of a soldier, when it is walking in the middle of 2 tiles.
Definition: Map.cpp:1236
void setUnitDying(bool flag)
Sets the unitDying flag.
Definition: Map.cpp:1509
void keyboardRelease(Action *action, State *state)
Special handling for key releases.
Definition: Map.cpp:1152
int getMessageY()
Get the vertical position of the hidden movement screen.
Definition: Map.cpp:1548
Represents a moving unit in the battlescape, player controlled or AI controlled it holds info about i...
Definition: BattleUnit.h:58
void offset(int off, int min=-1, int max=-1, int mul=1)
Offsets the surface's colors by a set amount.
Definition: Surface.cpp:403
void setHeight(int height)
Special handling for updating map height.
Definition: Map.cpp:1526