Implement writing outdoor sector to XML
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<sector boes="1.0">
|
||||
<name>Outdoor Section</name>
|
||||
<!-- Outdoor ambient sound -->
|
||||
<sound>birds</sound>
|
||||
|
||||
<!-- Wandering encounter info -->
|
||||
<wandering>
|
||||
@@ -8,8 +10,14 @@
|
||||
<monster friendly="true">27</monster>
|
||||
</wandering>
|
||||
|
||||
<sign id="0">This is a sample sign!</sign>
|
||||
<signs>
|
||||
<string id="0">This is a sample sign!</string>
|
||||
</signs>
|
||||
|
||||
<!-- outdoor description rects -->
|
||||
<description top="32" left="32" bottom="36" right="36">This is an area description!</description>
|
||||
<descriptions>
|
||||
<area top="32" left="32" bottom="36" right="36">This is an area description!</area>
|
||||
</descriptions>
|
||||
|
||||
<strings/>
|
||||
</sector>
|
@@ -42,28 +42,66 @@
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element name="name" type="xs:string"/>
|
||||
<xs:element name="comment" type="xs:string" minOccurs="0"/>
|
||||
<xs:element name="sound" minOccurs="0">
|
||||
<xs:simpleType>
|
||||
<xs:union memberTypes="xs:integer">
|
||||
<xs:simpleType>
|
||||
<xs:restriction base="xs:string">
|
||||
<xs:enumeration value="birds"/>
|
||||
<xs:enumeration value="drip"/>
|
||||
</xs:restriction>
|
||||
</xs:simpleType>
|
||||
</xs:union>
|
||||
</xs:simpleType>
|
||||
</xs:element>
|
||||
<xs:element name="encounter" type="encounter" minOccurs="0" maxOccurs="4"/>
|
||||
<xs:element name="wandering" type="encounter" minOccurs="0" maxOccurs="4"/>
|
||||
<xs:choice maxOccurs="unbounded">
|
||||
<xs:element name="sign">
|
||||
<xs:complexType>
|
||||
<xs:simpleContent>
|
||||
<xs:extension base="xs:string">
|
||||
<xs:attribute name="id" type="xs:integer"/>
|
||||
</xs:extension>
|
||||
</xs:simpleContent>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:element name="description">
|
||||
<xs:complexType>
|
||||
<xs:simpleContent>
|
||||
<xs:extension base="xs:string">
|
||||
<xs:attributeGroup ref="rect"/>
|
||||
</xs:extension>
|
||||
</xs:simpleContent>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
</xs:choice>
|
||||
<xs:element name="signs">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element name="string" minOccurs="0" maxOccurs="unbounded">
|
||||
<xs:complexType>
|
||||
<xs:simpleContent>
|
||||
<xs:extension base="xs:string">
|
||||
<xs:attribute name="id" type="xs:integer"/>
|
||||
</xs:extension>
|
||||
</xs:simpleContent>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:element name="descriptions">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element name="area" minOccurs="0" maxOccurs="unbounded">
|
||||
<xs:complexType>
|
||||
<xs:simpleContent>
|
||||
<xs:extension base="xs:string">
|
||||
<xs:attributeGroup ref="rect"/>
|
||||
</xs:extension>
|
||||
</xs:simpleContent>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:element name="strings">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element name="string" minOccurs="0" maxOccurs="unbounded">
|
||||
<xs:complexType>
|
||||
<xs:simpleContent>
|
||||
<xs:extension base="xs:string">
|
||||
<xs:attribute name="id" type="xs:integer"/>
|
||||
</xs:extension>
|
||||
</xs:simpleContent>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
</xs:sequence>
|
||||
<xs:attribute name="boes" type="xs:string"/>
|
||||
</xs:complexType>
|
||||
|
@@ -38,8 +38,8 @@ class cOutdoors {
|
||||
public:
|
||||
class cWandering { // formerly out_wandering_type
|
||||
public:
|
||||
mon_num_t monst[7];
|
||||
mon_num_t friendly[3];
|
||||
std::array<mon_num_t,7> monst;
|
||||
std::array<mon_num_t,3> friendly;
|
||||
short spec_on_meet,spec_on_win,spec_on_flee,cant_flee;
|
||||
short end_spec1,end_spec2;
|
||||
|
||||
@@ -65,7 +65,7 @@ public:
|
||||
location exit_locs[8];
|
||||
short exit_dests[8];
|
||||
location sign_locs[8];
|
||||
cWandering wandering[4],special_enc[4];
|
||||
std::array<cWandering,4> wandering, special_enc;
|
||||
location wandering_locs[4];
|
||||
std::array<cSpecial,60> specials;
|
||||
std::string out_name;
|
||||
|
@@ -70,6 +70,35 @@ template<> void ticpp::Printer::PushElement(std::string tagName, cMonster::cAtta
|
||||
CloseElement(tagName);
|
||||
}
|
||||
|
||||
template<> void ticpp::Printer::PushElement(std::string tagName, cOutdoors::cWandering enc) {
|
||||
OpenElement(tagName);
|
||||
PushAttribute("can-flee", !enc.cant_flee);
|
||||
for(size_t i = 0; i < enc.monst.size(); i++) {
|
||||
PushElement("monster", enc.monst[i]);
|
||||
}
|
||||
for(size_t i = 0; i < enc.friendly.size(); i++) {
|
||||
OpenElement("monster");
|
||||
PushAttribute("friendly", true);
|
||||
PushText(enc.friendly[i]);
|
||||
CloseElement("monster");
|
||||
}
|
||||
PushElement("onmeet", enc.spec_on_meet);
|
||||
PushElement("onwin", enc.spec_on_win);
|
||||
PushElement("onflee", enc.spec_on_flee);
|
||||
PushElement("sdf", loc(enc.end_spec1, enc.end_spec2));
|
||||
CloseElement(tagName);
|
||||
}
|
||||
|
||||
template<> void ticpp::Printer::PushElement(std::string tagName, info_rect_t rect) {
|
||||
OpenElement(tagName);
|
||||
PushAttribute("top", rect.top);
|
||||
PushAttribute("left", rect.left);
|
||||
PushAttribute("bottom", rect.bottom);
|
||||
PushAttribute("right", rect.right);
|
||||
PushText(rect.descr);
|
||||
CloseElement(tagName);
|
||||
}
|
||||
|
||||
static bool is_minmax(int lo, int hi, int val) {
|
||||
return minmax(lo, hi, val) == val;
|
||||
}
|
||||
@@ -445,6 +474,39 @@ void writeMonstersToXml(ticpp::Printer&& data) {
|
||||
data.CloseElement("monsters");
|
||||
}
|
||||
|
||||
void writeOutdoorsToXml(ticpp::Printer&& data, cOutdoors& sector) {
|
||||
data.OpenElement("sector");
|
||||
data.PushAttribute("boes", scenario.format_ed_version());
|
||||
data.PushElement("name", sector.out_name);
|
||||
if(!sector.comment.empty())
|
||||
data.PushElement("comment", sector.comment);
|
||||
switch(sector.ambient_sound) {
|
||||
case AMBIENT_NONE: break;
|
||||
case AMBIENT_BIRD: data.PushElement("sound", "birds"); break;
|
||||
case AMBIENT_DRIP: data.PushElement("sound", "drip"); break;
|
||||
case AMBIENT_CUSTOM: data.PushElement("sound", sector.out_sound); break;
|
||||
}
|
||||
for(auto& enc : sector.special_enc)
|
||||
data.PushElement("encounter", enc);
|
||||
for(auto& enc : sector.wandering)
|
||||
data.PushElement("wandering", enc);
|
||||
data.OpenElement("signs");
|
||||
for(auto& sign : sector.sign_strs)
|
||||
data.PushElement("string", sign);
|
||||
data.CloseElement("signs");
|
||||
data.OpenElement("descriptions");
|
||||
for(auto& area : sector.info_rect) {
|
||||
if(!area.descr.empty() && area.top < area.bottom && area.left < area.right)
|
||||
data.PushElement("area", area);
|
||||
}
|
||||
data.CloseElement("descriptions");
|
||||
data.OpenElement("strings");
|
||||
for(auto& str : sector.spec_strs)
|
||||
data.PushElement("string", str);
|
||||
data.CloseElement("strings");
|
||||
data.CloseElement("sector");
|
||||
}
|
||||
|
||||
void save_scenario(fs::path toFile) {
|
||||
// TODO: I'm not certain 1.0.0 is the correct version here?
|
||||
scenario.format.prog_make_ver[0] = 1;
|
||||
@@ -483,6 +545,7 @@ void save_scenario(fs::path toFile) {
|
||||
std::string file_basename = "out" + std::to_string(x) + '~' + std::to_string(y);
|
||||
// First the main data.
|
||||
std::ostream& outdoors = scen_file.newFile("scenario/out/" + file_basename + ".xml");
|
||||
writeOutdoorsToXml(ticpp::Printer(file_basename + ".xml", outdoors), *scenario.outdoors[x][y]);
|
||||
|
||||
// Then the map.
|
||||
std::ostream& out_map = scen_file.newFile("scenario/out/" + file_basename + ".map");
|
||||
|
Reference in New Issue
Block a user