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