Adonthell
0.4
Main Page
Related Pages
Classes
Files
File List
File Members
mapsquare_walkable.h
Go to the documentation of this file.
1
/*
2
$Id: mapsquare_walkable.h,v 1.1 2001/07/08 20:00:01 gnurou Exp $
3
4
Copyright (C) 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
* @file mapsquare_walkable.h
18
* @author Alexandre Courbot <alexandrecourbot@linuxgames.com>
19
*
20
* @brief Declares the mapsquare_walkable and mapsquare_walkable_area classes.
21
*
22
*
23
*/
24
25
26
#ifndef MAPSQUARE_WALKABLE_H_
27
#define MAPSQUARE_WALKABLE_H_
28
29
#include "
fileops.h
"
30
#include "
drawable.h
"
31
#include <vector>
32
33
34
/**
35
* Size of a mapsquare (in pixels).
36
*
37
*/
38
const
u_int16
MAPSQUARE_SIZE
= 20;
39
40
/**
41
* Walkable from every side.
42
*
43
*/
44
#define ALL_WALKABLE 15
45
46
/**
47
* Walkable from South.
48
*
49
*/
50
#define WALKABLE_SOUTH 1
51
52
/**
53
* Walkable from North.
54
*
55
*/
56
#define WALKABLE_NORTH 2
57
58
/**
59
* Walkable from East.
60
*
61
*/
62
#define WALKABLE_EAST 4
63
64
/**
65
* Walkable from West.
66
*
67
*/
68
#define WALKABLE_WEST 8
69
70
/**
71
* Unreachable.
72
*
73
*/
74
#define NONE_WALKABLE 0
75
76
77
78
/**
79
* Contains information about the walkability of a mapsquare.
80
*
81
*/
82
class
mapsquare_walkable
83
{
84
public
:
85
86
/**
87
* Default constructor.
88
*
89
*/
90
mapsquare_walkable
();
91
92
/**
93
* Loads a mapsquare_walkable from an opened file.
94
*
95
* @param file the file to load from.
96
*
97
* @return 0 in case of success, error code otherwise.
98
*/
99
s_int8
get
(
igzstream
& file);
100
101
/**
102
* Puts a mapsquare_walkable into an opened file.
103
*
104
* @param file the file where to save.
105
*
106
* @return 0 in case of success, error code otherwise.
107
*/
108
s_int8
put
(
ogzstream
& file)
const
;
109
110
/**
111
* Returns whether a mapsquare is walkable from west.
112
*
113
*
114
* @return true if the mapsquare is walkable from west, false otherwise.
115
*/
116
bool
is_walkable_west
()
const
117
{
118
return
walkable &
WALKABLE_WEST
;
119
}
120
121
/**
122
* Returns whether a mapsquare is walkable from east.
123
*
124
*
125
* @return true if the mapsquare is walkable from east, false otherwise.
126
*/
127
bool
is_walkable_east
()
const
128
{
129
return
walkable &
WALKABLE_EAST
;
130
}
131
132
/**
133
* Returns whether a mapsquare is walkable from north.
134
*
135
*
136
* @return true if the mapsquare is walkable from north, false otherwise.
137
*/
138
bool
is_walkable_north
()
const
139
{
140
return
walkable &
WALKABLE_NORTH
;
141
}
142
143
/**
144
* Returns whether a mapsquare is walkable from south.
145
*
146
*
147
* @return true if the mapsquare is walkable from south, false otherwise.
148
*/
149
bool
is_walkable_south
()
const
150
{
151
return
walkable &
WALKABLE_SOUTH
;
152
}
153
154
/**
155
* Sets the reachability from west of a mapsquare.
156
*
157
* @param w true if the mapsquare should be reachable from west, false otherwise.
158
*/
159
void
set_walkable_west
(
bool
w)
160
{
161
if
(!w)
162
walkable &= (
ALL_WALKABLE
-
WALKABLE_WEST
);
163
else
164
walkable |=
WALKABLE_WEST
;
165
}
166
167
/**
168
* Sets the reachability from east of a mapsquare.
169
*
170
* @param w true if the mapsquare should be reachable from east, false otherwise.
171
*/
172
void
set_walkable_east
(
bool
w)
173
{
174
if
(!w)
175
walkable &= (
ALL_WALKABLE
-
WALKABLE_EAST
);
176
else
177
walkable |=
WALKABLE_EAST
;
178
}
179
180
/**
181
* Sets the reachability from north of a mapsquare.
182
*
183
* @param w true if the mapsquare should be reachable from north, false otherwise.
184
*/
185
void
set_walkable_north
(
bool
w)
186
{
187
if
(!w)
188
walkable &= (
ALL_WALKABLE
-
WALKABLE_NORTH
);
189
else
190
walkable |=
WALKABLE_NORTH
;
191
}
192
193
/**
194
* Sets the reachability from south of a mapsquare.
195
*
196
* @param w true if the mapsquare should be reachable from south, false otherwise.
197
*/
198
void
set_walkable_south
(
bool
w)
199
{
200
if
(!w)
201
walkable &= (
ALL_WALKABLE
-
WALKABLE_SOUTH
);
202
else
203
walkable |=
WALKABLE_SOUTH
;
204
}
205
206
/**
207
* Gets the raw walkable parameter of a mapsquare.
208
*
209
* @return walkable parameter of this mapsquare.
210
*/
211
u_int8
get_walkable
()
const
212
{
213
return
walkable;
214
}
215
216
/**
217
* Sets the walkable parameter of a mapsquare.
218
*
219
* @param w new walkable status.
220
*/
221
void
set_walkable
(
u_int8
w)
222
{
223
walkable = w;
224
}
225
226
private
:
227
u_int8
walkable;
228
};
229
230
231
/**
232
* Area of mapsquare_walkables, for use with mapcharacter and mapobject classes.
233
*
234
*/
235
class
mapsquare_walkable_area
:
public
drawable
236
{
237
public
:
238
/**
239
* Default constructor.
240
*
241
*/
242
mapsquare_walkable_area
();
243
244
/**
245
* Destructor.
246
*
247
*/
248
~mapsquare_walkable_area
();
249
250
/**
251
* Totally clears the area.
252
*
253
*/
254
void
clear
();
255
256
virtual
void
draw
(
s_int16
x,
s_int16
y,
const
drawing_area
* da_opt = NULL,
257
surface
* target = NULL)
const
= 0;
258
259
/**
260
* @name Area settings.
261
*
262
*/
263
//@{
264
265
/**
266
* Returns the length of the area.
267
*
268
* @return length (in number of squares) of the area.
269
*
270
*/
271
u_int16
area_length
()
const
272
{
273
return
area.size ();
274
}
275
276
/**
277
* Returns the height of the area.
278
*
279
* @return height (in number of squares) of the area.
280
*
281
*/
282
u_int16
area_height
()
const
283
{
284
if
(area.size ())
return
area[0].size ();
285
else
return
0;
286
}
287
288
/**
289
* Returns a pointer to a desired square.
290
*
291
* @param x X position of the square to get.
292
* @param y Y position of the square to get.
293
*
294
* @return pointer to the (x,y) square.
295
*/
296
mapsquare_walkable
*
get_square
(
u_int16
x,
u_int16
y)
const
297
{
298
return
&(area[x][y]);
299
}
300
301
/**
302
* Resize the area.
303
*
304
* @param nl new length (in number of squares) of the area.
305
* @param nh new height (in number of squares) of the area.
306
*/
307
void
resize_area
(
u_int16
nl,
u_int16
nh);
308
309
//@}
310
311
312
/**
313
* @name Base square settings.
314
*
315
*/
316
//@{
317
318
/**
319
* Returns the X offset of the base square of this object.
320
*
321
*
322
* @return X offset of the base square.
323
*/
324
u_int16
base_x
()
const
325
{
326
return
basex;
327
}
328
329
/**
330
* Returns the Y offset of the base square of this object.
331
*
332
*
333
* @return Y offset of the base square.
334
*/
335
u_int16
base_y
()
const
336
{
337
return
basey;
338
}
339
340
/**
341
* Sets the base square of this object.
342
*
343
* @param nx X offset of the new base square.
344
* @param ny Y offset of the new base square.
345
*/
346
void
set_base
(
u_int16
nx,
u_int16
ny);
347
348
//@}
349
350
/**
351
* Loads an area from an opened file.
352
* @param file the opened file from which to load.
353
* @return 0 in case of success, error code otherwise.
354
*
355
*/
356
s_int8
get
(
igzstream
& file);
357
358
/**
359
* Saves an area into an opened file.
360
* @param file the opened file where to write.
361
* @return 0 in case of success, error code otherwise.
362
*
363
*/
364
s_int8
put
(
ogzstream
& file)
const
;
365
366
#ifndef SWIG
367
/**
368
* Area copy (similar to copy ()).
369
*
370
* @attention Not available from Python. Use copy () from Python instead.
371
* @sa copy ()
372
*/
373
mapsquare_walkable_area
&
operator =
(
const
mapsquare_walkable_area
& mo);
374
#endif
375
376
/**
377
* Synonym of operator = to guarantee its access from Python.
378
*
379
* @sa operator =
380
*/
381
void
copy
(
const
mapsquare_walkable_area
& src)
382
{
383
*
this
= src;
384
}
385
386
private
:
387
/**
388
* Forbids value passing.
389
*
390
*/
391
mapsquare_walkable_area
(
const
mapsquare_walkable_area
& src);
392
393
mutable
vector <vector<mapsquare_walkable> > area;
394
395
u_int16
basex;
396
u_int16
basey;
397
};
398
399
#endif
src
mapsquare_walkable.h
Generated by
1.8.1.1