I'm studying lua AI, and I have problems with the following
Moderator: Forum Moderators
-
- Posts: 1
- Joined: June 13th, 2015, 8:40 am
I'm studying lua AI, and I have problems with the following
Code: Select all
local keeps = wesnoth.get_locations
{
terrain = 'K*,K*^*,*^K*', -- Keeps
x = '1-'..width,
y = '1-'..height,
{ "not", { {"filter", {}} }}, -- That have no unit
{ "not", { radius = 6, {"filter", { canrecruit = 'yes',
{ "filter_side", { { "enemy_of", {side = wesnoth.current.side} } } }
}} }}, -- That are not too close to an enemy leader
{ "not", {
x = leader.x, y = leader.y, terrain = 'K*,K*^*,*^K*',
radius = 3,
{ "filter_radius", { terrain = 'C*,K*,C*^*,K*^*,*^K*,*^C*' } }
}}, -- That are not close and connected to a keep the leader is on
{ "filter_adjacent_location", {
terrain = 'C*,K*,C*^*,K*^*,*^K*,*^C*'
}} -- That are not one-hex keeps
}
Re: I'm studying lua AI, and I have problems with the follow
wesnoth.get_locations() takes a Standard Location Filter (SLF) as defined on the wiki here. So that will tell you what the parameters mean.
As for the syntax, a WML tag such asis coded in Lua like this
Formatted somewhat differently (possibly easier to decipher), since line breaks don't matter in Lua, you could also write it like this
Note that the "", the commas and all the brackets are important and cannot be omitted.
Thus, the beginning of your example is the Lua version of the following WML code (for simplicity for this example, I assumed that the Lua variable 'width' equals 20, and 'height' equals 15):
Hope that helps and it's always great having somebody trying to work on Wesnoth AIs!
As for the syntax, a WML tag such as
Code: Select all
[tag]
key1=value1
key2=value2
[/tag]
Code: Select all
{ "tag", { key1 = value1, key2 = value2 } }
Code: Select all
{ "tag",
{
key1 = value1,
key2 = value2
}
}
Thus, the beginning of your example is the Lua version of the following WML code (for simplicity for this example, I assumed that the Lua variable 'width' equals 20, and 'height' equals 15):
Code: Select all
terrain = 'K*,K*^*,*^K*' # Keeps
x = 1-20
y = 1-15
[not] # That have no unit
[filter]
[/filter]
[/not]
[not] # That are not too close to an enemy leader
radius = 6
[filter]
canrecruit = yes
[filter_side]
[enemy_of]
side = $side_number
[/enemy_of]
[/filter_side]
[/filter]
[/not]
...
SP campaigns: Galuldur's First Journey (1.12 & 1.14) & Grnk the Mighty (1.10 & 1.12)
AI experiments: Micro AIs (wiki, forum thread, known/fixed bugs), Fred, AI-demos add-on
AI experiments: Micro AIs (wiki, forum thread, known/fixed bugs), Fred, AI-demos add-on