Adonthell  0.4
mapobject.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 1999/2000/2001 Alexandre Courbot
3  Part of the Adonthell Project <http://adonthell.nongnu.org>
4 
5  Adonthell is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  Adonthell is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with Adonthell. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 
20 /**
21  * @file mapobject.h
22  *
23  * @author Alexandre Courbot <alexandrecourbot@linuxgames.com>
24  * @brief Declares the mapobject class.
25  */
26 
27 
28 #ifndef _MAPOBJECT_H
29 #define _MAPOBJECT_H
30 
31 #include "animation.h"
32 #include "mapsquare_walkable.h"
33 
34 
35 /// Where the mapobjects resides in the data tree.
36 #define MAPOBJECTS_DIR "gfx/mapobjects/"
37 
38 
39 
40 /**
41  * Objects that can be placed on a landmap.
42  *
43  * A mapobject is basically a set of animations. Each animation can be freely
44  * placed on a resizeable grid which represents the actual land where the
45  * object will be placed. This grid also has information about the walkability
46  * of it's squares, which will be repercuted on the landmap as soon as the
47  * object is placed.
48  *
49  */
51 {
52 public:
53 
54  /**
55  * Default constructor.
56  *
57  */
58  mapobject ();
59 
60  /**
61  * Destructor.
62  *
63  */
64  ~mapobject ();
65 
66  /**
67  * Resets the mapobject to its post-constructor state.
68  *
69  */
70  void clear ();
71 
72  /**
73  * @name State updating.
74  *
75  */
76  //@{
77 
78  /**
79  * Updates the mapobject's state.
80  *
81  */
82  bool update ();
83 
84  //@}
85 
86 
87  /**
88  * @name Drawing methods.
89  *
90  */
91  //@{
92 
93  void draw (s_int16 x, s_int16 y, const drawing_area * da_opt = NULL, surface * target = NULL) const;
94 
95  /**
96  * Similar to draw (), but assume the x and y parameters are where the base
97  * square should appear.
98  *
99  * @param x X position where to draw.
100  * @param y Y position where to draw.
101  * @param da_opt optional drawing_area to use during the drawing operation.
102  * @param target pointer to the surface where to draw the drawable. If NULL, draw on the screen.
103  */
104  void draw_from_base (s_int16 x, s_int16 y, const drawing_area * da_opt = NULL,
105  surface * target = NULL) const;
106 
107 
108  //@}
109 
110 
111 
112  /**
113  * @name Loading/saving methods.
114  *
115  * @note You can't save a mapobject with this class.
116  *
117  */
118  //@{
119 
120  /**
121  * Loads a mapobject from an opened file.
122  * @param file the opened file from which to load.
123  * @return 0 in case of success, error code otherwise.
124  *
125  */
126  s_int8 get (igzstream & file);
127 
128  /**
129  * Loads a mapobject from it's filename.
130  *
131  * @param fname the name of the file to load.
132  *
133  * @return 0 in case of success, error code otherwise.
134  */
135  s_int8 load (string fname);
136 
137  /** Saves an mapobject into an opened file, in %game format, with
138  * alpha and mask values.
139  * @warning as the mapobject which is saved comes from a %screen's depth
140  * surface, it will be slightly altered during the save.
141  * If you want a class capable of saving mapobjects with full
142  * truecolor quality, use mapobject_edit instead.
143  * @param file opened file where to save into.
144  * @return
145  * @li 0 in case of success.
146  * @li -1 in case of error.
147  * @sa save ()
148  */
149  s_int8 put (ogzstream& file) const;
150 
151  /** Saves an mapobject into an file, in %game format, with
152  * alpha and mask values.
153  * @warning as the mapobject which is saved comes from a %screen's depth
154  * surface, it will be slightly altered during the save.
155  * If you want a class capable of saving mapobjects with full
156  * truecolor quality, use mapobject_edit instead.
157  * @param fname file name where to save into.
158  * @return
159  * @li 0 in case of success.
160  * @li -1 in case of error.
161  * @sa put ()
162  */
163  s_int8 save (string fname) const;
164 
165  //@}
166 
167 
168 
169  /**
170  * @name Individual animations manipulation.
171  *
172  */
173  //@{
174 
175  /**
176  * Returns the number of animations of this mapobject.
177  *
178  *
179  * @return the number of animations of this mapobject.
180  */
182  {
183  return anim.size ();
184  }
185 
186  /**
187  * Returns a pointer to one of the mapobject's animations.
188  *
189  * @param nbr index of the animation to get.
190  *
191  * @return pointer to the nbr animation.
192  */
194  {
195  return anim[nbr];
196  }
197 
198  /**
199  * Inserts an animation at a given position of the animations array.
200  *
201  * The mapobject will be responsible for freeing the inserted animation.
202  *
203  * @param an pointer to the animation to add.
204  * @param pos index where to add the animation.
205  *
206  * @return 0 in case of success, error code otherwise.
207  */
209 
210 
211  /**
212  * Removes an animation at a given position.
213  * The animation itself will also be deleted ().
214  *
215  * @param pos The index of the animation to remove.
216  *
217  * @return 0 in case of success, error code otherwise.
218  */
220 
221  //@}
222 
223 
224 #ifndef SWIG
225  /**
226  * Mapobject copy (similar to copy ()).
227  *
228  * @attention Not available from Python. Use copy () from Python instead.
229  * @sa copy ()
230  */
231  mapobject & operator = (const mapobject & mo);
232 #endif
233 
234  /**
235  * Synonym of operator = to guarantee its access from Python.
236  *
237  * @sa operator =
238  */
239  void copy (const mapobject& src)
240  {
241  *this = src;
242  }
243 
244 private:
245 
246  /**
247  * Forbid value passing.
248  *
249  */
250  mapobject (mapobject &src);
251 
252  mutable vector <animation *> anim;
253 };
254 
255 #endif
void draw(s_int16 x, s_int16 y, const drawing_area *da_opt=NULL, surface *target=NULL) const
Draw the object on the screen.
Definition: mapobject.cc:67
Class to write data from a Gzip compressed file.
Definition: fileops.h:227
Class to read data from a Gzip compressed file.
Definition: fileops.h:135
Declares the animationframe and animation classes.
#define u_int16
16 bits long unsigned integer
Definition: types.h:38
s_int8 load(string fname)
Loads a mapobject from it&#39;s filename.
Definition: mapobject.cc:107
Class where drawables can actually be drawn to.
Definition: surface.h:85
u_int16 nbr_of_animations() const
Returns the number of animations of this mapobject.
Definition: mapobject.h:181
~mapobject()
Destructor.
Definition: mapobject.cc:42
Declares the mapsquare_walkable and mapsquare_walkable_area classes.
s_int8 insert_animation(animation *an, u_int16 pos)
Inserts an animation at a given position of the animations array.
Definition: mapobject.cc:159
Implements "drawing zones" for drawing operations.
Definition: drawing_area.h:54
s_int8 delete_animation(u_int16 pos)
Removes an animation at a given position.
Definition: mapobject.cc:172
#define s_int16
16 bits long signed integer
Definition: types.h:47
void copy(const mapobject &src)
Synonym of operator = to guarantee its access from Python.
Definition: mapobject.h:239
void draw_from_base(s_int16 x, s_int16 y, const drawing_area *da_opt=NULL, surface *target=NULL) const
Similar to draw (), but assume the x and y parameters are where the base square should appear...
Definition: mapobject.cc:75
mapobject & operator=(const mapobject &mo)
Mapobject copy (similar to copy ()).
Definition: mapobject.cc:185
animation * get_animation(u_int16 nbr)
Returns a pointer to one of the mapobject&#39;s animations.
Definition: mapobject.h:193
Area of mapsquare_walkables, for use with mapcharacter and mapobject classes.
mapobject()
Default constructor.
Definition: mapobject.cc:37
bool update()
Updates the mapobject&#39;s state.
Definition: mapobject.cc:57
Class that handles animated elements, their update and their playback.
Definition: animation.h:312
s_int8 save(string fname) const
Saves an mapobject into an file, in game format, with alpha and mask values.
Definition: mapobject.cc:142
#define s_int8
8 bits long signed integer
Definition: types.h:44
Objects that can be placed on a landmap.
Definition: mapobject.h:50
s_int8 put(ogzstream &file) const
Saves an mapobject into an opened file, in game format, with alpha and mask values.
Definition: mapobject.cc:124
void clear()
Resets the mapobject to its post-constructor state.
Definition: mapobject.cc:47