designs_bank.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #ifndef __DESIGNS_BANK
  2. #define __DESIGNS_BANK
  3. #include <string>
  4. #include <unordered_map>
  5. struct DesignsBank {
  6. std::unordered_map<tag_t,Design> bank;
  7. counters::Counts counts;
  8. counters::Counts bonus_a_counts;
  9. counters::Counts bonus_b_counts;
  10. void copy(const Design& d) {
  11. if (bank.count(d.tag) != 0) {
  12. throw std::runtime_error("Duplicate design tag: " + d.name);
  13. }
  14. bank[d.tag] = d;
  15. counts.init(d.tag, d.level, d.count);
  16. if (d.bonus_a_count > 0) {
  17. bonus_a_counts.init(d.tag, d.level, d.bonus_a_count);
  18. }
  19. if (d.bonus_b_count > 0) {
  20. bonus_b_counts.init(d.tag, d.level, d.bonus_b_count);
  21. }
  22. }
  23. const Design& get(tag_t tag) const {
  24. auto i = bank.find(tag);
  25. if (i == bank.end()) {
  26. throw std::runtime_error("Invalid designs tag");
  27. }
  28. return i->second;
  29. }
  30. };
  31. inline DesignsBank& __designs__() {
  32. static DesignsBank ret;
  33. return ret;
  34. }
  35. inline const DesignsBank& designs() {
  36. return __designs__();
  37. }
  38. inline void init_design_copy(const Design& d) {
  39. __designs__().copy(d);
  40. }
  41. #endif