return true;
}
-void InventorySystem::add(const std::string& name, int count)
+void InventorySystem::add(const std::string& name, int count, int slot)
{
- auto i = std::find_if(items.begin(), items.end(),
- [&name](const InventoryEntry& ie) {
- // either matching item that isn't filled, or empty slow
- return (ie.item != nullptr && ie.item->name == name && ie.count < ie.item->stackSize) || ie.count == 0;
- });
+ auto& ie = items[slot];
- if (i != items.end()) {
- auto& ie = *i;
+ if (isGoodEntry(ie)) {
+ if (ie.item->name != name)
+ return; // TODO behavior?
+ ie.count += count;
+ } else {
+ ie.item = &itemList[name];
+ ie.count = count;
+ }
- // update the slot
- if (!isGoodEntry(ie)) {
- ie.item = &itemList[name];
- ie.count = count;
- } else {
- ie.count += count;
- }
+ if (ie.count > ie.item->stackSize) {
+ int diff = ie.count - ie.item->stackSize;
+ ie.count = ie.item->stackSize;
+ add(name, diff);
+ }
+}
- // handle overflow
- if (ie.count > ie.item->stackSize) {
- int diff = ie.count - ie.item->stackSize;
- ie.count = ie.item->stackSize;
- add(name, diff);
+void InventorySystem::add(const std::string& name, int count)
+{
+ for (unsigned int i = 0; i < items.size(); i++) {
+ if ((items[i].item != nullptr && items[i].item->name == name
+ && items[i].count < items[i].item->stackSize)
+ || items[i].count == 0) {
+ add(name, count, static_cast<int>(i));
+ break;
}
}
}
// signature?
s << "831998\n";
+ int idx = 0;
for (const auto& i : items) {
if (i.item != nullptr && i.count > 0)
- s << std::string(i.item->name) << '\n' << i.count << '\n';
+ s << std::string(i.item->name) << '\n' << i.count << '\n' << idx << '\n';
+ idx++;
}
// end of list?
if (std::stoi(lines[0]) != 831998)
UserError("Save file signature is invalid... (delete it)");
- for (unsigned int i = 1; i < lines.size(); i += 2) {
+ for (unsigned int i = 1; i < lines.size(); i += 3) {
if (lines[i].size() > 0) {
int count = std::stoi(lines[i + 1]);
+ int slot = std::stoi(lines[i + 2]);
if (count > 0)
- add(lines[i], count);
+ add(lines[i], count, slot);
}
}
}
if (!dialogRun.load()) {
// copy entity, windows destroys the original after thread detach
+ dialogRun.store(true);
std::thread([e, &pos, &dim, &d, &name] {
std::string questAssignedText;
int newIndex;
auto exml = WorldSystem::getXML()->FirstChildElement("Dialog");
- dialogRun.store(true);
if (e.has_component<Direction>())
d.talking = true;
} else {
UISystem::dialogBox(name.name, "Finish my quest u nug");
UISystem::waitForDialog();
- return;
+ goto END;
}
// oldidx = d.index;
// d.index = qxml->UnsignedAttribute("fail");
else if (exml->QueryIntAttribute("nextid", &newIndex) == XML_NO_ERROR)
d.index = newIndex;
}
-
+END:
d.talking = false;
dialogRun.store(false);
}).detach();
<text id="0" nextid="1">
<give name="Hunters Bow" count="1"/>
<give name="Arrow" count="50"/>
- <option name="Yes" />
- <content>
+ <option name="Yes"/>
+ <content>
Hey there! The name's Bob. Good to see you've finally woken up from your nap by the cliff there... lol
</content>
</text>
<text id="1" pause="true" nextid="2">
- <quest assign="Check out m'swag, man!" desc="Go inside Bob's house and check out the stuff he has.">
+ <quest assign="Check out m'swag, man!" desc="Go inside Bob's house and check out the stuff he has.">
Debug, 5,
Reward,
Dank MayMay, 50
</quest>
- <content>
+ <content>
Looks like you've got yourself pretty empty handed... you know, I have a simple solution for that. Come on inside, I have somethin' to show you.
</content>
</text>