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 
39 enum CursorType { CT_NONE, CT_NORMAL, CT_AIM, CT_PSI, CT_WAYPOINT, CT_THROW };
43 class Map : public InteractiveSurface
44 {
45 private:
46  static const int SCROLL_INTERVAL = 15;
47  static const int BULLET_SPRITES = 35;
48  Timer *_scrollMouseTimer, *_scrollKeyTimer;
49  Game *_game;
50  SavedBattleGame *_save;
51  Surface *_arrow;
52  int _spriteWidth, _spriteHeight;
53  int _selectorX, _selectorY;
54  int _mouseX, _mouseY;
55  CursorType _cursorType;
56  int _cursorSize;
57  int _animFrame;
58  Projectile *_projectile;
59  bool _projectileInFOV;
60  std::list<Explosion *> _explosions;
61  bool _explosionInFOV, _launch;
62  BattlescapeMessage *_message;
63  Camera *_camera;
64  int _visibleMapHeight;
65  std::vector<Position> _waypoints;
66  bool _unitDying, _smoothCamera, _smoothingEngaged, _flashScreen;
67  PathPreview _previewSetting;
68  Text *_txtAccuracy;
69  SurfaceSet *_projectileSet;
70 
71  void drawTerrain(Surface *surface);
72  int getTerrainLevel(const Position& pos, int size) const;
73  int _iconHeight, _iconWidth, _messageColor;
74  const std::vector<Uint8> *_transparencies;
75 public:
77  Map(Game* game, int width, int height, int x, int y, int visibleMapHeight);
79  ~Map();
81  void init();
83  void think();
85  void draw();
87  void setPalette(SDL_Color *colors, int firstcolor = 0, int ncolors = 256);
89  void mousePress(Action *action, State *state);
91  void mouseRelease(Action *action, State *state);
93  void mouseOver(Action *action, State *state);
95  void keyboardPress(Action *action, State *state);
97  void keyboardRelease(Action *action, State *state);
99  void animate(bool redraw);
101  void setSelectorPosition(int mx, int my);
103  void getSelectorPosition(Position *pos) const;
107  void setCursorType(CursorType type, int size = 1);
109  CursorType getCursorType() const;
111  void cacheUnits();
113  void cacheUnit(BattleUnit *unit);
115  void setProjectile(Projectile *projectile);
117  Projectile *getProjectile() const;
119  std::list<Explosion*> *getExplosions();
121  Camera *getCamera();
123  void scrollMouse();
125  void scrollKey();
127  std::vector<Position> *getWaypoints();
129  void setButtonsPressed(Uint8 button, bool pressed);
131  void setUnitDying(bool flag);
135  void setHeight(int height);
137  void setWidth(int width);
139  int getMessageY() const;
141  int getIconHeight() const;
143  int getIconWidth() const;
145  int getSoundAngle(const Position& pos) const;
147  void resetCameraSmoothing();
149  void setBlastFlash(bool flash);
151  bool getBlastFlash() const;
152 };
153 
154 }
void keyboardPress(Action *action, State *state)
Special handling for key presses.
Definition: Map.cpp:1284
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:78
void setSelectorPosition(int mx, int my)
Sets the battlescape selector position relative to mouseposition.
Definition: Map.cpp:1321
A game state that receives user input and reacts accordingly.
Definition: State.h:43
CursorType getCursorType() const
Gets the 3D cursor type.
Definition: Map.cpp:1526
void setProjectile(Projectile *projectile)
Sets projectile.
Definition: Map.cpp:1583
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:1763
void animate(bool redraw)
Rotates the tileframes 0-7.
Definition: Map.cpp:1337
void draw()
Draws the surface.
Definition: Map.cpp:179
Text string displayed on screen.
Definition: Text.h:40
void scrollMouse()
Mouse-scrolls the camera.
Definition: Map.cpp:1622
~Map()
Cleans up the map.
Definition: Map.cpp:120
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:1745
void setButtonsPressed(Uint8 button, bool pressed)
Set mouse-buttons&#39; pressed state.
Definition: Map.cpp:1649
void scrollKey()
Keyboard-scrolls the camera.
Definition: Map.cpp:1630
std::list< Explosion * > * getExplosions()
Gets explosion set.
Definition: Map.cpp:1605
void setWidth(int width)
Special handling for updating map width.
Definition: Map.cpp:1687
void mouseOver(Action *action, State *state)
Special handling for mouse over.
Definition: Map.cpp:1306
void refreshSelectorPosition()
Refreshes the battlescape selector after scrolling.
Definition: Map.cpp:1666
int getSoundAngle(const Position &pos) const
Convert a map position to a sound angle.
Definition: Map.cpp:1725
Container of a set of surfaces.
Definition: SurfaceSet.h:35
void mousePress(Action *action, State *state)
Special handling for mouse press.
Definition: Map.cpp:1262
void cacheUnit(BattleUnit *unit)
Caches the unit.
Definition: Map.cpp:1546
Interactive map of the battlescape.
Definition: Map.h:43
void getSelectorPosition(Position *pos) const
Gets the currently selected position.
Definition: Map.cpp:1372
void think()
Handles timers.
Definition: Map.cpp:170
std::vector< Position > * getWaypoints()
Get waypoints vector.
Definition: Map.cpp:1639
Element that is blit (rendered) onto the screen.
Definition: Surface.h:36
void mouseRelease(Action *action, State *state)
Special handling for mouse release.
Definition: Map.cpp:1273
Camera * getCamera()
Gets the pointer to the camera.
Definition: Map.cpp:1614
void setBlastFlash(bool flash)
Set whether the screen should "flash" or not.
Definition: Map.cpp:1754
void cacheUnits()
Caches units.
Definition: Map.cpp:1534
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:1698
void setPalette(SDL_Color *colors, int firstcolor=0, int ncolors=256)
Sets the palette.
Definition: Map.cpp:233
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:133
void setCursorType(CursorType type, int size=1)
Sets the 3D cursor type.
Definition: Map.cpp:1513
Projectile * getProjectile() const
Gets projectile.
Definition: Map.cpp:1596
Easy handling of X-Y-Z coordinates.
Definition: Position.h:28
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:1384
void setUnitDying(bool flag)
Sets the unitDying flag.
Definition: Map.cpp:1658
int getIconHeight() const
Get the icon height.
Definition: Map.cpp:1706
void keyboardRelease(Action *action, State *state)
Special handling for key releases.
Definition: Map.cpp:1295
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:1714
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:452
void setHeight(int height)
Special handling for updating map height.
Definition: Map.cpp:1675