void tod_manager::set_start_ToD(config &level, int current_turn) { if (!level["current_tod"].empty()) { set_time_of_day(level["current_tod"]); return; } std::string random_start_time = level["random_start_time"]; if (tod_manager::is_start_ToD(random_start_time)) { std::vector<std::string> start_strings = utils::split(random_start_time, ',', utils::STRIP_SPACES | utils::REMOVE_EMPTY); if (utils::string_bool(random_start_time,false)) { // We had boolean value set_time_of_day(rand()%times_.size()); } else { set_time_of_day(atoi(start_strings[rand()%start_strings.size()].c_str()) - 1); } } else { // We have to set right ToD for oldsaves set_time_of_day((current_turn - 1) % times_.size()); } // Setting ToD to level data level["current_tod"] = currentTime_; }
void tod_manager::set_turn(unsigned int num) { const unsigned int old_num = turn_; // Correct ToD int current_time = (currentTime_ + num - old_num) % times_.size(); if (current_time < 0) { current_time += times_.size(); } set_time_of_day(current_time); if(static_cast<int>(num) > num_turns_ && num_turns_ != -1) { set_number_of_turns(num); } turn_ = num; LOG_NG << "changed current turn number from " << old_num << " to " << num << '\n'; }
void tod_manager::set_turn(unsigned int num) { VALIDATE(times_.size(), _("No time of day has been defined.")); const unsigned int old_num = turn_; // Correct ToD int current_time = (num - 1) % times_.size(); if (current_time < 0) { current_time += times_.size(); } set_time_of_day(current_time); if(static_cast<int>(num) > num_turns_ && num_turns_ != -1) { this->add_turns(num_turns_ - num); } turn_ = num; LOG_NG << "changed current turn number from " << old_num << " to " << num << '\n'; }