OpenXcom  1.0
Open-source clone of the original X-Com
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Globe.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_GLOBE_H
20 #define OPENXCOM_GLOBE_H
21 
22 #include <vector>
23 #include <list>
24 #include "../Engine/InteractiveSurface.h"
25 #include "../Engine/FastLineClip.h"
26 #include "Cord.h"
27 
28 namespace OpenXcom
29 {
30 
31 class Game;
32 class Polygon;
33 class SurfaceSet;
34 class Timer;
35 class Target;
36 class LocalizedText;
37 
44 class Globe : public InteractiveSurface
45 {
46 private:
47  static const int NUM_TEXTURES = 13;
48  static const int NUM_LANDSHADES = 48;
49  static const int NUM_SEASHADES = 72;
50  static const int NEAR_RADIUS = 25;
51  static const int DOGFIGHT_ZOOM = 3;
52  static const double ROTATE_LONGITUDE;
53  static const double ROTATE_LATITUDE;
54 
55  double _cenLon, _cenLat, _rotLon, _rotLat, _hoverLon, _hoverLat;
56  Sint16 _cenX, _cenY;
57  size_t _zoom, _zoomOld;
58  SurfaceSet *_texture;
59  Game *_game;
60  Surface *_markers, *_countries, *_radars;
61  bool _blink, _hover;
62  Timer *_blinkTimer, *_rotTimer;
63  std::list<Polygon*> _cacheLand;
64  Surface *_mkXcomBase, *_mkAlienBase, *_mkCraft, *_mkWaypoint, *_mkCity;
65  Surface *_mkFlyingUfo, *_mkLandedUfo, *_mkCrashedUfo, *_mkAlienSite;
66  FastLineClip *_clipper;
67  double _radius, _radiusStep;
69  std::vector<std::vector<Cord> > _earthData;
71  std::vector<Sint16> _randomNoiseData;
73  std::vector<double> _zoomRadius;
74 
75  bool _isMouseScrolling, _isMouseScrolled;
76  int _xBeforeMouseScrolling, _yBeforeMouseScrolling;
77  double _lonBeforeMouseScrolling, _latBeforeMouseScrolling;
78  Uint32 _mouseScrollingStartTime;
79  int _totalMouseMoveX, _totalMouseMoveY;
80  bool _mouseMovedOverThreshold;
81 
83  void setZoom(size_t zoom);
85  bool pointBack(double lon, double lat) const;
87  double lastVisibleLat(double lon) const;
89  bool insidePolygon(double lon, double lat, Polygon *poly) const;
91  bool targetNear(Target* target, int x, int y) const;
93  void cache(std::list<Polygon*> *polygons, std::list<Polygon*> *cache);
95  Cord getSunDirection(double lon, double lat) const;
97  void drawGlobeCircle(double lat, double lon, double radius, int segments);
99  void XuLine(Surface* surface, Surface* src, double x1, double y1, double x2, double y2, int shade);
101  void drawVHLine(Surface *surface, double lon1, double lat1, double lon2, double lat2, Uint8 color);
103  void drawPath(Surface *surface, double lon1, double lat1, double lon2, double lat2);
104 public:
106  Globe(Game *game, int cenX, int cenY, int width, int height, int x = 0, int y = 0);
108  ~Globe();
110  static void loadDat(const std::string &filename, std::list<Polygon*> *polygons);
112  void polarToCart(double lon, double lat, Sint16 *x, Sint16 *y) const;
114  void polarToCart(double lon, double lat, double *x, double *y) const;
116  void cartToPolar(Sint16 x, Sint16 y, double *lon, double *lat) const;
118  void setTexture(SurfaceSet *texture);
120  void rotateLeft();
122  void rotateRight();
124  void rotateUp();
126  void rotateDown();
128  void rotateStop();
130  void rotateStopLon();
132  void rotateStopLat();
134  void zoomIn();
136  void zoomOut();
138  void zoomMin();
140  void zoomMax();
142  void saveZoomDogfight();
144  bool zoomDogfightIn();
146  bool zoomDogfightOut();
148  size_t getZoom() const;
150  void center(double lon, double lat);
152  bool insideLand(double lon, double lat) const;
154  void toggleDetail();
156  std::vector<Target*> getTargets(int x, int y, bool craft) const;
158  void cachePolygons();
160  void setPalette(SDL_Color *colors, int firstcolor = 0, int ncolors = 256);
162  void think();
164  void blink();
166  void rotate();
168  void draw();
170  void drawOcean();
172  void drawLand();
174  void drawShadow();
176  void drawRadars();
178  void drawFlights();
180  void drawDetail();
182  void drawMarkers();
184  void blit(Surface *surface);
186  void mouseOver(Action *action, State *state);
188  void mousePress(Action *action, State *state);
190  void mouseRelease(Action *action, State *state);
192  void mouseClick(Action *action, State *state);
194  void keyboardPress(Action *action, State *state);
196  void getPolygonTextureAndShade(double lon, double lat, int *texture, int *shade) const;
198  const LocalizedText &tr(const std::string &id) const;
200  LocalizedText tr(const std::string &id, unsigned n) const;
202  void setNewBaseHoverPos(double lon, double lat);
204  void setNewBaseHover(void);
206  void unsetNewBaseHover(void);
208  bool getNewBaseHover(void);
210  bool getShowRadar(void);
212  void toggleRadarLines();
214  void resize();
216  void setupRadii(int width, int height);
218  void stopScrolling(Action *action);
219 };
220 
221 }
222 
223 #endif
bool zoomDogfightIn()
Zooms the globe in for dogfights.
Definition: Globe.cpp:745
Container for all the information associated with a given user action, like mouse clicks...
Definition: Action.h:34
void polarToCart(double lon, double lat, Sint16 *x, Sint16 *y) const
Converts polar coordinates to cartesian coordinates.
Definition: Globe.cpp:426
void setNewBaseHoverPos(double lon, double lat)
Sets hover base position.
Definition: Globe.cpp:1374
void rotateUp()
Starts rotating the globe up.
Definition: Globe.cpp:622
void getPolygonTextureAndShade(double lon, double lat, int *texture, int *shade) const
Get the polygons texture and shade at the given point.
Definition: Globe.cpp:2036
size_t getZoom() const
Gets the current zoom.
Definition: Globe.cpp:2068
A game state that receives user input and reacts accordingly.
Definition: State.h:44
void drawMarkers()
Draws all the markers over the globe.
Definition: Globe.cpp:1694
void drawFlights()
Draws the flight paths of the globe.
Definition: Globe.cpp:1658
Timer used to run code in fixed intervals.
Definition: Timer.h:37
Surface that the user can interact with.
Definition: InteractiveSurface.h:39
void drawDetail()
Draws the country details of the globe.
Definition: Globe.cpp:1426
void mouseRelease(Action *action, State *state)
Special handling for mouse releases.
Definition: Globe.cpp:1923
void blit(Surface *surface)
Blits the globe onto another surface.
Definition: Globe.cpp:1806
Interactive globe view of the world.
Definition: Globe.h:44
Globe(Game *game, int cenX, int cenY, int width, int height, int x=0, int y=0)
Creates a new globe at the specified position and size.
Definition: Globe.cpp:257
void mousePress(Action *action, State *state)
Special handling for mouse presses.
Definition: Globe.cpp:1895
void rotateStopLon()
Stops longitude rotation of the globe.
Definition: Globe.cpp:650
void toggleDetail()
Turns on/off the globe detail.
Definition: Globe.cpp:833
void keyboardPress(Action *action, State *state)
Special handling for key presses.
Definition: Globe.cpp:2016
void drawLand()
Draws the land of the globe.
Definition: Globe.cpp:1101
void drawOcean()
Draws the ocean of the globe.
Definition: Globe.cpp:1086
bool zoomDogfightOut()
Zooms the globe out for dogfights.
Definition: Globe.cpp:770
std::vector< Target * > getTargets(int x, int y, bool craft) const
Gets all the targets near a point on the globe.
Definition: Globe.cpp:867
A string that is already translated.
Definition: LocalizedText.h:45
const LocalizedText & tr(const std::string &id) const
Get the localized text.
void toggleRadarLines()
set the _radarLines variable
Definition: Globe.cpp:2076
void center(double lon, double lat)
Centers the globe on a point.
Definition: Globe.cpp:797
void rotateLeft()
Starts rotating the globe left.
Definition: Globe.cpp:604
Container of a set of surfaces.
Definition: SurfaceSet.h:38
bool getShowRadar(void)
Gets _detail variable.
void draw()
Draws the whole globe.
Definition: Globe.cpp:1066
void unsetNewBaseHover(void)
Turns off new base hover mode.
Definition: Globe.cpp:1366
bool insideLand(double lon, double lat) const
Checks if a point is inside land.
Definition: Globe.cpp:812
void zoomIn()
Zooms the globe in.
Definition: Globe.cpp:692
Fast line clip.
Definition: FastLineClip.h:27
void mouseClick(Action *action, State *state)
Special handling for mouse clicks.
Definition: Globe.cpp:1944
void drawRadars()
Draws the radar ranges of the globe.
Definition: Globe.cpp:1260
static void loadDat(const std::string &filename, std::list< Polygon * > *polygons)
Loads a set of polygons from a DAT file.
Definition: Globe.cpp:548
void setNewBaseHover(void)
Turns on new base hover mode.
Definition: Globe.cpp:1362
void rotateDown()
Starts rotating the globe down.
Definition: Globe.cpp:631
~Globe()
Cleans up the globe.
Definition: Globe.cpp:392
Represents a polygon in the world map.
Definition: Polygon.h:32
void mouseOver(Action *action, State *state)
Special handling for mouse hover.
Definition: Globe.cpp:1819
void cachePolygons()
Caches visible globe polygons.
Definition: Globe.cpp:937
void rotateStop()
Stops rotating the globe.
Definition: Globe.cpp:640
void zoomOut()
Zooms the globe out.
Definition: Globe.cpp:703
void zoomMin()
Zooms the globe minimum.
Definition: Globe.cpp:714
void setTexture(SurfaceSet *texture)
Sets the texture set for the globe's polygons.
void drawShadow()
Draws the shadow.
Definition: Globe.cpp:1176
void stopScrolling(Action *action)
Move the mouse back to where it started after we finish drag scrolling.
Definition: Globe.cpp:2142
void rotateStopLat()
Stops latitude rotation of the globe.
Definition: Globe.cpp:662
Element that is blit (rendered) onto the screen.
Definition: Surface.h:39
void setupRadii(int width, int height)
Set up the radius of earth and stuff.
Definition: Globe.cpp:2110
void setPalette(SDL_Color *colors, int firstcolor=0, int ncolors=256)
Sets the palette of the globe.
Definition: Globe.cpp:995
void rotateRight()
Starts rotating the globe right.
Definition: Globe.cpp:613
void blink()
Blinks the markers.
Definition: Globe.cpp:1027
Definition: Cord.h:51
The core of the game engine, manages the game's entire contents and structure.
Definition: Game.h:44
Base class for targets on the globe with a set of radian coordinates.
Definition: Target.h:35
void cartToPolar(Sint16 x, Sint16 y, double *lon, double *lat) const
Converts cartesian coordinates to polar coordinates.
Definition: Globe.cpp:449
bool getNewBaseHover(void)
Gets state of base hover mode.
Definition: Globe.cpp:1370
void rotate()
Rotates the globe.
Definition: Globe.cpp:1054
void think()
Handles the timers.
Definition: Globe.cpp:1018
void saveZoomDogfight()
Saves the zoom level for dogfights.
Definition: Globe.cpp:736
void resize()
Update the resolution settings, we just resized the window.
Definition: Globe.cpp:2085
void zoomMax()
Zooms the globe maximum.
Definition: Globe.cpp:725