Author: nephro
Date: Tue Apr  3 04:13:15 2012
New Revision: 53758

URL: http://svn.gna.org/viewcvs/wesnoth?rev=53758&view=rev
Log:
(1)LuaAI ai.get_avoid() now provides the correct coordinates(not offset by -1), 
this reduced some code duplication and code inconsistency (2)Tweaked 
ai.attack() of LuaAI to consider weapons are numbered from 1 and so forth, so 
that this function is more consistent to the Lua indexing style

Modified:
    trunk/data/ai/scenarios/scenario-lua-ai.cfg
    trunk/src/ai/lua/core.cpp

Modified: trunk/data/ai/scenarios/scenario-lua-ai.cfg
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/data/ai/scenarios/scenario-lua-ai.cfg?rev=53758&r1=53757&r2=53758&view=diff
==============================================================================
--- trunk/data/ai/scenarios/scenario-lua-ai.cfg (original)
+++ trunk/data/ai/scenarios/scenario-lua-ai.cfg Tue Apr  3 04:13:15 2012
@@ -161,6 +161,24 @@
         {MODIFY_AI_DELETE_CANDIDATE_ACTION 2 ca_loop firstca}
     [/event]
 
+       [event]
+               name=side 2 turn 1 
+               [modify_side]
+                       side=2
+                       [ai]
+                               [avoid]
+                                       x,y=1,11
+                               [/avoid]
+ 
+                               [leader_goal]
+                                       x,y=2,12
+                               [/leader_goal]
+                       [/ai]
+               [/modify_side]
+ 
+        #{MODIFY_UNIT side=1 moves 0}
+       [/event]
+
     [side]
         type=Dwarvish Steelclad
         id=side_1_leader
@@ -290,6 +308,7 @@
                     x,y=42,20
                 [/criteria]
             [/goal]
+
             [goal]
                 name=lua_goal
                 value=6
@@ -311,7 +330,7 @@
                 code= <<
 --! ==============================================================
 ai = ...
--- local data = {} -- @note: this shouldn't be here
+
 
 local my_ai = { }
 
@@ -321,16 +340,13 @@
 ai_stdlib.init(ai)
 
 
-function my_ai:stage_hello()
-       wesnoth.message('hello from stage!')
-       --wesnoth.message('PERSISTANCE: ' .. tostring(self.data["pers"]) .. 
self.data["stringg"])
-       --local tg = ai.get_targets()
-       --for k,v in pairs(tg) do
-       --      if v.type==3 or v.type==4 then
-       --              wesnoth.message(tg[k].type .. " " .. tg[k].value .. " " 
.. tg[k].loc.x .. " " ..tg[k].loc.y)
-       --      end
-       --end
-
+function my_ai:stage_hello()   
+       wesnoth.message('hello from stage!')
+       local debug_utils = wesnoth.require 
"~add-ons/Wesnoth_Lua_Pack/debug_utils.lua"
+       local avoid = ai.get_avoid()
+        local leader_goal = ai.get_leader_goal()
+        debug_utils.dbms(avoid,false,"variable",false)
+        debug_utils.dbms(leader_goal,false,"variable",false)
 end
 
 function my_ai:candidate_action_evaluation_hello()
@@ -348,14 +364,6 @@
 
 function my_ai:candidate_action_evaluation_hello2()
        wesnoth.message('hello from second candidate action evaluation!')
-       wesnoth.message("LuaDebug", "hello")    
-       local map = ai.get_enemy_dstsrc()
-       wesnoth.message("LuaDebug", "hello " .. #map)
-       for dst,src in pairs(map) do
-               for k,v in pairs(src) do
-                       wesnoth.message("LuaDebug", dst.x .. "," .. dst.y .. " 
-> " .. v.x .. "," .. v.y)
-               end
-       end
        return 99
 end
 
@@ -375,7 +383,7 @@
        --! full move. note that the my_leader still can be used altrough x and 
y are now different.
        --ai.move_full(my_leader, 11, 23)
        --! attack with auto weapon/aggression
-       ai.attack(2, 12, 3, 12)
+       ai.attack(2, 12, 3, 12, 2)
        --! attack with weapon selected
        ai.attack(3, 11, 3, 12, 1)
        --! attack with different aggression

Modified: trunk/src/ai/lua/core.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/ai/lua/core.cpp?rev=53758&r1=53757&r2=53758&view=diff
==============================================================================
--- trunk/src/ai/lua/core.cpp (original)
+++ trunk/src/ai/lua/core.cpp Tue Apr  3 04:13:15 2012
@@ -218,8 +218,8 @@
                aggression = lua_tonumber(L, index+1);
        }
 
-       if (!lua_isnoneornil(L, index)) {
-               attacker_weapon = lua_tointeger(L, index);
+       if (!lua_isnoneornil(L, index) &&  attacker_weapon != -1) {
+               attacker_weapon = lua_tointeger(L, index) - 1; // Done for 
consistency of the Lua style 
        }
 
        ai::attack_result_ptr attack_result = 
ai::actions::execute_attack_action(side,true,attacker,defender,attacker_weapon,aggression);
@@ -351,15 +351,19 @@
        for (int i = 0; it != locs.end(); ++it, ++i)
        {
                lua_pushinteger(L, i + 1); // Index for the map location
-               lua_createtable(L, 2, 0); // Table for a single map location
-
-               lua_pushstring(L, "x");
-               lua_pushinteger(L, it->x);
-               lua_settable(L, -3);
-
-               lua_pushstring(L, "y");
-               lua_pushinteger(L, it->y);
-               lua_settable(L, -3);
+               
+               push_map_location(L, *it);
+               
+               // Deprecated
+               //lua_createtable(L, 2, 0); // Table for a single map location
+
+               //lua_pushstring(L, "x");
+               //lua_pushinteger(L, it->x + 1);
+               //lua_settable(L, -3);
+
+               //lua_pushstring(L, "y");
+               //lua_pushinteger(L, it->y + 1);
+               //lua_settable(L, -3);
 
                lua_settable(L, -3);
        }


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

Reply via email to