Generalize the editor's terrain frills mechanism
This commit is contained in:
@@ -84,6 +84,11 @@
|
||||
<xs:complexType>
|
||||
<xs:all>
|
||||
<xs:element name="shortcut" minOccurs="0" type="key"/>
|
||||
<xs:element name="frill" minOccurs="0">
|
||||
<xs:extension base="xs:integer">
|
||||
<xs:attribute name="chance" type="xs:integer" use="optional" default="10"/>
|
||||
</xs:extension>
|
||||
</xs:element>
|
||||
<xs:element name="object" minOccurs="0">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
|
||||
@@ -384,4 +384,12 @@ void cTerrain::append(legacy::terrain_type_type& old){
|
||||
};
|
||||
if(picture < 1000) map_pic = picture;
|
||||
else map_pic = NO_PIC;
|
||||
if(i == 1)
|
||||
frill_for = 0, frill_chance = 10;
|
||||
else if(i == 3)
|
||||
frill_for = 2, frill_chance = 15;
|
||||
else if(i == 4)
|
||||
frill_for = 2, frill_chance = 10;
|
||||
else if(i == 37)
|
||||
frill_for = 36, frill_chance = 25;
|
||||
}
|
||||
|
||||
@@ -38,6 +38,8 @@ public:
|
||||
unsigned int ground_type = 0; // ditto
|
||||
eTrimType trim_type = eTrimType::NONE; // ditto, mostly
|
||||
long trim_ter = 0; // ditto
|
||||
long frill_for = -1;
|
||||
unsigned short frill_chance = 0;
|
||||
unsigned short combat_arena = 0;
|
||||
location obj_pos; // editor use only
|
||||
location obj_size; // editor use only
|
||||
|
||||
@@ -1882,14 +1882,13 @@ void frill_up_terrain() {
|
||||
for(j = 0; j < ((editing_town) ? town->max_dim() : 48); j++) {
|
||||
terrain_type = editing_town ? town->terrain(i,j) : current_terrain->terrain[i][j];
|
||||
|
||||
if((terrain_type == 2) && (get_ran(1,1,20) < 3))
|
||||
terrain_type = 3;
|
||||
if((terrain_type == 2) && (get_ran(1,1,20) < 2))
|
||||
terrain_type = 4;
|
||||
if((terrain_type == 0) && (get_ran(1,1,20) < 2))
|
||||
terrain_type = 1;
|
||||
if((terrain_type == 36) && (get_ran(1,1,20) < 5))
|
||||
terrain_type = 37;
|
||||
for(size_t k = 0; k < scenario.ter_types.size(); k++) {
|
||||
if(terrain_type == k) continue;
|
||||
cTerrain& ter = scenario.ter_types[k];
|
||||
if(terrain_type == ter.frill_for && get_ran(1,1,100) < ter.frill_chance)
|
||||
terrain_type = k;
|
||||
}
|
||||
|
||||
if(editing_town)
|
||||
town->terrain(i,j) = terrain_type;
|
||||
else current_terrain->terrain[i][j] = terrain_type;
|
||||
@@ -1904,14 +1903,11 @@ void unfrill_terrain() {
|
||||
for(i = 0; i < ((editing_town) ? town->max_dim() : 48); i++)
|
||||
for(j = 0; j < ((editing_town) ? town->max_dim() : 48); j++) {
|
||||
terrain_type = editing_town ? town->terrain(i,j) : current_terrain->terrain[i][j];
|
||||
if(terrain_type == 3)
|
||||
terrain_type = 2;
|
||||
if(terrain_type == 4)
|
||||
terrain_type = 2;
|
||||
if(terrain_type == 1)
|
||||
terrain_type = 0;
|
||||
if(terrain_type == 37)
|
||||
terrain_type = 36;
|
||||
cTerrain& ter = scenario.ter_types[terrain_type];
|
||||
|
||||
if(ter.frill_for >= 0)
|
||||
terrain_type = ter.frill_for;
|
||||
|
||||
if(editing_town)
|
||||
town->terrain(i,j) = terrain_type;
|
||||
else current_terrain->terrain[i][j] = terrain_type;
|
||||
|
||||
@@ -393,6 +393,13 @@ void writeTerrainToXml(ticpp::Printer&& data, cScenario& scenario) {
|
||||
data.OpenElement("editor");
|
||||
if(ter.shortcut_key > 0 && ter.shortcut_key < '\x7f')
|
||||
data.PushElement("shortcut", ter.shortcut_key);
|
||||
if(ter.frill_for >= 0) {
|
||||
data.OpenElement("frill");
|
||||
if(ter.frill_chance != 10)
|
||||
data.PushAttribute("chance", ter.frill_chance);
|
||||
data.PushText(ter.frill_for);
|
||||
data.CloseElement("frill");
|
||||
}
|
||||
if(ter.obj_num > 0) {
|
||||
data.OpenElement("object");
|
||||
data.PushElement("num", ter.obj_num);
|
||||
|
||||
@@ -1008,6 +1008,9 @@ void readTerrainFromXml(ticpp::Document&& data, cScenario& scenario) {
|
||||
val.clear();
|
||||
edit->GetText(&val, false);
|
||||
the_ter.shortcut_key = val.empty() ? 0 : val[0];
|
||||
} else if(type == "frill") {
|
||||
edit->GetText(&the_ter.frill_for);
|
||||
edit->GetAttributeOrDefault("chance", &the_ter.frill_chance, 10);
|
||||
} else if(type == "object") {
|
||||
std::set<std::string> reqs = {"num", "pos", "size"};
|
||||
Iterator<Element> obj;
|
||||
|
||||
16
test/files/terrain/default_frill.xml
Normal file
16
test/files/terrain/default_frill.xml
Normal file
@@ -0,0 +1,16 @@
|
||||
<terrains boes="2.0.0">
|
||||
<terrain id='0'>
|
||||
<name>Test Terrain</name>
|
||||
<pic>0</pic>
|
||||
<map>0</map>
|
||||
<blockage>move</blockage>
|
||||
<trim>none</trim>
|
||||
<arena>0</arena>
|
||||
<special>
|
||||
<type>none</type>
|
||||
</special>
|
||||
<editor>
|
||||
<frill>0</frill>
|
||||
</editor>
|
||||
</terrain>
|
||||
</terrains>
|
||||
@@ -23,6 +23,7 @@
|
||||
</special>
|
||||
<editor>
|
||||
<shortcut>u</shortcut>
|
||||
<frill chance='30'>9</frill>
|
||||
<object>
|
||||
<num>1</num>
|
||||
<pos x='0' y='0'/>
|
||||
|
||||
@@ -104,6 +104,13 @@ TEST_CASE("Loading a terrain type definition") {
|
||||
doc = xmlDocFromStream(fin, "bad_editor.xml");
|
||||
REQUIRE_THROWS_AS(readTerrainFromXml(move(doc), scen), xBadNode);
|
||||
}
|
||||
SECTION("With a default-chance frill reference") {
|
||||
fin.open("files/terrain/default_frill.xml");
|
||||
doc = xmlDocFromStream(fin, "default_frill.xml");
|
||||
REQUIRE_NOTHROW(readTerrainFromXml(move(doc), scen));
|
||||
CHECK(scen.ter_types[0].frill_for == 0);
|
||||
CHECK(scen.ter_types[0].frill_chance == 10);
|
||||
}
|
||||
SECTION("With the minimal required data") {
|
||||
fin.open("files/terrain/minimal.xml");
|
||||
doc = xmlDocFromStream(fin, "minimal.xml");
|
||||
@@ -141,6 +148,8 @@ TEST_CASE("Loading a terrain type definition") {
|
||||
CHECK(scen.ter_types[0].ground_type == 2);
|
||||
CHECK(scen.ter_types[0].trim_ter == 1);
|
||||
CHECK(scen.ter_types[0].shortcut_key == 'u');
|
||||
CHECK(scen.ter_types[0].frill_for == 9);
|
||||
CHECK(scen.ter_types[0].frill_chance == 30);
|
||||
CHECK(scen.ter_types[0].obj_num == 1);
|
||||
CHECK(scen.ter_types[0].obj_pos == loc(0,0));
|
||||
CHECK(scen.ter_types[0].obj_size == loc(2,1));
|
||||
|
||||
@@ -73,10 +73,12 @@ TEST_CASE("Saving terrain types") {
|
||||
scen.ter_types[0].ground_type = 2;
|
||||
scen.ter_types[0].trim_ter = 1;
|
||||
scen.ter_types[0].shortcut_key = 'u';
|
||||
scen.ter_types[0].frill_for = 5;
|
||||
scen.ter_types[0].frill_chance = 15;
|
||||
scen.ter_types[0].obj_num = 1;
|
||||
scen.ter_types[0].obj_pos = loc(0,0);
|
||||
scen.ter_types[0].obj_size = loc(2,1);
|
||||
in_and_out("basic", scen);
|
||||
in_and_out("full", scen);
|
||||
REQUIRE(scen.ter_types.size() == 1);
|
||||
CHECK(scen.ter_types[0].flag1 == 1);
|
||||
CHECK(scen.ter_types[0].flag2 == 2);
|
||||
@@ -91,8 +93,16 @@ TEST_CASE("Saving terrain types") {
|
||||
CHECK(scen.ter_types[0].ground_type == 2);
|
||||
CHECK(scen.ter_types[0].trim_ter == 1);
|
||||
CHECK(scen.ter_types[0].shortcut_key == 'u');
|
||||
CHECK(scen.ter_types[0].frill_for == 5);
|
||||
CHECK(scen.ter_types[0].frill_chance == 15);
|
||||
CHECK(scen.ter_types[0].obj_num == 1);
|
||||
CHECK(scen.ter_types[0].obj_pos == loc(0,0));
|
||||
CHECK(scen.ter_types[0].obj_size == loc(2,1));
|
||||
}
|
||||
SECTION("With default frill chance") {
|
||||
scen.ter_types[0].frill_for = 5;
|
||||
scen.ter_types[0].frill_chance = 10;
|
||||
in_and_out("default_frill", scen);
|
||||
CHECK(scen.ter_types[0].frill_chance == 10);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user