Adonthell  0.4
mapsquare_walkable.cc
Go to the documentation of this file.
1 /*
2  $Id: mapsquare_walkable.cc,v 1.3 2002/09/28 17:21:50 ksterker 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  * @file mapsquare_walkable.cc
17  * @author Alexandre Courbot <alexandrecourbot@linuxgames.com>
18  *
19  * @brief Defines the mapsquare_walkable and mapsquare_walkable_area classes.
20  *
21  *
22  */
23 
24 #include "mapsquare_walkable.h"
25 
27 {
29 }
30 
32 {
33  walkable << file;
34  return 0;
35 }
36 
38 {
39  walkable >> file;
40  return 0;
41 }
42 
44 {
45  basex = 0;
46  basey = 0;
47 }
48 
50 {
51 }
52 
54 {
55  area.clear ();
56 
57  basex = 0;
58  basey = 0;
59 }
60 
62 {
63  vector <vector<mapsquare_walkable> >::iterator it;
64  vector <mapsquare_walkable>::iterator jt;
65  u_int16 t_length, t_height;
66  u_int16 basex_, basey_;
67 
68  // Get the area size.
69  t_length << file;
70  t_height << file;
71  resize_area (t_length, t_height);
72 
73  // Load the area.
74  for (it = area.begin (); it != area.end (); it++)
75  for (jt = it->begin (); jt < it->end (); jt++)
76  jt->get (file);
77 
78  // Load the base square information.
79  basex_ << file;
80  basey_ << file;
81  set_base (basex_, basey_);
82 
83  return 0;
84 }
85 
87 {
88  vector <vector<mapsquare_walkable> >::iterator it;
89  vector <mapsquare_walkable>::iterator jt;
90 
91  // Put the area size.
92  area_length () >> file;
93  area_height () >> file;
94 
95  // Save the area.
96  for (it = area.begin (); it != area.end (); it++)
97  for (jt = it->begin (); jt < it->end (); jt++)
98  jt->put (file);
99 
100  // Save the base square information.
101  base_x () >> file;
102  base_y () >> file;
103 
104  return 0;
105 }
106 
108 {
109  vector <vector<mapsquare_walkable> >::iterator i;
110 
111  area.resize (nl);
112  for (i = area.begin (); i != area.end (); i++)
113  i->resize (nh);
114 
115  set_length (nl * MAPSQUARE_SIZE);
116  set_height (nh * MAPSQUARE_SIZE);
117 }
118 
120 {
121  basex = nx;
122  basey = ny;
123 }
124 
126 {
127  u_int16 i, j;
128 
129  // Clear everything.
130  clear ();
131 
132  (drawable&) (*this) = (drawable&) src;
133 
134  // Copy the area.
135  resize_area (src.area_length (), src.area_height ());
136  for (i = 0; i < src.area_length (); i++)
137  for (j = 0; j < src.area_height (); j++)
138  area[i][j] = src.area[i][j];
139 
140  // Copy the base square information.
141  set_base (src.base_x (), src.base_y ());
142 
143  return *this;
144 }
Class to write data from a Gzip compressed file.
Definition: fileops.h:223
void resize_area(u_int16 nl, u_int16 nh)
Resize the area.
Class to read data from a Gzip compressed file.
Definition: fileops.h:131
s_int8 get(igzstream &file)
Loads a mapsquare_walkable from an opened file.
#define u_int16
16 bits long unsigned integer
Definition: types.h:32
~mapsquare_walkable_area()
Destructor.
u_int16 base_y() const
Returns the Y offset of the base square of this object.
Declares the mapsquare_walkable and mapsquare_walkable_area classes.
s_int8 put(ogzstream &file) const
Saves an area into an opened file.
mapsquare_walkable_area()
Default constructor.
u_int16 area_length() const
Returns the length of the area.
#define ALL_WALKABLE
Walkable from every side.
void clear()
Totally clears the area.
u_int16 base_x() const
Returns the X offset of the base square of this object.
void set_walkable(u_int8 w)
Sets the walkable parameter of a mapsquare.
const u_int16 MAPSQUARE_SIZE
Size of a mapsquare (in pixels).
mapsquare_walkable()
Default constructor.
Area of mapsquare_walkables, for use with mapcharacter and mapobject classes.
void set_base(u_int16 nx, u_int16 ny)
Sets the base square of this object.
s_int8 put(ogzstream &file) const
Puts a mapsquare_walkable into an opened file.
Abstract class for drawable objects manipulation.
Definition: drawable.h:55
s_int8 get(igzstream &file)
Loads an area from an opened file.
u_int16 area_height() const
Returns the height of the area.
void clear()
Cleanup the map.
Definition: landmap.cc:37
mapsquare_walkable_area & operator=(const mapsquare_walkable_area &mo)
Area copy (similar to copy ()).
#define s_int8
8 bits long signed integer
Definition: types.h:38