-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmap.hpp
133 lines (100 loc) · 3.98 KB
/
map.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*
This file is part of Heroes of Wesnoth.
Copyright (C) 2007, 2008, 2009 Jon Ander Peñalba <[email protected]>
Heroes of Wesnoth is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License version 3 as
published by the Free Software Foundation.
Heroes of Wesnoth is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Heroes of Wesnoth. If not, see <http://www.gnu.org/licenses/>
*/
/// @file
/// The Map class.
/// @author Jonan
#ifndef MAP_HPP
#define MAP_HPP
#include "game_loop.hpp"
#include "util.hpp"
class Cell;
class Unit;
class UnitAnimation;
/// Controls all the attributes of a map.
/// Basically consist of lots of Cell classes working
/// together to create a map an to be able to use it.
/// (This class is meant to be inherit, not to be used directly)
class Map : public GameLoop {
public:
/// Starts the map.
virtual void start(void);
protected:
// @{
// Constructors
Map(const int width, const int height);
Map(const char *map_file);
// @}
virtual ~Map(void); // Destructor
// Sets the terrain type to all the cells in the map.
void setTerrainToAllCells(const char *id);
// Loads the terrain, creatures and items of the map from a file.
void loadMapFile(const char *file_name);
// Adjusts the visible map to the window size.
void adjustVisibleMap(void);
// Makes the hole map visible.
void makeMapVisible(void);
// Returns a cell where the creature can attack.
Cell* getAttackCell(void);
// Updates the map according to the mouse state
void updateMouse(void);
// Function to execute when the mouse is over a cell.
virtual void mouseOverCell(const int x, const int y);
// Function to execute when the user left clicks on a cell.
virtual void mouseLeftClick(const int x, const int y) {}
// Function to execute when the user right clicks on a cell.
virtual void mouseRightClick(const int x, const int y);
// Starts the next turn.
virtual void nextTurn(void) {}
// Moves the selected creature to a cell.
void move(Cell &cell);
// Makes the selected creature attack the unit in the given cell.
virtual void attack(Cell &cell) {}
// Connects all the cells in the map.
void connectCells(void);
// Softens the map to make it look nicer.
void smoothMap(void);
// Centers the map view in a given cell
void centerView(Cell& position);
// Centers the map view in a given creature
void centerView(Unit& creature);
// Draws the map in the screen.
virtual void draw(void);
// This function is executed in the main loop. If
// it returns true, the loop ends, else it continues.
virtual bool frame(void);
// @{
// Functions to delete parts of the map.
// This functions shouldn't normally be called (the
// desctructor will call them), but they are usefull in some cases.
void deleteCells (void);
void deleteCreatures (void);
// @}
int map_width, map_height; // The map's size.
Cell **map;
Unit *selected_unit; // The unit that's selected.
UnitAnimation *animation;
Cell *mouse_over_cell; // The cell where the mouse is.
bool end_map;
private:
// Initialize all the variables.
void init(void);
// Adds the corresponding smooth images to the cell.
void addSmoothImages(Cell *cell, bool *need_smooth, const char *terrain);
Coordinates first_cell_coor; // Map coordinates of the top left visible cell.
Coordinates first_cell_pos; // Position of the top left visible cell in the screen.
int window_width, window_height; // Size of the map's window
int window_horizontal_cells, window_vertical_cells; // Number of visible cells
DISALLOW_COPY_AND_ASSIGN(Map);
};
#endif // MAP_HPP