Adonthell
0.4
|
00001 /* 00002 $Id: mapsquare_walkable.h,v 1.1 2001/07/08 20:00:01 gnurou Exp $ 00003 00004 Copyright (C) 2001 Alexandre Courbot 00005 Part of the Adonthell Project http://adonthell.linuxgames.com 00006 00007 This program is free software; you can redistribute it and/or modify 00008 it under the terms of the GNU General Public License. 00009 This program is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY. 00011 00012 See the COPYING file for more details. 00013 */ 00014 00015 00016 /** 00017 * @file mapsquare_walkable.h 00018 * @author Alexandre Courbot <alexandrecourbot@linuxgames.com> 00019 * 00020 * @brief Declares the mapsquare_walkable and mapsquare_walkable_area classes. 00021 * 00022 * 00023 */ 00024 00025 00026 #ifndef MAPSQUARE_WALKABLE_H_ 00027 #define MAPSQUARE_WALKABLE_H_ 00028 00029 #include "fileops.h" 00030 #include "drawable.h" 00031 #include <vector> 00032 00033 00034 /** 00035 * Size of a mapsquare (in pixels). 00036 * 00037 */ 00038 const u_int16 MAPSQUARE_SIZE = 20; 00039 00040 /** 00041 * Walkable from every side. 00042 * 00043 */ 00044 #define ALL_WALKABLE 15 00045 00046 /** 00047 * Walkable from South. 00048 * 00049 */ 00050 #define WALKABLE_SOUTH 1 00051 00052 /** 00053 * Walkable from North. 00054 * 00055 */ 00056 #define WALKABLE_NORTH 2 00057 00058 /** 00059 * Walkable from East. 00060 * 00061 */ 00062 #define WALKABLE_EAST 4 00063 00064 /** 00065 * Walkable from West. 00066 * 00067 */ 00068 #define WALKABLE_WEST 8 00069 00070 /** 00071 * Unreachable. 00072 * 00073 */ 00074 #define NONE_WALKABLE 0 00075 00076 00077 00078 /** 00079 * Contains information about the walkability of a mapsquare. 00080 * 00081 */ 00082 class mapsquare_walkable 00083 { 00084 public: 00085 00086 /** 00087 * Default constructor. 00088 * 00089 */ 00090 mapsquare_walkable(); 00091 00092 /** 00093 * Loads a mapsquare_walkable from an opened file. 00094 * 00095 * @param file the file to load from. 00096 * 00097 * @return 0 in case of success, error code otherwise. 00098 */ 00099 s_int8 get (igzstream& file); 00100 00101 /** 00102 * Puts a mapsquare_walkable into an opened file. 00103 * 00104 * @param file the file where to save. 00105 * 00106 * @return 0 in case of success, error code otherwise. 00107 */ 00108 s_int8 put (ogzstream& file) const; 00109 00110 /** 00111 * Returns whether a mapsquare is walkable from west. 00112 * 00113 * 00114 * @return true if the mapsquare is walkable from west, false otherwise. 00115 */ 00116 bool is_walkable_west () const 00117 { 00118 return walkable & WALKABLE_WEST; 00119 } 00120 00121 /** 00122 * Returns whether a mapsquare is walkable from east. 00123 * 00124 * 00125 * @return true if the mapsquare is walkable from east, false otherwise. 00126 */ 00127 bool is_walkable_east () const 00128 { 00129 return walkable & WALKABLE_EAST; 00130 } 00131 00132 /** 00133 * Returns whether a mapsquare is walkable from north. 00134 * 00135 * 00136 * @return true if the mapsquare is walkable from north, false otherwise. 00137 */ 00138 bool is_walkable_north () const 00139 { 00140 return walkable & WALKABLE_NORTH; 00141 } 00142 00143 /** 00144 * Returns whether a mapsquare is walkable from south. 00145 * 00146 * 00147 * @return true if the mapsquare is walkable from south, false otherwise. 00148 */ 00149 bool is_walkable_south () const 00150 { 00151 return walkable & WALKABLE_SOUTH; 00152 } 00153 00154 /** 00155 * Sets the reachability from west of a mapsquare. 00156 * 00157 * @param w true if the mapsquare should be reachable from west, false otherwise. 00158 */ 00159 void set_walkable_west (bool w) 00160 { 00161 if (!w) 00162 walkable &= (ALL_WALKABLE - WALKABLE_WEST); 00163 else 00164 walkable |= WALKABLE_WEST; 00165 } 00166 00167 /** 00168 * Sets the reachability from east of a mapsquare. 00169 * 00170 * @param w true if the mapsquare should be reachable from east, false otherwise. 00171 */ 00172 void set_walkable_east (bool w) 00173 { 00174 if (!w) 00175 walkable &= (ALL_WALKABLE - WALKABLE_EAST); 00176 else 00177 walkable |= WALKABLE_EAST; 00178 } 00179 00180 /** 00181 * Sets the reachability from north of a mapsquare. 00182 * 00183 * @param w true if the mapsquare should be reachable from north, false otherwise. 00184 */ 00185 void set_walkable_north (bool w) 00186 { 00187 if (!w) 00188 walkable &= (ALL_WALKABLE - WALKABLE_NORTH); 00189 else 00190 walkable |= WALKABLE_NORTH; 00191 } 00192 00193 /** 00194 * Sets the reachability from south of a mapsquare. 00195 * 00196 * @param w true if the mapsquare should be reachable from south, false otherwise. 00197 */ 00198 void set_walkable_south (bool w) 00199 { 00200 if (!w) 00201 walkable &= (ALL_WALKABLE - WALKABLE_SOUTH); 00202 else 00203 walkable |= WALKABLE_SOUTH; 00204 } 00205 00206 /** 00207 * Gets the raw walkable parameter of a mapsquare. 00208 * 00209 * @return walkable parameter of this mapsquare. 00210 */ 00211 u_int8 get_walkable () const 00212 { 00213 return walkable; 00214 } 00215 00216 /** 00217 * Sets the walkable parameter of a mapsquare. 00218 * 00219 * @param w new walkable status. 00220 */ 00221 void set_walkable (u_int8 w) 00222 { 00223 walkable = w; 00224 } 00225 00226 private: 00227 u_int8 walkable; 00228 }; 00229 00230 00231 /** 00232 * Area of mapsquare_walkables, for use with mapcharacter and mapobject classes. 00233 * 00234 */ 00235 class mapsquare_walkable_area : public drawable 00236 { 00237 public: 00238 /** 00239 * Default constructor. 00240 * 00241 */ 00242 mapsquare_walkable_area (); 00243 00244 /** 00245 * Destructor. 00246 * 00247 */ 00248 ~mapsquare_walkable_area (); 00249 00250 /** 00251 * Totally clears the area. 00252 * 00253 */ 00254 void clear (); 00255 00256 virtual void draw (s_int16 x, s_int16 y, const drawing_area * da_opt = NULL, 00257 surface * target = NULL) const = 0; 00258 00259 /** 00260 * @name Area settings. 00261 * 00262 */ 00263 //@{ 00264 00265 /** 00266 * Returns the length of the area. 00267 * 00268 * @return length (in number of squares) of the area. 00269 * 00270 */ 00271 u_int16 area_length () const 00272 { 00273 return area.size (); 00274 } 00275 00276 /** 00277 * Returns the height of the area. 00278 * 00279 * @return height (in number of squares) of the area. 00280 * 00281 */ 00282 u_int16 area_height () const 00283 { 00284 if (area.size ()) return area[0].size (); 00285 else return 0; 00286 } 00287 00288 /** 00289 * Returns a pointer to a desired square. 00290 * 00291 * @param x X position of the square to get. 00292 * @param y Y position of the square to get. 00293 * 00294 * @return pointer to the (x,y) square. 00295 */ 00296 mapsquare_walkable * get_square (u_int16 x, u_int16 y) const 00297 { 00298 return &(area[x][y]); 00299 } 00300 00301 /** 00302 * Resize the area. 00303 * 00304 * @param nl new length (in number of squares) of the area. 00305 * @param nh new height (in number of squares) of the area. 00306 */ 00307 void resize_area (u_int16 nl, u_int16 nh); 00308 00309 //@} 00310 00311 00312 /** 00313 * @name Base square settings. 00314 * 00315 */ 00316 //@{ 00317 00318 /** 00319 * Returns the X offset of the base square of this object. 00320 * 00321 * 00322 * @return X offset of the base square. 00323 */ 00324 u_int16 base_x () const 00325 { 00326 return basex; 00327 } 00328 00329 /** 00330 * Returns the Y offset of the base square of this object. 00331 * 00332 * 00333 * @return Y offset of the base square. 00334 */ 00335 u_int16 base_y () const 00336 { 00337 return basey; 00338 } 00339 00340 /** 00341 * Sets the base square of this object. 00342 * 00343 * @param nx X offset of the new base square. 00344 * @param ny Y offset of the new base square. 00345 */ 00346 void set_base (u_int16 nx, u_int16 ny); 00347 00348 //@} 00349 00350 /** 00351 * Loads an area from an opened file. 00352 * @param file the opened file from which to load. 00353 * @return 0 in case of success, error code otherwise. 00354 * 00355 */ 00356 s_int8 get (igzstream & file); 00357 00358 /** 00359 * Saves an area into an opened file. 00360 * @param file the opened file where to write. 00361 * @return 0 in case of success, error code otherwise. 00362 * 00363 */ 00364 s_int8 put (ogzstream & file) const; 00365 00366 #ifndef SWIG 00367 /** 00368 * Area copy (similar to copy ()). 00369 * 00370 * @attention Not available from Python. Use copy () from Python instead. 00371 * @sa copy () 00372 */ 00373 mapsquare_walkable_area & operator = (const mapsquare_walkable_area & mo); 00374 #endif 00375 00376 /** 00377 * Synonym of operator = to guarantee its access from Python. 00378 * 00379 * @sa operator = 00380 */ 00381 void copy (const mapsquare_walkable_area& src) 00382 { 00383 *this = src; 00384 } 00385 00386 private: 00387 /** 00388 * Forbids value passing. 00389 * 00390 */ 00391 mapsquare_walkable_area (const mapsquare_walkable_area & src); 00392 00393 mutable vector <vector<mapsquare_walkable> > area; 00394 00395 u_int16 basex; 00396 u_int16 basey; 00397 }; 00398 00399 #endif