Author: crab
Date: Tue Apr 14 02:05:48 2009
New Revision: 34889

URL: http://svn.gna.org/viewcvs/wesnoth?rev=34889&view=rev
Log:
Used lua scripting to make AI Arena independent from test situations.
Special thanks to silene for hints on using lua.

Added:
    trunk/data/ai/scenarios/ai_arena_small/0001-healing.cfg   (contents, props 
changed)
      - copied, changed from r34874, 
trunk/data/ai/scenarios/ai_arena_small/test_0001.cfg
    trunk/data/ai/scenarios/ai_arena_small/0002-poisoning.cfg   (contents, 
props changed)
      - copied, changed from r34874, 
trunk/data/ai/scenarios/ai_arena_small/test_0002.cfg
Removed:
    trunk/data/ai/scenarios/ai_arena_small/test_0001.cfg
    trunk/data/ai/scenarios/ai_arena_small/test_0002.cfg
Modified:
    trunk/data/ai/scenarios/scenario-AI_Arena_small.cfg

Copied: trunk/data/ai/scenarios/ai_arena_small/0001-healing.cfg (from r34874, 
trunk/data/ai/scenarios/ai_arena_small/test_0001.cfg)
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/data/ai/scenarios/ai_arena_small/0001-healing.cfg?p2=trunk/data/ai/scenarios/ai_arena_small/0001-healing.cfg&p1=trunk/data/ai/scenarios/ai_arena_small/test_0001.cfg&r1=34874&r2=34889&rev=34889&view=diff
==============================================================================
--- trunk/data/ai/scenarios/ai_arena_small/test_0001.cfg (original)
+++ trunk/data/ai/scenarios/ai_arena_small/0001-healing.cfg Tue Apr 14 02:05:48 
2009
@@ -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]

Propchange: trunk/data/ai/scenarios/ai_arena_small/0001-healing.cfg
------------------------------------------------------------------------------
    svn:eol-style = native

Copied: trunk/data/ai/scenarios/ai_arena_small/0002-poisoning.cfg (from r34874, 
trunk/data/ai/scenarios/ai_arena_small/test_0002.cfg)
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/data/ai/scenarios/ai_arena_small/0002-poisoning.cfg?p2=trunk/data/ai/scenarios/ai_arena_small/0002-poisoning.cfg&p1=trunk/data/ai/scenarios/ai_arena_small/test_0002.cfg&r1=34874&r2=34889&rev=34889&view=diff
==============================================================================
--- trunk/data/ai/scenarios/ai_arena_small/test_0002.cfg (original)
+++ trunk/data/ai/scenarios/ai_arena_small/0002-poisoning.cfg Tue Apr 14 
02:05:48 2009
@@ -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]

Propchange: trunk/data/ai/scenarios/ai_arena_small/0002-poisoning.cfg
------------------------------------------------------------------------------
    svn:eol-style = native

Removed: trunk/data/ai/scenarios/ai_arena_small/test_0001.cfg
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/data/ai/scenarios/ai_arena_small/test_0001.cfg?rev=34888&view=auto
==============================================================================
--- trunk/data/ai/scenarios/ai_arena_small/test_0001.cfg (original)
+++ trunk/data/ai/scenarios/ai_arena_small/test_0001.cfg (removed)
@@ -1,74 +1,0 @@
-[event]
-    name=test_0001
-    first_time_only=no
-
-    [message]
-        speaker=narrator
-        image=wesnoth-icon.png
-        message= "This situation should test the ability of AI to heal 
efficiently..."
-    [/message]
-    {UNIT 2 Peasant 10 11 hitpoints=1}
-    {NOTRAIT_UNIT 2 "Mage of Light" 16 16}
-    {UNIT 2 "Heavy Infantryman" 19 13 hitpoints=1}
-    {UNIT 2 "General" 21 13 hitpoints=1}
-    {UNIT 2 "Grand Knight" 21 14 hitpoints=1}
-    {UNIT 2 "Halberdier" 10 12 hitpoints=1}
-    {UNIT 2 "Pikeman" 9 17 hitpoints=1}
-    {UNIT 2 "Master at Arms" 20 12 hitpoints=1}
-    {UNIT 2 Peasant 21 9 hitpoints=1}
-    {UNIT 2 Peasant 16 17 hitpoints=1}
-    {UNIT 2 Peasant 9 17 hitpoints=1}
-
-    [capture_village]
-        side=2
-        x,y=5,9
-    [/capture_village]
-    [capture_village]
-        side=2
-        x,y=6,19
-    [/capture_village]
-    [capture_village]
-        side=2
-        x,y=9,17
-    [/capture_village]
-    [capture_village]
-        side=2
-        x,y=10,20
-    [/capture_village]
-    [capture_village]
-        side=2
-        x,y=11,4
-    [/capture_village]
-    [capture_village]
-        side=2
-        x,y=14,8
-    [/capture_village]
-    [capture_village]
-        side=2
-        x,y=16,17
-    [/capture_village]
-    [capture_village]
-        x,y=19,22
-        side=2
-    [/capture_village]
-    [capture_village]
-        side=2
-        x,y=20,5
-    [/capture_village]
-    [capture_village]
-        side=2
-        x,y=21,9
-    [/capture_village]
-    [capture_village]
-        side=2
-        x,y=24,6
-    [/capture_village]
-    [capture_village]
-        side=2
-        x,y=25,17
-    [/capture_village]
-    [modify_side]
-        side=2
-        gold=10000
-    [/modify_side]
-[/event]

