1 // Copyright (C) 2007, 2008, 2009 Ben Asselstine
3 // This program is free software; you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation; either version 3 of the License, or
6 // (at your option) any later version.
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU Library General Public License for more details.
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
28 //! What a player can see on a hidden map.
31 * Map that represents fog. Overlays regular SmallMap.
36 //! The xml tag of this object in a saved-game file.
37 static std::string d_tag;
39 //! The two fog types.
41 //! Completely open to view.
43 //! Closed to view can be partially obscured.
48 LIGHTLY_TO_SOUTH_AND_EAST = 1,
49 LIGHTLY_TO_SOUTH_AND_WEST = 2,
50 LIGHTLY_TO_NORTH_AND_WEST = 3,
51 LIGHTLY_TO_NORTH_AND_EAST = 4,
52 DARKLY_TO_NORTH_AND_WEST_LIGHTLY_TO_SOUTH_AND_EAST = 5,
53 DARKLY_TO_NORTH_AND_EAST_LIGHTLY_TO_SOUTH_AND_WEST = 6,
54 DARKLY_TO_SOUTH_AND_EAST_LIGHTLY_TO_NORTH_AND_WEST = 7,
55 DARKLY_TO_SOUTH_AND_WEST_LIGHTLY_TO_NORTH_AND_EAST = 8,
56 DARKLY_TO_SOUTH_LIGHTLY_TO_EAST_AND_WEST = 9,
57 DARKLY_TO_NORTH_LIGHTLY_TO_EAST_AND_WEST = 10,
58 DARKLY_TO_WEST_LIGHTLY_TO_NORTH_AND_SOUTH = 11,
59 DARKLY_TO_EAST_LIGHTLY_TO_NORTH_AND_SOUTH = 12,
61 DARKLY_TO_SOUTH_AND_WEST_DARKLY_TO_NORTH_AND_EAST = 14,
62 DARKLY_TO_NORTH_AND_WEST_DARKLY_TO_SOUTH_AND_EAST = 15,
65 //! Standard constructor: create a given map
67 * @param width The GameMap is this wide.
68 * @param height The GameMap is this hight.
70 FogMap(int width, int height);
72 //! Loading constructor.
74 * Load the fogmap from a file.
75 * FogMaps are stored in the saved-game file at:
76 * lordsawar.playerlist.player.fogmap.
78 * @param helper The opened saved-game file to load the fogmap from.
80 FogMap(XML_Helper* helper);
83 FogMap(const FogMap&);
88 //! Returns the width of the fog map.
89 int getWidth() const {return d_width;}
91 //! Returns the height of the fog map.
92 int getHeight() const {return d_height;}
94 //! Fill the fogmap with a status.
96 * @param type The status to use.
98 * @return True on success, false on error.
100 bool fill(FogType type);
102 //! Get the foggedness of a given position.
103 FogType getFogTile(Vector<int> pos) const;
104 ShadeType getShadeTile(Vector<int> pos) const;
106 //! Alter the fog around a given position in the fog map.
108 * @param pt The point around which status is altered.
109 * @param radius The radius around the point where the fog is altered.
110 * @param new_type The type which the area gets.
112 void alterFogRadius(Vector<int> pt, int radius, FogType new_type);
114 //! Alter the fog in a rectangle at a given position on the fog map.
116 * @param pt The upper left point of the rectangle.
117 * @param width The width of the rectangle.
118 * @param height The height of the rectangle.
119 * @param new_type The fog type which the area gets.
121 void alterFogRectangle(Vector<int> pt, int height, int width, FogType new_type);
123 //! Defog the map according to the given sightmap.
125 * @param sightmap The portion of the map to defog.
127 void alterFog(SightMap *sightmap);
129 //! Smooth the fogmap.
131 * Sweep the fog map for squares that are fogged that are
132 * surrounded by defogged squres, and remove them.
136 //! Returns whether or not the fog on a tile is surrounded by openness.
138 * This method is for BigMap purposes, it helps to know when a given
139 * fog tile shouldn't be rendered.
141 bool isLoneFogTile(Vector<int> pos);
145 * @param helper The opened saved-game file to save the fogmap to.
147 * @return True if saving went well, false otherwise.
149 bool save(XML_Helper* helper) const;
151 //! Is a tile fogged?
153 * Assists the BigMap and SmallMap in knowing if a given tile is
156 * @param pos The position in the fogmap to query.
157 * @param player The player's fogmap to query.
159 * @return True if the position is obscured due to fog, false if not.
161 //static bool isFogged(Vector <int> pos, Player *player);
162 bool isFogged(Vector <int> pos);
163 static bool isClear(Vector <int> pos, Player *player) ;
165 bool isCompletelyObscuredFogTile(Vector<int> pos) const;
167 ShadeType calculateShade(Vector<int> tile);
171 void calculateShadeMap();
173 //! The width of the fog map.
176 //! The height of the fog map.
179 //! An array of tiles that describe how a tile is fogged.
183 //! A list of tiles that are completely obscured.
184 std::list<Vector<int> > completely_obscured;