Store talk node type in scenario file as enumerator instead of numer

- Also, don't write empty CDATA sections when dialogue name/look/job sections are completely empty.
This commit is contained in:
2015-07-05 23:30:43 -04:00
parent 6cc9e81a7b
commit 7b76d37237
7 changed files with 32 additions and 11 deletions

View File

@@ -47,7 +47,7 @@
<xs:complexType>
<xs:sequence>
<xs:element name="keyword" minOccurs="1" maxOccurs="2" type="xs:string"/>
<xs:element name="type" type="xs:integer"/>
<xs:element name="type" type="xs:token"/>
<xs:element name="param" minOccurs="0" maxOccurs="4" type="xs:integer"/>
<xs:element name="text" minOccurs="1" maxOccurs="2" type="xs:string"/>
</xs:sequence>

View File

@@ -167,7 +167,7 @@
<xs:element name='description' type='xs:string'/>
<xs:element name='node' type='xs:integer'/>
<xs:element name='quantity' type='shop-amount'/>
<xs:element name='cost' type='xs:integer' minOccurs="0"/>
<xs:element name='cost' type='xs:integer'/>
<xs:element name='icon' type='xs:integer'/>
</xs:all>
</xs:complexType>

View File

@@ -139,7 +139,7 @@
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="item">
<xs:element name="item" minOccurs="0">
<xs:complexType>
<xs:all>
<xs:element name="type" type="xs:integer"/>
@@ -152,7 +152,7 @@
<xs:attribute name="id" type="xs:integer"/>
</xs:complexType>
</xs:element>
<xs:element name="creature">
<xs:element name="creature" minOccurs="0">
<xs:complexType>
<xs:all>
<xs:element name="type" type="xs:integer"/>

View File

@@ -596,3 +596,23 @@ std::istream& operator>> (std::istream& in, eLighting& light) {
in.setstate(std::ios::failbit);
return in;
}
// MARK: eTalkNode
cEnumLookup talk_nodes = {
"reg","if-sdf","set-sdf","inn","if-time","if-event","if-town","shop","train","jobs",
"","","","sell-weap","sell-prot","sell-any","id","ench","buy-info","buy-sdf",
"buy-ship","buy-horse","buy-spec-item","quest","buy-town","end-force","end-fight","end-alarm","end-die","call-local",
"call-global",
};
std::ostream& operator<< (std::ostream& out, eTalkNode node) {
writeEnum(out, node, talk_nodes, "reg");
return out;
}
std::istream& operator>> (std::istream& in, eTalkNode& node) {
if(!readEnum(in, node, talk_nodes, eTalkNode::REGULAR))
in.setstate(std::ios::failbit);
return in;
}

View File

@@ -54,4 +54,7 @@ public:
void writeTo(std::ostream& file) const;
};
std::ostream& operator<< (std::ostream& out, eTalkNode node);
std::istream& operator>> (std::istream& in, eTalkNode& node);
#endif

View File

@@ -786,9 +786,9 @@ static void writeDialogueToXml(ticpp::Printer&& data, cSpeech& talk, int town_nu
data.OpenElement("personality");
data.PushAttribute("id", i + 10 * town_num);
data.PushElement("title", who.title);
data.PushElement("look", who.look, true);
data.PushElement("name", who.name, true);
data.PushElement("job", who.job, true);
data.PushElement("look", who.look, !who.look.empty());
data.PushElement("name", who.name, !who.look.empty());
data.PushElement("job", who.job, !who.look.empty());
if(!who.dunno.empty())
data.PushElement("unknown", who.dunno, true);
data.CloseElement("personality");
@@ -805,7 +805,7 @@ static void writeDialogueToXml(ticpp::Printer&& data, cSpeech& talk, int town_nu
data.PushElement("keyword", std::string(node.link1, 4));
if(std::string(node.link2, 4) != "xxxx")
data.PushElement("keyword", std::string(node.link2, 4));
data.PushElement("type", int(node.type));
data.PushElement("type", node.type);
if(node.extras[0] >= 0 || node.extras[1] >= 0 || node.extras[2] >= 0 || node.extras[3] >= 0)
data.PushElement("param", node.extras[0]);
if(node.extras[1] >= 0 || node.extras[2] >= 0 || node.extras[3] >= 0)

View File

@@ -1789,9 +1789,7 @@ static void readDialogueFromXml(ticpp::Document&& data, cSpeech& talk, int town_
else throw xBadNode(type, node->Row(), node->Column(), fname);
num_keys++;
} else if(type == "type") {
int type;
node->GetText(&type);
talk.talk_nodes[num_nodes].type = eTalkNode(type);
node->GetText(&talk.talk_nodes[num_nodes].type);
got_type = true;
} else if(type == "param") {
if(num_params >= 4)