OpenXcom  1.0
Open-source clone of the original X-Com
Globe.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 <vector>
21 #include <list>
22 #include "../Engine/InteractiveSurface.h"
23 #include "../Engine/FastLineClip.h"
24 #include "Cord.h"
25 
26 namespace OpenXcom
27 {
28 
29 class Game;
30 class Polygon;
31 class SurfaceSet;
32 class Timer;
33 class Target;
34 class LocalizedText;
35 class RuleGlobe;
36 
43 class Globe : public InteractiveSurface
44 {
45 private:
46  static const int NUM_LANDSHADES = 48;
47  static const int NUM_SEASHADES = 72;
48  static const int NEAR_RADIUS = 25;
49  static const size_t DOGFIGHT_ZOOM = 3;
50  static const int CITY_MARKER = 8;
51  static const double ROTATE_LONGITUDE;
52  static const double ROTATE_LATITUDE;
53 
54  RuleGlobe *_rules;
55  double _cenLon, _cenLat, _rotLon, _rotLat, _hoverLon, _hoverLat;
56  Sint16 _cenX, _cenY;
57  size_t _zoom, _zoomOld, _zoomTexture;
58  SurfaceSet *_texture, *_markerSet;
59  Game *_game;
60  Surface *_markers, *_countries, *_radars;
61  bool _hover;
62  int _blink;
63  Timer *_blinkTimer, *_rotTimer;
64  std::list<Polygon*> _cacheLand;
65  FastLineClip *_clipper;
66  double _radius, _radiusStep;
68  std::vector<std::vector<Cord> > _earthData;
70  std::vector<Sint16> _randomNoiseData;
72  std::vector<double> _zoomRadius;
73 
74  bool _isMouseScrolling, _isMouseScrolled;
75  int _xBeforeMouseScrolling, _yBeforeMouseScrolling;
76  double _lonBeforeMouseScrolling, _latBeforeMouseScrolling;
77  Uint32 _mouseScrollingStartTime;
78  int _totalMouseMoveX, _totalMouseMoveY;
79  bool _mouseMovedOverThreshold;
80 
82  void setZoom(size_t zoom);
84  bool pointBack(double lon, double lat) const;
86  double lastVisibleLat(double lon) const;
88  Polygon* getPolygonFromLonLat(double lon, double lat) const;
90  bool targetNear(Target* target, int x, int y) const;
92  void cache(std::list<Polygon*> *polygons, std::list<Polygon*> *cache);
94  Cord getSunDirection(double lon, double lat) const;
96  void drawGlobeCircle(double lat, double lon, double radius, int segments);
98  void XuLine(Surface* surface, Surface* src, double x1, double y1, double x2, double y2, int shade);
100  void drawVHLine(Surface *surface, double lon1, double lat1, double lon2, double lat2, Uint8 color);
102  void drawPath(Surface *surface, double lon1, double lat1, double lon2, double lat2);
104  void drawTarget(Target *target, Surface *surface);
105 public:
106 
107  static Uint8 COUNTRY_LABEL_COLOR;
108  static Uint8 LINE_COLOR;
109  static Uint8 CITY_LABEL_COLOR;
110  static Uint8 BASE_LABEL_COLOR;
111  static Uint8 OCEAN_COLOR;
113  Globe(Game* game, int cenX, int cenY, int width, int height, int x = 0, int y = 0);
115  ~Globe();
117  void polarToCart(double lon, double lat, Sint16 *x, Sint16 *y) const;
119  void polarToCart(double lon, double lat, double *x, double *y) const;
121  void cartToPolar(Sint16 x, Sint16 y, double *lon, double *lat) const;
123  void rotateLeft();
125  void rotateRight();
127  void rotateUp();
129  void rotateDown();
131  void rotateStop();
133  void rotateStopLon();
135  void rotateStopLat();
137  void zoomIn();
139  void zoomOut();
141  void zoomMin();
143  void zoomMax();
145  void saveZoomDogfight();
147  bool zoomDogfightIn();
149  bool zoomDogfightOut();
151  size_t getZoom() const;
153  void center(double lon, double lat);
155  bool insideLand(double lon, double lat) const;
157  void toggleDetail();
159  std::vector<Target*> getTargets(int x, int y, bool craft) const;
161  void cachePolygons();
163  void setPalette(SDL_Color *colors, int firstcolor = 0, int ncolors = 256);
165  void think();
167  void blink();
169  void rotate();
171  void draw();
173  void drawOcean();
175  void drawLand();
177  void drawShadow();
179  void drawRadars();
181  void drawFlights();
183  void drawDetail();
185  void drawMarkers();
187  void blit(Surface *surface);
189  void mouseOver(Action *action, State *state);
191  void mousePress(Action *action, State *state);
193  void mouseRelease(Action *action, State *state);
195  void mouseClick(Action *action, State *state);
197  void keyboardPress(Action *action, State *state);
199  void getPolygonTextureAndShade(double lon, double lat, int *texture, int *shade) const;
201  void setNewBaseHoverPos(double lon, double lat);
203  void setNewBaseHover(void);
205  void unsetNewBaseHover(void);
207  bool getNewBaseHover(void) const;
209  void toggleRadarLines();
211  void resize();
213  void setupRadii(int width, int height);
215  void stopScrolling(Action *action);
216 };
217 
218 }
bool zoomDogfightIn()
Zooms the globe in for dogfights.
Definition: Globe.cpp:586
Container for all the information associated with a given user action, like mouse clicks...
Definition: Action.h:32
void setNewBaseHoverPos(double lon, double lat)
Sets hover base position.
Definition: Globe.cpp:1183
void rotateUp()
Starts rotating the globe up.
Definition: Globe.cpp:462
A game state that receives user input and reacts accordingly.
Definition: State.h:43
bool getNewBaseHover(void) const
Gets state of base hover mode.
Definition: Globe.cpp:1178
void drawMarkers()
Draws all the markers over the globe.
Definition: Globe.cpp:1516
void drawFlights()
Draws the flight paths of the globe.
Definition: Globe.cpp:1463
Timer used to run code in fixed intervals.
Definition: Timer.h:35
std::vector< Target * > getTargets(int x, int y, bool craft) const
Gets all the targets near a point on the globe.
Definition: Globe.cpp:696
Surface that the user can interact with.
Definition: InteractiveSurface.h:37
void drawDetail()
Draws the country details of the globe.
Definition: Globe.cpp:1234
void mouseRelease(Action *action, State *state)
Special handling for mouse releases.
Definition: Globe.cpp:1689
void blit(Surface *surface)
Blits the globe onto another surface.
Definition: Globe.cpp:1564
Interactive globe view of the world.
Definition: Globe.h:43
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:1661
void cartToPolar(Sint16 x, Sint16 y, double *lon, double *lat) const
Converts cartesian coordinates to polar coordinates.
Definition: Globe.cpp:343
void rotateStopLon()
Stops longitude rotation of the globe.
Definition: Globe.cpp:490
void toggleDetail()
Turns on/off the globe detail.
Definition: Globe.cpp:662
void keyboardPress(Action *action, State *state)
Special handling for key presses.
Definition: Globe.cpp:1782
void drawLand()
Draws the land of the globe.
Definition: Globe.cpp:913
void drawOcean()
Draws the ocean of the globe.
Definition: Globe.cpp:898
bool zoomDogfightOut()
Zooms the globe out for dogfights.
Definition: Globe.cpp:611
void toggleRadarLines()
set the _radarLines variable
Definition: Globe.cpp:1827
void center(double lon, double lat)
Centers the globe on a point.
Definition: Globe.cpp:638
void rotateLeft()
Starts rotating the globe left.
Definition: Globe.cpp:444
Container of a set of surfaces.
Definition: SurfaceSet.h:35
void draw()
Draws the whole globe.
Definition: Globe.cpp:878
void unsetNewBaseHover(void)
Turns off new base hover mode.
Definition: Globe.cpp:1173
void polarToCart(double lon, double lat, Sint16 *x, Sint16 *y) const
Converts polar coordinates to cartesian coordinates.
Definition: Globe.cpp:320
void zoomIn()
Zooms the globe in.
Definition: Globe.cpp:533
Fast line clip.
Definition: FastLineClip.h:25
void mouseClick(Action *action, State *state)
Special handling for mouse clicks.
Definition: Globe.cpp:1710
void drawRadars()
Draws the radar ranges of the globe.
Definition: Globe.cpp:1071
void setNewBaseHover(void)
Turns on new base hover mode.
Definition: Globe.cpp:1168
bool insideLand(double lon, double lat) const
Checks if a point is inside land.
Definition: Globe.cpp:653
void rotateDown()
Starts rotating the globe down.
Definition: Globe.cpp:471
~Globe()
Cleans up the globe.
Definition: Globe.cpp:295
Represents a polygon in the world map.
Definition: Polygon.h:31
void mouseOver(Action *action, State *state)
Special handling for mouse hover.
Definition: Globe.cpp:1577
void cachePolygons()
Caches visible globe polygons.
Definition: Globe.cpp:766
void rotateStop()
Stops rotating the globe.
Definition: Globe.cpp:480
void zoomOut()
Zooms the globe out.
Definition: Globe.cpp:544
void zoomMin()
Zooms the globe minimum.
Definition: Globe.cpp:555
Represents the contents of the Geoscape globe, such as world polygons, polylines, etc...
Definition: RuleGlobe.h:36
void drawShadow()
Draws the shadow.
Definition: Globe.cpp:987
void stopScrolling(Action *action)
Move the mouse back to where it started after we finish drag scrolling.
Definition: Globe.cpp:1893
void rotateStopLat()
Stops latitude rotation of the globe.
Definition: Globe.cpp:502
Element that is blit (rendered) onto the screen.
Definition: Surface.h:36
void setupRadii(int width, int height)
Set up the radius of earth and stuff.
Definition: Globe.cpp:1861
void setPalette(SDL_Color *colors, int firstcolor=0, int ncolors=256)
Sets the palette of the globe.
Definition: Globe.cpp:824
void rotateRight()
Starts rotating the globe right.
Definition: Globe.cpp:453
void blink()
Blinks the markers.
Definition: Globe.cpp:848
Definition: Cord.h:49
The core of the game engine, manages the game&#39;s entire contents and structure.
Definition: Game.h:41
size_t getZoom() const
Gets the current zoom.
Definition: Globe.cpp:1819
Base class for targets on the globe with a set of radian coordinates.
Definition: Target.h:33
void rotate()
Rotates the globe.
Definition: Globe.cpp:866
void getPolygonTextureAndShade(double lon, double lat, int *texture, int *shade) const
Get the polygons texture and shade at the given point.
Definition: Globe.cpp:1802
void think()
Handles the timers.
Definition: Globe.cpp:839
void saveZoomDogfight()
Saves the zoom level for dogfights.
Definition: Globe.cpp:577
void resize()
Update the resolution settings, we just resized the window.
Definition: Globe.cpp:1836
Definition: BaseInfoState.cpp:40
void zoomMax()
Zooms the globe maximum.
Definition: Globe.cpp:566