Main Page | Class List | File List | Class Members | Related Pages

map.h

00001 /***************************************************************************
00002                            map.h
00003                            -------------------
00004     begin                : 2004-04-16
00005     copyright            : (C) 2004-2005 by Michael Menne
00006     email                : menne@users.sourceforge.net
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  This program is free software; you can redistribute it and/or
00011  modify it under the terms of the GNU General Public License
00012  as published by the Free Software Foundation; either version 2
00013  of the License, or (at your option) any later version.
00014 
00015  This program is distributed in the hope that it will be useful,
00016  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  GNU General Public License for more details.
00019 
00020  You should have received a copy of the GNU General Public License
00021  along with this program; if not, write to the Free Software
00022  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00023  ***************************************************************************/
00024 
00025 #ifndef WDSMAP_H
00026 #define WDSMAP_H
00027 
00028 #include "global.h"
00029 #include "tile.h"
00030 #include "town.h"
00031 #include "dlgpath.h"
00032 #include "townarray.h"
00033 
00034 
00035 namespace WDS
00036 {
00037 
00038 typedef vector< vector<CTile> > MapArray;
00039 
00040 class CGLCanvas;
00041 
00049 class CMap
00050 {
00051 
00052 public:
00053     CMap();
00054     virtual ~CMap();
00055 
00056     bool Load( const wxString& strTerrain, const wxString& strTowns );
00057     bool Update( const string strUpdate );
00058     void Clear();
00059 
00060     void Draw();
00061 
00062     bool    IsValidField( int x, int y );
00063     wxPoint GetFieldAtPoint( int x, int y );
00064     wxPoint GetPosFromField( int x, int y );
00065 
00066     int   GetWidth()  { return m_nMapWidth;  }
00067     int   GetHeigth() { return m_nMapHeigth; }
00068     Rect  GetBounds() { return m_rcBounds;   }
00069 
00070     CTown* GetTownAt( int x, int y );
00071 
00072     bool  FindPath( int sx, int sy, int ex, int ey );
00073 
00074     CTownArray& GetTownArray() { return m_aTowns; }
00075 
00076 protected:
00077     bool LoadTerrain( const wxString& strFile );
00078     bool LoadTowns( const wxString& strFile );
00079 
00080     bool LoadBuildings( ifstream &infile );
00081     bool LoadBorders( ifstream &infile );
00082     bool LoadUnits( ifstream &infile );
00083     bool LoadStreets( ifstream &infile );
00084     bool LoadTowns( ifstream &infile );
00085 
00086     bool  AStar( int sx, int sy, int ex, int ey );
00087     float Heuristic( int sx, int sy, int ex, int ey );
00088 
00089     CGLCanvas* GetGLCanvas();
00090 
00091     MapArray  m_aTiles;
00092     CTownArray m_aTowns;
00093 
00094     Rect m_rcBounds;
00095     CDlgPath *m_pDlgPath;
00096 
00097     // map size is: width x height fields
00098     int m_nMapWidth;
00099     int m_nMapHeigth;
00100 };
00101 
00102 class PathField
00103 {
00104 public:
00105     PathField( int x, int y, CTile *pTile )
00106     {
00107         this->x = x;
00108         this->y = y;
00109         this->pTile = pTile;
00110     }
00111 
00112     friend bool operator < (const PathField& f1, const PathField& f2 )
00113     {
00114         return f1.pTile->m_CostF < f2.pTile->m_CostF;
00115     }
00116 
00117     friend bool operator == (const PathField& f1, const PathField& f2 )
00118     {
00119         return f1.pTile->m_CostF == f2.pTile->m_CostF;
00120     }
00121 
00122     int x, y;
00123     CTile *pTile;
00124 };
00125 
00126 }
00127 
00128 #endif // WDSMAP_H
00129 // kate: space-indent off; tab-width 4; replace-tabs off;
00130 

Generated on Sun Jan 16 18:20:26 2005 for WDSMap by  doxygen 1.3.9.1