31 #include <boost/range/adaptors.hpp>
32 #include <boost/range/algorithm/copy.hpp>
36 #define LOG_NG LOG_STREAM(info, log_engine)
42 turn_(scenario_cfg[
"turn_at"].to_int(1)),
43 num_turns_(scenario_cfg[
"turns"].to_int(-1)),
44 has_turn_event_fired_(!scenario_cfg[
"it_is_a_new_turn"].to_bool(true))
47 if (scenario_cfg[
"current_time"].to_int(-17403) == -17403)
60 if(
this == &manager) {
92 | boost::adaptors::transformed(boost::bind(lexical_cast_default<int, std::string>, _1 , 0))
94 , std::back_inserter(output) );
98 int chosen = output[r.
next_random() % output.size()];
111 cfg[
"turn_at"] =
turn_;
116 std::vector<time_of_day>::const_iterator
t;
120 for(std::vector<area_time_of_day>::const_iterator
i =
areas_.begin();
i !=
areas_.end(); ++
i) {
123 if(
i->xsrc.empty() &&
i->ysrc.empty()) {
129 for(t =
i->times.begin(); t !=
i->times.end(); ++
t) {
132 area[
"current_time"] =
i->currentTime;
145 assert(index < static_cast<int>(
areas_.size()) );
152 for ( std::vector<area_time_of_day>::const_reverse_iterator
155 if (
i->hexes.find(loc) !=
i->hexes.end())
156 return i->currentTime;
166 for ( std::vector<area_time_of_day>::const_reverse_iterator
169 if (
i->hexes.find(loc) !=
i->hexes.end())
184 for ( std::vector<area_time_of_day>::const_reverse_iterator
187 if (
i->hexes.find(loc) !=
i->hexes.end())
205 std::vector<int> mod_list;
206 std::vector<int> max_list;
207 std::vector<int> min_list;
215 for (
size_t i = 0;
i != 7; ++
i ) {
217 if (itor != units.
end() &&
218 itor->get_ability_bool(
"illuminates") &&
219 !itor->incapacitated())
226 mod_list.push_back(unit_mod);
227 max_list.push_back(illum.
highest(
"max_value").first);
228 min_list.push_back(illum.
lowest(
"min_value").first);
229 if ( unit_mod > most_add )
231 else if ( unit_mod < most_sub )
235 const bool net_darker = most_add < -most_sub;
238 int best_result = terrain_light;
239 const int base_light = terrain_light + (net_darker ? most_add : most_sub);
240 for (
size_t i = 0;
i != mod_list.size(); ++
i ) {
242 bounded_add(base_light, mod_list[
i], max_list[i], min_list[i]);
244 if ( net_darker && result < best_result )
246 else if ( !net_darker && result > best_result )
261 return !random_start_time.empty()
287 assert(area_index < static_cast<int>(
areas_.size()));
288 areas_[area_index].hexes = locs;
294 assert(area_index < static_cast<int>(
areas_.size()));
297 area.
times = schedule;
305 assert(area_index < static_cast<int>(
areas_.size()));
311 std::vector<std::string> areas;
313 areas.push_back(area.id);
324 return areas_[0].hexes;
336 area.
id = cfg[
"id"].str();
337 area.
xsrc = cfg[
"x"].str();
338 area.
ysrc = cfg[
"y"].str();
341 area.
hexes.insert(locs.begin(), locs.end());
353 area.
currentTime = time_cfg[
"current_time"].to_int(0);
360 if(area_id.empty()) {
365 while(i !=
areas_.end()) {
366 if((*i).id == area_id) {
378 assert(area_index < static_cast<int>(
areas_.size()));
427 const int new_turn = std::max<int>(
num, 1);
428 LOG_NG <<
"changing current turn number from " <<
turn_ <<
" to " << new_turn <<
'\n';
442 set_turn(num, vars, increase_limit_if_needed);
451 new_current_turn_number,
458 const int number_of_times,
459 const int for_turn_number,
460 const int current_time,
461 const bool only_to_allowed_range)
const
463 if (number_of_times == 0)
return 0;
464 int new_current_time = 0;
465 if(only_to_allowed_range) new_current_time = current_time % number_of_times;
466 else new_current_time = (current_time + for_turn_number -
turn_) % number_of_times;
467 while(new_current_time < 0) { new_current_time += number_of_times; }
468 return new_current_time;
479 assert(area_index < static_cast<int>(
areas_.size()));
485 if (area.id == area_id)
491 assert(time < static_cast<int>(area.
times.size()) );
play_controller * controller
bool on_board_with_border(const map_location &loc) const
void set_new_current_times(const int new_current_turn_number)
For a change of the current turn number, sets the current times of the main time and all time areas...
void replace_local_schedule(const std::vector< time_of_day > &schedule, int area_index)
tod_manager & operator=(const tod_manager &manager)
virtual void send_to_wesnothd(const config &, const std::string &="unknown") const
bool has_turn_event_fired_
void replace_schedule(const config &time_cfg)
Replace the time of day schedule.
Add a special kind of assert to validate whether the input from WML doesn't contain any problems that...
bool to_bool(bool def=false) const
void set_turn(const int num, game_data *vars=nullptr, const bool increase_limit_if_needed=true)
Dynamically change the current turn number.
void get_adjacent_tiles(const map_location &a, map_location *res)
Function which, given a location, will place all adjacent locations in res.
const time_of_day & get_time_of_day(int for_turn=0) const
Returns global time of day for the passed turn.
int get_current_area_time(int index) const
void set_area_id(int area_index, const std::string &id)
bool has_tod_bonus_changed_
int lawful_bonus
The % bonus lawful units receive.
GLfloat GLfloat GLfloat v2
GLuint const GLfloat * val
void modify_turns_by_wml(const std::string &mod)
std::set< map_location > hexes
std::pair< int, map_location > highest(const std::string &key, int def=0) const
int light_bonus(int base) const
Returns the light (lawful) bonus for this terrain when the time of day gives a base bonus...
config::attribute_value & get_variable(const std::string &varname)
throws invalid_variablename_exception if varname is no valid variable name.
void modify_turns(const std::string &mod)
const time_of_day & get_previous_time_of_day() const
Object which defines a time of day with associated bonuses, image, sounds etc.
void set_current_time(int time)
bool operator()(T v2) const
void set_number_of_turns_by_wml(int num)
std::vector< time_of_day > times
uint32_t next_random()
Provides the next random draw.
config::attribute_value random_tod_
GLsizei const GLfloat * value
void update_server_information() const
void remove_time_area(const std::string &id)
Removes a time area from config, making it follow the scenario's normal time-of-day sequence...
std::vector< time_of_day > times_
Encapsulates the map of the game.
tod_manager(const config &scenario_cfg=config())
config & add_child(const std::string &key)
static const map_location & null_location()
bool is_time_left()
Function to check the end of turns.
void set_turn_by_wml(const int num, game_data *vars=nullptr, const bool increase_limit_if_needed=true)
Dynamically change the current turn number.
Encapsulates the map of the game.
const terrain_type & get_terrain_info(const t_translation::t_terrain &terrain) const
std::vector< map_location > parse_location_range(const std::string &xvals, const std::string &yvals, bool with_border=false) const
Parses ranges of locations into a vector of locations, using this map's dimensions as bounds...
static const char * output
std::vector< std::string > get_area_ids() const
std::map< std::string, tfilter >::iterator itor
void write_location_range(const std::set< map_location > &locs, config &cfg)
Write a set of locations into a config using ranges, adding keys x=x1,..,xn and y=y1a-y1b,..,yna-ynb.
void set_number_of_turns(int num)
const time_of_day & get_time_of_day_turn(const std::vector< time_of_day > ×, int nturn, const int current_time) const
Returns time of day object in the turn "nturn".
this class does not give synced random results derived classes might do.
const std::set< map_location > & get_area_by_index(int index) const
static void parse_times(const config &cfg, std::vector< time_of_day > &normal_times)
Parse config and add time of day entries into passed vector.
bool string_bool(const std::string &str, bool def)
Convert no, false, off, 0, 0.0 to false, empty to def, and others to true.
GLdouble GLdouble GLdouble r
static lg::log_domain log_engine("engine")
static bool is_start_ToD(const std::string &)
const std::set< map_location > & get_area_by_id(const std::string &id) const
const time_of_day get_illuminated_time_of_day(const unit_map &units, const gamemap &map, const map_location &loc, int for_turn=0) const
Returns time of day object for the passed turn at a location.
int bounded_add(int base, int increment, int max_sum, int min_sum=0)
Returns base + increment, but will not increase base above max_sum, nor decrease it below min_sum...
std::pair< int, map_location > lowest(const std::string &key, int def=0) const
int calculate_current_time(const int number_of_times, const int for_turn_number, const int current_time, const bool only_to_allowed_range=false) const
Computes for the main time or a time area the index of its times where we're currently at...
int get_current_time(const map_location &loc=map_location::null_location()) const
void replace_area_locations(int index, const std::set< map_location > &locs)
void add_time_area(const gamemap &map, const config &cfg)
Adds a new local time area from config, making it follow its own time-of-day sequence.
int apply_modifier(const int number, const std::string &amount, const int minimum)
const std::vector< time_of_day > & times(const map_location &loc=map_location::null_location()) const
Standard logging facilities (interface).
Container associating units to locations.
std::vector< area_time_of_day > areas_
std::vector< std::string > split(std::string const &val, const char c, const int flags)
Splits a (comma-)separated string into a vector of pieces.
int get_composite_value() const
void resolve_random(random_new::rng &r)
handles random_start_time, should be called before the game starts.
unit_iterator find(size_t id)
bool next_turn(game_data *vars)
Function to move to the next turn.
A config object defines a single node in a WML file, with access to child nodes.
GLsizei const GLcharARB ** string