• Main Page
  • Related Pages
  • Classes
  • Files
  • File List
  • File Members

mapsquare_walkable.cc

Go to the documentation of this file.
00001 /*
00002    $Id: mapsquare_walkable.cc,v 1.3 2002/09/28 17:21:50 ksterker Exp $
00003 
00004    Copyright (C) 2001   Alexandre Courbot
00005    Part of the Adonthell Project http://adonthell.linuxgames.com
00006 
00007    This program is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License.
00009    This program is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY.
00011 
00012    See the COPYING file for more details.
00013 */
00014 
00015 /**
00016  * @file   mapsquare_walkable.cc
00017  * @author Alexandre Courbot <alexandrecourbot@linuxgames.com>
00018  * 
00019  * @brief  Defines the mapsquare_walkable and mapsquare_walkable_area classes.
00020  * 
00021  * 
00022  */
00023 
00024 #include "mapsquare_walkable.h"
00025 
00026 mapsquare_walkable::mapsquare_walkable () 
00027 {
00028     set_walkable (ALL_WALKABLE);
00029 }
00030 
00031 s_int8 mapsquare_walkable::get (igzstream& file) 
00032 {
00033     walkable << file;
00034     return 0; 
00035 }
00036 
00037 s_int8 mapsquare_walkable::put (ogzstream& file) const
00038 {
00039     walkable >> file;
00040     return 0; 
00041 }
00042 
00043 mapsquare_walkable_area::mapsquare_walkable_area ()
00044 {
00045     basex = 0;
00046     basey = 0;  
00047 }
00048 
00049 mapsquare_walkable_area::~mapsquare_walkable_area ()
00050 {
00051 }
00052 
00053 void mapsquare_walkable_area::clear ()
00054 {
00055     area.clear (); 
00056     
00057     basex = 0;
00058     basey = 0;  
00059 } 
00060 
00061 s_int8 mapsquare_walkable_area::get (igzstream& file)
00062 {
00063     vector <vector<mapsquare_walkable> >::iterator it;
00064     vector <mapsquare_walkable>::iterator jt;
00065     u_int16 t_length, t_height;
00066     u_int16 basex_, basey_; 
00067     
00068     // Get the area size.
00069     t_length << file;
00070     t_height << file; 
00071     resize_area (t_length, t_height); 
00072     
00073     // Load the area.
00074     for (it = area.begin (); it != area.end (); it++)
00075         for (jt = it->begin (); jt < it->end (); jt++)
00076             jt->get (file);
00077     
00078     // Load the base square information.
00079     basex_ << file;
00080     basey_ << file;  
00081     set_base (basex_, basey_); 
00082     
00083     return 0; 
00084 }
00085 
00086 s_int8 mapsquare_walkable_area::put (ogzstream& file) const
00087 {
00088     vector <vector<mapsquare_walkable> >::iterator it;
00089     vector <mapsquare_walkable>::iterator jt;
00090 
00091     // Put the area size.
00092     area_length () >> file;
00093     area_height () >> file; 
00094     
00095     // Save the area.
00096     for (it = area.begin (); it != area.end (); it++)
00097         for (jt = it->begin (); jt < it->end (); jt++)
00098             jt->put (file);
00099     
00100     // Save the base square information.
00101     base_x () >> file;
00102     base_y () >> file; 
00103     
00104     return 0; 
00105 }
00106  
00107 void mapsquare_walkable_area::resize_area (u_int16 nl, u_int16 nh)
00108 {
00109     vector <vector<mapsquare_walkable> >::iterator i;
00110 
00111     area.resize (nl);
00112     for (i = area.begin (); i !=  area.end (); i++)
00113         i->resize (nh);
00114     
00115     set_length (nl * MAPSQUARE_SIZE);
00116     set_height (nh * MAPSQUARE_SIZE); 
00117 }
00118 
00119 void mapsquare_walkable_area::set_base (u_int16 nx, u_int16 ny)
00120 {
00121     basex = nx;
00122     basey = ny; 
00123 } 
00124 
00125 mapsquare_walkable_area & mapsquare_walkable_area::operator = (const mapsquare_walkable_area & src)
00126 {
00127     u_int16 i, j;
00128     
00129     // Clear everything.
00130     clear (); 
00131     
00132     (drawable&) (*this) = (drawable&) src; 
00133 
00134     // Copy the area.
00135     resize_area (src.area_length (), src.area_height ()); 
00136     for (i = 0; i < src.area_length (); i++)
00137         for (j = 0; j < src.area_height (); j++)
00138             area[i][j] = src.area[i][j]; 
00139     
00140     // Copy the base square information.
00141     set_base (src.base_x (), src.base_y ());
00142     
00143     return *this; 
00144 }

Generated on Tue Jul 27 2010 for Adonthell by  doxygen 1.7.1