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))
58 , undo_stack_(new
actions::undo_list())
59 , player_number_(level[
"playing_team"].to_int() + 1)
60 , next_player_number_(level[
"next_player_number"].to_int(player_number_ + 1))
61 , do_healing_(level[
"do_healing"].to_bool(false))
62 , server_request_number_(level[
"server_request_number"].to_int())
63 , first_human_team_(-1)
66 if(
const config& endlevel_cfg = level.
child(
"end_level_data")) {
68 el_data.
read(endlevel_cfg);
78 int positions = 0, liked = 0;
81 for(
int i = -8;
i != 8; ++
i) {
82 for(
int j = -8; j != +8; ++j) {
86 if(std::count(terrain.begin(),terrain.end(),map[pos2])) {
93 return (100*liked)/positions;
114 std::vector<placing_info> placings;
121 for(
int p = 1;
p <= num_pos; ++
p) {
128 placings.push_back(obj);
133 std::stable_sort(placings.begin(),placings.end());
134 std::set<int> placed;
135 std::set<map_location> positions_taken;
137 for (std::vector<placing_info>::const_iterator
i = placings.begin();
i != placings.end() &&
static_cast<int>(placed.size()) != side_num - 1; ++
i) {
138 if(placed.count(
i->side) == 0 && positions_taken.count(
i->pos) == 0) {
139 placed.insert(
i->side);
140 positions_taken.insert(
i->pos);
142 LOG_NG <<
"placing side " <<
i->side <<
" at " <<
i->pos;
151 if (level[
"modify_placing"].to_bool()) {
152 LOG_NG <<
"modifying placing...";
156 LOG_NG <<
"initialized time of day regions... " << (SDL_GetTicks() - pc.
ticks());
161 LOG_NG <<
"initialized teams... " << (SDL_GetTicks() - pc.
ticks());
170 std::vector<team_builder> team_builders;
181 const std::string &
controller = side[
"controller"];
182 if (controller == side_controller::human && side[
"is_local"].to_bool(
true)) {
189 team_builders.back().build_team_stage_one();
204 tb.build_team_stage_two();
207 tb.build_team_stage_three();
213 std::string label_cat =
"side:" + std::to_string(
i + 1);
264 castle_cost_calculator(
const gamemap& map,
const team & view_team) :
270 virtual double cost(
const map_location& loc,
const double)
const 272 if(!map_.is_castle(loc))
275 if ( use_shroud_ && viewer_.shrouded(loc) )
284 const bool use_shroud_;
306 }
catch(
const std::out_of_range&) {
342 if(view_team.
shrouded(recruit_loc)) {
350 castle_cost_calculator calc(map, view_team);
358 return !rt.
steps.empty();
359 }
catch(
const std::out_of_range&) {
377 return leader->can_recruit() && leader->side() == side &&
can_recruit_from(*leader);
381 if ( leader->can_recruit() && leader->side() == side &&
can_recruit_on(*leader, hex) ) {
407 add_side_wml_choice()
412 virtual config local_choice()
const 418 virtual config request()
const 423 virtual const char* name()
const 425 return "add_side_wml";
437 cfg[
"controller"] = side_controller::none;
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.
the preload [event] is fired next phase: PRESTART (normal game), TURN_STARTING_WAITING (reloaded game...
void merge_with(const config &c)
Merge config 'c' into this config, overwriting this config's values.
creating intitial [unit]s, executing toplevel [lua] etc.
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 *)
bool in_phase(game_data::PHASE phase) const
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)
const config & child_or_empty(config_key_type key) const
Returns the first child with the given key, or an empty config if there is none.
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.