Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.77 KB | None | 0 0
  1. class RuleEventScript
  2. {
  3. private:
  4. std::string _type;
  5. std::vector<std::pair<size_t, WeightedOptions*> > _eventWeights;
  6. int _firstMonth, _lastMonth, _executionOdds, _maxEvents, _minDifficulty, _maxDifficulty;
  7. std::map<std::string, bool> _researchTriggers;
  8. public:
  9. /// Creates a new event script.
  10. RuleEventScript(const std::string& type);
  11. /// Deletes an event script.
  12. ~RuleEventScript();
  13. /// Loads an event script from yaml.
  14. void load(const YAML::Node& node);
  15. /// Gets the name of the script command.
  16. const std::string &getType() const { return _type; }
  17. /// Gets a list of the event types in this command's event weights for a given month.
  18. std::vector<std::string> getEventTypes(const int month) const;
  19. /// Gets the first month this command will run.
  20. int getFirstMonth() const { return _firstMonth; }
  21. /// Gets the last month this command will run.
  22. int getLastMonth() const { return _lastMonth; }
  23. /// Gets the odds of this command executing.
  24. int getExecutionOdds() const { return _executionOdds; }
  25. /// Gets the maximum number of events this command can generate (during the whole game).
  26. int getMaxArcs() const { return _maxEvents; }
  27. /// Gets the minimum difficulty for this command to run.
  28. int getMinDifficulty() const { return _minDifficulty; }
  29. /// Gets the maximum difficulty for this command to run.
  30. int getMaxDifficulty() const { return _maxDifficulty; }
  31. /// Gets the research triggers that may apply to this command.
  32. const std::map<std::string, bool> &getResearchTriggers() const { return _researchTriggers; }
  33.  
  34. void RuleEventScript::load(const YAML::Node& node)
  35. {
  36. if (const YAML::Node & parent = node["refNode"])
  37. {
  38. load(parent);
  39. }
  40. _type = node["type"].as<std::string>(_type);
  41. _firstMonth = node["firstMonth"].as<int>(_firstMonth);
  42. _lastMonth = node["lastMonth"].as<int>(_lastMonth);
  43. _executionOdds = node["executionOdds"].as<int>(_executionOdds);
  44. _maxEvents = node["maxEvents"].as<int>(_maxEvents);
  45. _minDifficulty = node["minDifficulty"].as<int>(_minDifficulty);
  46. _maxDifficulty = node["maxDifficulty"].as<int>(_maxDifficulty);
  47. _researchTriggers = node["researchTriggers"].as<std::map<std::string, bool> >(_researchTriggers);
  48. if (const YAML::Node &weights = node["eventWeights"])
  49. {
  50. for (YAML::const_iterator nn = weights.begin(); nn != weights.end(); ++nn)
  51. {
  52. WeightedOptions *nw = new WeightedOptions();
  53. nw->load(nn->second);
  54. _eventWeights.push_back(std::make_pair(nn->first.as<size_t>(0), nw));
  55. }
  56. }
  57. Log(LOG_INFO) << "was loaded eventScript = " << _type; //for testing
  58. Log(LOG_INFO) << "it has _eventWeights = " << &_eventWeights; //for testing
  59. Log(LOG_INFO) << "it has _firstMonth = " << _firstMonth; //for testing
  60. Log(LOG_INFO) << "it has _lastMonth = " << _lastMonth; //for testing
  61. Log(LOG_INFO) << "it has _executionOdds = " << _executionOdds; //for testing
  62. Log(LOG_INFO) << "it has _maxEvents = " << _maxEvents; //for testing
  63. Log(LOG_INFO) << "it has _minDifficulty = " << _minDifficulty; //for testing
  64. Log(LOG_INFO) << "it has _maxDifficulty = " << _maxDifficulty; //for testing
  65. Log(LOG_INFO) << "it has _researchTriggers = " << &_researchTriggers; //for testing
  66. }
  67.  
  68. /**
  69. * @param month the month for which we want info.
  70. * @return a list of the possible events for the given month.
  71. */
  72. std::vector<std::string> RuleEventScript::getEventTypes(const int month) const
  73. {
  74. std::vector<std::string> events;
  75. std::vector<std::pair<size_t, WeightedOptions*> >::const_reverse_iterator rw = _eventWeights.rbegin();
  76. while (month < (int)(rw->first))
  77. {
  78. ++rw;
  79. if (rw == _eventWeights.rend())
  80. {
  81. --rw;
  82. break;
  83. }
  84. }
  85. std::vector<std::string> names = rw->second->getNames();
  86. for (std::vector<std::string>::const_iterator i = names.begin(); i != names.end(); ++i)
  87. {
  88. events.push_back(*i);
  89. }
  90. return events;
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement