Fix bug #14754...
(host can start a game before the client has selected a leader).
This commit is contained in:
parent
a1b4770a9d
commit
f05fad35a1
3 changed files with 49 additions and 3 deletions
|
@ -6,6 +6,7 @@ Version 1.7.13+svn:
|
|||
* Updated translations: Czech , Italian
|
||||
* Multiplayer
|
||||
* Fixes players to get different side colours across scenarios of mp campaigns
|
||||
* Fix bug #14754: Host can start game before the client has selected a leader
|
||||
|
||||
Version 1.7.13-1.8beta6:
|
||||
* AI:
|
||||
|
|
|
@ -72,6 +72,7 @@ connect::side::side(connect& parent, const config& cfg, int index) :
|
|||
gold_(lexical_cast_default<int>(cfg_.get_attribute("gold"), 100)),
|
||||
income_(lexical_cast_default<int>(cfg_.get_attribute("income"), 0)),
|
||||
leader_(),
|
||||
ready_for_start_(false),
|
||||
gender_(),
|
||||
ai_algorithm_(),
|
||||
player_number_(parent.video(), lexical_cast_default<std::string>(index+1, ""),
|
||||
|
@ -335,7 +336,7 @@ connect::side::side(const side& a) :
|
|||
current_player_(a.current_player_),
|
||||
controller_(a.controller_),
|
||||
faction_(a.faction_), team_(a.team_), colour_(a.colour_),
|
||||
gold_(a.gold_), income_(a.income_), leader_(a.leader_), /* taken_(a.taken_), */
|
||||
gold_(a.gold_), income_(a.income_), leader_(a.leader_), ready_for_start_(a.ready_for_start_),
|
||||
gender_(a.gender_),
|
||||
ai_algorithm_(a.ai_algorithm_),
|
||||
player_number_(a.player_number_), combo_controller_(a.combo_controller_),
|
||||
|
@ -413,6 +414,7 @@ void connect::side::process_event()
|
|||
// Correct entry number if CNTR_NETWORK is not allowed for combo_controller_
|
||||
controller_ = mp::controller(combo_controller_->selected() + (parent_->local_only_ ? 1 : 0));
|
||||
player_id_ = "";
|
||||
ready_for_start_ = false;
|
||||
changed_ = true;
|
||||
} else {
|
||||
// give user second side
|
||||
|
@ -422,6 +424,7 @@ void connect::side::process_event()
|
|||
if (new_id != player_id_) {
|
||||
player_id_ = new_id;
|
||||
controller_ = parent_->users_[user].controller;
|
||||
ready_for_start_ = true;
|
||||
changed_ = true;
|
||||
}
|
||||
}
|
||||
|
@ -491,6 +494,21 @@ bool connect::side::changed()
|
|||
return res;
|
||||
}
|
||||
|
||||
bool connect::side::ready_for_start() const
|
||||
{
|
||||
//sides without players are always ready
|
||||
if (!allow_player_)
|
||||
return true;
|
||||
|
||||
//the host and the AI are always ready
|
||||
if ((controller_ == mp::CNTR_COMPUTER) ||
|
||||
(controller_ == mp::CNTR_EMPTY) ||
|
||||
(controller_ == mp::CNTR_LOCAL))
|
||||
return true;
|
||||
|
||||
return ready_for_start_;
|
||||
}
|
||||
|
||||
bool connect::side::available(const std::string& name) const
|
||||
{
|
||||
if (name.empty())
|
||||
|
@ -820,6 +838,11 @@ void connect::side::set_player_id(const std::string& player_id)
|
|||
update_ui();
|
||||
}
|
||||
|
||||
void connect::side::set_ready_for_start(bool ready_for_start)
|
||||
{
|
||||
ready_for_start_ = ready_for_start;
|
||||
}
|
||||
|
||||
const std::string& connect::side::get_save_id() const
|
||||
{
|
||||
return save_id_;
|
||||
|
@ -857,6 +880,9 @@ void connect::side::reset(mp::controller controller)
|
|||
player_id_ = "";
|
||||
controller_ = controller;
|
||||
|
||||
if ((controller == mp::CNTR_NETWORK) || (controller == mp::CNTR_RESERVED))
|
||||
ready_for_start_ = false;
|
||||
|
||||
if(enabled_ && !parent_->era_sides_.empty()) {
|
||||
if(combo_faction_.enabled())
|
||||
faction_ = 0;
|
||||
|
@ -1265,6 +1291,7 @@ void connect::process_network_data(const config& data, const network::connection
|
|||
int side_taken = find_player_side(change_faction["name"]);
|
||||
if(side_taken != -1) {
|
||||
sides_[side_taken].import_network_user(change_faction);
|
||||
sides_[side_taken].set_ready_for_start(true);
|
||||
update_playerlist_state();
|
||||
update_and_send_diff();
|
||||
}
|
||||
|
@ -1635,6 +1662,15 @@ void connect::update_and_send_diff(bool update_time_of_day)
|
|||
}
|
||||
}
|
||||
|
||||
bool connect::sides_ready() const
|
||||
{
|
||||
for(side_list::const_iterator itor = sides_.begin(); itor != sides_.end(); ++itor) {
|
||||
if (!itor->ready_for_start())
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool connect::sides_available() const
|
||||
{
|
||||
for(side_list::const_iterator itor = sides_.begin(); itor != sides_.end(); ++itor) {
|
||||
|
@ -1646,7 +1682,7 @@ bool connect::sides_available() const
|
|||
|
||||
bool connect::can_start_game() const
|
||||
{
|
||||
if(sides_available()) {
|
||||
if(!sides_ready()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -80,6 +80,9 @@ public:
|
|||
*/
|
||||
bool available(const std::string& name = "") const;
|
||||
|
||||
/** Returns true, if the player has chosen his leader and this side is ready for the game to start */
|
||||
bool ready_for_start() const;
|
||||
|
||||
/** Return true if players are allowed to take this side. */
|
||||
bool allow_player() const;
|
||||
|
||||
|
@ -99,6 +102,9 @@ public:
|
|||
/** Sets the username of this side. */
|
||||
void set_player_id(const std::string& player_id);
|
||||
|
||||
/** Sets if the joining player has chosen his leader. */
|
||||
void set_ready_for_start(bool ready_for_start);
|
||||
|
||||
const std::string& get_save_id() const;
|
||||
|
||||
/**
|
||||
|
@ -151,7 +157,7 @@ public:
|
|||
std::string leader_;
|
||||
std::string gender_;
|
||||
std::string ai_algorithm_;
|
||||
//bool taken_;
|
||||
bool ready_for_start_;
|
||||
|
||||
// Widgets for this side
|
||||
gui::label player_number_;
|
||||
|
@ -232,6 +238,9 @@ private:
|
|||
/** Returns true if there still are sides available for this game. */
|
||||
bool sides_available() const;
|
||||
|
||||
/** Returns true if all sides are ready to start the game. */
|
||||
bool sides_ready() const;
|
||||
|
||||
/**
|
||||
* Validates whether the game can be started.
|
||||
*
|
||||
|
|
Loading…
Add table
Reference in a new issue