Adonthell
0.4
|
00001 /* 00002 $Id: landmap.h,v 1.26 2003/02/23 23:14:34 ksterker Exp $ 00003 00004 Copyright (C) 1999/2000/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 /** 00018 * @file landmap.h 00019 * Declares the landmap class. 00020 */ 00021 00022 00023 00024 #ifndef LANDMAP_H_ 00025 #define LANDMAP_H_ 00026 00027 #include "mapobject.h" 00028 #include "mapcharacter.h" 00029 00030 /** 00031 * Subdirectory where maps are saved. 00032 */ 00033 #define MAPS_DIR "maps/" 00034 00035 class mapview; 00036 00037 /** 00038 * Map where the world takes place. 00039 * This class handles everything that is needed for map display. More 00040 * specifically, it includes: 00041 * @li submaps (i.e mapsquare_area), 00042 * @li mapobjects. 00043 * @li pointers to mapcharacters, 00044 * It can make a map and the characters that are on it "live", but isn't 00045 * designed for display. See the mapview class for that. 00046 * 00047 * This class is responsible for the storage of it's submaps and mapobjects, 00048 * but NOT mapcharacters. So be sure to delete () yourself your mapcharacters 00049 * when you don't need them anymore. 00050 * 00051 */ 00052 class landmap : public event_list 00053 { 00054 public: 00055 /** 00056 * Default constructor. 00057 * 00058 */ 00059 landmap (); 00060 00061 /** 00062 * Destructor. 00063 * 00064 */ 00065 ~landmap (); 00066 00067 /** 00068 * Cleanup the map. 00069 * Totally cleanup a map, that is deleting every 00070 * mapobject/mapcharacter/landsubmap it contains, and reset it to 00071 * a stable state (just like it has just been created). 00072 */ 00073 void clear (); 00074 00075 /** 00076 * @name Map information 00077 * 00078 */ 00079 //@{ 00080 00081 /** 00082 * Get the number of mapobjects that the map owns. 00083 * @return number of mapobjects the map contains. 00084 */ 00085 u_int16 nbr_of_mapobjects () const 00086 { 00087 return mobj.size (); 00088 } 00089 00090 /** 00091 * Get the number of landsubmaps that the map owns. 00092 * @return number of landsubmaps the map contains. 00093 */ 00094 u_int16 nbr_of_submaps () const 00095 { 00096 return submap.size (); 00097 } 00098 00099 /** 00100 * Get the number of mapcharacters that are on this map. 00101 * @return number of mapcharacters on this map. 00102 */ 00103 u_int16 nbr_of_mapcharacters () const 00104 { 00105 return mapchar.size (); 00106 } 00107 00108 /** 00109 * Get the filename of the map, i.e the file from which 00110 * it has been loaded (if any). 00111 * 00112 * 00113 * @return filename of the map. 00114 */ 00115 string filename () const 00116 { 00117 return filename_; 00118 } 00119 00120 //@} 00121 00122 00123 /** 00124 * @name Individual map elements manipulation 00125 * Using these methods should be avoided as long as possible. They 00126 * are here for completeness, but their use should be exceptionnal. 00127 * 00128 */ 00129 00130 //@{ 00131 00132 /** 00133 * Returns a pointer to a mapcharacter on this landmap. 00134 * 00135 * @param pos index of the mapcharacter to return. 00136 * 00137 * @return pointer to the \e pos mapcharacter. 00138 */ 00139 mapcharacter * get_mapcharacter (u_int16 pos) 00140 { 00141 return mapchar[pos]; 00142 } 00143 00144 /** 00145 * Returns a pointer to a mapobject belonging to this landmap. 00146 * 00147 * @param pos index of the mapobject to return. 00148 * 00149 * @return pointer to the \e pos mapobject. 00150 */ 00151 mapobject * get_mapobject (u_int16 pos) 00152 { 00153 return mobj[pos]; 00154 } 00155 00156 /** 00157 * Returns a pointer to a submap belonging to this landmap. 00158 * 00159 * @param pos index of the submap to return. 00160 * 00161 * @return pointer to the \e pos submap. 00162 */ 00163 mapsquare_area * get_submap (u_int16 pos) 00164 { 00165 return submap[pos]; 00166 } 00167 00168 //@} 00169 00170 00171 /** 00172 * @name State updating 00173 * 00174 */ 00175 00176 //@{ 00177 00178 /** 00179 * Update the entire map (mapcharacters, mapobjects, etc... of 1 cycle. 00180 * 00181 */ 00182 void update (); 00183 00184 //@} 00185 00186 00187 /** 00188 * @name Loading/Saving methods. 00189 * 00190 */ 00191 00192 //@{ 00193 00194 /** 00195 * Load a map from an opened file. 00196 * 00197 * @param file the file from which to load. 00198 * 00199 * @return 00200 * @li 0 in case of success. 00201 * @li -1 in case of failure. 00202 */ 00203 s_int8 get (igzstream& file); 00204 00205 /** 00206 * Load a map from a filename. 00207 * 00208 * @param fname the filename from which to load. 00209 * 00210 * @return 00211 * @li 0 in case of success. 00212 * @li -1 in case of failure. 00213 */ 00214 s_int8 load (string fname); 00215 00216 /** 00217 * Put a map into an opened file. 00218 * 00219 * @param file the file where to save. 00220 * 00221 * @return 00222 * @li 0 in case of success. 00223 * @li -1 in case of failure. 00224 */ 00225 s_int8 put (ogzstream& file) const; 00226 00227 /** 00228 * Save a map into a file. 00229 * 00230 * @param fname the filename where to save. 00231 * 00232 * @return 00233 * @li 0 in case of success. 00234 * @li -1 in case of failure. 00235 */ 00236 s_int8 save (string fname); 00237 00238 //@} 00239 00240 00241 /** 00242 * @name State loading/saving methods. 00243 * 00244 */ 00245 00246 //@{ 00247 00248 /** 00249 * Restore the landmap's state from an opened file. 00250 * 00251 * @param file the opened file from which to load the state. 00252 * 00253 * @return 0 in case of success, error code otherwise. 00254 */ 00255 s_int8 get_state (igzstream& file); 00256 00257 /** 00258 * Saves the landmap's state into an opened file. 00259 * 00260 * @param file the opened file where to the state. 00261 * 00262 * @return 0 in case of success, error code otherwise. 00263 */ 00264 s_int8 put_state (ogzstream& file) const; 00265 00266 //@} 00267 00268 /** 00269 * @name Landmap modification 00270 * Although it should be very rare to modify a landmap 00271 * during gameplay, these methods are here to allow you 00272 * to safely to it. Be aware that they check if each element 00273 * is in a safe state, and modify them if necessary. Therefore, 00274 * they are quite slow and should be used in exceptionnal situations. 00275 * 00276 * Note however that put_mapobject () and remove_mapobject () should 00277 * be fast enough to allow real-time map modifications. But beware anyway. 00278 * 00279 */ 00280 00281 //@{ 00282 00283 00284 /** 00285 * Put a mapobject on the map. 00286 * 00287 * @param smap index of the submap to put the object on. 00288 * @param px X position to put the mapobject on 00289 * @param py Y position to put the mapobject on. 00290 * @param mobjnbr index of the mapobject to put. 00291 * 00292 * @return 00293 * @li 0 in case of success. 00294 * @li -1 in case of failure. 00295 */ 00296 s_int8 put_mapobject (u_int16 smap, u_int16 px, u_int16 py, 00297 u_int16 mobjnbr); 00298 00299 /** 00300 * Remove a mapobject from the map. 00301 * 00302 * @param smap index of the submap to remove the object on. 00303 * @param px X position of the mapobject. 00304 * @param py Y position of the mapobject. 00305 * @param mobjnbr index of the mapobject to remove. 00306 */ 00307 void remove_mapobject (u_int16 smap, u_int16 px, u_int16 py, 00308 u_int16 mobjnbr); 00309 00310 00311 /** 00312 * Inserts an empty landsubmap into the landmap. 00313 * 00314 * The landmap can then be accessed for resizing with 00315 * get_submap () 00316 * 00317 * @param pos the position where to insert the submap. 00318 * 00319 * @return 00320 * @li 0 in case of success. 00321 * @li -1 in case of error. 00322 * 00323 * @sa get_submap () 00324 */ 00325 s_int8 insert_submap (u_int16 pos); 00326 00327 /** 00328 * Remove a landsubmap from the landmap. 00329 * 00330 * @param pos the index of the submap to remove 00331 * 00332 * @return 00333 * @li 0 in case of success. 00334 * @li -1 in case of error. 00335 */ 00336 s_int8 delete_submap (u_int16 pos); 00337 00338 /** 00339 * Adds a mapobject to a landmap. 00340 * 00341 * @param an the mapobject to insert. 00342 * @param pos the position where to insert the mapobject. 00343 * @param srcfile the name of the file where the mapobject come from. 00344 * 00345 * @return 00346 * @li 0 in case of success. 00347 * @li -1 in case of error. 00348 */ 00349 s_int8 insert_mapobject (mapobject * an, u_int16 pos, 00350 string srcfile = ""); 00351 00352 /** 00353 * Delete a mapobject from a landmap. 00354 * 00355 * @param pos the index of the mapobject to delete. 00356 * 00357 * @return 00358 * @li 0 in case of success. 00359 * @li -1 in case of failure. 00360 */ 00361 s_int8 delete_mapobject (u_int16 pos); 00362 00363 //@} 00364 00365 private: 00366 /** 00367 * Forbids value passing. 00368 * 00369 */ 00370 landmap (const landmap& src); 00371 00372 #ifndef SWIG 00373 /** 00374 * Forbids landmap copy. 00375 * 00376 */ 00377 landmap & operator = (const landmap & src); 00378 #endif 00379 00380 string filename_; 00381 vector <mapcharacter *> mapchar; 00382 vector <mapobject *> mobj; 00383 vector <string> mobjsrc; 00384 vector <mapsquare_area *> submap; 00385 00386 #ifndef SWIG 00387 friend class mapcharacter; 00388 friend class mapview; 00389 #endif 00390 00391 }; 00392 00393 #endif