41 #define LOG_NG LOG_STREAM(info, log_engine)
42 #define DBG_NG LOG_STREAM(debug, log_engine)
43 #define ERR_NG LOG_STREAM(err, log_engine)
54 , undo_stack_(new
actions::undo_list())
55 , player_number_(
level[
"playing_team"].to_int() + 1)
56 , next_player_number_(
level[
"next_player_number"].to_int(player_number_ + 1))
57 , do_healing_(
level[
"do_healing"].to_bool(false))
58 , victory_when_enemies_defeated_(
level[
"victory_when_enemies_defeated"].to_bool(true))
59 , remove_from_carryover_on_defeat_(
level[
"remove_from_carryover_on_defeat"].to_bool(true))
60 , server_request_number_(
level[
"server_request_number"].to_int())
63 if(
auto endlevel_cfg =
level.optional_child(
"end_level_data")) {
65 el_data.
read(*endlevel_cfg);
75 int positions = 0, liked = 0;
78 for(
int i = -8;
i != 8; ++
i) {
79 for(
int j = -8; j != +8; ++j) {
83 if(std::count(terrain.begin(),terrain.end(),map[pos2])) {
90 return (100*liked)/positions;
111 std::vector<placing_info> placings;
116 for(
const config &side :
level.child_range(
"side"))
118 for(
int p = 1;
p <= num_pos; ++
p) {
125 placings.push_back(obj);
130 std::stable_sort(placings.begin(),placings.end());
131 std::set<int> placed;
132 std::set<map_location> positions_taken;
134 for (std::vector<placing_info>::const_iterator
i = placings.begin();
i != placings.end() &&
static_cast<int>(placed.size()) != side_num - 1; ++
i) {
135 if(placed.count(
i->side) == 0 && positions_taken.count(
i->pos) == 0) {
136 placed.insert(
i->side);
137 positions_taken.insert(
i->pos);
139 LOG_NG <<
"placing side " <<
i->side <<
" at " <<
i->pos;
148 if (
level[
"modify_placing"].to_bool()) {
149 LOG_NG <<
"modifying placing...";
153 LOG_NG <<
"initialized time of day regions... " << pc.
timer();
154 for (
const config &
t :
level.child_range(
"time_area")) {
167 std::vector<team_builder> team_builders;
175 for (
const config &side :
level.child_range(
"side"))
180 team_builders.back().build_team_stage_one();
195 tb.build_team_stage_two();
198 tb.build_team_stage_three();
204 std::string label_cat =
"side:" + std::to_string(
t.side());
257 castle_cost_calculator(
const gamemap& map,
const team & view_team) :
260 use_shroud_(view_team.uses_shroud())
265 if(!map_.is_castle(
loc))
268 if ( use_shroud_ && viewer_.shrouded(
loc) )
277 const bool use_shroud_;
299 }
catch(
const std::out_of_range&) {
335 if(view_team.
shrouded(recruit_loc)) {
343 castle_cost_calculator calc(map, view_team);
351 return !rt.
steps.empty();
352 }
catch(
const std::out_of_range&) {
370 return leader->can_recruit() && leader->side() == side &&
can_recruit_from(*leader);
374 if ( leader->can_recruit() && leader->side() == side &&
can_recruit_on(*leader, hex) ) {
404 add_side_wml_choice()
420 virtual const char*
name()
const
422 return "add_side_wml";
434 cfg[
"controller"] = side_controller::none;
A config object defines a single node in a WML file, with access to child nodes.
void merge_with(const config &c)
Merge config 'c' into this config, overwriting this config's values.
config & add_child(config_key_type key)
bool has_visible_unit(const map_location &loc, const team &team, bool see_all=false) const
virtual const std::vector< team > & teams() const override
virtual const std::vector< std::string > & hidden_label_categories() const override
void write_config(config &cfg) const
virtual const unit_map & units() const override
virtual const gamemap & map() const override
@ PRELOAD
the preload [event] is fired next phase: PRESTART (normal game), TURN_STARTING_WAITING (reloaded game...
@ INITIAL
creating intitial [unit]s, executing toplevel [lua] etc.
const randomness::mt_rng & rng() const
void write_snapshot(config &cfg) const
const std::string & next_scenario() const
void write(config &cfg) const
utils::optional< end_level_data > end_level_data_
bool remove_from_carryover_on_defeat_
void add_side_wml(config cfg)
creates a new side during a game.
bool has_next_scenario() const
Checks whether this is not the last scenario (usually of a campaign)
int server_request_number_
bool can_recruit_from(const map_location &leader_loc, int side) const
Checks to see if a leader at leader_loc could recruit somewhere.
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.
bool side_can_recruit_on(int side, map_location loc) const
Checks if any of the sides leaders can recruit at a location.
bool in_phase(game_data::PHASE phase) const
void set_game_display(game_display *)
std::unique_ptr< game_lua_kernel > lua_kernel_
game_state(const config &level, play_controller &)
std::unique_ptr< pathfind::manager > pathfind_manager_
const std::unique_ptr< actions::undo_list > undo_stack_
undo_stack_ is never nullptr.
void init(const config &level, play_controller &)
bool do_healing_
True if healing should be done at the beginning of the next side turn.
void place_sides_in_preferred_locations(const config &level)
const std::unique_ptr< game_events::manager > events_manager_
game_events::wmi_manager & get_wml_menu_items()
bool victory_when_enemies_defeated_
int w() const
Effective map width.
void set_starting_position(int side, const map_location &loc)
Manipulate starting positions of the different sides.
int h() const
Effective map height.
map_location starting_position(int side) const
int num_valid_starting_positions() const
Counts the number of sides that have valid starting positions on this map.
bool on_board(const map_location &loc) const
Tell if a location is on the map.
Encapsulates the map of the game.
bool is_castle(const map_location &loc) const
bool is_keep(const map_location &loc) const
static void progress(loading_stage stage=loading_stage::none)
Report what is being loaded to the loading screen.
const auto & timer() const
RAII class to use rng_deterministic in the current scope.
virtual config request() const =0
The request which is sent to the mp server.
virtual const char * name() const =0
virtual config local_choice() const =0
We are in a game with no mp server and need to do this choice locally.
static config ask_server_choice(const server_choice &)
If we are in a mp game, ask the server, otherwise generate the answer ourselves.
This class stores all the data for a single 'side' (in game nomenclature).
bool shrouded(const map_location &loc) const
config to_config(const std::string &textdomain="") 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.
void resolve_random(randomness::rng &r)
handles random_start_time, should be called before the game starts.
unit_iterator find(std::size_t id)
This class represents a single unit of a specific type.
static bool operator<(const placing_info &a, const placing_info &b)
static int placing_score(const config &side, const gamemap &map, const map_location &pos)
static lg::log_domain log_engine("engine")
int side() const
The side this unit belongs to.
const map_location & get_location() const
The current map location this unit is at.
Standard logging facilities (interface).
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)
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,...
rng * generator
This generator is automatically synced during synced context.
Unit and team statistics.
std::vector< terrain_code > ter_list
ter_list read_list(std::string_view str, const ter_layer filler)
Reads a list of terrains from a string, when reading the.
This module contains various pathfinding functions and utilities.
Additional information on the game outcome which can be provided by WML.
void read(const config &cfg)
transient_end_level transient
Encapsulates the map of the game.
static const map_location & null_location()
map_location plus(int x_diff, int y_diff) const
virtual double cost(const map_location &loc, const double so_far) const =0
Structure which holds a single route between one location and another.
std::vector< map_location > steps
bool carryover_report
Should a summary of the scenario outcome be displayed?
Various functions that implement the undoing (and redoing) of in-game commands.