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;*/ } } }
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); } }
int main(int argc, char* argv[]) { log_error("----------------------------------------------------"); log_error("---------------DEBUG MODE --------------------------"); log_error("----------------------------------------------------"); /*Read in configuration*/ server_config* tmp = NULL; try { #ifdef CASCADE_DEBUG tmp = new server_config("default.config",true); #else tmp = new server_config("default.config",false); #endif } catch(server_config_exception &e) { cerr << "Invalid Configuration file" << endl; return -3; } catch(...) { cerr << "Invalid Configuration file" << endl; return -3; } boost::scoped_ptr<server_config> config(tmp); /*Load logging module*/ logger* lh = NULL; try { lh = new logger(config->getOpt("LOGFILE"),logger::DEBUG); } catch(logger_exception &e) { cerr << e.what() << endl; return -4; } boost::scoped_ptr<logger> loghandle(lh); lh = NULL; loghandle->consolelog(stringtobool(config->getOpt("LOGCONSOLE"))); loghandle->entry("Starting up server",logger::WARNING); /*Start up data module*/ //server_storage* storagehandle = new mysql_storage(config->dbuser,config->dbpasswd,config->dbhost,config->db); mysql_storage* sh; try { sh = new mysql_storage(config->getOpt("DBUSER"),config->getOpt("DBPASSWORD"),config->getOpt("DBHOST"),config->getOpt("DB")); sh->setLog(loghandle.get()); sh->setAuthenticated(config->getOpt("AUTHENTICATED_MODE")); #ifdef CASCADE_chaintest sh->testrun(); #else sh->run(); #endif } catch(server_storage_exception &e) { cerr << "ERROR starting up storage module (" << e.what() << ")." << endl; //loghandle->entry(string("Server storage module failed (") + string(e.what()) + string(")."),logger::FATAL); return -1; } catch(...) { cerr << "UNHANDLED EXCEPTION IN STORAGE MODULE" << endl; //loghandle->entry(string("Unhandled exception in server storage."),logger::FATAL); return -1; } boost::scoped_ptr<mysql_storage> storagehandle(sh); sh = NULL; /*start up network module*/ server_network* nh; try { nh = new server_network(); nh->setLog(loghandle.get()); nh->setPort(config->getOpt("CONNPORT")); nh->setMaxConn(config->getOpt("MAXCONCURRENT")); nh->setRecvTimeout(config->getOpt("MAXRECVTIMEOUT")); nh->setDataModule(storagehandle.get()); nh->setMinMaxProx(config->getOpt("MINPROXY"),config->getOpt("MAXPROXY")); nh->setUpdateInt(config->getOpt("UPDATEINTERVAL")); storagehandle->setNetworkModule(nh); nh->run(); } catch(server_network_exception &e) { cerr << "ERROR starting up network module (" << e.what() << ")." << endl; loghandle->entry(string("Network module failed") + string(e.what()) + string(")."),logger::FATAL); sig_death = 1; } catch(...) { cerr << "UNHANDLED EXCEPTION IN NETWORK MODULE" << endl; loghandle->entry(string("Unhandled exception in network module."),logger::FATAL); sig_death = 1; } boost::scoped_ptr<server_network> networkhandle(nh); nh = NULL; signal(SIGINT,handle_sigint); /*Old way but eh*/ string input; #ifdef CASCADE_DEBUG storagehandle->purgedb(); #endif while(sig_death == 0) { cout << "Console>>> "; getline(cin,input); if(input == string("quit")) { /*Wait for threads to die off*/ sig_death = 1; } else if(input == string("dumpmap")) { networkhandle->dumpmap(); } else if(input == string("purgedb")) { storagehandle->purgedb(); } else { cout << "Unknown command" << endl;; } } loghandle->entry("Shutting down server",logger::WARNING); // delete networkhandle; // delete config; // delete storagehandle; // delete loghandle; }
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. }
bool CCards::ParseLines(vector<string>& lines) { if (lines.empty()) return false; for (vector<string>::iterator it = lines.begin(); it < lines.end(); ++it) { string& data(*it); if (!data.empty()) { vector<string> fields; Card card; uri::decode(data); Tokenize(data, fields, "|"); // field 0 = idCard // field 1 = devicePath // field 2 = name // field 3 = priority // field 4 = grabEPG // field 5 = lastEpgGrab (2000-01-01 00:00:00 = infinite) // field 6 = recordingFolder // field 7 = idServer // field 8 = enabled // field 9 = camType // field 10 = timeshiftingFolder // field 11 = recordingFormat // field 12 = decryptLimit // field 13 = preload // field 14 = CAM // field 15 = NetProvider // field 16 = stopgraph // field 17 = UNC path recording folder (when shared) // field 18 = UNC path timeshift folder (when shared) card.IdCard = atoi(fields[0].c_str()); card.DevicePath = fields[1]; card.Name = fields[2]; card.Priority = atoi(fields[3].c_str()); card.GrabEPG = stringtobool(fields[4]); card.LastEpgGrab = DateTimeToTimeT(fields[5]); card.RecordingFolder = fields[6]; card.IdServer = atoi(fields[7].c_str()); card.Enabled = stringtobool(fields[8]); card.CamType = atoi(fields[9].c_str()); card.TimeshiftFolder = fields[10]; card.RecordingFormat = atoi(fields[11].c_str()); card.DecryptLimit = atoi(fields[12].c_str()); card.Preload = stringtobool(fields[13]); card.CAM = stringtobool(fields[14]); card.NetProvider = atoi(fields[15].c_str()); card.StopGraph = stringtobool(fields[16]); if (fields.size() > 17) // since TVServerXBMC build 115 { card.RecordingFolderUNC = fields[17]; card.TimeshiftFolderUNC = fields[18]; } else { card.RecordingFolderUNC = ""; card.TimeshiftFolderUNC = ""; } push_back(card); } } return true; }
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(); }
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_)); } }