Fix PC names being cut off at a space when loading

(Thanks to Erdos for discovering this.)
- This commit uses the quoting mechanism on PC names. It also applies it to item names, though that wasn't actually broken like PC names was.
This commit is contained in:
2015-02-16 16:31:18 -05:00
parent 012d40129b
commit 57983c1b1e
2 changed files with 8 additions and 11 deletions

View File

@@ -19,6 +19,7 @@
#include "oldstructs.h"
#include "spell.hpp"
#include "graphtool.hpp" // for get_str()
#include "fileio.hpp"
extern const std::multiset<eItemType> equippable = {
eItemType::ONE_HANDED, eItemType::TWO_HANDED, eItemType::BOW, eItemType::ARROW, eItemType::THROWN_MISSILE,
@@ -1263,8 +1264,8 @@ void cItem::writeTo(std::ostream& file, std::string prefix) const {
file << prefix << "WEIGHT " << weight << '\n';
file << prefix << "SPEC " << special_class << '\n';
file << prefix << "AT " << item_loc.x << ' ' << item_loc.y << '\n';
file << prefix << "FULLNAME " << full_name << '\n';
file << prefix << "NAME " << name << '\n';
file << prefix << "FULLNAME " << maybe_quote_string(full_name) << '\n';
file << prefix << "NAME " << maybe_quote_string(name) << '\n';
file << prefix << "TREASURE " << treas_class << '\n';
if(ident) file << prefix << "IDENTIFIED\n";
if(property) file << prefix << "PROPERTY\n";
@@ -1299,13 +1300,8 @@ void cItem::readFrom(std::istream& sin){
else if(cur == "WEIGHT") sin >> weight;
else if(cur == "SPEC") sin >> special_class;
else if(cur == "AT") sin >> item_loc.x >> item_loc.y;
else if(cur == "FULLNAME"){
getline(sin,cur);
full_name = cur;
}else if(cur == "NAME"){
getline(sin,cur);
name = cur;
}
else if(cur == "FULLNAME") full_name = read_maybe_quoted_string(sin);
else if(cur == "NAME") name = read_maybe_quoted_string(sin);
else if(cur == "TREASURE") sin >> treas_class;
else if(cur == "IDENTIFIED") ident = true;
else if(cur == "PROPERTY") property = true;

View File

@@ -16,6 +16,7 @@
#include "universe.h"
#include "oldstructs.h"
#include "mathutil.hpp"
#include "fileio.hpp"
extern short skill_bonus[21];
@@ -884,7 +885,7 @@ void operator -= (eMainStatus& stat, eMainStatus othr){
void cPlayer::writeTo(std::ostream& file) const {
file << "UID " << unique_id << '\n';
file << "STATUS -1 " << main_status << '\n';
file << "NAME " << name << '\n';
file << "NAME " << maybe_quote_string(name) << '\n';
file << "SKILL 19 " << max_health << '\n';
file << "SKILL 20 " << max_sp << '\n';
for(auto p : skills) {
@@ -947,7 +948,7 @@ void cPlayer::readFrom(std::istream& file){
if(i == eStatus::MAIN) sin >> main_status;
else sin >> status[i];
}else if(cur == "NAME")
sin >> name;
name = read_maybe_quoted_string(sin);
else if(cur == "SKILL"){
int i;
sin >> i;