Tests for saving and loading shops
- Fix shop name not being loaded from the file - Fix skills in shops not storing the skill ID
This commit is contained in:
@@ -209,6 +209,7 @@ void cShop::replaceSpecial(size_t i, eShopItemType type, int n) {
|
||||
items[i].item = store_alchemy(n);
|
||||
else if(type == eShopItemType::SKILL) {
|
||||
items[i].item.graphic_num = 108;
|
||||
items[i].item.item_level = n;
|
||||
items[i].item.full_name = get_str("skills", n * 2 + 1);
|
||||
} else if(type == eShopItemType::TREASURE) {
|
||||
items[i].item.graphic_num = 45;
|
||||
|
@@ -554,7 +554,7 @@ static void readShopFromXml(ticpp::Element& data, cShop& shop) {
|
||||
}
|
||||
if(!reqs.empty())
|
||||
throw xMissingElem("special", *reqs.begin(), entry->Row(), entry->Column(), fname);
|
||||
shop.addSpecial(name, descr, icon, node, cost, amount);
|
||||
shop.addSpecial(title, descr, icon, node, cost, amount);
|
||||
} else {
|
||||
eShopItemType itype;
|
||||
int n = 0;
|
||||
|
85
test/files/scenario/shop.xml
Normal file
85
test/files/scenario/shop.xml
Normal file
@@ -0,0 +1,85 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
|
||||
<scenario boes="2.0.0">
|
||||
<title>Test Scenario</title>
|
||||
<icon>0</icon>
|
||||
<id>campaign</id>
|
||||
<version>2.6.7</version>
|
||||
<language>en-US</language>
|
||||
<author>
|
||||
<name>BoE Test Suite</name>
|
||||
<email>nowhere@example.com</email>
|
||||
</author>
|
||||
<text>
|
||||
<teaser>Teaser 1</teaser>
|
||||
<teaser>Teaser 2</teaser>
|
||||
<intro-msg>Welcome to the test scenario!</intro-msg>
|
||||
</text>
|
||||
<ratings>
|
||||
<content>R</content>
|
||||
<difficulty>3</difficulty>
|
||||
</ratings>
|
||||
<flags>
|
||||
<adjust-difficulty>true</adjust-difficulty>
|
||||
<legacy>false</legacy>
|
||||
<custom-graphics>false</custom-graphics>
|
||||
</flags>
|
||||
<creator>
|
||||
<type>oboe</type>
|
||||
<version>2.0.0</version>
|
||||
<os></os>
|
||||
</creator>
|
||||
<game>
|
||||
<num-towns>0</num-towns>
|
||||
<out-width>0</out-width>
|
||||
<out-height>0</out-height>
|
||||
<start-town>7</start-town>
|
||||
<town-start x="24" y="28" />
|
||||
<outdoor-start x="1" y="3" />
|
||||
<sector-start x="12" y="21" />
|
||||
<shop>
|
||||
<name>The Shop of Everything</name>
|
||||
<type>live</type>
|
||||
<prompt>shop</prompt>
|
||||
<face>0</face>
|
||||
<entries>
|
||||
<item quantity='3'>10</item>
|
||||
<item quantity='infinite'>11</item>
|
||||
<item chance='42'>12</item>
|
||||
<mage-spell>30</mage-spell>
|
||||
<priest-spell>31</priest-spell>
|
||||
<recipe>14</recipe>
|
||||
<skill>9</skill>
|
||||
<treasure>2</treasure>
|
||||
<class>147</class>
|
||||
<heal>2</heal>
|
||||
<special>
|
||||
<quantity>42</quantity>
|
||||
<node>100</node>
|
||||
<icon>0</icon>
|
||||
<name>Special Shop Item the First</name>
|
||||
<description><![CDATA[ Haha! It's a magic purchase!]]></description>
|
||||
</special>
|
||||
<special>
|
||||
<quantity>infinite</quantity>
|
||||
<node>101</node>
|
||||
<icon>12</icon>
|
||||
<name>Special Shop Item the Second</name>
|
||||
<description><![CDATA[Another magic purchase!]]></description>
|
||||
</special>
|
||||
<special>
|
||||
<quantity>1</quantity>
|
||||
<cost>12000</cost>
|
||||
<node>102</node>
|
||||
<icon>9</icon>
|
||||
<name>Special Shop Item the Third</name>
|
||||
<description><![CDATA[Yay for the magic purchase!]]></description>
|
||||
</special>
|
||||
</entries>
|
||||
</shop>
|
||||
</game>
|
||||
<editor>
|
||||
<default-ground>2</default-ground>
|
||||
<last-out-section x="0" y="0" />
|
||||
<last-town>0</last-town>
|
||||
</editor>
|
||||
</scenario>
|
@@ -5,6 +5,7 @@
|
||||
#include "dialog.hpp"
|
||||
#include "catch.hpp"
|
||||
#include "scenario.hpp"
|
||||
#include "restypes.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace ticpp;
|
||||
@@ -242,4 +243,63 @@ TEST_CASE("Loading a new-format scenario record") {
|
||||
REQUIRE_THROWS_AS(readScenarioFromXml(move(doc), scen), xBadNode);
|
||||
}
|
||||
}
|
||||
SECTION("With a shop") {
|
||||
// Loading shops requires strings to be available
|
||||
// Here we fetch them from the rsrc dir, rather than the data dir
|
||||
ResMgr::pushPath<StringRsrc>("../rsrc/strings");
|
||||
SECTION("Valid shop") {
|
||||
fin.open("files/scenario/shop.xml");
|
||||
doc = xmlDocFromStream(fin, "shop.xml");
|
||||
REQUIRE_NOTHROW(readScenarioFromXml(move(doc), scen));
|
||||
REQUIRE(scen.shops.size() == 1);
|
||||
REQUIRE(scen.shops[0].size() == 13);
|
||||
CHECK(scen.shops[0].getFace() == 0);
|
||||
CHECK(scen.shops[0].getName() == "The Shop of Everything");
|
||||
CHECK(scen.shops[0].getType() == eShopType::NORMAL);
|
||||
CHECK(scen.shops[0].getPrompt() == eShopPrompt::SHOPPING);
|
||||
CHECK(scen.shops[0].getItem(0).type == eShopItemType::ITEM);
|
||||
CHECK(scen.shops[0].getItem(0).quantity == 3);
|
||||
CHECK(scen.shops[0].getItem(0).index == 10);
|
||||
CHECK(scen.shops[0].getItem(1).type == eShopItemType::ITEM);
|
||||
CHECK(scen.shops[0].getItem(1).quantity == 0);
|
||||
CHECK(scen.shops[0].getItem(1).index == 11);
|
||||
CHECK(scen.shops[0].getItem(2).type == eShopItemType::OPT_ITEM);
|
||||
CHECK(scen.shops[0].getItem(2).quantity == 42000);
|
||||
CHECK(scen.shops[0].getItem(2).index == 12);
|
||||
CHECK(scen.shops[0].getItem(3).type == eShopItemType::MAGE_SPELL);
|
||||
CHECK(scen.shops[0].getItem(3).item.item_level == 30);
|
||||
CHECK(scen.shops[0].getItem(4).type == eShopItemType::PRIEST_SPELL);
|
||||
CHECK(scen.shops[0].getItem(4).item.item_level == 31);
|
||||
CHECK(scen.shops[0].getItem(5).type == eShopItemType::ALCHEMY);
|
||||
CHECK(scen.shops[0].getItem(5).item.item_level == 14);
|
||||
CHECK(scen.shops[0].getItem(6).type == eShopItemType::SKILL);
|
||||
CHECK(scen.shops[0].getItem(6).item.item_level == 9);
|
||||
CHECK(scen.shops[0].getItem(7).type == eShopItemType::TREASURE);
|
||||
CHECK(scen.shops[0].getItem(7).item.item_level == 2);
|
||||
CHECK(scen.shops[0].getItem(8).type == eShopItemType::CLASS);
|
||||
CHECK(scen.shops[0].getItem(8).item.special_class == 147);
|
||||
CHECK(scen.shops[0].getItem(9).type == eShopItemType::CURE_DISEASE);
|
||||
CHECK(scen.shops[0].getItem(10).type == eShopItemType::CALL_SPECIAL);
|
||||
CHECK(scen.shops[0].getItem(10).quantity == 42);
|
||||
CHECK(scen.shops[0].getItem(10).item.graphic_num == 0);
|
||||
CHECK(scen.shops[0].getItem(10).item.item_level == 100);
|
||||
CHECK(scen.shops[0].getItem(10).item.value == 0);
|
||||
CHECK(scen.shops[0].getItem(10).item.full_name == "Special Shop Item the First");
|
||||
CHECK(scen.shops[0].getItem(10).item.desc == " Haha! It's a magic purchase!");
|
||||
CHECK(scen.shops[0].getItem(11).type == eShopItemType::CALL_SPECIAL);
|
||||
CHECK(scen.shops[0].getItem(11).quantity == 0);
|
||||
CHECK(scen.shops[0].getItem(11).item.graphic_num == 12);
|
||||
CHECK(scen.shops[0].getItem(11).item.item_level == 101);
|
||||
CHECK(scen.shops[0].getItem(11).item.value == 0);
|
||||
CHECK(scen.shops[0].getItem(11).item.full_name == "Special Shop Item the Second");
|
||||
CHECK(scen.shops[0].getItem(11).item.desc == "Another magic purchase!");
|
||||
CHECK(scen.shops[0].getItem(12).type == eShopItemType::CALL_SPECIAL);
|
||||
CHECK(scen.shops[0].getItem(12).quantity == 1);
|
||||
CHECK(scen.shops[0].getItem(12).item.graphic_num == 9);
|
||||
CHECK(scen.shops[0].getItem(12).item.item_level == 102);
|
||||
CHECK(scen.shops[0].getItem(12).item.value == 12000);
|
||||
CHECK(scen.shops[0].getItem(12).item.full_name == "Special Shop Item the Third");
|
||||
CHECK(scen.shops[0].getItem(12).item.desc == "Yay for the magic purchase!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -6,6 +6,7 @@
|
||||
#include "catch.hpp"
|
||||
#include "scenario.hpp"
|
||||
#include "regtown.hpp"
|
||||
#include "restypes.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace ticpp;
|
||||
@@ -164,6 +165,78 @@ TEST_CASE("Saving a scenario record") {
|
||||
CHECK(scen.quests[2].bank2 == -1);
|
||||
CHECK(scen.quests[2].name == "Test Quest 3");
|
||||
}
|
||||
SECTION("With a shop") {
|
||||
// Loading/building shops requires strings to be available
|
||||
// Here we fetch them from the rsrc dir, rather than the data dir
|
||||
ResMgr::pushPath<StringRsrc>("../rsrc/strings");
|
||||
cItem dummy_item('alch');
|
||||
scen.shops.resize(3);
|
||||
scen.shops[0] = cShop('junk');
|
||||
scen.shops[1] = cShop('heal');
|
||||
scen.shops[2].setName("The Test Shop");
|
||||
scen.shops[2].setType(eShopType::NORMAL);
|
||||
scen.shops[2].setPrompt(eShopPrompt::SHOPPING);
|
||||
scen.shops[2].setFace(17);
|
||||
scen.shops[2].addItem(1, dummy_item, 0);
|
||||
scen.shops[2].addItem(2, dummy_item, 5, 10);
|
||||
scen.shops[2].addSpecial(eShopItemType::ALCHEMY, 3);
|
||||
scen.shops[2].addSpecial(eShopItemType::CLASS, 4);
|
||||
scen.shops[2].addSpecial(eShopItemType::CURE_ACID);
|
||||
scen.shops[2].addSpecial(eShopItemType::CURE_POISON);
|
||||
scen.shops[2].addSpecial(eShopItemType::MAGE_SPELL, 5);
|
||||
scen.shops[2].addSpecial(eShopItemType::PRIEST_SPELL, 6);
|
||||
scen.shops[2].addSpecial(eShopItemType::REMOVE_CURSE);
|
||||
scen.shops[2].addSpecial(eShopItemType::SKILL, 7);
|
||||
scen.shops[2].addSpecial(eShopItemType::TREASURE, 0);
|
||||
scen.shops[2].addSpecial("Magic!", "This is magic!", 24, 100, 12, 1);
|
||||
in_and_out("shops", scen);
|
||||
REQUIRE(scen.shops.size() == 3);
|
||||
REQUIRE(scen.shops[0].size() == 10);
|
||||
CHECK(scen.shops[0].getItem(0).type == eShopItemType::TREASURE);
|
||||
CHECK(scen.shops[0].getItem(0).item.item_level == 1);
|
||||
CHECK(scen.shops[0].getItem(4).item.item_level == 2);
|
||||
CHECK(scen.shops[0].getItem(7).item.item_level == 3);
|
||||
CHECK(scen.shops[0].getItem(9).item.item_level == 4);
|
||||
REQUIRE(scen.shops[1].size() == 9);
|
||||
CHECK(scen.shops[1].getItem(0).type == eShopItemType::HEAL_WOUNDS);
|
||||
CHECK(scen.shops[1].getItem(1).type == eShopItemType::CURE_POISON);
|
||||
CHECK(scen.shops[1].getItem(2).type == eShopItemType::CURE_DISEASE);
|
||||
CHECK(scen.shops[1].getItem(3).type == eShopItemType::CURE_PARALYSIS);
|
||||
CHECK(scen.shops[1].getItem(4).type == eShopItemType::CURE_DUMBFOUNDING);
|
||||
CHECK(scen.shops[1].getItem(5).type == eShopItemType::REMOVE_CURSE);
|
||||
CHECK(scen.shops[1].getItem(6).type == eShopItemType::DESTONE);
|
||||
CHECK(scen.shops[1].getItem(7).type == eShopItemType::RAISE_DEAD);
|
||||
CHECK(scen.shops[1].getItem(8).type == eShopItemType::RESURRECT);
|
||||
REQUIRE(scen.shops[2].size() == 12);
|
||||
CHECK(scen.shops[2].getItem(0).type == eShopItemType::ITEM);
|
||||
CHECK(scen.shops[2].getItem(0).index == 1);
|
||||
CHECK(scen.shops[2].getItem(0).quantity == 0);
|
||||
CHECK(scen.shops[2].getItem(1).type == eShopItemType::OPT_ITEM);
|
||||
CHECK(scen.shops[2].getItem(1).index == 2);
|
||||
CHECK(scen.shops[2].getItem(1).quantity == 10005);
|
||||
CHECK(scen.shops[2].getItem(2).type == eShopItemType::ALCHEMY);
|
||||
CHECK(scen.shops[2].getItem(2).item.item_level == 3);
|
||||
CHECK(scen.shops[2].getItem(3).type == eShopItemType::CLASS);
|
||||
CHECK(scen.shops[2].getItem(3).item.special_class == 4);
|
||||
CHECK(scen.shops[2].getItem(4).type == eShopItemType::CURE_ACID);
|
||||
CHECK(scen.shops[2].getItem(5).type == eShopItemType::CURE_POISON);
|
||||
CHECK(scen.shops[2].getItem(6).type == eShopItemType::MAGE_SPELL);
|
||||
CHECK(scen.shops[2].getItem(6).item.item_level == 5);
|
||||
CHECK(scen.shops[2].getItem(7).type == eShopItemType::PRIEST_SPELL);
|
||||
CHECK(scen.shops[2].getItem(7).item.item_level == 6);
|
||||
CHECK(scen.shops[2].getItem(8).type == eShopItemType::REMOVE_CURSE);
|
||||
CHECK(scen.shops[2].getItem(9).type == eShopItemType::SKILL);
|
||||
CHECK(scen.shops[2].getItem(9).item.item_level == 7);
|
||||
CHECK(scen.shops[2].getItem(10).type == eShopItemType::TREASURE);
|
||||
CHECK(scen.shops[2].getItem(10).item.item_level == 0);
|
||||
CHECK(scen.shops[2].getItem(11).type == eShopItemType::CALL_SPECIAL);
|
||||
CHECK(scen.shops[2].getItem(11).quantity == 1);
|
||||
CHECK(scen.shops[2].getItem(11).item.value == 12);
|
||||
CHECK(scen.shops[2].getItem(11).item.item_level == 100);
|
||||
CHECK(scen.shops[2].getItem(11).item.graphic_num == 24);
|
||||
CHECK(scen.shops[2].getItem(11).item.full_name == "Magic!");
|
||||
CHECK(scen.shops[2].getItem(11).item.desc == "This is magic!");
|
||||
}
|
||||
SECTION("With some empty strings, only trailing ones are stripped") {
|
||||
scen.spec_strs.resize(12);
|
||||
scen.spec_strs[3] = "Hello World!";
|
||||
|
Reference in New Issue
Block a user