39 #include <SDL2/SDL_timer.h> 45 #define LOG_NG LOG_STREAM(info, log_engine) 46 #define DBG_NG LOG_STREAM(debug, log_engine) 47 #define ERR_NG LOG_STREAM(err, log_engine) 53 , pathfind_manager_(new
pathfind::manager(level))
60 , undo_stack_(new
actions::undo_list(level.child(
"undo_stack")))
61 , player_number_(level[
"playing_team"].to_int() + 1)
62 , next_player_number_(level[
"next_player_number"].to_int(player_number_ + 1))
63 , do_healing_(level[
"do_healing"].to_bool(false))
64 , init_side_done_(level[
"init_side_done"].to_bool(false))
65 , start_event_fired_(!level[
"playing_team"].empty())
66 , server_request_number_(level[
"server_request_number"].to_int())
67 , first_human_team_(-1)
70 if(
const config& endlevel_cfg = level.
child(
"end_level_data")) {
72 el_data.
read(endlevel_cfg);
98 if(
const config& endlevel_cfg = level.
child(
"end_level_data")) {
100 el_data.
read(endlevel_cfg);
110 int positions = 0, liked = 0;
113 for(
int i = -8;
i != 8; ++
i) {
114 for(
int j = -8; j != +8; ++j) {
118 if(std::count(terrain.begin(),terrain.end(),map[pos2])) {
125 return (100*liked)/positions;
146 std::vector<placing_info> placings;
153 for(
int p = 1;
p <= num_pos; ++
p) {
160 placings.push_back(obj);
165 std::stable_sort(placings.begin(),placings.end());
166 std::set<int> placed;
167 std::set<map_location> positions_taken;
169 for (std::vector<placing_info>::const_iterator
i = placings.begin();
i != placings.end() &&
static_cast<int>(placed.size()) != side_num - 1; ++
i) {
170 if(placed.count(
i->side) == 0 && positions_taken.count(
i->pos) == 0) {
171 placed.insert(
i->side);
172 positions_taken.insert(
i->pos);
174 LOG_NG <<
"placing side " <<
i->side <<
" at " <<
i->pos;
183 if (level[
"modify_placing"].to_bool()) {
184 LOG_NG <<
"modifying placing...";
188 LOG_NG <<
"initialized time of day regions... " << (SDL_GetTicks() - pc.
ticks());
193 LOG_NG <<
"initialized teams... " << (SDL_GetTicks() - pc.
ticks());
202 std::vector<team_builder> team_builders;
213 const std::string &
controller = side[
"controller"];
214 if (controller == side_controller::human && side[
"is_local"].to_bool(
true)) {
221 team_builders.back().build_team_stage_one();
234 tb.build_team_stage_two();
240 std::string label_cat =
"side:" + std::to_string(
i + 1);
290 castle_cost_calculator(
const gamemap& map,
const team & view_team) :
296 virtual double cost(
const map_location& loc,
const double)
const 298 if(!map_.is_castle(loc))
301 if ( use_shroud_ && viewer_.shrouded(loc) )
310 const bool use_shroud_;
332 }
catch(
const std::out_of_range&) {
368 if(view_team.
shrouded(recruit_loc)) {
376 castle_cost_calculator calc(map, view_team);
384 return !rt.
steps.empty();
385 }
catch(
const std::out_of_range&) {
403 return leader->can_recruit() && leader->side() == side &&
can_recruit_from(*leader);
407 if ( leader->can_recruit() && leader->side() == side &&
can_recruit_on(*leader, hex) ) {
433 add_side_wml_choice()
438 virtual config local_choice()
const 444 virtual config request()
const 449 virtual const char* name()
const 451 return "add_side_wml";
463 cfg[
"controller"] = side_controller::none;
const std::unique_ptr< reports > reports_
void read(const config &cfg)
bool is_keep(const map_location &loc) const
const std::unique_ptr< actions::undo_list > undo_stack_
undo_stack_ is never nullptr.
virtual const std::vector< std::string > & hidden_label_categories() const override
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...
virtual const std::vector< team > & teams() const override
std::unique_ptr< game_lua_kernel > lua_kernel_
virtual const unit_map & units() const override
std::optional< end_level_data > end_level_data_
This class represents a single unit of a specific type.
bool is_castle(const map_location &loc) const
map_location starting_position(int side) const
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)
Report what is being loaded to the loading screen.
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.
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
int w() const
Effective map width.
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.
std::unique_ptr< pathfind::manager > pathfind_manager_
void set_starting_position(int side, const map_location &loc)
Manipulate starting positions of the different sides.
bool carryover_report
Should a summary of the scenario outcome be displayed?
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
transient_end_level transient
int num_valid_starting_positions() const
Counts the number of sides that have valid starting positions on this map.
static bool operator<(const placing_info &a, const placing_info &b)
bool on_board(const map_location &loc) const
Tell if a location is on the map.
Additional information on the game outcome which can be provided by WML.
rng * generator
This generator is automatically synced during synced context.
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.
Standard logging facilities (interface).
std::vector< terrain_code > ter_list
static const map_location & null_location()
static lg::log_domain log_engine("engine")
int side() const
The side this unit belongs to.
void place_sides_in_preferred_locations(const config &level)
game_state(const config &level, play_controller &)
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
int h() const
Effective map height.
This module contains various pathfinding functions and utilities.
void add_side_wml(config cfg)
creates a new side during a game.
ter_list read_list(std::string_view str, const ter_layer filler)
Reads a list of terrains from a string, when reading the.
static config ask_server_choice(const server_choice &)
If we are in a mp game, ask the server, otherwise generate the answer ourselves.