00001 /****************************************************************************** 00002 * Wormux is a convivial mass murder game. 00003 * Copyright (C) 2001-2004 Lawrence Azzoug. 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License as published by 00007 * the Free Software Foundation; either version 2 of the License, or 00008 * (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program; if not, write to the Free Software 00017 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 00018 ****************************************************************************** 00019 * Maps List 00020 *****************************************************************************/ 00021 00022 #ifndef LST_TERRAINS_H 00023 #define LST_TERRAINS_H 00024 #include <SDL.h> 00025 #include <string> 00026 #include <map> 00027 #include "../graphic/surface.h" 00028 #include "../include/base.h" 00029 #include "../tool/resource_manager.h" 00030 #include "../tool/xml_document.h" 00031 00032 class InfoMap{ 00033 00034 private: 00035 std::string name; 00036 std::string author_info; 00037 Surface img_ground, img_sky; 00038 Surface preview; 00039 00040 uint nb_mine; 00041 uint nb_barrel; 00042 00043 bool is_opened; 00044 bool use_water; 00045 bool is_data_loaded; 00046 00047 Profile *res_profile; 00048 00049 bool ProcessXmlData(xmlpp::Element *xml); 00050 void LoadData(); 00051 00052 public: 00053 std::string m_directory; 00054 struct s_wind 00055 { 00056 uint nb_sprite; 00057 uint default_nb_sprite; 00058 bool need_flip; //do we need to flip the sprite when it changes direction? 00059 } wind; 00060 00061 public: 00062 InfoMap (); 00063 bool Init(const std::string &nom, const std::string &repertoire); 00064 void FreeData(); 00065 00066 const std::string& ReadName() const { return name; } 00067 const std::string& ReadAuthorInfo() const { return author_info; } 00068 00069 Surface ReadImgGround(); 00070 Surface ReadImgSky(); 00071 const Surface& ReadPreview() const { return preview; } 00072 00073 uint GetNbBarrel() const { return nb_barrel; } 00074 uint GetNbMine() const { return nb_mine; } 00075 const Profile * const ResProfile() const { return res_profile; } 00076 00077 bool IsOpened() const { return is_opened; } 00078 bool UseWater() const { return use_water; } 00079 00080 }; 00081 00082 00083 class MapsList 00084 { 00085 public: 00086 std::vector<InfoMap> lst; 00087 typedef std::vector<InfoMap>::iterator iterator; 00088 00089 private: 00090 int terrain_actif; 00091 bool m_init; 00092 static MapsList * singleton; 00093 00094 void LoadOneMap (const std::string &dir, const std::string &file); 00095 MapsList(); 00096 00097 public: 00098 static MapsList * GetInstance(); 00099 00100 // Return -1 if fails 00101 int FindMapById (const std::string &id); 00102 void SelectMapByName (const std::string &nom); 00103 void SelectMapByIndex (uint index); 00104 int GetActiveMapIndex (); 00105 InfoMap& ActiveMap(); 00106 }; 00107 00108 InfoMap& ActiveMap(); 00109 00110 bool compareMaps(const InfoMap& a, const InfoMap& b) ; 00111 00112 #endif