00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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
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 }