Item::Item(const std::string& inputXml) { CMarkup xml; xml.SetDoc(inputXml); xml.FindElem(); xml.IntoElem(); while(xml.FindElem()) { std::string tag=xml.GetTagName(); if(tag=="itemtypename") itemtypename_=xml.GetData(); else if(tag=="itemtypeid") itemtypeid_=atoi(xml.GetData()); else if(tag=="number") number_=atoi(xml.GetData()); } }
//This method allow you to load the XML file std::vector<Stage*>* Stage::LoadFromXML(std::string path) { //creating object std::vector<Stage*>* stages = nullptr; //creating a vector of stage object CMarkup xml; //if cant load file return if (!xml.Load(path)) return stages; //it cant find element return stages if (!xml.FindElem("Stages")) return stages; stages = new std::vector<Stage*>(); //creating a vector of stages object xml.IntoElem(); //go up 1 level while (xml.FindElem("Stage")) //find stage { Stage* stage = new Stage(); stages->push_back(stage); //push each stage into vector of stage xml.IntoElem(); //go up 1 level if (xml.FindElem("Flag")) //find the flag { int x, y; xml.IntoElem(); //go up 1 level xml.FindElem("x"); //find x x = atoi(xml.GetData().c_str()); //assign x cord from xml into int xml.FindElem("y"); //find y y = atoi(xml.GetData().c_str()); //assign y cord from xml into int stage->flagPosition = new Vector2(x, y); //push x and y into vector for flag position xml.OutOfElem(); //go back 1 level } while (xml.FindElem("Block")) //find block and do the same as flag { Block* block; int x; int y; xml.IntoElem(); xml.FindElem("x"); x = atoi(xml.GetData().c_str()); xml.FindElem("y"); y = atoi(xml.GetData().c_str()); block = new Block(x, y); stage->Blocks->push_back(block); xml.OutOfElem(); } xml.OutOfElem(); } return stages; }
LootType::LootType(MCD_STR xmlstring) : ItemType(xmlstring), stackable_(true), no_quick_fencing_(false), cloth_(false) { CMarkup xml; xml.SetDoc(xmlstring); xml.FindElem(); xml.IntoElem(); while (xml.FindElem()) //Loop over all the elements inside the loottype element. { std::string element = xml.GetTagName(); if (element == "stackable") { int b = stringtobool(xml.GetData()); if (b == 1) stackable_ = true; else if (b == 0) stackable_ = false; /*else errorlog << "Invalid boolean value for loot type " << idname << "::stackable: " << xml.GetData() << std::endl;*/ } else if (element == "no_quick_fencing") { int b = stringtobool(xml.GetData()); if (b == 1) no_quick_fencing_ = true; else if (b == 0) no_quick_fencing_ = false; /*else errorlog << "Invalid boolean value for loot type " << idname << "::no_quick_fencing: " << xml.GetData() << std::endl;*/ } else if (element == "cloth") { int b = stringtobool(xml.GetData()); if (b == 1) cloth_ = true; else if (b == 0) cloth_ = false; /*else errorlog << "Invalid boolean value for loot type " << idname << "::cloth: " << xml.GetData() << std::endl;*/ } } }
Shop::ShopItem::ShopItem(MCD_STR xmlstring, bool only_sell_legal, bool increase_price_with_illegality) : price_(0), only_sell_legal_(only_sell_legal), increase_price_with_illegality_(increase_price_with_illegality), description_defined_(false) { CMarkup xml; xml.SetDoc(xmlstring); xml.FindElem(); xml.IntoElem(); while (xml.FindElem()) { std::string tag = xml.GetTagName(); if (tag == "class") { if (xml.GetData() == "WEAPON") itemclass_ = WEAPON; else if (xml.GetData() == "CLIP") itemclass_ = CLIP; else if (xml.GetData() == "ARMOR") itemclass_ = ARMOR; else if (xml.GetData() == "LOOT") itemclass_ = LOOT; } else if (tag == "type") itemtypename_ = xml.GetData(); else if (tag == "description") { description_ = xml.GetData(); description_defined_ = true; } else if (tag == "price") price_ = atoi(xml.GetData().c_str()); else if (tag == "sleeperprice") sleeperprice_ = atoi(xml.GetData().c_str()); else if (tag == "letter") { letter_ = xml.GetData()[0]; if (97 <= letter_ && letter_ <= 122) //Check it is a letter. letter_defined_ = true; else if (65 <= letter_ && letter_ <= 90) { letter_ += 32; letter_defined_ = true; } else if (letter_ == '!') //Allow special character. letter_defined_ = true; } } }
Vehicle::Vehicle(const char * inputXml) { CMarkup xml; xml.SetDoc (inputXml); xml.FindElem (); xml.IntoElem (); while (xml.FindElem ()) { std::string tag = xml.GetTagName (); if (tag == "vtypeidname") { vtypeidname_ = xml.GetData(); } else if (tag == "vtypeid") { vtypeid_ = atoi (xml.GetData().c_str()); } else if (tag == "color") { color_ = xml.GetData(); } else if (tag == "heat") { heat_ = atoi (xml.GetData().c_str()); } else if (tag == "location") { location_ = atoi (xml.GetData().c_str()); } else if (tag == "myear") { myear_ = atoi (xml.GetData().c_str()); } else if (tag == "id") { id_ = atoi (xml.GetData().c_str()); } } }
Weapon::Weapon(const char * inputXml) : Item(inputXml) { CMarkup xml; xml.SetDoc (inputXml); xml.FindElem (); xml.IntoElem (); while (xml.FindElem ()) { std::string tag = xml.GetTagName (); if (tag == "loaded_cliptype") loaded_cliptype_ = xml.GetData(); else if (tag == "ammo") ammo_ = atoi(xml.GetData().c_str()); } }
CString XMLSerialized::LoadInfo(const CString& sName,TagType tagType,const CString parent=L""){ CMarkup xml = OpenFile(); if(tagType== TagType::Element){ if(FindPath(sName,&xml)) return xml.GetData(); } if(tagType== TagType::Attribute){ if(FindPath(parent,&xml)) return xml.GetAttrib(sName); } return L""; }
ClipType::ClipType(MCD_STR xmlstring) : ItemType(xmlstring), ammo_(1) { CMarkup xml; xml.SetDoc(xmlstring); xml.FindElem(); xml.IntoElem(); while(xml.FindElem()) //Loop over all the elements inside the cliptype element. { std::string element=xml.GetTagName(); if(element=="ammo") ammo_=atoi(xml.GetData()); /*else errorlog << "Unknown element for clip type " << idname() << ": " << element << endl;*/ } }
Money::Money(const char * inputXml) : Item(inputXml) { CMarkup xml; xml.SetDoc (inputXml); xml.FindElem (); xml.IntoElem (); while (xml.FindElem ()) { std::string tag = xml.GetTagName (); if (tag == "amount") amount_ = atoi(xml.GetData().c_str()); } }
void db_leos::DownloadLyrics(window_config *wcfg, lyric_data* data) { data->Text = _T(""); tstring xmltext; if (!ReadInternetTextFromUrl(xmltext, _T("FOO_UIE_LYRICS2"), data->Source, wcfg->cfg_timeout, wcfg)) return ; tstring info_text; CMarkup xml; if (!xml.SetDoc(xmltext.c_str())) return ; if (xml.FindChildElem(_T("lyric"))) { xml.IntoElem(); if (xml.FindChildElem(_T("text"))) { xml.IntoElem(); info_text = xml.GetData(); xml.OutOfElem(); } xml.OutOfElem(); } data->Text = info_text; data->Text = ReplaceString(_T("\r"), _T(""), data->Text); data->Text = ReplaceString(_T("\n"), _T("\r\n"), data->Text); data->IsLoaded = true; if (data->Text.find(_T("[")) != tstring::npos) data->IsTimestamped = true; else data->IsTimestamped = false; }
bool ESDBXMLResponse::ParseXMLString(CString sXML, ESDBXMLRequestMan* pReqMan){ CMarkup xmlDoc; if( !xmlDoc.SetDoc(sXML) ) return false; if( !xmlDoc.FindElem() ) return false; StringToIntArray* pReqTypes = ESDBXMLRequest::GetRequestTypes(); RequestType reqType = (RequestType)pReqTypes->GetValue(xmlDoc.GetTagName()); if( reqType == RequestType::db_unknown ) return false; if( !xmlDoc.IntoElem() ) return false; // Fill params array. ###### if( m_pParams ) delete m_pParams; m_pParams = new StringToStringArray(); while( xmlDoc.FindElem() ){ m_pParams->Add(xmlDoc.GetTagName(), xmlDoc.GetData()); } // ######################### int nReqId = atoi(m_pParams->GetValue("req_id")); ESDBXMLRequest* req = pReqMan->GetRequestById(nReqId); if( req == NULL || req->GetResponse() != NULL ) return false; // Attach to request object. m_pRequest = req; req->SetType (reqType); req->SetResponse(this); return true; }
/** 调用此函数前需保证xml中已经通过FindElem()定位到当前元素。 */ void CXmlElement::Load(CMarkup& xml) { _name = xml.GetTagName(); CString attrib_name, attrib_value; int i = 0; while(xml.GetNthAttrib(i, attrib_name, attrib_value)) { _attributes.push_back(std::make_pair(attrib_name, attrib_value)); ++i; } _value = xml.GetData(); if (_value.IsEmpty()) { xml.IntoElem(); while (xml.FindElem()) { CXmlElement* element = new CXmlElement; element->Load(xml); _children.push_back(element); } xml.OutOfElem(); } }
bool populate_masks_from_xml(vector<ArmorType*>& masks,string file,Log& log) { CMarkup xml; if(!xml.Load(string(artdir)+file)) { //File is missing or not valid XML. addstr("Failed to load "+file+"!",log); getkey(); return false; //Abort. } xml.FindElem(); xml.IntoElem(); int defaultindex; if(xml.FindElem("default")) defaultindex=getarmortype(xml.GetData()); else { addstr("Default missing for masks!",log); getkey(); return false; //Abort. } if(defaultindex==-1) { addstr("Default for masks is not a known armor type!",log); getkey(); return false; //Abort. } xml.ResetMainPos(); while(xml.FindElem("masktype")) armortype.push_back(new ArmorType(*armortype[defaultindex],xml.GetSubDoc())); return true; }
int CMakeFrame::InitUserInfo(const char *info) { CMarkup xmlConfig; xmlConfig.SetDoc(info); xmlConfig.ResetPos(); xmlConfig.FindChildElem( "all" ); xmlConfig.IntoElem(); xmlConfig.FindElem( "head"); xmlConfig.IntoElem(); xmlConfig.FindElem( "afn" ); afn = atoi(xmlConfig.GetData().c_str()) % 256; if(afn == 0x04 || afn == 0x0c || 1) { xmlConfig.ResetPos(); xmlConfig.FindChildElem( "all" ); xmlConfig.IntoElem(); xmlConfig.FindElem( "body" ); xmlConfig.IntoElem(); xmlConfig.FindElem( "index" ); index = atoi(xmlConfig.GetData().c_str()); xmlConfig.FindElem("fn"); xmlConfig.IntoElem(); FnTotalNum = 0; while(xmlConfig.FindElem()){ FnTotalNum ++; } xmlConfig.ResetPos(); xmlConfig.FindChildElem( "all" ); xmlConfig.IntoElem(); xmlConfig.FindElem( "body" ); xmlConfig.IntoElem(); xmlConfig.FindElem("fn"); xmlConfig.IntoElem(); int j; for(j=0;j<FnTotalNum;j++) { xmlConfig.FindElem( "value" ); fnValue[j]= xmlConfig.GetData(); } xmlConfig.ResetPos(); xmlConfig.FindChildElem( "all" ); xmlConfig.IntoElem(); xmlConfig.FindElem( "body" ); xmlConfig.IntoElem(); xmlConfig.FindElem("pn"); xmlConfig.IntoElem(); PnTotalNum = 0; while(xmlConfig.FindElem()){ PnTotalNum ++; } xmlConfig.ResetPos(); xmlConfig.FindChildElem( "all" ); xmlConfig.IntoElem(); xmlConfig.FindElem( "body" ); xmlConfig.IntoElem(); xmlConfig.FindElem("pn"); xmlConfig.IntoElem(); for(j=0;j<PnTotalNum;j++) { xmlConfig.FindElem( "value" ); pnValue[j]= xmlConfig.GetData(); } } return 1; }
FicsCfgParser::FicsCfgParser( MCD_CSTR cfgName ) { m_nodeNum = 0; CMarkup xml; tstring strTmp; const u32 invalidNodeNo = -1; u32 curNode = invalidNodeNo, backupNode = invalidNodeNo; bool brTmp = false; if (!xml.Load(cfgName)) { VTRACE(_T("load ficsconfig xml[%s] failed \n"), cfgName); return; } if (xml.FindElem(_T("/fics/NodeServersInfo"))){ xml.IntoElem(); while (xml.FindElem(_T("OneNodeServer"))) { xml.IntoElem(); brTmp = xml.FindElem(_T("NodeSeq")); assert(brTmp); strTmp = xml.GetData(); curNode = MCD_TTOI(strTmp.c_str()); //½âÎöInternalIPs brTmp = xml.FindElem(_T("InternalIPs")); assert(brTmp); xml.IntoElem(); vector<u32> tmp; tmp.clear(); while (xml.FindElem(_T("IP"))) { strTmp = xml.GetData(); CStdString ipTmp = strTmp.c_str(); tmp.push_back(ConvertIPtoDWORD(ipTmp)); m_ipToNode[ConvertIPtoDWORD(ipTmp)] = curNode; } if (isLocalNodeIp(tmp)){ m_internalIpLocal.insert(m_internalIpLocal.end(), tmp.begin(), tmp.end()); }else { m_internalIpOther.insert(m_internalIpOther.end(), tmp.begin(), tmp.end()); } m_nodeToInternalIp[curNode] = tmp; xml.OutOfElem(); //½âÎöExternalIps brTmp = xml.FindElem(_T("ExternalIps")); assert(brTmp); xml.IntoElem(); tmp.clear(); while (xml.FindElem(_T("IP"))) { strTmp = xml.GetData(); CStdString ipTmp = strTmp.c_str(); tmp.push_back(ConvertIPtoDWORD(ipTmp)); m_ipToNode[ConvertIPtoDWORD(ipTmp)] = curNode; } if (isLocalNodeIp(tmp)){ m_externalIpLocal.insert(m_externalIpLocal.end(), tmp.begin(), tmp.end()); }else { m_externalIpOther.insert(m_externalIpOther.end(), tmp.begin(), tmp.end()); } m_nodeToExternalIp[curNode] = tmp; brTmp = xml.FindElem(_T("MdsBackNodeSeq")); if (brTmp){ strTmp = xml.GetData(); backupNode = MCD_TTOI(strTmp.c_str()); }else{ backupNode = invalidNodeNo; } m_nodeToBackup[curNode] = backupNode; xml.OutOfElem(); xml.OutOfElem(); } } if (xml.FindElem(_T("/fics/nodeStripPar"))) { xml.IntoElem(); strTmp = xmlNode.GetData(); m_nodeStripPar = atoi(strTmp); xml.OutOfElem(); } else { m_nodeStripPar = 2 * 1024 * 1024; } }
bool XMLSerialized::Deserialize(){ if(m_mapping.size()==0) return false; CMarkup * xml = new CMarkup(); if(!xml->Load(sFileName)){ delete xml; xml = NULL; return false; } std::map<int,DATA*>::const_iterator item; for(item= m_mapping.begin(); item != m_mapping.end(); item ++){ DATA* data = item->second; if(data->_tagType== TagType::Attribute){ if(FindPath(data->_parent,xml)){ xml->OutOfElem(); switch(data->_dataType){ case DataType::Int: (*(int*)data->_value) = _ttoi(xml->GetAttrib(data->_tagName)); break; case DataType::Bool: (*(bool*)data->_value) = (bool)_ttoi(xml->GetAttrib(data->_tagName)); break; case DataType::ByteArray: StringToByteArray(xml->GetAttrib(data->_tagName),L"|",(byte*)data->_value); break; case DataType::IntArray: StringToIntArray(xml->GetAttrib(data->_tagName),L"|",(int*)data->_value); break; case DataType::String: (*(CString*)data->_value) = (CString)(xml->GetAttrib(data->_tagName)); break; } } } if(data->_tagType== TagType::Element && data->_dataType!=DataType::None){ if(FindPath(data->_parent,xml)){ if(xml->FindElem(data->_tagName)){ switch(data->_dataType){ case DataType::Int: (*(int*)data->_value) = _ttoi(xml->GetData()); break; case DataType::Bool: (*(bool*)data->_value) = (bool)_ttoi(xml->GetData()); break; case DataType::ByteArray: StringToByteArray(xml->GetData(),L"|",(byte*)data->_value); break; case DataType::IntArray: StringToIntArray(xml->GetData(),L"|",(int*)data->_value); break; case DataType::String: (*(CString*)data->_value) = (CString)(xml->GetData()); break; } } } } } delete xml; xml = NULL; return true; }
int getIPfromXml(std::vector<nodeIp_t>& vecIpAddr) { CMarkup xml; const char *cfgConfig = "../config/FicsConfig.xml"; std::string strTmp; int ret = -1; char cmdBuf[256]; FILE *fp = NULL; char tmppath[256]={0}; int r=0; std::vector<string> pathList; vector<string>::iterator iter; vector<nodeIp_t>::iterator it; int nodeId; if (!FiIsExistFile(cfgConfig)) { // if ()//服务端不允许不存在 ut_err("file [%s] is not exist, try to auto generate\n", cfgConfig); //scan all FicsConfig.xml then connect all ip who is node[0-1]. #ifdef WIN32 sprintf(cmdBuf, "dir /s /b ..\\*FicsConfig.xml"); #else sprintf(cmdBuf, "find ../client/Config -name \'FicsConfig.xml\'"); #endif if (NULL == (fp = popen(cmdBuf, "r"))) { ut_err("popen error errno[%d]\n", errno); ret = -2; return ret; } do { r = fscanf(fp, "%[^\n]s", tmppath); fgetc(fp); if (r != EOF) { pathList.push_back(tmppath); } }while (r != EOF); pclose(fp); } else { pathList.push_back(cfgConfig); } for (iter = pathList.begin(); iter != pathList.end(); iter++) { if (!xml.Load(iter->c_str())) { ut_err("load ficsconfig xml[%s] failed\n", cfgConfig); return ret; } /*----------------------------------------------------------------------------- * parse extern IP from FicsConfig.xml *-----------------------------------------------------------------------------*/ if (xml.FindElem("fics")) { xml.IntoElem(); if (xml.FindElem("NodeServersInfo")) { xml.IntoElem(); while (xml.FindElem("OneNodeServer")) { xml.IntoElem(); if (xml.FindElem("NodeSeq")) { #ifdef WIN32 std::string nodeSeq; nodeSeq = xml.GetData(); nodeId = atoi(nodeSeq.c_str()); #else nodeId = atoi(xml.GetData().c_str()); #endif } xml.FindElem("ExternalIps"); xml.IntoElem(); while (xml.FindElem("IP")) { strTmp = xml.GetData(); unsigned long ip = inet_addr(strTmp.c_str()); bool exist = false; for (it = vecIpAddr.begin(); it != vecIpAddr.end(); it++) { if (it->ip == ip && it->nodeId == nodeId) { exist = true; break; } } if (exist == false) { nodeIp_t tmp; tmp.ip = ip; tmp.nodeId = nodeId; vecIpAddr.push_back(tmp); } } xml.OutOfElem(); xml.OutOfElem(); } } } } if (!vecIpAddr.empty()) { ret = 0; } return ret; }
BOOL CNetConfig::ReadXml() { CMarkup xml; tstring strTmp; if (!xml.Load(_T("finet.xml"))) { printf("load finet xml failed \n"); return FALSE; } if (xml.FindChildElem(_T("iocpnum"))) { xml.IntoElem(); strTmp = xml.GetData(); if (!strTmp.empty()) { #if (defined(_WIN32) || defined(_WIN64)) char tmp[64]; memset(tmp,0,64); UTF16ConvertANSI((WCHAR*)strTmp.c_str(), strTmp.length(), tmp, 64); m_iocp_num = atoi(tmp); #else m_iocp_num = atoi(strTmp.c_str()); #endif } xml.OutOfElem(); } if (xml.FindChildElem(_T("local"))) { xml.IntoElem(); CHostInfo hs; if (xml.FindChildElem(_T("host"))) { xml.IntoElem(); while (xml.FindChildElem(_T("ip"))) { xml.IntoElem(); strTmp = xml.GetData(); CStdString aa = strTmp.c_str(); CNetCard nc(ConvertIPtoDWORD(aa)); hs.AddCard(nc,FiGetPid()); xml.OutOfElem(); } xml.OutOfElem(); } CProcId cid = hs.m_mapProcId.begin()->second; hs.m_identify = cid.m_mapIp.begin()->first; m_LocalIp = hs; xml.OutOfElem(); } if (xml.FindChildElem(_T("remote"))) { xml.IntoElem(); while (xml.FindChildElem(_T("host"))) { CHostInfo *hs = new CHostInfo; xml.IntoElem(); while (xml.FindChildElem(_T("ip"))) { xml.IntoElem(); strTmp = xml.GetData(); CStdString bb = strTmp.c_str(); CNetCard nc(ConvertIPtoDWORD(bb)); hs->AddCard(nc, FiGetPid()); xml.OutOfElem(); /// all remote ip can be indexed by ip (ip to all ip (hostinfo class)) m_RemoteIp.insert(make_pair(nc.GetIp(),hs)); } xml.OutOfElem(); } xml.OutOfElem(); } return TRUE; }
VehicleType::VehicleType(MCD_STR xmlstring) : /*idname_("UNDEFINED"), id_(-1),*/ year_startcurrent_(true), year_start_(0), //Default values year_randomuptocurrent_(false), year_addrandom_(0), year_add_(0), displaycolor_(true), longname_("UNDEFINED"), shortname_("UNDEF"), steal_difficultytofind_(1), steal_juice_(0), steal_extraheat_(0), sensealarmchance_(0), touchalarmchance_(0), availableatshop_(true), price_(1234), sleeperprice_(1111), armormidpoint_(50), lowarmormin_(4), lowarmormax_(6), higharmormin_(0), higharmormax_(2), drivebonus_(0), drivebonus_factor_(1), drivebonus_limit1_(8), drivebonus_limit2_(99), dodgebonus_(0), dodgebonus_factor_(1), dodgebonus_limit1_(8), dodgebonus_limit2_(99), attackbonus_driver_(-2), attackbonus_passenger_(0) { id_ = number_of_vehicletypes++; CMarkup xmlfile; xmlfile.SetDoc(xmlstring); xmlfile.FindElem(); idname_ = xmlfile.GetAttrib("idname"); if (idname_ == "") idname_ = "LACKS IDNAME " + tostring(id_); xmlfile.IntoElem(); while(xmlfile.FindElem()) //Loop over all the elements inside the vehicletype element. { std::string element = xmlfile.GetTagName(); if (element == "year") { xmlfile.IntoElem(); while(xmlfile.FindElem()) { element = xmlfile.GetTagName(); if (element == "start_at_current_year") { int b = stringtobool(xmlfile.GetData()); if (b == 1) year_startcurrent_ = true; else if (b == 0) year_startcurrent_ = false; /*else std::cerr << "Invalid boolean value for vehicle type " << idname << "::year::start_at_current_year: " << xmlfile.GetData() << std::endl;*/ } else if (element == "start_at_year") year_start_ = atoi(xmlfile.GetData()); else if (element == "add_random_up_to_current_year") { int b = stringtobool(xmlfile.GetData()); if (b == 1) year_randomuptocurrent_ = true; else if (b == 0) year_randomuptocurrent_ = false; /*else std::cerr << "Invalid boolean value for vehicle type " << idname << "::year::add_random_up_to_current_year: " << xmlfile.GetData() << std::endl;*/ } else if (element == "add_random") year_addrandom_ = atoi(xmlfile.GetData()); else if (element == "add") year_add_ = atoi(xmlfile.GetData()); /*else std::cerr << "Unknown element for vehicle type " << idname << "::year: " << element << std::endl;*/ } xmlfile.OutOfElem(); } else if (element == "colors") { xmlfile.IntoElem(); //std::string color; while(xmlfile.FindElem()) { element = xmlfile.GetTagName(); if (element == "color") { color_.push_back(xmlfile.GetData()); } else if (element == "display_color") { int b = stringtobool(xmlfile.GetData()); if (b == 1) displaycolor_ = true; else if (b == 0) displaycolor_ = false; /*else std::cerr << "Invalid boolean value for vehicle type " << idname << "::colors::display_color: " << xmlfile.GetData() << std::endl;*/ } /*else std::cerr << "Unknown element for vehicle type " << idname << "::colors: " << element << std::endl;*/ } xmlfile.OutOfElem(); } else if (element == "drivebonus") { xmlfile.IntoElem(); while(xmlfile.FindElem()) { element = xmlfile.GetTagName(); if (element == "base") drivebonus_ = atoi(xmlfile.GetData()); else if (element == "skillfactor") drivebonus_factor_ = atof(xmlfile.GetData()); else if (element == "softlimit") drivebonus_limit1_ = atoi(xmlfile.GetData()); else if (element == "hardlimit") drivebonus_limit2_ = atoi(xmlfile.GetData()); /*else std::cerr << "Unknown element for vehicle type " << idname << "::stealing: " << element << std::endl;*/ } xmlfile.OutOfElem(); } else if (element == "dodgebonus") { xmlfile.IntoElem(); while(xmlfile.FindElem()) { element = xmlfile.GetTagName(); if (element == "base") dodgebonus_ = atoi(xmlfile.GetData()); else if (element == "skillfactor") dodgebonus_factor_ = atof(xmlfile.GetData()); else if (element == "softlimit") dodgebonus_limit1_ = atoi(xmlfile.GetData()); else if (element == "hardlimit") dodgebonus_limit2_ = atoi(xmlfile.GetData()); /*else std::cerr << "Unknown element for vehicle type " << idname << "::stealing: " << element << std::endl;*/ } xmlfile.OutOfElem(); } else if (element == "attackbonus") { xmlfile.IntoElem(); while(xmlfile.FindElem()) { element = xmlfile.GetTagName(); if (element == "driver") attackbonus_driver_ = atoi(xmlfile.GetData()); else if (element == "passenger") attackbonus_passenger_ = atoi(xmlfile.GetData()); /*else std::cerr << "Unknown element for vehicle type " << idname << "::stealing: " << element << std::endl;*/ } xmlfile.OutOfElem(); } else if (element == "longname") longname_ = xmlfile.GetData(); else if (element == "shortname") { shortname_ = xmlfile.GetData(); if (len(shortname_) > 7) shortname_.resize(7); //Only seven characters allowed for shortname_. } else if (element == "stealing") { xmlfile.IntoElem(); while(xmlfile.FindElem()) { element = xmlfile.GetTagName(); if (element == "difficulty_to_find") steal_difficultytofind_ = atoi(xmlfile.GetData()); else if (element == "juice") steal_juice_ = atoi(xmlfile.GetData()); else if (element == "extra_heat") steal_extraheat_ = atoi(xmlfile.GetData()); else if (element == "sense_alarm_chance") sensealarmchance_ = atoi(xmlfile.GetData()); else if (element == "touch_alarm_chance") touchalarmchance_ = atoi(xmlfile.GetData()); /*else std::cerr << "Unknown element for vehicle type " << idname << "::stealing: " << element << std::endl;*/ } xmlfile.OutOfElem(); } else if (element == "armor") { xmlfile.IntoElem(); while(xmlfile.FindElem()) { element = xmlfile.GetTagName(); if (element == "low_armor_min") lowarmormin_ = atoi(xmlfile.GetData()); else if (element == "low_armor_max") lowarmormax_ = atoi(xmlfile.GetData()); else if (element == "high_armor_min") higharmormin_ = atoi(xmlfile.GetData()); else if (element == "high_armor_max") higharmormax_ = atoi(xmlfile.GetData()); else if (element == "armor_midpoint") armormidpoint_ = atoi(xmlfile.GetData()); /*else std::cerr << "Unknown element for vehicle type " << idname << "::stealing: " << element << std::endl;*/ } xmlfile.OutOfElem(); } else if (element == "available_at_dealership") { int b = stringtobool(xmlfile.GetData()); if (b == 1) availableatshop_ = true; else if (b == 0) availableatshop_ = false; /*else std::cerr << "Invalid boolean value for vehicle type " << idname << "::available_at_dealership: " << xmlfile.GetData() << std::endl;*/ } else if (element == "price") price_ = atoi(xmlfile.GetData()); else if (element == "sleeperprice") sleeperprice_ = atoi(xmlfile.GetData()); /*else std::cerr << "Unknown element for vehicle type " << idname << ": " << element << std::endl;*/ } if (len(color_) == 0) color_.push_back("Translucent"); //Default. //xmlfile.OutOfElem(); }
void Shop::init(const MCD_STR &xmlstring) { CMarkup xml; xml.SetDoc(xmlstring); xml.FindElem(); xml.IntoElem(); while (xml.FindElem()) { std::string tag = xml.GetTagName(); if (tag == "only_sell_legal_items") { int b = stringtobool(xml.GetData()); if (b == 1) only_sell_legal_ = true; else if (b == 0) only_sell_legal_ = false; } else if (tag == "fullscreen") { int b = stringtobool(xml.GetData()); if (b == 1) fullscreen_ = true; else if (b == 0) fullscreen_ = false; } else if (tag == "allow_selling") { int b = stringtobool(xml.GetData()); if (b == 1) allow_selling_ = true; else if (b == 0) allow_selling_ = false; } else if (tag == "increase_prices_with_illegality") { int b = stringtobool(xml.GetData()); if (b == 1) increase_prices_with_illegality_ = true; else if (b == 0) increase_prices_with_illegality_ = false; } else if (tag == "department") { options_.push_back(new Shop(xml.GetSubDoc(), fullscreen_, only_sell_legal_, increase_prices_with_illegality_)); } else if (tag == "entry") description_ = xml.GetData(); else if (tag == "exit") exit_ = xml.GetData(); else if (tag == "sell_masks") { int b = stringtobool(xml.GetData()); if (b == 1) sell_masks_ = true; else if (b == 0) sell_masks_ = false; } else if (tag == "letter") { letter_ = xml.GetData()[0]; if (97 <= letter_ && letter_ <= 122) //Check it is a letter. letter_defined_ = true; else if (65 <= letter_ && letter_ <= 90) { letter_ += 32; letter_defined_ = true; } else if (letter_ == '!') //Allow special character. letter_defined_ = true; } else if (tag == "item") options_.push_back(new ShopItem(xml.GetSubDoc(), only_sell_legal_, increase_prices_with_illegality_)); } }
void CMISView::openXmlFile(CString& fileName,bool first) { CMarkup xml; xml.Load(fileName); xml.FindElem("Obj"); CString objPath=xml.GetData(); xml.ResetMainPos(); xml.FindElem("CollisionSafe"); CString cSafe=xml.GetData(); xml.ResetMainPos(); xml.FindElem("SupportThreshold"); para.supportThreshold=atof(xml.GetData()); xml.ResetMainPos(); xml.FindElem("ObjType"); int ObjType=atof(xml.GetData()); xml.ResetMainPos(); xml.FindElem("Thickness"); para.modelThickness=atof(xml.GetData()); xml.ResetMainPos(); xml.FindElem("Name"); para.modelName=xml.GetData(); xml.ResetMainPos(); xml.FindElem("StepLen"); para.stepLen=atof(xml.GetData()); xml.ResetMainPos(); xml.FindElem("EdgeLen"); para.maxEdgeLen=atof(xml.GetData()); xml.ResetMainPos(); xml.FindElem("BoundEdgeLen"); para.boundEdgeLen=atof(xml.GetData()); xml.ResetMainPos(); xml.FindElem("MatDensity"); para.matDensity=atof(xml.GetData()); xml.ResetMainPos(); xml.FindElem("FluidDensity"); para.fluidDensity=atof(xml.GetData()); xml.ResetMainPos(); xml.FindElem("DisruptAngle"); para.disruptAngle=atof(xml.GetData()); cout<<para.boundEdgeLen<<endl; if (cSafe=="true") para.collisionSafe=true; else para.collisionSafe=false; if (support!=NULL) { reset(); } switch (ObjType) { case 0: myObj.loadObjFromFile(objPath); break; case 1: myObj.loadObjFromFileEx(objPath); break; case 2: myObj.loadObjFromFileEx2(objPath); break; case 3: myObj.loadObjFromFileEx3(objPath); break; } BBox bbox=myObj.getBBox(); Vector3d boxCenter; boxCenter[0]=(bbox.H[0]+bbox.L[0])/2; boxCenter[1]=(bbox.H[1]+bbox.L[1])/2; boxCenter[2]=(bbox.H[2]+bbox.L[2])/2; boxCenter=-boxCenter; double maxW=-1; for (int i=0;i<3;i++) { if (bbox.H[i]-bbox.L[i]>maxW) { maxW=bbox.H[i]-bbox.L[i]; } } myObj.translate(boxCenter); myObj.scale(1/maxW); cout<<myObj.vertexNum<<endl; cout<<myObj.faceNum<<endl; //myObj.translate(Vector3d(0.5,0.5,0.5)); support=new Support(&myObj,para,mode,fluidHeight); support->setMeshRotation(meshRotation); cY=support->getLowestH(); updateCam(); if (!first) { defaultXml=fileName; CPaintDC dc(this); OnDraw(&dc); } }
CreatureType::WeaponsAndClips::WeaponsAndClips(CMarkup& xml, const string& owner) : number_weapons(1), cliptype("APPROPRIATE"), number_clips(4) { // The main position of the CMarkup object is expected not to be changed here. weapontype = xml.GetData(); // Read in values. if(!len(weapontype)) { while(xml.FindChildElem()) { std::string element=xml.GetChildTagName(); if(element=="type") weapontype=xml.GetChildData(); else if(element=="number_weapons") assign_interval(number_weapons,xml.GetChildData(),owner,element); else if(element=="cliptype") cliptype=xml.GetChildData(); else if(element=="number_clips") assign_interval(number_clips,xml.GetChildData(),owner,element); else xmllog.log("Unknown element for weapon in "+owner+": "+element); } } // Check values. if (weapontype != "CIVILIAN") { if (getweapontype(weapontype) == -1) { xmllog.log("Invalid weapon type for " + owner + ": " + weapontype); weapontype = "WEAPON_NONE"; cliptype = "NONE"; } else { const vector<attackst*>& attacks = ::weapontype[getweapontype(weapontype)]->get_attacks(); // Find a usable clip type for the weapon. if (cliptype == "APPROPRIATE") { cliptype = "NONE"; for(int i=0; i<len(attacks); i++) { if(attacks[i]->uses_ammo) { cliptype=attacks[i]->ammotype; break; } } } // Check clip is usable by the weapon. else if (getcliptype(cliptype) != -1) //Must be a clip type too. { int i; for(i=0; i<len(attacks)&&cliptype!=attacks[i]->ammotype; i++); if(i==len(attacks)) { xmllog.log("In " + owner + ", " + cliptype + "can not be used by " + weapontype + "."); cliptype = "NONE"; } } // Undefined clip type. else { xmllog.log("Invalid clip type for " + owner + ": " + cliptype); cliptype = "NONE"; } } } }
WeaponType::WeaponType(MCD_STR xmlstring) : ItemType(xmlstring), name_sub_1_defined_(false), name_sub_2_defined_(false), name_future_sub_1_defined_(false), name_future_sub_2_defined_(false), shortname_("UNDEF"), shortname_defined_(false), shortname_future_defined_(false), shortname_sub_1_defined_(false), shortname_sub_2_defined_(false), shortname_future_sub_1_defined_(false), shortname_future_sub_2_defined_(false), can_take_hostages_(false), threatening_(false), can_threaten_hostages_(true), protects_against_kidnapping_(true), musical_attack_(false), instrument_(false), legality_(2), bashstrengthmod_(1), suspicious_(true), size_(15), can_graffiti_(false), auto_break_lock_(false) { CMarkup xml; xml.SetDoc(xmlstring); xml.FindElem(); xml.IntoElem(); while (xml.FindElem()) //Loop over all the elements inside the weapontype element. { std::string element = xml.GetTagName(); if (element == "shortname") { shortname_ = xml.GetData(); shortname_defined_ = true; } else if (element == "shortname_future") { shortname_future_ = xml.GetData(); shortname_future_defined_ = true; } else if (element == "name_sub_1") { name_sub_1_ = xml.GetData(); name_sub_1_defined_ = true; } else if (element == "name_sub_2") { name_sub_2_ = xml.GetData(); name_sub_2_defined_ = true; } else if (element == "name_future_sub_1") { name_future_sub_1_ = xml.GetData(); name_future_sub_1_defined_ = true; } else if (element == "name_future_sub_2") { name_future_sub_2_ = xml.GetData(); name_future_sub_2_defined_ = true; } else if (element == "shortname_sub_1") { shortname_sub_1_ = xml.GetData(); shortname_sub_1_defined_ = true; } else if (element == "shortname_sub_2") { shortname_sub_2_ = xml.GetData(); shortname_sub_2_defined_ = true; } else if (element == "shortname_future_sub_1") { shortname_future_sub_1_ = xml.GetData(); shortname_future_sub_1_defined_ = true; } else if (element == "shortname_future_sub_2") { shortname_future_sub_2_ = xml.GetData(); shortname_future_sub_2_defined_ = true; } else if (element == "can_take_hostages") { int b = stringtobool(xml.GetData()); if (b == 1) can_take_hostages_ = true; else if (b == 0) can_take_hostages_ = false; /*else errorlog << "Invalid boolean value for weapon type " << idname() << "::can_take_hostages: " << xml.GetData() << endl;*/ } else if (element == "threatening") { int b = stringtobool(xml.GetData()); if (b == 1) threatening_ = true; else if (b == 0) threatening_ = false; /*else errorlog << "Invalid boolean value for weapon type " << idname() << "::threatening: " << xml.GetData() << endl;*/ } else if (element == "can_threaten_hostages") { int b = stringtobool(xml.GetData()); if (b == 1) can_threaten_hostages_ = true; else if (b == 0) can_threaten_hostages_ = false; } else if (element == "protects_against_kidnapping") { int b = stringtobool(xml.GetData()); if (b == 1) protects_against_kidnapping_ = true; else if (b == 0) protects_against_kidnapping_ = false; } else if (element == "musical_attack") { int b = stringtobool(xml.GetData()); if (b == 1) musical_attack_ = true; else if (b == 0) musical_attack_ = false; /*else errorlog << "Invalid boolean value for weapon type " << idname() << "::musical_attack: " << xml.GetData() << endl;*/ } else if (element == "instrument") { int b = stringtobool(xml.GetData()); if (b == 1) instrument_ = true; else if (b == 0) instrument_ = false; /*else errorlog << "Invalid boolean value for weapon type " << idname() << "::instrument: " << xml.GetData() << endl;*/ } else if (element == "graffiti") { int b = stringtobool(xml.GetData()); if (b == 1) can_graffiti_ = true; else if (b == 0) can_graffiti_ = false; /*else errorlog << "Invalid boolean value for weapon type " << idname() << "::graffiti: " << xml.GetData() << endl;*/ } else if (element == "legality") legality_ = atoi(xml.GetData().c_str()); else if (element == "bashstrengthmod") bashstrengthmod_ = atoi(xml.GetData().c_str()) / 100.0; else if (element == "auto_break_locks") { int b = stringtobool(xml.GetData()); if (b == 1) auto_break_lock_ = true; else if (b == 0) auto_break_lock_ = false; /*else errorlog << "Invalid boolean value for weapon type " << idname() << "::auto_break_locks: " << xml.GetData() << endl;*/ } else if (element == "suspicious") { int b = stringtobool(xml.GetData()); if (b == 1) suspicious_ = true; else if (b == 0) suspicious_ = false; /*else errorlog << "Invalid boolean value for weapon type " << idname() << "::suspicious: " << xml.GetData() << endl;*/ } else if (element == "size") size_ = atoi(xml.GetData().c_str()); else if (element == "attack") { attackst* attack = new attackst(xml.GetSubDoc()); vector<attackst*>::iterator it = attacks_.begin(); while (it != attacks_.end() && attack->priority >= (*it)->priority) ++it; attacks_.insert(it,attack); } /*else errorlog << "Unknown element for weapon type " << idname() << ": " << element << endl;*/ } if (!shortname_defined_) { if ((uses_ammo() && name().length() <= 9) || name().length() <= 14) shortname_ = name(); } else { if (shortname_.length() > 9 && uses_ammo()) shortname_.resize(9); else if (shortname_.length() > 14) shortname_.resize(14); } }
CreatureType::CreatureType(const std::string& xmlstring) : age_(18,57), alignment_public_mood_(true), attribute_points_(40), gender_liberal_(GENDER_RANDOM), gender_conservative_(GENDER_RANDOM), infiltration_(0), juice_(0), money_(20,40) { for(int i=0; i<ATTNUM; i++) attributes_[i].set_interval(1,10); id_=number_of_creaturetypes++; CMarkup xml; xml.SetDoc(xmlstring); xml.FindElem(); idname_=xml.GetAttrib("idname"); if(!len(idname_)) { idname_ = "LACKS IDNAME "+tostring(id_); xmllog.log("Creature type "+tostring(id_)+" lacks idname."); } type_=creaturetype_string_to_enum(idname_); xml.IntoElem(); // Loop over all the elements inside the creaturetype element. while(xml.FindElem()) { std::string element = xml.GetTagName(); if (element == "alignment") { std::string alignment = xml.GetData(); if (alignment == "PUBLIC MOOD") alignment_public_mood_ = true; else if (alignment == "LIBERAL") { alignment_ = ALIGN_LIBERAL; alignment_public_mood_ = false; } else if (alignment == "MODERATE") { alignment_ = ALIGN_MODERATE; alignment_public_mood_ = false; } else if (alignment == "CONSERVATIVE") { alignment_ = ALIGN_CONSERVATIVE; alignment_public_mood_ = false; } else xmllog.log("Invalid alignment for " + idname_ + ": " + alignment); } else if (element == "age") { std::string age = xml.GetData(); if (age == "DOGYEARS") age_.set_interval(2,6); else if (age == "CHILD") age_.set_interval(7,10); else if (age == "TEENAGER") age_.set_interval(14,17); else if (age == "YOUNGADULT") age_.set_interval(18,35); else if (age == "MATURE") age_.set_interval(20,59); else if (age == "GRADUATE") age_.set_interval(26,59); else if (age == "MIDDLEAGED") age_.set_interval(35,59); else if (age == "SENIOR") age_.set_interval(65,94); else assign_interval(age_, age, idname_, element); } else if (element == "attribute_points") assign_interval(attribute_points_, xml.GetData(), idname_, element); else if (element == "attributes") { while(xml.FindChildElem()) { int attribute = attribute_string_to_enum(xml.GetChildTagName()); if (attribute != -1) assign_interval(attributes_[attribute], xml.GetChildData(), idname_, element); else xmllog.log("Unknown attribute in " + idname_ + ": " + xml.GetTagName()); } } else if (element == "juice") assign_interval(juice_, xml.GetData(), idname_, element); else if (element == "gender") { int gender = gender_string_to_enum(xml.GetData()); if (gender != -1 && gender != GENDER_WHITEMALEPATRIARCH) gender_liberal_ = gender_conservative_ = gender; else xmllog.log("Invalid gender for " + idname_ + ": " + xml.GetData()); } else if (element == "infiltration") assign_interval(infiltration_, xml.GetData(), idname_, element); else if (element == "money") assign_interval(money_, xml.GetData(), idname_, element); else if (element == "skills") { while(xml.FindChildElem()) { int skill = skill_string_to_enum(xml.GetChildTagName()); if (skill != -1) assign_interval(skills_[skill], xml.GetChildData(), idname_, element); else xmllog.log("Unknown skill for " + idname_ + ": " + xml.GetChildTagName()); } } else if (element == "armor") { if (getarmortype(xml.GetData()) != -1) armortypes_.push_back(xml.GetData()); else xmllog.log("Invalid armor type for " + idname_ + ": " + xml.GetData());; } else if (element == "weapon") { //xml.SavePos("creature"); weapons_and_clips_.push_back(WeaponsAndClips(xml, idname_)); //xml.RestorePos("creature"); } else if (element == "encounter_name") encounter_name_ = xml.GetData(); else if (element == "type_name") type_name_ = xml.GetData(); else xmllog.log("Unknown element for " + idname_ + ": " + element); } if (!len(type_name_)) { xmllog.log("type_name not defined for " + idname_ + "."); type_name_ = "UNDEFINED"; } // If no weapon type has been given then use WEAPON_NONE. if (!len(weapons_and_clips_)) weapons_and_clips_.push_back(WeaponsAndClips("WEAPON_NONE", 1, "NONE", 0)); // If no armor type has been given then use ARMOR_NONE. if (!len(armortypes_)) armortypes_.push_back("ARMOR_NONE"); }
void GameSetting::LoadSetting() { TCHAR settingXMLPath[256]; CSVFile::GetAbsolutePath(L"settings.xml", settingXMLPath); CMarkup xml; if (xml.Load( settingXMLPath )) { xml.FindElem(); xml.IntoElem(); while (xml.FindElem(L"scene")) { if (xml.GetAttrib(L"name").compare(L"select") == 0) { xml.IntoElem(); xml.FindElem(); wcscpy(scene.select, xml.GetData().c_str()); xml.OutOfElem(); } else if (xml.GetAttrib(L"name").compare(L"decide") == 0) { xml.IntoElem(); xml.FindElem(); wcscpy(scene.decide, xml.GetData().c_str()); xml.OutOfElem(); } else if (xml.GetAttrib(L"name").compare(L"play") == 0) { xml.IntoElem(); xml.FindElem(); wcscpy(scene.play, xml.GetData().c_str()); xml.OutOfElem(); } else if (xml.GetAttrib(L"name").compare(L"result") == 0) { xml.IntoElem(); xml.FindElem(); wcscpy(scene.result, xml.GetData().c_str()); xml.OutOfElem(); } else if (xml.GetAttrib(L"name").compare(L"keysetting") == 0) { xml.IntoElem(); xml.FindElem(); wcscpy(scene.keysetting, xml.GetData().c_str()); xml.OutOfElem(); } else if (xml.GetAttrib(L"name").compare(L"skinselect") == 0) { xml.IntoElem(); xml.FindElem(); wcscpy(scene.skinselect, xml.GetData().c_str()); xml.OutOfElem(); } } while (xml.FindElem(L"setting")) { if (xml.GetAttrib(L"name").compare(L"screen")==0) { xml.IntoElem(); xml.FindElem(L"width"); screen.width = _wtoi(xml.GetData().c_str()); xml.FindElem(L"height"); screen.height = _wtoi(xml.GetData().c_str()); xml.OutOfElem(); } else if (xml.GetAttrib(L"name").compare(L"key")==0) { // TODO: save key } else if (xml.GetAttrib(L"name").compare(L"play")==0) { xml.IntoElem(); xml.FindElem(L"speed"); play.speed = _wtoi(xml.GetData().c_str()); xml.FindElem(L"shutter"); play.shutter = _wtoi(xml.GetData().c_str()); xml.OutOfElem(); } } } }
void ArmorType::init(const MCD_STR& xmlstring) { CMarkup xml; xml.SetDoc(xmlstring); xml.FindElem(); xml.IntoElem(); while (xml.FindElem()) //Loop over all the elements inside the armortype element. { std::string element = xml.GetTagName(); if (element == "make_difficulty") make_difficulty_ = atoi(xml.GetData().c_str()); else if (element == "make_price") make_price_ = atoi(xml.GetData().c_str()); else if (element == "deathsquad_legality") { int b = stringtobool(xml.GetData()); if (b == 1) deathsquad_legality_ = true; else if (b == 0) deathsquad_legality_ = false; /*else errorlog << "Invalid boolean value for armor type " << idname() << "::deathsquad_legality: " << xml.GetData() << std::endl;*/ } else if (element == "can_get_bloody") { int b = stringtobool(xml.GetData()); if (b == 1) can_get_bloody_ = true; else if (b == 0) can_get_bloody_ = false; } else if (element == "can_get_damaged") { int b = stringtobool(xml.GetData()); if (b == 1) can_get_damaged_ = true; else if (b == 0) can_get_damaged_ = false; } else if (element == "armor") { xml.IntoElem(); while (xml.FindElem()) { element = xml.GetTagName(); if (element == "body") armor_body_ = atoi(xml.GetData().c_str()); else if (element == "head") armor_head_ = atoi(xml.GetData().c_str()); else if (element == "limbs") armor_limbs_ = atoi(xml.GetData().c_str()); else if (element == "fireprotection") { int b = stringtobool(xml.GetData()); if (b == 1) fireprotection_ = true; else if (b == 0) fireprotection_ = false; /*else errorlog << "Invalid boolean value for armor type " << idname() << "::armor::fireprotection: " << xml.GetData() << std::endl;*/ } /*else errorlog << "Unknown element for armor type " << idname() << "::armor: " << element << endl;*/ } xml.OutOfElem(); } else if (element == "body_covering") { xml.IntoElem(); while (xml.FindElem()) { element = xml.GetTagName(); if (element == "body") { int b = stringtobool(xml.GetData()); if (b == 1) cover_body_ = true; else if (b == 0) cover_body_ = false; /*else errorlog << "Invalid boolean value for armor type " << idname() << "::body_covering::body: " << xml.GetData() << std::endl;*/ } else if (element == "head") { int b = stringtobool(xml.GetData()); if (b == 1) cover_head_ = true; else if (b == 0) cover_head_ = false; /*else errorlog << "Invalid boolean value for armor type " << idname() << "::body_covering::head: " << xml.GetData() << std::endl;*/ } else if (element == "arms") { int b = stringtobool(xml.GetData()); if (b == 1) cover_arms_ = true; else if (b == 0) cover_arms_ = false; /*else errorlog << "Invalid boolean value for armor type " << idname() << "::body_covering::arms: " << xml.GetData() << std::endl;*/ } else if (element == "legs") { int b = stringtobool(xml.GetData()); if (b == 1) cover_legs_ = true; else if (b == 0) cover_legs_ = false; /*else errorlog << "Invalid boolean value for armor type " << idname() << "::body_covering::legs: " << xml.GetData() << std::endl;*/ } else if (element == "conceals_face") { int b = stringtobool(xml.GetData()); if (b == 1) conceal_face_ = true; else if (b == 0) conceal_face_ = false; /*else errorlog << "Invalid boolean value for armor type " << idname() << "::body_covering::conceal_face: " << xml.GetData() << std::endl;*/ } /*else errorlog << "Unknown element for armor type " << idname() << "::armor: " << element << endl;*/ } xml.OutOfElem(); } else if (element == "shortname") { shortname_ = xml.GetData(); shortname_defined_ = true; if (shortname_.length() > 14) shortname_.resize(14); } else if (element == "interrogation") { xml.IntoElem(); while (xml.FindElem()) { if (element == "basepower") interrogation_basepower_ = atoi(xml.GetData().c_str()); else if (element == "assaultbonus") interrogation_assaultbonus_ = atoi(xml.GetData().c_str()); else if (element == "drugbonus") interrogation_drugbonus_ = atoi(xml.GetData().c_str()); /*else errorlog << "Unknown element for armor type " << idname() << "::interrogation: " << element << endl;*/ } xml.OutOfElem(); } else if (element == "professionalism") professionalism_ = atoi(xml.GetData().c_str()); else if (element == "conceal_weapon_size") conceal_weaponsize_ = atoi(xml.GetData().c_str()); else if (element == "stealth_value") stealth_value_ = atoi(xml.GetData().c_str()); else if (element == "mask") { int b = stringtobool(xml.GetData()); if (b == 1) mask_ = true; else if (b == 0) mask_ = false; } else if (element == "surprise") { int b = stringtobool(xml.GetData()); if (b == 1) surprise_mask_ = true; else if (b == 0) surprise_mask_ = false; } else if (element == "description") description_ = xml.GetData(); /*else errorlog << "Unknown element for armor type " << idname() << ": " << element << endl;*/ } if (!shortname_defined_ && name().length() <= 14) shortname_ = name(); }
attackst::attackst(MCD_STR xmlstring) : priority(1), ranged(false), thrown(false), uses_ammo(false), attack_description("assaults"), hit_description("striking"), always_describe_hit(false), hit_punctuation("."), skill(SKILL_CLUB), accuracy_bonus(0), number_attacks(1), successive_attacks_difficulty(0), strength_min(5), strength_max(10), random_damage(1), fixed_damage(1), bruises(false), tears(false), cuts(false), burns(false), shoots(false), bleeding(false), severtype(0), damages_armor(false), armorpiercing(0), no_damage_reduction_for_limbs_chance(0), can_backstab(false) { CMarkup xml; xml.SetDoc(xmlstring); xml.FindElem(); xml.IntoElem(); while (xml.FindElem()) //Loop over all the elements inside the vehicletype element. { std::string element = xml.GetTagName(); if (element == "priority") priority = atoi(xml.GetData().c_str()); else if (element == "ranged") { int b = stringtobool(xml.GetData()); if (b == 1) ranged = true; else if (b == 0) ranged = false; /*else errorlog << "Invalid boolean value for attack::ranged " << xml.GetData() << endl;*/ } else if (element == "thrown") { int b = stringtobool(xml.GetData()); if (b == 1) thrown = true; else if (b == 0) thrown = false; /*else errorlog << "Invalid boolean value for attack::thrown " << xml.GetData() << endl;*/ } else if (element == "can_backstab") { int b = stringtobool(xml.GetData()); if (b == 1) can_backstab = true; else if (b == 0) can_backstab = false; } else if (element == "ammotype") { ammotype = xml.GetData(); uses_ammo = true; } else if (element == "attack_description") attack_description = xml.GetData(); else if (element == "hit_description") hit_description = xml.GetData(); else if (element == "always_describe_hit") { int b = stringtobool(xml.GetData()); if (b == 1) always_describe_hit = true; else if (b == 0) always_describe_hit = false; /*else errorlog << "Invalid boolean value for attack::always_describe_hit: " << xml.GetData() << endl;*/ } else if (element == "hit_punctuation") hit_punctuation = xml.GetData(); else if (element == "skill") { int s = skill_string_to_enum(xml.GetData()); if (s != -1) skill = s; /*else errorlog << "Invalid skill name for attack::skill: " << xml.GetData() << endl; */ } else if (element == "accuracy_bonus") accuracy_bonus = atoi(xml.GetData().c_str()); else if (element == "number_attacks") number_attacks = atoi(xml.GetData().c_str()); else if (element == "successive_attacks_difficulty") successive_attacks_difficulty = atoi(xml.GetData().c_str()); else if (element == "strength_min") strength_min = atoi(xml.GetData().c_str()); else if (element == "strength_max") strength_max = atoi(xml.GetData().c_str()); else if (element == "random_damage") random_damage = atoi(xml.GetData().c_str()); else if (element == "fixed_damage") fixed_damage = atoi(xml.GetData().c_str()); else if (element == "bruises") { int b = stringtobool(xml.GetData()); if (b == 1) bruises = true; else if (b == 0) bruises = false; /*else errorlog << "Invalid boolean value for attack::bruises: " << xml.GetData() << endl;*/ } else if (element == "tears") { int b = stringtobool(xml.GetData()); if (b == 1) tears = true; else if (b == 0) tears = false; /*else errorlog << "Invalid boolean value for attack::tears: " << xml.GetData() << endl;*/ } else if (element == "cuts") { int b = stringtobool(xml.GetData()); if (b == 1) cuts = true; else if (b == 0) cuts = false; /*else errorlog << "Invalid boolean value for attack::cuts: " << xml.GetData() << endl;*/ } else if (element == "burns") { int b = stringtobool(xml.GetData()); if (b == 1) burns = true; else if (b == 0) burns = false; /*else errorlog << "Invalid boolean value for attack::burns: " << xml.GetData() << endl;*/ } else if (element == "shoots") { int b = stringtobool(xml.GetData()); if (b == 1) shoots = true; else if (b == 0) shoots = false; /*else errorlog << "Invalid boolean value for attack::shoots: " << xml.GetData() << endl;*/ } else if (element == "bleeding") { int b = stringtobool(xml.GetData()); if (b == 1) bleeding = true; else if (b == 0) bleeding = false; /*else errorlog << "Invalid boolean value for attack::bleeding: " << xml.GetData() << endl;*/ } else if (element == "severtype") { int s = severtype_string_to_enum(xml.GetData()); if (s != -1) severtype = s; /*else errorlog << "Invalid severtype for attack::severtype: " << xml.GetData() << endl; */ } else if (element == "damages_armor") { int b = stringtobool(xml.GetData()); if (b == 1) damages_armor = true; else if (b == 0) damages_armor = false; /*else errorlog << "Invalid boolean value for attack::damages_armor: " << xml.GetData() << endl;*/ } else if (element == "armorpiercing") armorpiercing = atoi(xml.GetData().c_str()); else if (element == "no_damage_reduction_for_limbs_chance") no_damage_reduction_for_limbs_chance = atoi(xml.GetData().c_str()); else if (element == "critical") { xml.IntoElem(); while (xml.FindElem()) { element = xml.GetTagName(); if (element == "chance") critical.chance = atoi(xml.GetData().c_str()); else if (element == "hits_required") critical.hits_required = atoi(xml.GetData().c_str()); else if (element == "random_damage") { critical.random_damage = atoi(xml.GetData().c_str()); critical.random_damage_defined = true; } else if (element == "fixed_damage") { critical.fixed_damage = atoi(xml.GetData().c_str()); critical.fixed_damage_defined = true; } else if (element == "severtype") { int s = severtype_string_to_enum(xml.GetData()); if (s != -1) { critical.severtype = s; critical.severtype_defined = true; } /*else errorlog << "Invalid severtype for attack::critical::severtype: " << xml.GetData() << endl; */ } /*else errorlog << "Unknown element for attack::critical: " << element << endl; */ } xml.OutOfElem(); } else if (element == "fire") { xml.IntoElem(); while (xml.FindElem()) { element = xml.GetTagName(); if (element == "chance") fire.chance = atoi(xml.GetData().c_str()); else if (element == "chance_causes_debris") fire.chance_causes_debris = atoi(xml.GetData().c_str()); /*else errorlog << "Unknown element for attack::fire: " << element << endl; */ } xml.OutOfElem(); } /*else errorlog << "Unknown element for attack: " << element << endl; */ } if (!bruises && !tears && !cuts && !burns && !shoots) bruises = true; //If no type specified, then bruise. }