36 #include <boost/make_shared.hpp>
37 #include <boost/shared_ptr.hpp>
38 #include <SDL_timer.h>
44 #define LOG_NG LOG_STREAM(info, log_engine)
45 #define DBG_NG LOG_STREAM(debug, log_engine)
55 undo_stack_(new
actions::undo_list(level.child(
"undo_stack"))),
56 player_number_(level[
"playing_team"].to_int() + 1),
57 init_side_done_(level[
"init_side_done"].to_bool(false)),
58 start_event_fired_(!level[
"playing_team"].empty()),
59 server_request_number_(level[
"server_request_number"].to_int()),
62 if(
const config& endlevel_cfg = level.
child(
"end_level_data")) {
64 el_data.
read(endlevel_cfg);
73 pathfind_manager_(new
pathfind::manager(level)),
77 player_number_(level[
"playing_team"].to_int() + 1),
79 init_side_done_(level[
"init_side_done"].to_bool(false)),
83 if(
const config& endlevel_cfg = level.
child(
"end_level_data")) {
85 el_data.
read(endlevel_cfg);
96 int positions = 0, liked = 0;
99 for(
int i = pos.
x-8;
i != pos.
x+8; ++
i) {
100 for(
int j = pos.
y-8; j != pos.
y+8; ++j) {
111 return (100*liked)/positions;
132 std::vector<placing_info> placings;
139 for(
int p = 1;
p <= num_pos; ++
p) {
146 placings.push_back(obj);
151 std::stable_sort(placings.begin(),placings.end());
152 std::set<int> placed;
153 std::set<map_location> positions_taken;
155 for (std::vector<placing_info>::const_iterator
i = placings.begin();
i != placings.end() &&
int(placed.size()) != side_num - 1; ++
i) {
156 if(placed.count(
i->side) == 0 && positions_taken.count(
i->pos) == 0) {
157 placed.insert(
i->side);
158 positions_taken.insert(
i->pos);
160 LOG_NG <<
"placing side " <<
i->side <<
" at " <<
i->pos << std::endl;
169 if (level[
"modify_placing"].to_bool()) {
170 LOG_NG <<
"modifying placing..." << std::endl;
174 LOG_NG <<
"initialized time of day regions... " << (SDL_GetTicks() - pc.
ticks()) << std::endl;
179 LOG_NG <<
"initialized teams... " << (SDL_GetTicks() - pc.
ticks()) << std::endl;
183 std::vector<team_builder_ptr> team_builders;
190 if (controller ==
"human") {
198 team_builders.push_back(tb_ptr);
213 std::string label_cat =
"side:" + std::to_string(
i + 1);
265 castle_cost_calculator(
const gamemap& map,
const team & view_team) :
268 use_shroud_(view_team.uses_shroud())
273 if(!
map_.is_castle(loc))
276 if ( use_shroud_ && viewer_.shrouded(loc) )
285 const bool use_shroud_;
303 if ( side < 1 ||
board_.
teams().size() <
static_cast<size_t>(side) ) {
338 if ( side < 1 ||
board_.
teams().size() <
static_cast<size_t>(side) ) {
347 if ( view_team.
shrouded(recruit_loc) )
353 castle_cost_calculator calc(map, view_team);
360 return !rt.
steps.empty();
372 return leader->can_recruit() && leader->side() == side &&
can_recruit_from(*leader);
376 if ( leader->can_recruit() && leader->side() == side &&
can_recruit_on(*leader, hex) ) {
void read(const config &cfg)
child_itors child_range(const std::string &key)
plain_route a_star_search(const map_location &src, const map_location &dst, double stop_at, const cost_calculator *calc, const size_t width, const size_t height, const teleport_map *teleports, bool border)
virtual const unit_map & units() const
const map_location & get_location() const
void build_team_stage_two(team_builder_ptr tb_ptr)
const rand_rng::mt_rng & rng() const
t_list read_list(const std::string &str, const t_layer filler)
Reads a list of terrains from a string, when reading the.
bool shrouded(const map_location &loc) const
void write_config(config &cfg) const
std::vector< std::string > & hidden_label_categories_ref()
rng * generator
This generator is automatically synced during synced context.
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.
int server_request_number_
boost::scoped_ptr< gamemap > map_
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.
boost::scoped_ptr< pathfind::manager > pathfind_manager_
virtual const std::vector< team > & teams() const
game_state(const config &level, play_controller &, const tdata_cache &tdata)
RAII class to use rng_deterministic in the current scope.
Unit and team statistics.
boost::scoped_ptr< game_lua_kernel > lua_kernel_
GLdouble GLdouble GLdouble b
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).
std::vector< map_location > steps
bool side_can_recruit_on(int side, map_location loc) const
Checks if any of the sides leaders can recruit at a location.
map_location starting_position(int side) const
std::vector< team > teams_
Structure which holds a single route between one location and another.
boost::scoped_ptr< game_events::manager > events_manager_
void write_snapshot(config &cfg) const
int w() const
Effective map width.
GLboolean GLboolean GLboolean GLboolean a
Encapsulates the map of the game.
config & add_child(const std::string &key)
boost::scoped_ptr< actions::undo_list > undo_stack_
undo_stack_ is never nullptr.
bool carryover_report
Should a summary of the scenario outcome be displayed?
static const map_location & null_location()
static const ::config * terrain
The terrain used to create the cache.
typedef int(WINAPI *PFNWGLRELEASEPBUFFERDCARBPROC)(HPBUFFERARB hPbuffer
static int placing_score(const config &side, const gamemap &map, const map_location &pos)
GLuint GLuint GLsizei count
bool is_ignored(const std::string &nick)
Encapsulates the map of the game.
static void progress(const char *stage_name=nullptr)
transient_end_level transient
bool has_visible_unit(const map_location &loc, const team &team, bool see_all=false) const
void write(config &cfg) const
int h() const
Effective map height.
A container of wml_menu_item.
t_possible_end_level_data end_level_data_
static bool operator<(const placing_info &a, const placing_info &b)
bool can_recruit_from(const map_location &leader_loc, int side) const
Checks to see if a leader at leader_loc could recruit somewhere.
Additional information on the game outcome which can be provided by WML.
bool is_castle(const map_location &loc) const
void build_team_stage_one(team_builder_ptr tb_ptr)
void init(const config &level, play_controller &)
unsigned child_count(const std::string &key) const
team_builder_ptr create_team_builder(const config &side_cfg, std::vector< team > &teams, const config &level, game_board &board)
virtual const gamemap & map() const
bool on_board(const map_location &loc) const
Tell if a location is on the map.
void set_game_display(game_display *)
virtual double cost(const map_location &loc, const double so_far) const =0
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.
config & child(const std::string &key, int n=0)
Returns the nth child with the given key, or a reference to an invalid config if there is none...
int num_valid_starting_positions() const
Various functions that implement the undoing (and redoing) of in-game commands.
Standard logging facilities (interface).
static lg::log_domain log_engine("engine")
void place_sides_in_preferred_locations(const config &level)
void resolve_random(random_new::rng &r)
handles random_start_time, should be called before the game starts.
unit_iterator find(size_t id)
A config object defines a single node in a WML file, with access to child nodes.
This module contains various pathfinding functions and utilities.
GLsizei const GLcharARB ** string
boost::scoped_ptr< reports > reports_
bool is_keep(const map_location &loc) const
std::vector< t_terrain > t_list
game_events::wmi_container & get_wml_menu_items()