]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
drop.hpp
authorClyne Sullivan <tullivan99@gmail.com>
Sun, 30 Apr 2017 23:57:28 +0000 (19:57 -0400)
committerClyne Sullivan <tullivan99@gmail.com>
Sun, 30 Apr 2017 23:57:28 +0000 (19:57 -0400)
include/components/drop.hpp [new file with mode: 0644]

diff --git a/include/components/drop.hpp b/include/components/drop.hpp
new file mode 100644 (file)
index 0000000..80502a1
--- /dev/null
@@ -0,0 +1,39 @@
+#ifndef COMPONENTS_DROP_HPP
+#define COMPONENTS_DROP_HPP
+
+#include "base.hpp"
+
+#include <inventory.hpp>
+#include <random.hpp>
+
+#include <string>
+#include <vector>
+
+using DropInfo = std::pair<std::string, int>;
+
+struct Drop : public Component {
+       Drop(void) {}
+       Drop(XMLElement* imp, XMLElement* def) {
+               fromXML(imp, def);
+       }
+
+       std::vector<DropInfo> items;
+
+       void fromXML(XMLElement* imp, XMLElement* def) final {
+               (void)imp;
+               
+               auto dxml = def->FirstChildElement("item");
+               while (dxml != nullptr) {
+                       int min = dxml->IntAttribute("min");
+                       int max = dxml->IntAttribute("max");
+                       int count = randGet() % (max - min) + min;
+
+                       items.emplace_back(dxml->StrAttribute("name"), count);
+
+                       dxml = dxml->NextSiblingElement();
+               }
+       }
+
+};
+
+#endif // COMPONENTS_DROP_HPP