Move some code from gui to engine (mp::connect).
The moved code is to set up ai::configuration and sending network data at connect window creation.
This commit is contained in:
parent
10eb9642e7
commit
63294a7799
3 changed files with 36 additions and 33 deletions
|
@ -382,11 +382,6 @@ connect::connect(game_display& disp, const std::string& game_name,
|
|||
throw config::error(_("The scenario is invalid because it has no id."));
|
||||
}
|
||||
|
||||
// AI algorithms.
|
||||
const config &era = engine_.level().child("era");
|
||||
ai::configuration::add_era_ai_from_config(era);
|
||||
ai::configuration::add_mod_ai_from_config(
|
||||
engine_.level().child_range("modification"));
|
||||
ai_algorithms_ = ai::configuration::get_available_ais();
|
||||
|
||||
// Colors.
|
||||
|
@ -414,32 +409,11 @@ connect::connect(game_display& disp, const std::string& game_name,
|
|||
side_pos_y_offset += 60;
|
||||
}
|
||||
|
||||
if (engine_.first_scenario()) {
|
||||
// Send Initial information
|
||||
config response;
|
||||
config& create_game = response.add_child("create_game");
|
||||
create_game["name"] = params().name;
|
||||
if (params().password.empty() == false) {
|
||||
response["password"] = params().password;
|
||||
}
|
||||
network::send_data(response, 0);
|
||||
}
|
||||
|
||||
append_to_title(" — " + engine_.level()["name"].t_str());
|
||||
gold_title_label_.hide(params().saved_game);
|
||||
income_title_label_.hide(params().saved_game);
|
||||
|
||||
engine_.update_level();
|
||||
update_playerlist_state(true);
|
||||
|
||||
// If we are connected, send data to the connected host.
|
||||
if (engine_.first_scenario()) {
|
||||
network::send_data(engine_.level(), 0);
|
||||
} else {
|
||||
config next_level;
|
||||
next_level.add_child("store_next_scenario", engine_.level());
|
||||
network::send_data(next_level, 0);
|
||||
}
|
||||
}
|
||||
|
||||
connect::~connect()
|
||||
|
|
|
@ -89,6 +89,11 @@ connect_engine::connect_engine(game_display& disp, game_state& state,
|
|||
// Original level sides.
|
||||
config::child_itors sides = current_config()->child_range("side");
|
||||
|
||||
// AI algorithms.
|
||||
ai::configuration::add_era_ai_from_config(level_.child("era"));
|
||||
ai::configuration::add_mod_ai_from_config(
|
||||
level_.child_range("modification"));
|
||||
|
||||
// Set the team name lists and modify the original level sides,
|
||||
// if necessary.
|
||||
std::vector<std::string> original_team_names;
|
||||
|
@ -194,6 +199,22 @@ connect_engine::connect_engine(game_display& disp, game_state& state,
|
|||
|
||||
// Add host to the connected users list.
|
||||
import_user(preferences::login(), false);
|
||||
|
||||
if (first_scenario_) {
|
||||
// Send initial information.
|
||||
config response;
|
||||
config& create_game = response.add_child("create_game");
|
||||
create_game["name"] = params_.name;
|
||||
if (params_.password.empty() == false) {
|
||||
response["password"] = params_.password;
|
||||
}
|
||||
network::send_data(response, 0);
|
||||
}
|
||||
|
||||
update_level();
|
||||
|
||||
// If we are connected, send data to the connected host.
|
||||
send_level_data(0);
|
||||
}
|
||||
|
||||
connect_engine::~connect_engine()
|
||||
|
@ -680,14 +701,9 @@ void connect_engine::process_network_error(network::error& error)
|
|||
void connect_engine::process_network_connection(const network::connection sock)
|
||||
{
|
||||
network::send_data(config("join_game"), 0);
|
||||
|
||||
// If we are connected, send data to the connected host.
|
||||
if (first_scenario_) {
|
||||
network::send_data(level_, sock);
|
||||
} else {
|
||||
config next_level;
|
||||
next_level.add_child("store_next_scenario", level_);
|
||||
network::send_data(next_level, sock);
|
||||
}
|
||||
send_level_data(sock);
|
||||
}
|
||||
|
||||
int connect_engine::find_user_side_index_by_id(const std::string& id) const
|
||||
|
@ -708,6 +724,17 @@ int connect_engine::find_user_side_index_by_id(const std::string& id) const
|
|||
return i;
|
||||
}
|
||||
|
||||
void connect_engine::send_level_data(const network::connection sock) const
|
||||
{
|
||||
if (first_scenario_) {
|
||||
network::send_data(level_, sock);
|
||||
} else {
|
||||
config next_level;
|
||||
next_level.add_child("store_next_scenario", level_);
|
||||
network::send_data(next_level, sock);
|
||||
}
|
||||
}
|
||||
|
||||
void connect_engine::save_reserved_sides_information()
|
||||
{
|
||||
// Add information about reserved sides to the level config.
|
||||
|
|
|
@ -94,6 +94,8 @@ private:
|
|||
connect_engine(const connect_engine&);
|
||||
void operator=(const connect_engine&);
|
||||
|
||||
void send_level_data(const network::connection sock) const;
|
||||
|
||||
void save_reserved_sides_information();
|
||||
|
||||
void update_side_controller_options();
|
||||
|
|
Loading…
Add table
Reference in a new issue