OpenXcom  1.0
Open-source clone of the original X-Com
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
OpenXcom::Map::cacheUnits
void cacheUnits()
Caches units.
Definition: Map.cpp:1370
OpenXcom
COPYING:
Definition: BaseInfoState.cpp:41
OpenXcom::Map::mouseRelease
void mouseRelease(Action *action, State *state)
Special handling for mouse release.
Definition: Map.cpp:1130
OpenXcom::Map::mousePress
void mousePress(Action *action, State *state)
Special handling for mouse press.
Definition: Map.cpp:1119
OpenXcom::Map::getWaypoints
std::vector< Position > * getWaypoints()
Get waypoints vector.
Definition: Map.cpp:1490
OpenXcom::Map::setUnitDying
void setUnitDying(bool flag)
Sets the unitDying flag.
Definition: Map.cpp:1509
OpenXcom::Map::refreshSelectorPosition
void refreshSelectorPosition()
Refreshes the battlescape selector after scrolling.
Definition: Map.cpp:1517
OpenXcom::Map::setProjectile
void setProjectile(Projectile *projectile)
Sets projectile.
Definition: Map.cpp:1434
OpenXcom::Map::getSelectorPosition
void getSelectorPosition(Position *pos) const
Gets the currently selected position.
Definition: Map.cpp:1224
OpenXcom::Map::getExplosions
std::list< Explosion * > * getExplosions()
Gets explosion set.
Definition: Map.cpp:1456
OpenXcom::Map::scrollKey
void scrollKey()
Keyboard-scrolls the camera.
Definition: Map.cpp:1481
OpenXcom::Map::getProjectile
Projectile * getProjectile() const
Gets projectile.
Definition: Map.cpp:1447
OpenXcom::Map::setHeight
void setHeight(int height)
Special handling for updating map height.
Definition: Map.cpp:1526
OpenXcom::Map::getCamera
Camera * getCamera()
Gets the pointer to the camera.
Definition: Map.cpp:1465
OpenXcom::Map::mouseOver
void mouseOver(Action *action, State *state)
Special handling for mouse over.
Definition: Map.cpp:1163
OpenXcom::Map::setPalette
void setPalette(SDL_Color *colors, int firstcolor=0, int ncolors=256)
Sets the palette.
Definition: Map.cpp:212
OpenXcom::Action
Container for all the information associated with a given user action, like mouse clicks,...
Definition: Action.h:35
OpenXcom::Map::keyboardPress
void keyboardPress(Action *action, State *state)
Special handling for key presses.
Definition: Map.cpp:1141
OpenXcom::Map::calculateWalkingOffset
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
OpenXcom::SavedBattleGame
The battlescape data that gets written to disk when the game is saved.
Definition: SavedBattleGame.h:51
OpenXcom::Map::cacheUnit
void cacheUnit(BattleUnit *unit)
Caches the unit.
Definition: Map.cpp:1382
OpenXcom::Map::setCursorType
void setCursorType(CursorType type, int size=1)
Sets the 3D cursor type.
Definition: Map.cpp:1349
OpenXcom::Surface
Element that is blit (rendered) onto the screen.
Definition: Surface.h:40
OpenXcom::Map::getMessageY
int getMessageY()
Get the vertical position of the hidden movement screen.
Definition: Map.cpp:1548
OpenXcom::Map::~Map
~Map()
Cleans up the map.
Definition: Map.cpp:113
OpenXcom::Map
Interactive map of the battlescape.
Definition: Map.h:47
OpenXcom::Map::draw
void draw()
Draws the surface.
Definition: Map.cpp:164
OpenXcom::Projectile
A class that represents a projectile.
Definition: Projectile.h:40
OpenXcom::BattleUnit
Represents a moving unit in the battlescape, player controlled or AI controlled it holds info about i...
Definition: BattleUnit.h:59
OpenXcom::Map::setSelectorPosition
void setSelectorPosition(int mx, int my)
Sets the battlescape selector position relative to mouseposition.
Definition: Map.cpp:1178
OpenXcom::Map::Map
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
OpenXcom::InteractiveSurface
Surface that the user can interact with.
Definition: InteractiveSurface.h:40
OpenXcom::Text
Text string displayed on screen.
Definition: Text.h:42
OpenXcom::PathPreview
PathPreview
Path preview modes (can be OR'd together).
Definition: Options.h:41
OpenXcom::ResourcePack
Packs of external game media.
Definition: ResourcePack.h:51
OpenXcom::Map::keyboardRelease
void keyboardRelease(Action *action, State *state)
Special handling for key releases.
Definition: Map.cpp:1152
OpenXcom::Surface::offset
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
OpenXcom::Map::getCursorType
CursorType getCursorType() const
Gets the 3D cursor type.
Definition: Map.cpp:1362
OpenXcom::Map::scrollMouse
void scrollMouse()
Mouse-scrolls the camera.
Definition: Map.cpp:1473
OpenXcom::Map::init
void init()
Initializes the map.
Definition: Map.cpp:126
OpenXcom::Map::setWidth
void setWidth(int width)
Special handling for updating map width.
Definition: Map.cpp:1537
OpenXcom::BattlescapeMessage
Generic window used to display messages over the Battlescape map.
Definition: BattlescapeMessage.h:37
OpenXcom::Map::think
void think()
Handles timers.
Definition: Map.cpp:155
OpenXcom::State
A game state that receives user input and reacts accordingly.
Definition: State.h:45
OpenXcom::Camera
Class handling camera movement, either by mouse or by events on the battlescape.
Definition: Camera.h:36
OpenXcom::Timer
Timer used to run code in fixed intervals.
Definition: Timer.h:38
OpenXcom::Game
The core of the game engine, manages the game's entire contents and structure.
Definition: Game.h:45
OpenXcom::Map::animate
void animate(bool redraw)
Rotates the tileframes 0-7.
Definition: Map.cpp:1194
OpenXcom::Map::setButtonsPressed
void setButtonsPressed(Uint8 button, bool pressed)
Set mouse-buttons' pressed state.
Definition: Map.cpp:1500
OpenXcom::Position
Easy handling of X-Y-Z coordinates.
Definition: Position.h:31