-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcell.hpp
145 lines (113 loc) · 4.92 KB
/
cell.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
134
135
136
137
138
139
140
141
142
143
144
145
/*
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 Cell class.
/// @author Jonan
#ifndef CELL_HPP
#define CELL_HPP
#include <deque>
#include <string>
#include <SDL/SDL.h>
#include "util.hpp"
class Unit;
struct Coordinates;
struct SpecialImage;
/// The six relative positions to a cell
enum {N, NE, SE, S, SW, NW};
/// Parts of the drawing of a cell
enum {DRAW_TERRAIN, DRAW_SPECIAL_IMG, DRAW_UNIT};
/// Class to control all each independent cell in a map.
class Cell {
public:
Cell(void); // Constructor
~Cell(void); // Destructor
// @{
/// Set functions.
void setPassable (const bool passable) {this->passable = passable;}
void setTerrain (const char *type);
void setCreature (Unit *creature);
void setItem (const char *type);
void setCoordinates (const int x, const int y);
// @}
// @{
/// Get functions.
const char* getTerrainId (void) {return type.c_str(); }
const char* getBaseTerrain (void);
const char* getItemId (void) {return item.c_str(); }
Unit* getCreature (void) {return creature; }
Cell* getConnectedCell (const int place) {return connected_cell[place];}
void getCoordinates (int &x, int &y);
void getPath (int* &path, int &movements);
// @}
/// Adds an image to the cell's terrain.
/// @param[in] terrain Surface of the terrain.
void addImage(SDL_Surface &terrain) {terrain_images.push_back(&terrain);}
/// Adds a special image to the cell's terrain.
/// @param[in] terrain Surface of the terrain.
void addSpecialImage(SDL_Surface &terrain);
// @{
/// Indicates if the mouse is in the cell or not
void putMouse (void) {mouse_over = true; }
void removeMouse (void) {mouse_over = false;}
// @}
/// Indicates that the cell is now selected.
/// The cell is selected and the cells where
/// the unit can move are marked.
void select(void);
/// The cell is no longer selected.
/// Marks the cell as not being selected and tells all the cells
/// where the unit could move that now it can not move there.
void unselect(void);
/// Calculates which cells are visible.
/// @param[in] visibility Visibility of the hero on the cell.
void calculateView(int visibility);
/// Connects a cell to this one.
/// Indicates which are the cells next to this one
/// in any direction (N, NE, SE, S, SW or NW).
/// @param[in] position Relative position of the cell (N, NE, SE, S, SW or NW).
/// @param[in] connected_cell The cell to conect.
void connectCell(const int position, Cell* connected_cell);
/// Draws the cell in the screen.
/// @param[in] position Position where to draw the cell.
/// @param[in] part Part of the cell to draw.
void draw(SDL_Rect position, const int part);
// @{
/// Indicates if an action can be performed.
bool canMoveHere (void) {return can_move; }
bool canAttackHere (void) {return can_attack;}
// @}
private:
// Calculates to what cells can a creature move.
void calculateMovement(const int creature_movement, int *path, const int movements);
// Erases previos calculations about a creatures movement.
void eraseMovement(void);
std::string type; // Type of terrain of the cell
std::deque<SDL_Surface*> terrain_images; // Surfaces of the terrain
SpecialImage *special_images;
SDL_Surface *stars, *alpha;
Unit *creature;
std::string item;
Cell *connected_cell[6]; // The six cells that are next to this one
Coordinates *map_position; // Map coordinates of the cell
int *path; // Path to follow in a units movement
int movements; // Number of cells to go through to follow the path
bool passable; // Indicates if a unit can move to this cell
bool mouse_over; // Indicates if the mouse is over the cell
bool selected; // Indicates if the unit in the cell is selected
bool can_move; // Indicates if the selected creature can move to this cell
bool can_attack; // Indicates if the unit in the cell can be attacked
bool visible; // Indicates if the cell is visible or not
DISALLOW_COPY_AND_ASSIGN(Cell);
};
#endif // CELL_HPP