From 0b6fa7ed192ea94b127f69cbcaba6002c8da7792 Mon Sep 17 00:00:00 2001 From: mattsc Date: Fri, 28 Feb 2014 07:03:02 -0800 Subject: [PATCH 1/4] Experimental AI: remove potential of causing errors through WML events Events taking units off the map after the move could previously have caused errors, and thus disabled the AI for the rest of the turn. --- data/ai/lua/generic_rush_engine.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/data/ai/lua/generic_rush_engine.lua b/data/ai/lua/generic_rush_engine.lua index d73c7df5de9..c97636ce57f 100644 --- a/data/ai/lua/generic_rush_engine.lua +++ b/data/ai/lua/generic_rush_engine.lua @@ -493,6 +493,8 @@ return { local defender = wesnoth.get_unit(self.data.attack.target.x, self.data.attack.target.y) AH.movefull_stopunit(ai, attacker, self.data.attack.dst.x, self.data.attack.dst.y) + if (not attacker) or (not attacker.valid) then return end + if (not defender) or (not defender.valid) then return end -- Find the poison weapon -- If several attacks have poison, this will always find the last one From 496a58d343fa194bcdffceeac99a1a98db9694ad Mon Sep 17 00:00:00 2001 From: mattsc Date: Fri, 28 Feb 2014 07:04:54 -0800 Subject: [PATCH 2/4] Experimental AI: use checked versions of the AI actions So that only valid actions are executed and useful error messages are produced if something goes wrong. --- data/ai/lua/generic_recruit_engine.lua | 2 +- data/ai/lua/generic_rush_engine.lua | 6 +++--- data/ai/lua/move_to_any_target.lua | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/data/ai/lua/generic_recruit_engine.lua b/data/ai/lua/generic_recruit_engine.lua index 0d17134f318..a469043fbb8 100644 --- a/data/ai/lua/generic_recruit_engine.lua +++ b/data/ai/lua/generic_recruit_engine.lua @@ -559,7 +559,7 @@ return { until recruit_type ~= nil if wesnoth.unit_types[recruit_type].cost <= wesnoth.sides[wesnoth.current.side].gold then - ai.recruit(recruit_type, recruit_data.recruit.best_hex[1], recruit_data.recruit.best_hex[2]) + AH.checked_recruit(ai, recruit_type, recruit_data.recruit.best_hex[1], recruit_data.recruit.best_hex[2]) -- If the recruited unit cannot reach the target hex, return it to the pool of targets if recruit_data.recruit.target_hex ~= nil and recruit_data.recruit.target_hex[1] ~= nil then diff --git a/data/ai/lua/generic_rush_engine.lua b/data/ai/lua/generic_rush_engine.lua index c97636ce57f..b034c6311a7 100644 --- a/data/ai/lua/generic_rush_engine.lua +++ b/data/ai/lua/generic_rush_engine.lua @@ -254,7 +254,7 @@ return { if AH.print_exec() then print_time(' Executing castle_switch CA') end if AH.show_messages() then W.message { speaker = leader.id, message = 'Switching castles' } end - ai.move(leader, self.data.leader_target[1], self.data.leader_target[2]) + AH.checked_move(ai, leader, self.data.leader_target[1], self.data.leader_target[2]) self.data.leader_target = nil end @@ -500,7 +500,7 @@ return { -- If several attacks have poison, this will always find the last one local is_poisoner, poison_weapon = AH.has_weapon_special(attacker, "poison") - ai.attack(attacker, defender, poison_weapon) + AH.checked_attack(ai, attacker, defender, poison_weapon) self.data.attack = nil end @@ -606,7 +606,7 @@ return { if target then local x, y = wesnoth.find_vacant_tile(target[1], target[2], unit) local dest = AH.next_hop(unit, x, y) - ai.move(unit, dest[1], dest[2]) + AH.checked_move(ai, unit, dest[1], dest[2]) end end diff --git a/data/ai/lua/move_to_any_target.lua b/data/ai/lua/move_to_any_target.lua index 4df572afd85..ef732b7ff9e 100644 --- a/data/ai/lua/move_to_any_target.lua +++ b/data/ai/lua/move_to_any_target.lua @@ -44,7 +44,7 @@ return { end function move_to_any_target:move_to_enemy_exec() - ai.move(self.data.unit, self.data.destination[1], self.data.destination[2]) + AH.checked_move(ai, self.data.unit, self.data.destination[1], self.data.destination[2]) end return move_to_any_target From c89449786e2ccc2ea9ee29ed07b85f18347d93a3 Mon Sep 17 00:00:00 2001 From: mattsc Date: Fri, 28 Feb 2014 07:50:35 -0800 Subject: [PATCH 3/4] Change deprecation version for AI aspects It was incorrectly set to 1.12.0. Set to 1.13.0 now. --- src/ai/configuration.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/ai/configuration.cpp b/src/ai/configuration.cpp index a823e8a9af4..07789918937 100644 --- a/src/ai/configuration.cpp +++ b/src/ai/configuration.cpp @@ -402,7 +402,7 @@ bool configuration::upgrade_side_config_from_1_07_02_to_1_07_03(side_number side BOOST_FOREACH(const config &aitarget, aiparam.child_range("target")) { - lg::wml_error << deprecate_wml_key_warning("target", "1.12.0") << "\n"; + lg::wml_error << deprecate_wml_key_warning("target", "1.13.0") << "\n"; config aigoal; transfer_turns_and_time_of_day_data(aiparam,aigoal); @@ -421,7 +421,7 @@ bool configuration::upgrade_side_config_from_1_07_02_to_1_07_03(side_number side BOOST_FOREACH(config &ai_protect_unit, aiparam.child_range("protect_unit")) { - lg::wml_error << deprecate_wml_key_warning("protect_unit", "1.12.0") << "\n"; + lg::wml_error << deprecate_wml_key_warning("protect_unit", "1.13.0") << "\n"; transfer_turns_and_time_of_day_data(aiparam,ai_protect_unit); upgrade_protect_goal_config_from_1_07_02_to_1_07_03(side,ai_protect_unit,parsed_cfg,true); } @@ -429,7 +429,7 @@ bool configuration::upgrade_side_config_from_1_07_02_to_1_07_03(side_number side BOOST_FOREACH(config &ai_protect_location, aiparam.child_range("protect_location")) { - lg::wml_error << deprecate_wml_key_warning("protect_location", "1.12.0") << "\n"; + lg::wml_error << deprecate_wml_key_warning("protect_location", "1.13.0") << "\n"; transfer_turns_and_time_of_day_data(aiparam,ai_protect_location); upgrade_protect_goal_config_from_1_07_02_to_1_07_03(side,ai_protect_location,parsed_cfg,false); } @@ -438,14 +438,14 @@ bool configuration::upgrade_side_config_from_1_07_02_to_1_07_03(side_number side if (const config::attribute_value *v = aiparam.get("protect_leader")) { - lg::wml_error << deprecate_wml_key_warning("protect_leader", "1.12.0") << "\n"; + lg::wml_error << deprecate_wml_key_warning("protect_leader", "1.13.0") << "\n"; config c; c["value"] = *v; c["canrecruit"] = true; c["side_number"] = side; transfer_turns_and_time_of_day_data(aiparam,c); if (const config::attribute_value *v = aiparam.get("protect_leader_radius")) { - lg::wml_error << deprecate_wml_key_warning("protect_leader_radius", "1.12.0") << "\n"; + lg::wml_error << deprecate_wml_key_warning("protect_leader_radius", "1.13.0") << "\n"; c["radius"] = *v; } From 910f8c9d4df6ba03cb4469b19a9b44c8043d3f71 Mon Sep 17 00:00:00 2001 From: mattsc Date: Fri, 28 Feb 2014 08:16:47 -0800 Subject: [PATCH 4/4] Update changelog with AI bug fixes --- changelog | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/changelog b/changelog index ab40cff419c..35a0b585a0a 100644 --- a/changelog +++ b/changelog @@ -1,6 +1,11 @@ Version 1.11.10+dev: * Add-ons server: * Filenames with whitespace in them are no longer allowed. + * AI: + * Non-default multiplayer and Micro AIs: + * Fixed bugs which could lead to the AIs being disabled for the rest of the + turn if WML events removed or changed units during the AI turn + * Improved error reporting of invalid AI actions * Campaigns: * Eastern Invasion: * Updated maps for scenario 8, 11, 12, 14, 16 and 17a.