Used lua scripting to make AI Arena independent from test situations.

Special thanks to silene for hints on using lua.
This commit is contained in:
Iurii Chernyi 2009-04-14 00:05:48 +00:00
parent f89acd9648
commit b8b7b2f1ce
3 changed files with 57 additions and 80 deletions

View file

@ -1,5 +1,12 @@
[event]
name=test_0001
name=preload
[lua]
code = << register_test('0001-healing','Healing test'); >>
[/lua]
[/event]
[event]
name=0001-healing
first_time_only=no
[message]

View file

@ -1,5 +1,12 @@
[event]
name=test_0002
name=preload
[lua]
code = << register_test('0002-poisoning','Poison use test'); >>
[/lua]
[/event]
[event]
name=0002-poisoning
first_time_only=no
[message]

View file

@ -15,7 +15,24 @@
{PLACE_IMAGE items/burial.png 15 13}
{PLACE_IMAGE items/burial.png 26 16}
{PLACE_IMAGE items/burial.png 4 9}
{ai/scenarios/ai_arena_small/}
[event]
name=preload
[lua]
code = <<
H = wesnoth.dofile("lua/helper.lua")
W = H.set_wml_action_metatable({})
H.set_wml_var_metatable(_G)
local tests_table = {}
function register_test(_name, _description)
tests_table[_name] = _description
end
function get_tests_table()
return tests_table
end
>>
[/lua]
[/event]
[event]
name=preload
@ -37,7 +54,7 @@
[/set_variable]
[set_variable]
name=test_id
value=2
value=0002-poisoning
[/set_variable]
[set_menu_item]
@ -47,8 +64,11 @@
[fire_event]
name="_clean_arena"
[/fire_event]
[lua]
code= << W.fire_event {name=wesnoth.get_variable("test_id") } >>
[/lua]
[fire_event]
name="_setup_test"
name="_replace_ai_2"
[/fire_event]
[/command]
[/set_menu_item]
@ -74,6 +94,8 @@
[/set_menu_item]
[/event]
{ai/scenarios/ai_arena_small/}
[side]
side=1
name="AI Developer"
@ -113,48 +135,27 @@
[event]
name=_select_test
first_time_only=no
[message]
speaker=narrator
message=_ "Which test do you want to run, oh Mightly AI Developer ?"
[option]
message=_ "Repeat last test [$test_id]"
[/option]
[option]
message=_ "Clean the Arena [0]"
[command]
[set_variable]
name=test_id
value=0
[/set_variable]
[/command]
[/option]
[option]
message=_ "Healing: Simple healing use [1]"
[command]
[set_variable]
name=test_id
value=1
[/set_variable]
[/command]
[/option]
[option]
message=_ "Poison: Spreading poison around [2]"
[command]
[set_variable]
name=test_id
value=2
[/set_variable]
[/command]
[/option]
[/message]
[command]
[fire_event]
name="_clean_arena"
[/fire_event]
[/command]
[lua]
code= <<
local opts = {}
for k,v in pairs(get_tests_table()) do
local cmd = { "command", {{ "set_variable", {name="test_id", value= k } } } }
table.insert(opts, { "option", { message = v, cmd } } )
end
W.message { speaker="narrator", message="Which test do you want to run, oh Mightly AI Developer?", unpack(opts) }
>>
[/lua]
[lua]
code= << W.fire_event {name=wesnoth.get_variable("test_id") } >>
[/lua]
[command]
[fire_event]
name="_setup_test"
name="_replace_ai_2"
[/fire_event]
[/command]
[/event]
@ -191,7 +192,7 @@
message=_ "I've come with my own AI, and I am ready to test its strength"
[command]
[message]
speaker=unit
speaker=narrator
message=_ "and where is it located ? (path follows the usual WML convention)"
[text_input]
label=_ "AI Location:"
@ -201,7 +202,7 @@
[/command]
[/option]
[option]
message=_ "I want to test formulaAI-based poisoning improvements written by Velory"
message=_ "I want to test formulaAI-based poisoning improvements"
[command]
[set_variable]
name=test_path_to_ai
@ -294,44 +295,6 @@
[/modify_side]
[/event]
[event]
name=_setup_test
first_time_only=no
[switch]
variable=test_id
[case]
value="0"
[message]
speaker=narrator
image=wesnoth-icon.png
message=_ "The Arena has been cleaned..."
[/message]
[/case]
[case]
value="1"
[fire_event]
name=test_0001
[/fire_event]
[/case]
[case]
value="2"
[fire_event]
name=test_0002
[/fire_event]
[/case]
[else]
[message]
speaker=narrator
message=_ "sadly, this test is not yet known in the land of Wesnoth..."
image=wesnoth-icon.png
[/message]
[/else]
[/switch]
[fire_event]
name="_replace_ai_2"
[/fire_event]
[/event]
[event]
name=_replace_ai_2
first_time_only=no