widelands-dev team mailing list archive
-
widelands-dev team
-
Mailing list archive
-
Message #09456
[Merge] lp:~widelands-dev/widelands/bug-1619157-random-ai-prevent-regression into lp:widelands
GunChleoc has proposed merging lp:~widelands-dev/widelands/bug-1619157-random-ai-prevent-regression into lp:widelands.
Commit message:
Added enum class Type to ComputerPlayer::Implementation to prevent bug #1619157 (Random AI sometimes selects the empty AI) from regressing.
Requested reviews:
Widelands Developers (widelands-dev)
Related bugs:
Bug #1619157 in widelands: "Random AI should not select "None""
https://bugs.launchpad.net/widelands/+bug/1619157
For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/bug-1619157-random-ai-prevent-regression/+merge/315351
--
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/bug-1619157-random-ai-prevent-regression into lp:widelands.
=== modified file 'src/ai/computer_player.cc'
--- src/ai/computer_player.cc 2016-08-04 15:49:05 +0000
+++ src/ai/computer_player.cc 2017-01-23 12:23:23 +0000
@@ -41,6 +41,7 @@
/** TRANSLATORS: This is the name of an AI used in the game setup screens */
descname = _("No AI");
icon_filename = "images/ai/ai_empty.png";
+ type = Implementation::Type::kEmpty;
}
ComputerPlayer* instantiate(Widelands::Game& g,
Widelands::PlayerNumber const pid) const override {
=== modified file 'src/ai/computer_player.h'
--- src/ai/computer_player.h 2016-08-04 15:49:05 +0000
+++ src/ai/computer_player.h 2017-01-23 12:23:23 +0000
@@ -55,9 +55,15 @@
* \see get_implementations()
*/
struct Implementation {
+ enum class Type {
+ kEmpty,
+ kDefault
+ };
+
std::string name;
std::string descname;
std::string icon_filename;
+ Type type;
virtual ~Implementation() {
}
virtual ComputerPlayer* instantiate(Widelands::Game&, Widelands::PlayerNumber) const = 0;
=== modified file 'src/ai/defaultai.h'
--- src/ai/defaultai.h 2017-01-22 12:41:40 +0000
+++ src/ai/defaultai.h 2017-01-23 12:23:23 +0000
@@ -101,6 +101,7 @@
/** TRANSLATORS: This is the name of an AI used in the game setup screens */
descname = _("Normal AI");
icon_filename = "images/ai/ai_normal.png";
+ type = Implementation::Type::kDefault;
}
ComputerPlayer* instantiate(Widelands::Game& game,
Widelands::PlayerNumber const p) const override {
@@ -114,6 +115,7 @@
/** TRANSLATORS: This is the name of an AI used in the game setup screens */
descname = _("Weak AI");
icon_filename = "images/ai/ai_weak.png";
+ type = Implementation::Type::kDefault;
}
ComputerPlayer* instantiate(Widelands::Game& game,
Widelands::PlayerNumber const p) const override {
@@ -127,6 +129,7 @@
/** TRANSLATORS: This is the name of an AI used in the game setup screens */
descname = _("Very Weak AI");
icon_filename = "images/ai/ai_very_weak.png";
+ type = Implementation::Type::kDefault;
}
ComputerPlayer* instantiate(Widelands::Game& game,
Widelands::PlayerNumber const p) const override {
=== modified file 'src/logic/single_player_game_settings_provider.cc'
--- src/logic/single_player_game_settings_provider.cc 2016-09-22 17:40:14 +0000
+++ src/logic/single_player_game_settings_provider.cc 2017-01-23 12:23:23 +0000
@@ -142,7 +142,7 @@
do {
uint8_t random = (std::rand() % impls.size()); // Choose a random AI
it = impls.begin() + random;
- } while ((*it)->name == "empty");
+ } while ((*it)->type == ComputerPlayer::Implementation::Type::kEmpty);
}
s.players[number].ai = (*it)->name;
}
=== modified file 'src/network/nethost.cc'
--- src/network/nethost.cc 2017-01-01 19:29:01 +0000
+++ src/network/nethost.cc 2017-01-23 12:23:23 +0000
@@ -179,7 +179,7 @@
do {
uint8_t random = (std::rand() % impls.size()); // Choose a random AI
it = impls.begin() + random;
- } while ((*it)->name == "empty");
+ } while ((*it)->type == ComputerPlayer::Implementation::Type::kEmpty);
set_player_ai(number, (*it)->name, true);
newstate = PlayerSettings::stateComputer;
break;
Follow ups