36 #include <SDL_timer.h> 42 #define LOG_NG LOG_STREAM(info, log_engine) 43 #define DBG_NG LOG_STREAM(debug, log_engine) 49 pathfind_manager_(new
pathfind::manager(level)),
56 undo_stack_(new
actions::undo_list(level.child(
"undo_stack"))),
57 player_number_(level[
"playing_team"].to_int() + 1),
58 next_player_number_(level[
"next_player_number"].to_int(player_number_ + 1)),
59 do_healing_(level[
"do_healing"].to_bool(false)),
60 init_side_done_(level[
"init_side_done"].to_bool(false)),
61 start_event_fired_(!level[
"playing_team"].empty()),
62 server_request_number_(level[
"server_request_number"].to_int()),
66 if(
const config& endlevel_cfg = level.
child(
"end_level_data")) {
68 el_data.
read(endlevel_cfg);
94 if(
const config& endlevel_cfg = level.
child(
"end_level_data")) {
96 el_data.
read(endlevel_cfg);
107 int positions = 0, liked = 0;
110 for(
int i = -8;
i != 8; ++
i) {
111 for(
int j = -8; j != +8; ++j) {
115 if(std::count(terrain.begin(),terrain.end(),map[pos2])) {
122 return (100*liked)/positions;
143 std::vector<placing_info> placings;
150 for(
int p = 1;
p <= num_pos; ++
p) {
157 placings.push_back(obj);
162 std::stable_sort(placings.begin(),placings.end());
163 std::set<int> placed;
164 std::set<map_location> positions_taken;
166 for (std::vector<placing_info>::const_iterator
i = placings.begin();
i != placings.end() &&
static_cast<int>(placed.size()) != side_num - 1; ++
i) {
167 if(placed.count(
i->side) == 0 && positions_taken.count(
i->pos) == 0) {
168 placed.insert(
i->side);
169 positions_taken.insert(
i->pos);
171 LOG_NG <<
"placing side " <<
i->side <<
" at " <<
i->pos << std::endl;
180 if (level[
"modify_placing"].to_bool()) {
181 LOG_NG <<
"modifying placing..." << std::endl;
185 LOG_NG <<
"initialized time of day regions... " << (SDL_GetTicks() - pc.
ticks()) << std::endl;
190 LOG_NG <<
"initialized teams... " << (SDL_GetTicks() - pc.
ticks()) << std::endl;
194 std::vector<team_builder_ptr> team_builders;
200 const std::string &
controller = side[
"controller"];
201 if (controller ==
"human" && side[
"is_local"].to_bool(
true)) {
209 team_builders.push_back(tb_ptr);
227 std::string label_cat =
"side:" + std::to_string(
i + 1);
277 castle_cost_calculator(
const gamemap& map,
const team & view_team) :
283 virtual double cost(
const map_location& loc,
const double)
const 285 if(!map_.is_castle(loc))
288 if ( use_shroud_ && viewer_.shrouded(loc) )
297 const bool use_shroud_;
319 }
catch(
const std::out_of_range&) {
355 if(view_team.
shrouded(recruit_loc)) {
363 castle_cost_calculator calc(map, view_team);
371 return !rt.
steps.empty();
372 }
catch(
const std::out_of_range&) {
390 return leader->can_recruit() && leader->side() == side &&
can_recruit_from(*leader);
394 if ( leader->can_recruit() && leader->side() == side &&
can_recruit_on(*leader, hex) ) {
const std::unique_ptr< reports > reports_
void read(const config &cfg)
std::unique_ptr< gamemap > map_
bool is_keep(const map_location &loc) const
const std::unique_ptr< actions::undo_list > undo_stack_
undo_stack_ is never nullptr.
config & child(config_key_type key, int n=0)
Returns the nth child with the given key, or a reference to an invalid config if there is none...
int h() const
Effective map height.
void build_team_stage_two(team_builder_ptr tb_ptr)
std::unique_ptr< game_lua_kernel > lua_kernel_
virtual const unit_map & units() const override
This class represents a single unit of a specific type.
bool is_castle(const map_location &loc) const
std::vector< std::string > & hidden_label_categories_ref()
bool can_recruit_on(const map_location &leader_loc, const map_location &recruit_loc, int side) const
Checks to see if a leader at leader_loc could recruit on recruit_loc.
game_events::wmi_manager & get_wml_menu_items()
unsigned child_count(config_key_type key) const
const randomness::mt_rng & rng() const
map_location find_vacant_tile(const map_location &loc, VACANT_TILE_TYPE vacancy, const unit *pass_check, const team *shroud_check, const game_board *board)
Function that will find a location on the board that is as near to loc as possible, but which is unoccupied by any units.
child_itors child_range(config_key_type key)
int server_request_number_
static void progress(loading_stage stage=loading_stage::none)
void resolve_random(randomness::rng &r)
handles random_start_time, should be called before the game starts.
virtual const gamemap & map() const override
bool do_healing_
True if healing should be done at the beginning of the next side turn.
bool on_board(const map_location &loc) const
Tell if a location is on the map.
const std::unique_ptr< game_events::manager > events_manager_
Unit and team statistics.
void merge_with(const config &c)
Merge config 'c' into this config, overwriting this config's values.
This class stores all the data for a single 'side' (in game nomenclature).
map_location plus(int x_diff, int y_diff) const
std::vector< map_location > steps
std::vector< team > teams_
bool can_recruit_from(const map_location &leader_loc, int side) const
Checks to see if a leader at leader_loc could recruit somewhere.
RAII class to use rng_deterministic in the current scope.
Structure which holds a single route between one location and another.
Encapsulates the map of the game.
int num_valid_starting_positions() const
std::unique_ptr< pathfind::manager > pathfind_manager_
bool carryover_report
Should a summary of the scenario outcome be displayed?
static const ::config * terrain
The terrain used to create the cache.
static int placing_score(const config &side, const gamemap &map, const map_location &pos)
bool has_visible_unit(const map_location &loc, const team &team, bool see_all=false) const
bool is_ignored(const std::string &nick)
Encapsulates the map of the game.
unit_iterator find(std::size_t id)
bool shrouded(const map_location &loc) const
int w() const
Effective map width.
transient_end_level transient
std::shared_ptr< team_builder > team_builder_ptr
static bool operator<(const placing_info &a, const placing_info &b)
map_location starting_position(int side) const
boost::optional< end_level_data > end_level_data_
Additional information on the game outcome which can be provided by WML.
game_state(const config &level, play_controller &, const ter_data_cache &tdata)
rng * generator
This generator is automatically synced during synced context.
void build_team_stage_one(team_builder_ptr tb_ptr)
void init(const config &level, play_controller &)
config & add_child(config_key_type key)
void write_config(config &cfg) const
bool side_can_recruit_on(int side, map_location loc) const
Checks if any of the sides leaders can recruit at a location.
void set_game_display(game_display *)
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.
const map_location & get_location() const
The current map location this unit is at.
Various functions that implement the undoing (and redoing) of in-game commands.
ter_list read_list(utils::string_view str, const ter_layer filler)
Reads a list of terrains from a string, when reading the.
Standard logging facilities (interface).
std::vector< terrain_code > ter_list
static const map_location & null_location()
static lg::log_domain log_engine("engine")
team_builder_ptr create_team_builder(const config &side_cfg, std::vector< team > &teams, const config &level, game_board &board, int num)
int side() const
The side this unit belongs to.
void place_sides_in_preferred_locations(const config &level)
void write_snapshot(config &cfg) const
plain_route a_star_search(const map_location &src, const map_location &dst, double stop_at, const cost_calculator &calc, const std::size_t width, const std::size_t height, const teleport_map *teleports, bool border)
A config object defines a single node in a WML file, with access to child nodes.
void write(config &cfg) const
This module contains various pathfinding functions and utilities.
std::shared_ptr< terrain_type_data > ter_data_cache