1 // Copyright (C) 2007, 2008, 2009, 2014, 2015 Ben Asselstine 2 // 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. 7 // 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. 12 // 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 16 // 02110-1301, USA. 17 18 #pragma once 19 #ifndef FOGMAP_H 20 #define FOGMAP_H 21 22 #include <list> 23 #include <glibmm.h> 24 #include "vector.h" 25 26 class XML_Helper; 27 class SightMap; 28 class Player; 29 30 //! What a player can see on a hidden map. 31 /** 32 * 33 * Map that represents fog. Overlays regular SmallMap. 34 */ 35 class FogMap 36 { 37 public: 38 //! The xml tag of this object in a saved-game file. 39 static Glib::ustring d_tag; 40 41 //! The two fog types. 42 enum FogType { 43 //! Completely open to view. 44 OPEN = 0, 45 //! Closed to view can be partially obscured. 46 CLOSED = 1 47 }; 48 enum ShadeType { 49 NONE = 0, 50 LIGHTLY_TO_SOUTH_AND_EAST = 1, 51 LIGHTLY_TO_SOUTH_AND_WEST = 2, 52 LIGHTLY_TO_NORTH_AND_WEST = 3, 53 LIGHTLY_TO_NORTH_AND_EAST = 4, 54 DARKLY_TO_NORTH_AND_WEST_LIGHTLY_TO_SOUTH_AND_EAST = 5, 55 DARKLY_TO_NORTH_AND_EAST_LIGHTLY_TO_SOUTH_AND_WEST = 6, 56 DARKLY_TO_SOUTH_AND_EAST_LIGHTLY_TO_NORTH_AND_WEST = 7, 57 DARKLY_TO_SOUTH_AND_WEST_LIGHTLY_TO_NORTH_AND_EAST = 8, 58 DARKLY_TO_SOUTH_LIGHTLY_TO_EAST_AND_WEST = 9, 59 DARKLY_TO_NORTH_LIGHTLY_TO_EAST_AND_WEST = 10, 60 DARKLY_TO_WEST_LIGHTLY_TO_NORTH_AND_SOUTH = 11, 61 DARKLY_TO_EAST_LIGHTLY_TO_NORTH_AND_SOUTH = 12, 62 ALL = 13, 63 DARKLY_TO_SOUTH_AND_WEST_DARKLY_TO_NORTH_AND_EAST = 14, 64 DARKLY_TO_NORTH_AND_WEST_DARKLY_TO_SOUTH_AND_EAST = 15 65 }; 66 67 //! Standard constructor: create a given map 68 /** 69 * @param width The GameMap is this wide. 70 * @param height The GameMap is this hight. 71 */ 72 FogMap(int width, int height); 73 74 //! Loading constructor. 75 /** 76 * Load the fogmap from a file. 77 * FogMaps are stored in the saved-game file at: 78 * lordsawar.playerlist.player.fogmap. 79 * 80 * @param helper The opened saved-game file to load the fogmap from. 81 */ 82 FogMap(XML_Helper* helper); 83 84 //! Copy constructor. 85 FogMap(const FogMap&); 86 87 //! Destructor. 88 ~FogMap(); 89 90 //! Returns the width of the fog map. getWidth()91 int getWidth() const {return d_width;} 92 93 //! Returns the height of the fog map. getHeight()94 int getHeight() const {return d_height;} 95 96 //! Fill the fogmap with a status. 97 /** 98 * @param type The status to use. 99 * 100 * @return True on success, false on error. 101 */ 102 bool fill(FogType type); 103 104 //! Get the foggedness of a given position. 105 FogType getFogTile(Vector<int> pos) const; 106 ShadeType getShadeTile(Vector<int> pos) const; 107 108 //! Alter the fog around a given position in the fog map. 109 /** 110 * @param pt The point around which status is altered. 111 * @param radius The radius around the point where the fog is altered. 112 * @param new_type The type which the area gets. 113 */ 114 void alterFogRadius(Vector<int> pt, int radius, FogType new_type); 115 116 //! Alter the fog in a rectangle at a given position on the fog map. 117 /** 118 * @param pt The upper left point of the rectangle. 119 * @param width The width of the rectangle. 120 * @param height The height of the rectangle. 121 * @param new_type The fog type which the area gets. 122 */ 123 void alterFogRectangle(Vector<int> pt, int height, int width, FogType new_type); 124 125 //! Defog the map according to the given sightmap. 126 /** 127 * @param sightmap The portion of the map to defog. 128 */ 129 void alterFog(SightMap *sightmap); 130 131 //! Smooth the fogmap. 132 /** 133 * Sweep the fog map for squares that are fogged that are 134 * surrounded by defogged squres, and remove them. 135 */ 136 void smooth(); 137 138 //! Returns whether or not the fog on a tile is surrounded by openness. 139 /** 140 * This method is for BigMap purposes, it helps to know when a given 141 * fog tile shouldn't be rendered. 142 */ 143 bool isLoneFogTile(Vector<int> pos); 144 145 //! Save a fogmap. 146 /** 147 * @param helper The opened saved-game file to save the fogmap to. 148 * 149 * @return True if saving went well, false otherwise. 150 */ 151 bool save(XML_Helper* helper) const; 152 153 //! Is a tile fogged? 154 /** 155 * Assists the BigMap and SmallMap in knowing if a given tile is 156 * obscured or not. 157 * 158 * @param pos The position in the fogmap to query. 159 * @param player The player's fogmap to query. 160 * 161 * @return True if the position is obscured due to fog, false if not. 162 */ 163 //static bool isFogged(Vector <int> pos, Player *player); 164 bool isFogged(Vector <int> pos); 165 static bool isClear(Vector <int> pos, Player *player) ; 166 167 bool isCompletelyObscuredFogTile(Vector<int> pos) const; 168 169 ShadeType calculateShade(Vector<int> tile); 170 171 private: 172 173 void calculateShadeMap(); 174 // Data 175 //! The width of the fog map. 176 int d_width; 177 178 //! The height of the fog map. 179 int d_height; 180 181 //! An array of tiles that describe how a tile is fogged. 182 FogType * d_fogmap; 183 ShadeType *shademap; 184 185 //! A list of tiles that are completely obscured. 186 std::list<Vector<int> > completely_obscured; 187 }; 188 189 #endif 190 191 // End of file 192