Skip to content

Commit

Permalink
Purge "human_ai" controller type
Browse files Browse the repository at this point in the history
This is a fixup of bugfix #18829 (which was commit
736ceaa)
  • Loading branch information
cbeck88 committed Mar 19, 2014
1 parent 73fac1b commit 0958a31
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 47 deletions.
2 changes: 2 additions & 0 deletions changelog
Expand Up @@ -9,6 +9,8 @@ Version 1.11.11+dev:
* Campaigns:
* The Hammer of Thursagan:
* Fixed missing objective in 'The Court of Karrag'.
* C++ Engine:
* Purge "human_ai" controller type. This is a fixup of bugfix #18829 below.
* Language and i18n:
* Updated translations: German, Scottish Gaelic, Slovak
* Lua API:
Expand Down
2 changes: 0 additions & 2 deletions data/gui/default/window/editor_edit_side.cfg
Expand Up @@ -399,8 +399,6 @@
[row]
{_GUI_SIDE_CONTROLLER_OPTION human ( _ "controller^Human")}

{_GUI_SIDE_CONTROLLER_OPTION human_ai ( _ "controller^Human/AI")}

{_GUI_SIDE_CONTROLLER_OPTION ai ( _ "controller^AI only")}

{_GUI_SIDE_CONTROLLER_OPTION null ( _ "controller^None")}
Expand Down
2 changes: 1 addition & 1 deletion src/game_controller.cpp
Expand Up @@ -529,7 +529,7 @@ bool game_controller::load_game()
if (side["controller"] == "network")
side["controller"] = "human";
if (side["controller"] == "network_ai")
side["controller"] = "human_ai";
side["controller"] = "ai";
}
gui2::show_message(disp().video(), _("Warning") , _("This is a multiplayer scenario. Some parts of it may not work properly in single-player. It is recommended to load this scenario through the Multiplayer -> Load Game dialog instead."));
}
Expand Down
1 change: 0 additions & 1 deletion src/gui/dialogs/editor/editor_edit_side.cpp
Expand Up @@ -95,7 +95,6 @@ teditor_edit_side::teditor_edit_side(int side,
void teditor_edit_side::pre_show(CVideo& /*video*/, twindow& window)
{
register_controller_toggle(window, "human", team::HUMAN);
register_controller_toggle(window, "human_ai", team::HUMAN_AI);
register_controller_toggle(window, "ai", team::AI);
register_controller_toggle(window, "null", team::EMPTY);
register_controller_toggle(window, "number", team::CONTROLLER(-1));
Expand Down
10 changes: 5 additions & 5 deletions src/menu_events.cpp
Expand Up @@ -2663,8 +2663,8 @@ void console_handler::do_droid() {
return;
} else if ((menu_handler_.teams_[side - 1].is_human() || menu_handler_.teams_[side - 1].is_idle()) && action != " off") {
//this is our side, so give it to AI
menu_handler_.teams_[side - 1].make_human_ai();
menu_handler_.change_controller(lexical_cast<std::string>(side),"human_ai");
menu_handler_.teams_[side - 1].make_ai();
menu_handler_.change_controller(lexical_cast<std::string>(side),"ai");
if(team_num_ == side) {
//if it is our turn at the moment, we have to indicate to the
//play_controller, that we are no longer in control
Expand Down Expand Up @@ -2705,9 +2705,9 @@ void console_handler::do_idle() {
throw end_turn_exception(side);
}
} else if (menu_handler_.teams_[side - 1].is_ai() && action != " off") {
//this is our side, so give it to idle
menu_handler_.teams_[side - 1].make_human_ai();
menu_handler_.change_controller(lexical_cast<std::string>(side),"human_ai");
//this is our side, so give it to idle, without end turn exception. tell network it is human
menu_handler_.teams_[side - 1].make_idle();
menu_handler_.change_controller(lexical_cast<std::string>(side),"human");
} else if (menu_handler_.teams_[side - 1].is_idle() && action != " on") {
menu_handler_.teams_[side - 1].make_human();
menu_handler_.change_controller(lexical_cast<std::string>(side),"human");
Expand Down
11 changes: 0 additions & 11 deletions src/playcampaign.cpp
Expand Up @@ -460,17 +460,6 @@ LEVEL_RESULT play_game(game_display& disp, game_state& gamestate,
//(did we miss anything?)
LOG_RG << "\t\t\t\t\t" << side["controller"] << std::endl;
}
} else if (io_type == IO_SERVER)
{
LOG_RG << "*** Playcampaign.cpp: We are a IO_SERVER ***" << std::endl;
BOOST_FOREACH(config &side, starting_pos.child_range("side"))
{
LOG_RG << "*** Playcampaign.cpp: Tweaked " << side["controller"] << " -> " << std::endl;
if (side["controller"] == "ai") {
side["controller"] = "human_ai"; //this is to guarantee that in an actual mp game, all ai sides will be "human_ai"
} //or "network_ai", and "ai" only occurs during configuration.
LOG_RG << "\t\t\t\t\t" << side["controller"] << std::endl;
}
}

config::const_child_itors story = scenario->child_range("story");
Expand Down
18 changes: 5 additions & 13 deletions src/playturn.cpp
Expand Up @@ -184,20 +184,12 @@ turn_info::PROCESS_DATA_RESULT turn_info::process_network_data(const config& cfg

if (controller == "human" && !tm.is_human()) {
tm.make_human();
} else if (controller == "human_ai" && !tm.is_human_ai()) {
tm.make_human_ai();
} else if (controller == "network" && !tm.is_network_human()) {
tm.make_network();
} else if (controller == "network_ai" && !tm.is_network_ai()) {
tm.make_network_ai();
} else if (controller == "ai" && !tm.is_ai()) {
//if we are the controller, this should become human_ai, if not then network_ai
//this is to ensure that no side during an mp game is ever "ai", and always either human_ai or network_ai (except during configuration)
if (player == preferences::login()) {
tm.make_human_ai();
} else {
tm.make_network_ai();
}
tm.make_ai();
} else if (controller == "idle" && !tm.is_idle()) {
tm.make_idle();
}
Expand Down Expand Up @@ -303,10 +295,10 @@ turn_info::PROCESS_DATA_RESULT turn_info::process_network_data(const config& cfg
//an AI.
switch(action) {
case 0:
tm.make_human_ai();
tm.make_ai();
tm.set_current_player("ai" + side_drop);
if (have_leader) leader->rename("ai" + side_drop);
change_controller(side_drop, "human_ai");
change_controller(side_drop, "ai");
resources::controller->maybe_do_init_side(side_index);

return restart?PROCESS_RESTART_TURN:PROCESS_CONTINUE;
Expand Down Expand Up @@ -349,10 +341,10 @@ turn_info::PROCESS_DATA_RESULT turn_info::process_network_data(const config& cfg
size_t i = index - observers.size();
change_side_controller(side_drop, allies[i]->current_player());
} else {
tm.make_human_ai();
tm.make_ai();
tm.set_current_player("ai"+side_drop);
if (have_leader) leader->rename("ai" + side_drop);
change_controller(side_drop, "human_ai");
change_controller(side_drop, "ai");
}
return restart?PROCESS_RESTART_TURN:PROCESS_CONTINUE;
}
Expand Down
8 changes: 4 additions & 4 deletions src/server/game.cpp
Expand Up @@ -373,7 +373,7 @@ void game::transfer_side_control(const network::connection sock, const simple_wm
send_server_message("You can only (un)droid your own sides!", sock);
}
return;
} else if (cfg["controller"] != "human_ai" && cfg["controller"] != "human") {
} else if (cfg["controller"] != "ai" && cfg["controller"] != "human") {
std::stringstream msg;
msg << "Wrong controller type received: '" << cfg["controller"] << "'";
DBG_GAME << msg.str() << "\n";
Expand Down Expand Up @@ -451,9 +451,9 @@ void game::change_controller(const size_t side_num,
send_and_record_server_message(player_name + " takes control of side " + side + ".");
side_controllers_[side_num] = "human";
} else {
send_and_record_server_message(player_name + (controller == "human_ai" ? " " : " un")
send_and_record_server_message(player_name + (controller == "ai" ? " " : " un")
+ "droids side " + side + ".");
side_controllers_[side_num] = (controller == "human_ai" ? "ai" : "human");
side_controllers_[side_num] = (controller == "ai" ? "ai" : "human");
}

simple_wml::document response;
Expand All @@ -470,7 +470,7 @@ void game::change_controller(const size_t side_num,
// Just don't send it when the player left the game. (The host gets the
// side_drop already.)
if (!player_left) {
change.set_attr("controller", (side_controllers_[side_num] == "ai" ? "human_ai" : "human"));
change.set_attr("controller", (side_controllers_[side_num] == "ai" ? "ai" : "human"));
wesnothd::send_to_one(response, sock);
}

Expand Down
7 changes: 1 addition & 6 deletions src/team.cpp
Expand Up @@ -188,8 +188,6 @@ void team::team_info::read(const config &cfg)
persistent = true;
if (control == "human")
controller = HUMAN;
else if (control == "human_ai")
controller = HUMAN_AI;
else if (control == "network")
controller = NETWORK;
else if (control == "network_ai")
Expand Down Expand Up @@ -226,7 +224,6 @@ char const *team::team_info::controller_string() const
switch(controller) {
case AI: return "ai";
case HUMAN: return "human";
case HUMAN_AI: return "human_ai";
case NETWORK: return "network";
case NETWORK_AI: return "network_ai";
case IDLE: return "idle";
Expand Down Expand Up @@ -494,8 +491,6 @@ void team::change_controller(const std::string& controller)
team::CONTROLLER cid;
if (controller == "human")
cid = team::HUMAN;
else if (controller == "human_ai")
cid = team::HUMAN_AI;
else if (controller == "network")
cid = team::NETWORK;
else if (controller == "network_ai")
Expand Down Expand Up @@ -658,7 +653,7 @@ bool is_observer()
}

BOOST_FOREACH(const team &t, *teams) {
if (t.is_human() || t.is_human_ai())
if (t.is_local())
return false;
}

Expand Down
6 changes: 2 additions & 4 deletions src/team.hpp
Expand Up @@ -32,7 +32,7 @@ namespace wb {
class team : public savegame::savegame_config
{
public:
enum CONTROLLER { HUMAN, HUMAN_AI, AI, NETWORK, NETWORK_AI, IDLE, EMPTY };
enum CONTROLLER { HUMAN, AI, NETWORK, NETWORK_AI, IDLE, EMPTY };

private:
class shroud_map {
Expand Down Expand Up @@ -207,18 +207,16 @@ class team : public savegame::savegame_config
const std::string& color() const { return info_.color; }
void set_color(const std::string& color) { info_.color = color; }
bool is_human() const { return info_.controller == HUMAN; }
bool is_human_ai() const { return info_.controller == HUMAN_AI; }
bool is_network_human() const { return info_.controller == NETWORK; }
bool is_network_ai() const { return info_.controller == NETWORK_AI; }
bool is_ai() const { return info_.controller == AI || is_human_ai(); }
bool is_ai() const { return info_.controller == AI; }
bool is_idle() const { return info_.controller == IDLE; }
bool is_empty() const { return info_.controller == EMPTY; }

bool is_local() const { return is_human() || is_ai() || is_idle(); }
bool is_network() const { return is_network_human() || is_network_ai(); }

void make_human() { info_.controller = HUMAN; }
void make_human_ai() { info_.controller = HUMAN_AI; }
void make_network() { info_.controller = NETWORK; }
void make_network_ai() { info_.controller = NETWORK_AI; }
void make_ai() { info_.controller = AI; }
Expand Down

0 comments on commit 0958a31

Please sign in to comment.