src/object/object_cfg.cpp

Go to the documentation of this file.
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  * Class containing object physic constants
00020  *****************************************************************************/
00021 
00022 //-----------------------------------------------------------------------------
00023 #include <cstring>
00024 #include <iostream>
00025 #include "object_cfg.h"
00026 #include "../game/config.h"
00027 #include "../include/base.h"
00028 #include "../tool/xml_document.h"
00029 //-----------------------------------------------------------------------------
00030 
00031 ObjectConfig::ObjectConfig()
00032 {
00033   m_rebounding = false;
00034   m_rebound_factor = 0.01;
00035   m_air_resist_factor = 1.0;
00036   m_wind_factor = 1.0;
00037   m_gravity_factor = 1.0;
00038   m_mass = 1.0;
00039 }
00040 
00041 ObjectConfig::~ObjectConfig()
00042 {
00043 }
00044 
00045 void ObjectConfig::LoadXml(const std::string& obj_name, const std::string &config_file)
00046 {
00047   std::string file;
00048   if(config_file=="")
00049     file = Config::GetInstance()->GetDataDir() + PATH_SEPARATOR + "game_mode" + PATH_SEPARATOR + "objects.xml";
00050   else
00051     file = config_file;
00052 
00053   // Load Xml configuration
00054   XmlReader doc;
00055   assert(doc.Load(file));
00056   xmlpp::Element* elem = XmlReader::GetMarker(doc.GetRoot(), obj_name);
00057 
00058   assert(elem != NULL);
00059   XmlReader::ReadDouble(elem, "mass", m_mass);
00060   XmlReader::ReadDouble(elem, "wind_factor", m_wind_factor);
00061   XmlReader::ReadDouble(elem, "air_resist_factor", m_air_resist_factor);
00062   XmlReader::ReadDouble(elem, "gravity_factor", m_gravity_factor);
00063   XmlReader::ReadDouble(elem, "rebound_factor", m_rebound_factor);
00064   XmlReader::ReadBool(elem, "rebounding", m_rebounding);
00065 }

Generated on Mon Jan 1 13:10:59 2007 for Wormux by  doxygen 1.4.7