Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class RuleEventScript
- {
- private:
- std::string _type;
- std::vector<std::pair<size_t, WeightedOptions*> > _eventWeights;
- int _firstMonth, _lastMonth, _executionOdds, _maxEvents, _minDifficulty, _maxDifficulty;
- std::map<std::string, bool> _researchTriggers;
- public:
- /// Creates a new event script.
- RuleEventScript(const std::string& type);
- /// Deletes an event script.
- ~RuleEventScript();
- /// Loads an event script from yaml.
- void load(const YAML::Node& node);
- /// Gets the name of the script command.
- const std::string &getType() const { return _type; }
- /// Gets a list of the event types in this command's event weights for a given month.
- std::vector<std::string> getEventTypes(const int month) const;
- /// Gets the first month this command will run.
- int getFirstMonth() const { return _firstMonth; }
- /// Gets the last month this command will run.
- int getLastMonth() const { return _lastMonth; }
- /// Gets the odds of this command executing.
- int getExecutionOdds() const { return _executionOdds; }
- /// Gets the maximum number of events this command can generate (during the whole game).
- int getMaxArcs() const { return _maxEvents; }
- /// Gets the minimum difficulty for this command to run.
- int getMinDifficulty() const { return _minDifficulty; }
- /// Gets the maximum difficulty for this command to run.
- int getMaxDifficulty() const { return _maxDifficulty; }
- /// Gets the research triggers that may apply to this command.
- const std::map<std::string, bool> &getResearchTriggers() const { return _researchTriggers; }
- void RuleEventScript::load(const YAML::Node& node)
- {
- if (const YAML::Node & parent = node["refNode"])
- {
- load(parent);
- }
- _type = node["type"].as<std::string>(_type);
- _firstMonth = node["firstMonth"].as<int>(_firstMonth);
- _lastMonth = node["lastMonth"].as<int>(_lastMonth);
- _executionOdds = node["executionOdds"].as<int>(_executionOdds);
- _maxEvents = node["maxEvents"].as<int>(_maxEvents);
- _minDifficulty = node["minDifficulty"].as<int>(_minDifficulty);
- _maxDifficulty = node["maxDifficulty"].as<int>(_maxDifficulty);
- _researchTriggers = node["researchTriggers"].as<std::map<std::string, bool> >(_researchTriggers);
- if (const YAML::Node &weights = node["eventWeights"])
- {
- for (YAML::const_iterator nn = weights.begin(); nn != weights.end(); ++nn)
- {
- WeightedOptions *nw = new WeightedOptions();
- nw->load(nn->second);
- _eventWeights.push_back(std::make_pair(nn->first.as<size_t>(0), nw));
- }
- }
- Log(LOG_INFO) << "was loaded eventScript = " << _type; //for testing
- Log(LOG_INFO) << "it has _eventWeights = " << &_eventWeights; //for testing
- Log(LOG_INFO) << "it has _firstMonth = " << _firstMonth; //for testing
- Log(LOG_INFO) << "it has _lastMonth = " << _lastMonth; //for testing
- Log(LOG_INFO) << "it has _executionOdds = " << _executionOdds; //for testing
- Log(LOG_INFO) << "it has _maxEvents = " << _maxEvents; //for testing
- Log(LOG_INFO) << "it has _minDifficulty = " << _minDifficulty; //for testing
- Log(LOG_INFO) << "it has _maxDifficulty = " << _maxDifficulty; //for testing
- Log(LOG_INFO) << "it has _researchTriggers = " << &_researchTriggers; //for testing
- }
- /**
- * @param month the month for which we want info.
- * @return a list of the possible events for the given month.
- */
- std::vector<std::string> RuleEventScript::getEventTypes(const int month) const
- {
- std::vector<std::string> events;
- std::vector<std::pair<size_t, WeightedOptions*> >::const_reverse_iterator rw = _eventWeights.rbegin();
- while (month < (int)(rw->first))
- {
- ++rw;
- if (rw == _eventWeights.rend())
- {
- --rw;
- break;
- }
- }
- std::vector<std::string> names = rw->second->getNames();
- for (std::vector<std::string>::const_iterator i = names.begin(); i != names.end(); ++i)
- {
- events.push_back(*i);
- }
- return events;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement