use team.current_player() as player id

first part, i will back port it to 1.2 when all is done
This commit is contained in:
Serge Martin 2006-10-27 10:23:18 +00:00
parent 247b760311
commit 175d594465
7 changed files with 64 additions and 35 deletions

View file

@ -951,7 +951,7 @@ void display::update_display()
void display::draw_sidebar()
{
draw_report(reports::REPORT_CLOCK);
draw_report(reports::REPORT_CLOCK);
draw_report(reports::REPORT_COUNTDOWN);
if(teams_.empty()) {

View file

@ -134,7 +134,7 @@ namespace gui{
if(teams[n].is_empty()) {
continue;
}
const std::string& name = teams[n].save_id();
const std::string& name = teams[n].current_player();
if( name.size() >= semiword.size() &&
std::equal(semiword.begin(),semiword.end(),name.begin(),chars_equal_insensitive)) {
if(matches.empty()) {

View file

@ -409,7 +409,7 @@ namespace events{
#endif
str << COLUMN_SEPARATOR << "\033[3" << lexical_cast<char, size_t>(n+1) << 'm';
// Delete all tags before name
str << font::del_tags(leader->second.description()) << COLUMN_SEPARATOR;
str << font::del_tags(teams_[n].current_player()) << COLUMN_SEPARATOR;
} else {
str << ' ' << COLUMN_SEPARATOR << "\033[3" << lexical_cast<char, size_t>(n+1) << "m-" << COLUMN_SEPARATOR;

View file

@ -159,20 +159,24 @@ turn_info::PROCESS_DATA_RESULT turn_info::process_network_data(const config& cfg
//if a side has dropped out of the game.
if(cfg["side_drop"] != "") {
const size_t side = atoi(cfg["side_drop"].c_str())-1;
const std::string controller = cfg["controller"];
const std::string side_str = cfg["side_drop"];
const size_t side = atoi(side_str.c_str());
const size_t side_index = side-1;
if(side >= teams_.size()) {
LOG_STREAM(err, network) << "unknown side " << side << " is dropping game\n";
if(side_index >= teams_.size()) {
LOG_STREAM(err, network) << "unknown side " << side_index << " is dropping game\n";
throw network::error("");
}
if (controller == "ai"){
teams_[side].make_ai();
teams_[side_index].make_ai();
teams_[side_index].set_current_player("ai"+side_str);
config cfg;
cfg.values["side"] = lexical_cast<std::string>(side+1);
cfg.values["side"] = side_str;
cfg.values["controller"] = "ai";
cfg.values["name"] = "ai"+side_str;
network::send_data(cfg);
return PROCESS_RESTART_TURN;
}
@ -186,7 +190,7 @@ turn_info::PROCESS_DATA_RESULT turn_info::process_network_data(const config& cfg
//see if the side still has a leader alive. If they have
//no leader, we assume they just want to be replaced by
//the AI.
const unit_map::const_iterator leader = find_leader(units_,side+1);
const unit_map::const_iterator leader = find_leader(units_,side);
if(leader != units_.end()) {
options.push_back(_("Replace with AI"));
options.push_back(_("Replace with local player"));
@ -200,8 +204,8 @@ turn_info::PROCESS_DATA_RESULT turn_info::process_network_data(const config& cfg
//get all allies in as options to transfer control
for (std::vector<team>::iterator team = teams_.begin(); team != teams_.end(); team++){
if ( (!team->is_enemy(side + 1)) && (!team->is_human()) && (!team->is_ai()) && (!team->is_empty())
&& (team->current_player() != teams_[side].current_player()) ){
if ( (!team->is_enemy(side)) && (!team->is_human()) && (!team->is_ai()) && (!team->is_empty())
&& (team->current_player() != teams_[side_index].current_player()) ){
//if this is an ally of the dropping side and it is not us (choose local player
//if you want that) and not ai or empty and if it is not the dropping side itself,
//get this team in as well
@ -219,20 +223,24 @@ turn_info::PROCESS_DATA_RESULT turn_info::process_network_data(const config& cfg
//an AI.
switch(action) {
case 0:
teams_[side].make_ai();
teams_[side_index].make_ai();
teams_[side_index].set_current_player("ai"+side_str);
{
config cfg;
cfg.values["side"] = lexical_cast<std::string>(side+1);
cfg.values["side"] = side_str;
cfg.values["controller"] = "ai";
cfg.values["name"] = "ai"+side_str;
network::send_data(cfg);
}
return PROCESS_RESTART_TURN;
case 1:
teams_[side].make_human();
teams_[side_index].make_human();
teams_[side_index].set_current_player("human"+side_str);
{
config cfg;
cfg.values["side"] = lexical_cast<std::string>(side+1);
cfg.values["side"] = side_str;
cfg.values["controller"] = "human";
cfg.values["name"] = "human"+side_str;
network::send_data(cfg);
}
return PROCESS_RESTART_TURN;
@ -240,14 +248,22 @@ turn_info::PROCESS_DATA_RESULT turn_info::process_network_data(const config& cfg
if (action > 2) {
const size_t index = static_cast<size_t>(action - 3);
if (index < observers.size()) {
teams_[side].make_network();
change_side_controller(cfg["side_drop"], observers[index], false /*not our own side*/);
teams_[side_index].make_network();
change_side_controller(side_str, observers[index], false /*not our own side*/);
} else if (index < options.size() - 1) {
size_t i = index - observers.size();
allies[i]->make_network();
change_side_controller(cfg["side_drop"], allies[i]->save_id(), false /*not our own side*/);
change_side_controller(side_str, allies[i]->save_id(), false /*not our own side*/);
} else {
teams_[side].make_ai();
teams_[side_index].make_ai();
teams_[side_index].set_current_player("ai"+side_str);
{
config cfg;
cfg.values["side"] = side_str;
cfg.values["controller"] = "ai";
cfg.values["name"] = "ai"+side_str;
network::send_data(cfg);
}
}
return PROCESS_RESTART_TURN;
}

View file

@ -278,7 +278,7 @@ void replay_controller::play_side(const unsigned int team_index, bool){
{
is_playing_ = false;
}
catch(end_level_exception& e){
catch(end_level_exception& e){
//VICTORY/DEFEAT end_level_exception shall not return to title screen
if ((e.result != VICTORY) && (e.result != DEFEAT)) { throw e; }
}

View file

@ -156,7 +156,7 @@ bool game::take_side(network::connection player, const config& cfg)
{
wassert(is_member(player));
// verify that side is a side id
//verify that side is a side id
const std::string& side = cfg["side"];
size_t side_num;
try {
@ -176,7 +176,7 @@ bool game::take_side(network::connection player, const config& cfg)
const config::child_list& sides = level_.get_children("side");
for(config::child_list::const_iterator i = sides.begin(); i != sides.end(); ++i) {
if((**i)["controller"] == "network") {
// don't allow players to take sides in games with invalid side numbers
//don't allow players to take sides in games with invalid side numbers
try {
side_num = lexical_cast<size_t, std::string>((**i)["side"]);
if(side_num < 1 || side_num > 9)
@ -185,7 +185,7 @@ bool game::take_side(network::connection player, const config& cfg)
catch(bad_lexical_cast&) {
return false;
}
// check if the side is taken if not take it
//check if the side is taken if not take it
side_index = static_cast<size_t>(side_num - 1);
if(!sides_taken_[side_index]) {
side_controllers_[side_index] = "network";
@ -198,18 +198,31 @@ bool game::take_side(network::connection player, const config& cfg)
}
}
}
// if we get here we couldn't find a side to take
//if we get here we couldn't find a side to take
return false;
} else { //else take the current side
//if the owner have transfer side to an ai or an human in game
//fake a "change_controller" command so other player update controler name
//and set controler to the type owner have set
if (player == owner_ && started_ && !cfg["controller"].empty()) {
config fake;
config& change = fake.add_child("change_controller");
change["side"] = side;
change["player"] = cfg["name"];
change["controller"] = cfg["controller"];
send_data(fake, owner_); //send change to all except owner
side_controllers_[side_index] = cfg["controller"];
} else {
side_controllers_[side_index] = "network";
}
sides_.insert(std::pair<network::connection, size_t>(player, side_index));
sides_taken_[side_index] = true;
network::queue_data(cfg, owner_);
return true;
}
// else take the current side
if (player == owner_ && started_ && !cfg["controller"].empty())
side_controllers_[side_index] = cfg["controller"];
else
side_controllers_[side_index] = "network";
sides_.insert(std::pair<network::connection, size_t>(player, side_index));
sides_taken_[side_index] = true;
network::queue_data(cfg, owner_);
return true;
return false;
}
void game::update_side_data()

View file

@ -1,5 +1,5 @@
/* $Id$ */
/*
/* $Id$
Copyright (C) 2003-5 by David White <davidnwhite@verizon.net>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/