Removed: trunk/data/ai/scenarios/ai_arena_small/test_0002.cfg
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/data/ai/scenarios/ai_arena_small/test_0002.cfg?rev=34888&view=auto
==============================================================================
--- trunk/data/ai/scenarios/ai_arena_small/test_0002.cfg (original)
+++ trunk/data/ai/scenarios/ai_arena_small/test_0002.cfg (removed)
@@ -1,133 +1,0 @@
-[event]
-    name=test_0002
-    first_time_only=no
-
-    [message]
-        speaker=narrator
-        image=wesnoth-icon.png
-        message=_ "This situation should test the ability of AI to spread 
poison around..."
-    [/message]
-    [unit]
-        side=2
-        x,y=23,14
-        type="Orcish Assassin"
-    [/unit]
-    [unit]
-        side=2
-        x,y=25,17
-        type="Orcish Assassin"
-    [/unit]
-    [unit]
-        side=2
-        x,y=19,7
-        type="Orcish Assassin"
-    [/unit]
-    [unit]
-        side=2
-        x,y=10,14
-        type="Orcish Assassin"
-    [/unit]
-    [unit]
-        side=2
-        x,y=20,7
-        type="Orcish Assassin"
-    [/unit]
-    [unit]
-        side=3
-        x,y=20,5
-        type="Drake Warden"
-        random_traits="no"
-        [modifications]
-            {TRAIT_RESILIENT}
-        [/modifications]
-    [/unit]
-    [unit]
-        side=3
-        x,y=21,7
-        type="Drake Warden"
-        random_traits=0
-    [/unit]
-    [unit]
-        side=3
-        x,y=23,16
-        type="Drake Warden"
-        random_traits=0
-        [modifications]
-            {TRAIT_RESILIENT}
-        [/modifications]
-    [/unit]
-    [unit]
-        side=3
-        x,y=17,5
-        type="Drake Warden"
-        random_traits=0
-    [/unit]
-    [unit]
-        side=3
-        x,y=15,7
-        type="Drake Warden"
-        random_traits=0
-    [/unit]
-    [unit]
-        side=3
-        x,y=17,8
-        type="Drake Warden"
-        random_traits=0
-    [/unit]
-    [unit]
-        side=3
-        x,y=19,9
-        type="Drake Warden"
-        random_traits=0
-    [/unit]
-    [unit]
-        side=3
-        x,y=26,18
-        type="Ancient Wose"
-        random_traits=0
-    [/unit]
-    [unit]
-        side=3
-        hitpoints=3
-        x,y=26,14
-        type="Drake Warden"
-        random_traits=0
-    [/unit]
-    [unit]
-        side=3
-        x,y=9,17
-        type="Skeleton"
-    [/unit]
-    [label]
-        colour="255,0,0,0"
-        text="Undead target test"
-        visible_in_fog="yes"
-        x="9"
-        y="17"
-    [/label]
-    [label]
-        colour="255,0,0,0"
-        text="Target choose test"
-        visible_in_fog="yes"
-        x="19"
-        y="6"
-    [/label]
-    [label]
-        colour="255,0,0,0"
-        text="Regeneration attack test"
-        visible_in_fog="yes"
-        x="25"
-        y="19"
-    [/label]
-    [label]
-        colour="255,0,0,0"
-        text="Weapon test with low hp target"
-        visible_in_fog="yes"
-        x="26"
-        y="14"
-    [/label]
-    [modify_side]
-        side=3
-        switch_ai=$test_path_to_idle_ai
-    [/modify_side]
-[/event]

Modified: trunk/data/ai/scenarios/scenario-AI_Arena_small.cfg
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/data/ai/scenarios/scenario-AI_Arena_small.cfg?rev=34889&r1=34888&r2=34889&view=diff
==============================================================================
--- trunk/data/ai/scenarios/scenario-AI_Arena_small.cfg (original)
+++ trunk/data/ai/scenarios/scenario-AI_Arena_small.cfg Tue Apr 14 02:05:48 2009
@@ -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]
@@ -73,6 +93,8 @@
             [/command]
         [/set_menu_item]
     [/event]
+
+    {ai/scenarios/ai_arena_small/}
 
     [side]
         side=1
@@ -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
@@ -295,44 +296,6 @@
     [/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
         [modify_side]


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to