42 #include "widgets/button.hpp"
44 #include <boost/shared_ptr.hpp>
51 #define ERR_NW LOG_STREAM(err, log_network)
54 replay_sender_(replay_sender),
55 host_transfer_(
"host_transfer"),
56 network_reader_(network_reader)
133 ERR_NW <<
"processing network data while still having data on the replay." << std::endl;
148 else if (
const config &ob = cfg.
child(
"observer") )
152 else if (
const config &ob = cfg.
child(
"observer_quit"))
156 else if (cfg.
child(
"leave_game")) {
167 else if (
const config &change = cfg.
child(
"change_controller"))
170 ERR_NW <<
"Bad [change_controller] signal from server, [change_controller] tag was empty." << std::endl;
174 const int side = change[
"side"].to_int();
175 const bool is_local = change[
"is_local"].to_bool();
177 const size_t index = side - 1;
179 ERR_NW <<
"Bad [change_controller] signal from server, side out of bounds: " << change.debug() << std::endl;
184 const bool was_local = tm.
is_local();
210 else if (
const config &side_drop_c = cfg.
child(
"side_drop"))
212 const int side_drop = side_drop_c[
"side_num"].to_int(0);
213 size_t index = side_drop -1;
218 ERR_NW <<
"unknown side " << side_drop <<
" is dropping game" << std::endl;
222 team::CONTROLLER ctrl;
223 if(!ctrl.parse(side_drop_c[
"controller"])) {
224 ERR_NW <<
"unknown controller type issued from server on side drop: " << side_drop_c[
"controller"] << std::endl;
228 if (ctrl == team::CONTROLLER::AI) {
233 else if (ctrl != team::CONTROLLER::HUMAN) {
234 ERR_NW <<
"unknown controller type issued from server on side drop: " << ctrl.to_cstring() << std::endl;
239 int first_observer_option_idx = 0;
240 int control_change_options = 0;
243 std::vector<std::string> observers;
244 std::vector<const team *> allies;
245 std::vector<std::string>
options;
250 if (!
t.is_enemy(side_drop) && !
t.is_local_human() && !
t.is_local_ai() && !
t.is_network_ai() && !
t.is_empty()
252 allies.push_back(&
t);
261 for (
const team *
t : allies) {
265 t_vars[
"player"] =
t->current_player();
266 options.push_back(
vgettext(
"Give control to their ally $player", t_vars));
267 control_change_options++;
270 first_observer_option_idx = options.size();
274 t_vars[
"player"] = ob;
275 options.push_back(
vgettext(
"Give control to observer $player", t_vars));
276 observers.push_back(ob);
277 control_change_options++;
280 options.push_back(
_(
"Replace with AI"));
281 options.push_back(
_(
"Replace with local player"));
282 options.push_back(
_(
"Set side to idle"));
283 options.push_back(
_(
"Save and abort game"));
294 action = control_change_options + 2;
301 if (action < control_change_options) {
309 if (action < first_observer_option_idx) {
317 action -= control_change_options;
352 else if (cfg.
child(
"notify_next_scenario")) {
355 btn_end->enable(
true);
361 else if (cfg.
child(
"host_transfer")){
366 ERR_NW <<
"found unknown command:\n" << cfg.
debug() << std::endl;
377 change[
"side"] = side;
378 change[
"player"] = player;
396 throw "found invalid REPLAY_RETURN";
std::shared_ptr< gui::button > find_action_button(const std::string &id)
Retrieves a pointer to a theme UI button.
play_controller * controller
static void change_side_controller(int side, const std::string &player)
virtual void send_to_wesnothd(const config &, const std::string &="unknown") const
replay_network_sender & replay_sender_
const std::string & current_player() const
virtual void notify_observers()
bool show(CVideo &video, const unsigned auto_close_time=0)
Shows the window.
events::generic_event host_transfer_
void redraw_everything()
Invalidates entire screen, including all tiles and sidebar.
PROCESS_DATA_RESULT sync_network()
virtual const std::vector< team > & teams() const
PROCESS_DATA_RESULT handle_turn(const config &t)
REPLAY_RETURN do_replay(bool one_move)
Contains the exception interfaces used to signal completion of a scenario, campaign or turn...
PROCESS_DATA_RESULT process_network_data_from_reader()
std::string debug() const
Definitions for the interface to Wesnoth Markup Language (WML).
turn_info(replay_network_sender &network_sender, playturn_network_adapter &network_reader)
void set_single_button(bool value)
Sets whether the Cancel button should be hidden or not.
bool has_child(const std::string &key) const
Determine whether a config has a child or not.
static std::vector< team > *& teams
This class stores all the data for a single 'side' (in game nomenclature).
static UNUSEDNOWARN std::string _(const char *str)
void throw_quit_game_exception()
std::map< std::string, t_string > string_map
std::vector< team > * teams
We received invalid data from wesnothd during a game This means we cannot continue with the game but ...
void side_drop_to(int side_num, team::CONTROLLER ctrl, team::PROXY_CONTROLLER proxy=team::PROXY_CONTROLLER::PROXY_HUMAN)
void recalculate_minimap()
Schedule the minimap for recalculation.
int selected_index() const
Returns the selected item index after displaying.
config & add_child(const std::string &key)
When we couldn't process the network data because we found a dependent command, this should only happ...
static lg::log_domain log_network("network")
bool is_local_human() const
playturn_network_adapter & network_reader_
Templates and utility-routines for strings and numbers.
void remove_observer(const std::string &name)
void recalculate_labels()
PROCESS_DATA_RESULT process_network_data(const config &cfg)
When the host uploaded the next scenario this is returned.
We foudn a player action in the replay that caused the game to end.
int playing_side() const
The playing team is the team whose turn it is.
const std::string & next_scenario() const
const_attr_itors attribute_range() const
static void msg(const char *act, debug_info &i, const char *to="", const char *result="")
display_chat_manager & get_chat_manager()
void add_config(const config &cfg, MARK_SENT mark=MARK_AS_UNSENT)
void add_observer(const std::string &name)
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...
virtual void on_not_observer()=0
unsigned all_children_count() const
Various functions that implement the undoing (and redoing) of in-game commands.
Standard logging facilities (interface).
static PROCESS_DATA_RESULT replay_to_process_data_result(REPLAY_RETURN replayreturn)
boost::shared_ptr< wb::manager > whiteboard
actions::undo_list * undo_stack
A config object defines a single node in a WML file, with access to child nodes.
void add_chat_message(const time_t &time, const std::string &speaker, int side, const std::string &msg, events::chat_handler::MESSAGE_TYPE type, bool bell)
Defines the MAKE_ENUM macro.
GLsizei const GLcharARB ** string
void side_change_controller(int side_num, bool is_local, const std::string &pname="")
void set_team(size_t team, bool observe=false)
Sets the team controlled by the player using the computer.