本文整理汇总了C++中Weapon::read_txt_properties方法的典型用法代码示例。如果您正苦于以下问题:C++ Weapon::read_txt_properties方法的具体用法?C++ Weapon::read_txt_properties怎么用?C++ Weapon::read_txt_properties使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Weapon
的用法示例。
在下文中一共展示了Weapon::read_txt_properties方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: read_weapons_txt
void Weapon::read_weapons_txt() {
std::ifstream weapons_file("weapons.txt");
std::string line;
if (!weapons_file.is_open()) {
log_file << "Unable to open weapons.txt" << std::endl;
std::cerr << "Unable to open weapons.txt" << std::endl;
return;
}
Weapon* weap;
while (std::getline(weapons_file, line)) {
if (line.front() == '#') continue;
if (line.find_first_not_of(" \n\t\r") == std::string::npos) continue; //if line is empty
while (line.find(";") == std::string::npos) { //line ends with semicolon
std::string buffer_line = "";
std::getline(weapons_file, buffer_line);
line += buffer_line;
}
line.erase(line.find(";"));
trimr_string(line); //erasing unnecessary from end
if (line == "NEW_ITEM")
weap = new Weapon();
else if (line == "PUSH_ITEM") {
LIST.insert(std::pair<std::string, Weapon>(weap->name, *weap));
log_file << "Added new weapon to WEAPONS_LIST: " << weap->name << std::endl;
delete weap;
weap = nullptr;
} else if (line.find("available_attacks") != std::string::npos) {
line = take_value(line);
for (auto& it : split_with_match_chars(line)) {
it = it.substr(it.find('{') + 1, it.find('}') - 1);
Attack::ptr attack;
if (it.find("Ranged ::") != std::string::npos) {
it = it.substr(it.find("::") + 2);
attack = RangedAttack::ptr(new RangedAttack(weap, it));
weap->available_attacks.push_back(attack);
} else if (it.find("Close ::") != std::string::npos) {
it = it.substr(it.find("::") + 2);
attack = CloseAttack::ptr(new CloseAttack(weap, it));
weap->available_attacks.push_back(attack);
}
}
} else if (line.find("ammo") != std::string::npos) {
for (auto& it : split_with_match_chars(take_value(line))) {
Ammo new_ammo = {it.substr(it.find("{") + 1, it.find("}") - 1)};
weap->ammo.insert({new_ammo.type, new_ammo});
}
} else if (line.find("hold_type") != std::string::npos) {
line = take_value(line);
if (line == "one_handed")
weap->hold_type = one_handed;
else if (line == "two_handed")
weap->hold_type = two_handed;
} else weap->read_txt_properties(line);
}
weapons_file.close();
}