Herding Micro AI: bug fix for dogs sometimes having moves left at end

The problem is due to a dog adjacent to a sheep being excluded from the
dog_move CA (so that it can act further later on in case the sheep
moves again). It is fixed by adding another CA at the end that simply
takes all moves away from all dogs once all other CAs are done.
This commit is contained in:
mattsc 2015-04-02 07:21:38 -07:00
parent 95616c5af9
commit 38b089358a
2 changed files with 30 additions and 1 deletions

View file

@ -0,0 +1,28 @@
local AH = wesnoth.require "ai/lua/ai_helper.lua"
local function get_dog(cfg)
local dogs = AH.get_units_with_moves {
side = wesnoth.current.side,
{ "and", cfg.filter },
}
return dogs[1]
end
-- This CA simply takes moves away from all dogs with moves left. This is done
-- at the end of the AI moves in order to keep dogs adjacent to sheep where
-- they are and not have the default AI take over.
local ca_herding_dog_stopmove = {}
function ca_herding_dog_stopmove:evaluation(ai, cfg)
if get_dog(cfg) then return cfg.ca_score end
return 0
end
function ca_herding_dog_stopmove:execution(ai, cfg)
local dog = get_dog(cfg)
AH.checked_stopunit_moves(ai, dog)
end
return ca_herding_dog_stopmove

View file

@ -312,7 +312,8 @@ function wesnoth.wml_actions.micro_ai(cfg)
{ ca_id = "sheep_runs_dog", location = CA_path .. 'ca_herding_sheep_runs_dog.lua', score = score - 2 },
{ ca_id = "herd_sheep", location = CA_path .. 'ca_herding_herd_sheep.lua', score = score - 3 },
{ ca_id = "sheep_move", location = CA_path .. 'ca_herding_sheep_move.lua', score = score - 4 },
{ ca_id = "dog_move", location = CA_path .. 'ca_herding_dog_move.lua', score = score - 5 }
{ ca_id = "dog_move", location = CA_path .. 'ca_herding_dog_move.lua', score = score - 5 },
{ ca_id = "dog_stopmove", location = CA_path .. 'ca_herding_dog_stopmove.lua', score = score - 6 }
}
elseif (cfg.ai_type == 'forest_animals') then