• Main Page
  • Related Pages
  • Classes
  • Files
  • File List
  • File Members

mapobject.h

Go to the documentation of this file.
00001 /*
00002    $Id: mapobject.h,v 1.13 2001/07/28 20:34:49 gnurou 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  * @file mapobject.h
00018  *
00019  * @author Alexandre Courbot <alexandrecourbot@linuxgames.com>
00020  * @brief Declares the mapobject class.
00021  */
00022 
00023 
00024 #ifndef _MAPOBJECT_H
00025 #define _MAPOBJECT_H
00026 
00027 #include "animation.h"
00028 #include "mapsquare_walkable.h"
00029 
00030 
00031 /// Where the mapobjects resides in the data tree.
00032 #define MAPOBJECTS_DIR "gfx/mapobjects/"
00033 
00034 
00035 
00036 /**
00037  * Objects that can be placed on a landmap.
00038  *
00039  * A mapobject is basically a set of animations. Each animation can be freely
00040  * placed on a resizeable grid which represents the actual land where the
00041  * object will be placed. This grid also has information about the walkability
00042  * of it's squares, which will be repercuted on the landmap as soon as the
00043  * object is placed.
00044  * 
00045  */ 
00046 class mapobject : public mapsquare_walkable_area
00047 {
00048 public:
00049 
00050     /**
00051      * Default constructor.
00052      * 
00053      */
00054     mapobject ();
00055 
00056     /**
00057      * Destructor.
00058      * 
00059      */ 
00060     ~mapobject ();
00061 
00062     /**
00063      * Resets the mapobject to its post-constructor state.
00064      * 
00065      */ 
00066     void clear ();      
00067  
00068     /**
00069      * @name State updating.
00070      * 
00071      */ 
00072     //@{ 
00073          
00074     /** 
00075      * Updates the mapobject's state.
00076      * 
00077      */
00078     bool update ();
00079 
00080     //@}
00081 
00082       
00083     /**
00084      * @name Drawing methods.
00085      * 
00086      */ 
00087     //@{ 
00088     
00089     void draw (s_int16 x, s_int16 y, const drawing_area * da_opt = NULL, surface * target = NULL) const;
00090 
00091     /** 
00092      * Similar to draw (), but assume the x and y parameters are where the base
00093      * square should appear.
00094      * 
00095      * @param x X position where to draw.
00096      * @param y Y position where to draw.
00097      * @param da_opt optional drawing_area to use during the drawing operation.
00098      * @param target pointer to the surface where to draw the drawable. If NULL, draw on the screen.
00099      */
00100     void draw_from_base (s_int16 x, s_int16 y, const drawing_area * da_opt = NULL,
00101                          surface * target = NULL) const; 
00102 
00103 
00104     //@}
00105 
00106 
00107  
00108     /**
00109      * @name Loading/saving methods.
00110      *
00111      * @note You can't save a mapobject with this class.
00112      * 
00113      */ 
00114     //@{ 
00115      
00116     /**
00117      * Loads a mapobject from an opened file.
00118      * @param file the opened file from which to load.
00119      * @return 0 in case of success, error code otherwise.
00120      *
00121      */ 
00122     s_int8 get (igzstream & file);
00123 
00124     /** 
00125      * Loads a mapobject from it's filename.
00126      * 
00127      * @param fname the name of the file to load.
00128      * 
00129      * @return 0 in case of success, error code otherwise.
00130      */
00131     s_int8 load (string fname);
00132 
00133     /** Saves an mapobject into an opened file, in %game format, with
00134      *  alpha and mask values. 
00135      *  @warning as the mapobject which is saved comes from a %screen's depth
00136      *           surface, it will be slightly altered during the save.
00137      *           If you want a class capable of saving mapobjects with full
00138      *           truecolor quality, use mapobject_edit instead.
00139      *  @param file opened file where to save into.
00140      *  @return
00141      *      @li 0 in case of success.
00142      *      @li -1 in case of error.
00143      *  @sa save ()
00144      */
00145     s_int8 put (ogzstream& file) const;
00146 
00147     /** Saves an mapobject into an file, in %game format, with
00148      *  alpha and mask values.
00149      *  @warning as the mapobject which is saved comes from a %screen's depth
00150      *           surface, it will be slightly altered during the save.
00151      *           If you want a class capable of saving mapobjects with full
00152      *           truecolor quality, use mapobject_edit instead.
00153      *  @param fname file name where to save into.
00154      *  @return
00155      *      @li 0 in case of success.
00156      *      @li -1 in case of error.
00157      *  @sa put ()
00158      */
00159     s_int8 save (string fname) const;
00160 
00161     //@}
00162 
00163 
00164      
00165     /**
00166      * @name Individual animations manipulation.
00167      * 
00168      */ 
00169     //@{ 
00170     
00171     /** 
00172      * Returns the number of animations of this mapobject.
00173      * 
00174      * 
00175      * @return the number of animations of this mapobject.
00176      */
00177     u_int16 nbr_of_animations () const
00178     {
00179         return anim.size ();
00180     }
00181     
00182     /** 
00183      * Returns a pointer to one of the mapobject's animations.
00184      * 
00185      * @param nbr index of the animation to get.
00186      * 
00187      * @return pointer to the nbr animation.
00188      */
00189     animation *get_animation (u_int16 nbr)
00190     {
00191         return anim[nbr];
00192     }
00193     
00194     /** 
00195      * Inserts an animation at a given position of the animations array.
00196      * 
00197      * The mapobject will be responsible for freeing the inserted animation.
00198      *
00199      * @param an pointer to the animation to add.
00200      * @param pos index where to add the animation.
00201      * 
00202      * @return 0 in case of success, error code otherwise.
00203      */
00204     s_int8 insert_animation (animation * an, u_int16 pos);
00205 
00206     
00207     /** 
00208      * Removes an animation at a given position.
00209      * The animation itself will also be deleted ().
00210      *
00211      * @param pos The index of the animation to remove.
00212      * 
00213      * @return 0 in case of success, error code otherwise.
00214      */
00215     s_int8 delete_animation (u_int16 pos);
00216     
00217     //@}
00218     
00219     
00220 #ifndef SWIG
00221     /**
00222      * Mapobject copy (similar to copy ()).
00223      *
00224      * @attention Not available from Python. Use copy () from Python instead.
00225      * @sa copy ()
00226      */ 
00227     mapobject & operator = (const mapobject & mo);
00228 #endif
00229 
00230     /**
00231      * Synonym of operator = to guarantee its access from Python.
00232      *
00233      * @sa operator = 
00234      */
00235     void copy (const mapobject& src) 
00236     {
00237         *this = src; 
00238     }
00239 
00240 private:
00241 
00242     /**
00243      * Forbid value passing.
00244      * 
00245      */ 
00246     mapobject (mapobject &src); 
00247 
00248     mutable vector <animation *> anim;
00249 };
00250 
00251 #endif

Generated on Mon Sep 12 2011 for Adonthell by  doxygen 1.7.1