Adonthell
0.4
Main Page
Related Pages
Classes
Files
File List
File Members
landmap.h
Go to the documentation of this file.
1
/*
2
$Id: landmap.h,v 1.26 2003/02/23 23:14:34 ksterker Exp $
3
4
Copyright (C) 1999/2000/2001 Alexandre Courbot
5
Part of the Adonthell Project http://adonthell.linuxgames.com
6
7
This program is free software; you can redistribute it and/or modify
8
it under the terms of the GNU General Public License.
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY.
11
12
See the COPYING file for more details.
13
*/
14
15
16
17
/**
18
* @file landmap.h
19
* Declares the landmap class.
20
*/
21
22
23
24
#ifndef LANDMAP_H_
25
#define LANDMAP_H_
26
27
#include "
mapobject.h
"
28
#include "
mapcharacter.h
"
29
30
/**
31
* Subdirectory where maps are saved.
32
*/
33
#define MAPS_DIR "maps/"
34
35
class
mapview
;
36
37
/**
38
* Map where the world takes place.
39
* This class handles everything that is needed for map display. More
40
* specifically, it includes:
41
* @li submaps (i.e mapsquare_area),
42
* @li mapobjects.
43
* @li pointers to mapcharacters,
44
* It can make a map and the characters that are on it "live", but isn't
45
* designed for display. See the mapview class for that.
46
*
47
* This class is responsible for the storage of it's submaps and mapobjects,
48
* but NOT mapcharacters. So be sure to delete () yourself your mapcharacters
49
* when you don't need them anymore.
50
*
51
*/
52
class
landmap
:
public
event_list
53
{
54
public
:
55
/**
56
* Default constructor.
57
*
58
*/
59
landmap
();
60
61
/**
62
* Destructor.
63
*
64
*/
65
~landmap
();
66
67
/**
68
* Cleanup the map.
69
* Totally cleanup a map, that is deleting every
70
* mapobject/mapcharacter/landsubmap it contains, and reset it to
71
* a stable state (just like it has just been created).
72
*/
73
void
clear
();
74
75
/**
76
* @name Map information
77
*
78
*/
79
//@{
80
81
/**
82
* Get the number of mapobjects that the map owns.
83
* @return number of mapobjects the map contains.
84
*/
85
u_int16
nbr_of_mapobjects
()
const
86
{
87
return
mobj.size ();
88
}
89
90
/**
91
* Get the number of landsubmaps that the map owns.
92
* @return number of landsubmaps the map contains.
93
*/
94
u_int16
nbr_of_submaps
()
const
95
{
96
return
submap.size ();
97
}
98
99
/**
100
* Get the number of mapcharacters that are on this map.
101
* @return number of mapcharacters on this map.
102
*/
103
u_int16
nbr_of_mapcharacters
()
const
104
{
105
return
mapchar.size ();
106
}
107
108
/**
109
* Get the filename of the map, i.e the file from which
110
* it has been loaded (if any).
111
*
112
*
113
* @return filename of the map.
114
*/
115
string
filename
()
const
116
{
117
return
filename_;
118
}
119
120
//@}
121
122
123
/**
124
* @name Individual map elements manipulation
125
* Using these methods should be avoided as long as possible. They
126
* are here for completeness, but their use should be exceptionnal.
127
*
128
*/
129
130
//@{
131
132
/**
133
* Returns a pointer to a mapcharacter on this landmap.
134
*
135
* @param pos index of the mapcharacter to return.
136
*
137
* @return pointer to the \e pos mapcharacter.
138
*/
139
mapcharacter
*
get_mapcharacter
(
u_int16
pos)
140
{
141
return
mapchar[pos];
142
}
143
144
/**
145
* Returns a pointer to a mapobject belonging to this landmap.
146
*
147
* @param pos index of the mapobject to return.
148
*
149
* @return pointer to the \e pos mapobject.
150
*/
151
mapobject
*
get_mapobject
(
u_int16
pos)
152
{
153
return
mobj[pos];
154
}
155
156
/**
157
* Returns a pointer to a submap belonging to this landmap.
158
*
159
* @param pos index of the submap to return.
160
*
161
* @return pointer to the \e pos submap.
162
*/
163
mapsquare_area
*
get_submap
(
u_int16
pos)
164
{
165
return
submap[pos];
166
}
167
168
//@}
169
170
171
/**
172
* @name State updating
173
*
174
*/
175
176
//@{
177
178
/**
179
* Update the entire map (mapcharacters, mapobjects, etc... of 1 cycle.
180
*
181
*/
182
void
update
();
183
184
//@}
185
186
187
/**
188
* @name Loading/Saving methods.
189
*
190
*/
191
192
//@{
193
194
/**
195
* Load a map from an opened file.
196
*
197
* @param file the file from which to load.
198
*
199
* @return
200
* @li 0 in case of success.
201
* @li -1 in case of failure.
202
*/
203
s_int8
get
(
igzstream
& file);
204
205
/**
206
* Load a map from a filename.
207
*
208
* @param fname the filename from which to load.
209
*
210
* @return
211
* @li 0 in case of success.
212
* @li -1 in case of failure.
213
*/
214
s_int8
load
(
string
fname);
215
216
/**
217
* Put a map into an opened file.
218
*
219
* @param file the file where to save.
220
*
221
* @return
222
* @li 0 in case of success.
223
* @li -1 in case of failure.
224
*/
225
s_int8
put
(
ogzstream
& file)
const
;
226
227
/**
228
* Save a map into a file.
229
*
230
* @param fname the filename where to save.
231
*
232
* @return
233
* @li 0 in case of success.
234
* @li -1 in case of failure.
235
*/
236
s_int8
save
(
string
fname);
237
238
//@}
239
240
241
/**
242
* @name State loading/saving methods.
243
*
244
*/
245
246
//@{
247
248
/**
249
* Restore the landmap's state from an opened file.
250
*
251
* @param file the opened file from which to load the state.
252
*
253
* @return 0 in case of success, error code otherwise.
254
*/
255
s_int8
get_state
(
igzstream
& file);
256
257
/**
258
* Saves the landmap's state into an opened file.
259
*
260
* @param file the opened file where to the state.
261
*
262
* @return 0 in case of success, error code otherwise.
263
*/
264
s_int8
put_state
(
ogzstream
& file)
const
;
265
266
//@}
267
268
/**
269
* @name Landmap modification
270
* Although it should be very rare to modify a landmap
271
* during gameplay, these methods are here to allow you
272
* to safely to it. Be aware that they check if each element
273
* is in a safe state, and modify them if necessary. Therefore,
274
* they are quite slow and should be used in exceptionnal situations.
275
*
276
* Note however that put_mapobject () and remove_mapobject () should
277
* be fast enough to allow real-time map modifications. But beware anyway.
278
*
279
*/
280
281
//@{
282
283
284
/**
285
* Put a mapobject on the map.
286
*
287
* @param smap index of the submap to put the object on.
288
* @param px X position to put the mapobject on
289
* @param py Y position to put the mapobject on.
290
* @param mobjnbr index of the mapobject to put.
291
*
292
* @return
293
* @li 0 in case of success.
294
* @li -1 in case of failure.
295
*/
296
s_int8
put_mapobject
(
u_int16
smap,
u_int16
px,
u_int16
py,
297
u_int16
mobjnbr);
298
299
/**
300
* Remove a mapobject from the map.
301
*
302
* @param smap index of the submap to remove the object on.
303
* @param px X position of the mapobject.
304
* @param py Y position of the mapobject.
305
* @param mobjnbr index of the mapobject to remove.
306
*/
307
void
remove_mapobject
(
u_int16
smap,
u_int16
px,
u_int16
py,
308
u_int16
mobjnbr);
309
310
311
/**
312
* Inserts an empty landsubmap into the landmap.
313
*
314
* The landmap can then be accessed for resizing with
315
* get_submap ()
316
*
317
* @param pos the position where to insert the submap.
318
*
319
* @return
320
* @li 0 in case of success.
321
* @li -1 in case of error.
322
*
323
* @sa get_submap ()
324
*/
325
s_int8
insert_submap
(
u_int16
pos);
326
327
/**
328
* Remove a landsubmap from the landmap.
329
*
330
* @param pos the index of the submap to remove
331
*
332
* @return
333
* @li 0 in case of success.
334
* @li -1 in case of error.
335
*/
336
s_int8
delete_submap
(
u_int16
pos);
337
338
/**
339
* Adds a mapobject to a landmap.
340
*
341
* @param an the mapobject to insert.
342
* @param pos the position where to insert the mapobject.
343
* @param srcfile the name of the file where the mapobject come from.
344
*
345
* @return
346
* @li 0 in case of success.
347
* @li -1 in case of error.
348
*/
349
s_int8
insert_mapobject
(
mapobject
* an,
u_int16
pos,
350
string
srcfile =
""
);
351
352
/**
353
* Delete a mapobject from a landmap.
354
*
355
* @param pos the index of the mapobject to delete.
356
*
357
* @return
358
* @li 0 in case of success.
359
* @li -1 in case of failure.
360
*/
361
s_int8
delete_mapobject
(
u_int16
pos);
362
363
//@}
364
365
private
:
366
/**
367
* Forbids value passing.
368
*
369
*/
370
landmap
(
const
landmap
& src);
371
372
#ifndef SWIG
373
/**
374
* Forbids landmap copy.
375
*
376
*/
377
landmap
& operator = (
const
landmap
& src);
378
#endif
379
380
string
filename_;
381
vector <mapcharacter *> mapchar;
382
vector <mapobject *> mobj;
383
vector <string> mobjsrc;
384
vector <mapsquare_area *> submap;
385
386
#ifndef SWIG
387
friend
class
mapcharacter
;
388
friend
class
mapview
;
389
#endif
390
391
};
392
393
#endif
src
landmap.h
Generated by
1.8.3.1