Lua AIs: avoid calling wesnoth.get_terrain() more than needed
It probably doen't make a noticeable difference for these AIs, but in general we should not call the slow functions more than necessary.
(cherry-picked from commit 42b4430841
)
This commit is contained in:
parent
8965939939
commit
2b6b1ed4fe
2 changed files with 10 additions and 7 deletions
|
@ -42,7 +42,8 @@ function ca_spread_poison:evaluation(cfg, data)
|
|||
local cant_poison = defender.status.poisoned or defender.status.unpoisonable
|
||||
|
||||
-- For now, we also simply don't poison units on villages (unless standard combat CA does it)
|
||||
local on_village = wesnoth.get_terrain_info(wesnoth.get_terrain(defender.x, defender.y)).village
|
||||
local defender_terrain = wesnoth.get_terrain(defender.x, defender.y)
|
||||
local on_village = wesnoth.get_terrain_info(defender_terrain).village
|
||||
|
||||
-- Also, poisoning units that would level up through the attack or could level on their turn as a result is very bad
|
||||
local about_to_level = defender.max_experience - defender.experience <= (attacker.level * 2)
|
||||
|
@ -58,15 +59,16 @@ function ca_spread_poison:evaluation(cfg, data)
|
|||
if defender:ability('regenerate') then rating = rating - 1000 end
|
||||
|
||||
-- More priority to enemies on strong terrain
|
||||
local defender_defense = 100 - defender:defense(wesnoth.get_terrain(defender.x, defender.y))
|
||||
local defender_defense = 100 - defender:defense(defender_terrain)
|
||||
rating = rating + defender_defense / 4.
|
||||
|
||||
-- For the same attacker/defender pair, go to strongest terrain
|
||||
local attack_defense = 100 - attacker:defense(wesnoth.get_terrain(a.dst.x, a.dst.y))
|
||||
rating = rating + attack_defense / 2.
|
||||
local attacker_terrain = wesnoth.get_terrain(a.dst.x, a.dst.y)
|
||||
local attacker_defense = 100 - attacker:defense(attacker_terrain)
|
||||
rating = rating + attacker_defense / 2.
|
||||
|
||||
-- And from village everything else being equal
|
||||
local is_village = wesnoth.get_terrain_info(wesnoth.get_terrain(a.dst.x, a.dst.y)).village
|
||||
local is_village = wesnoth.get_terrain_info(attacker_terrain).village
|
||||
if is_village then rating = rating + 0.5 end
|
||||
|
||||
if rating > max_rating then
|
||||
|
|
|
@ -103,10 +103,11 @@ function ca_healer_move:evaluation(cfg, data)
|
|||
rating = rating - enemies_in_reach * 1000
|
||||
|
||||
-- All else being more or less equal, prefer villages and strong terrain
|
||||
local is_village = wesnoth.get_terrain_info(wesnoth.get_terrain(loc[1], loc[2])).village
|
||||
local terrain = wesnoth.get_terrain(loc[1], loc[2])
|
||||
local is_village = wesnoth.get_terrain_info(terrain).village
|
||||
if is_village then rating = rating + 2 end
|
||||
|
||||
local defense = 100 - healer:defense(wesnoth.get_terrain(loc[1], loc[2]))
|
||||
local defense = 100 - healer:defense(terrain)
|
||||
rating = rating + defense / 10.
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue