Author: silene
Date: Sat Apr 18 20:38:34 2009
New Revision: 35025

URL: http://svn.gna.org/viewcvs/wesnoth?rev=35025&view=rev
Log:
Replaced C++ implementation of the [objectives] tag by a Lua function.

Added:
    trunk/data/lua/wml-tags.lua
Modified:
    trunk/data/core/_main.cfg

Modified: trunk/data/core/_main.cfg
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/data/core/_main.cfg?rev=35025&r1=35024&r2=35025&view=diff
==============================================================================
--- trunk/data/core/_main.cfg (original)
+++ trunk/data/core/_main.cfg Sat Apr 18 20:38:34 2009
@@ -12,3 +12,7 @@
 {core/terrain-graphics/}
 {core/units.cfg}
 {core/editor/}
+
+[lua]
+       code=<< wesnoth.dofile("lua/wml-tags.lua") >>
+[/lua]

Added: trunk/data/lua/wml-tags.lua
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/data/lua/wml-tags.lua?rev=35025&view=auto
==============================================================================
--- trunk/data/lua/wml-tags.lua (added)
+++ trunk/data/lua/wml-tags.lua Sat Apr 18 20:38:34 2009
@@ -1,0 +1,76 @@
+local function all_teams()
+       local function f(s)
+               local i = s.i
+               local team = wesnoth.get_side(i)
+               s.i = i + 1
+               return team
+       end
+       return f, { i = 1 }
+end
+
+local function child_range(cfg, tag)
+       local function f(s)
+               local c
+               repeat
+                       local i = s.i
+                       c = cfg[i]
+                       if not c then return end
+                       s.i = i + 1
+               until c[1] == tag
+               return c[2]
+       end
+       return f, { i = 1 }
+end
+
+local function wml_objectives(cfg)
+       local _ = wesnoth.textdomain("wesnoth")
+       local objectives = ""
+       local win_objectives = ""
+       local lose_objectives = ""
+
+       local win_string = cfg.victory_string
+       if not win_string then
+               win_string = _ "Victory:"
+       end
+       local lose_string = cfg.defeat_string
+       if not lose_string then
+               lose_string = _ "Defeat:"
+       end
+
+       for obj in child_range(cfg, "objective") do
+               local condition = obj.condition
+               if condition == "win" then
+                       win_objectives = win_objectives .. "\n@" .. 
obj.description
+               elseif condition == "lose" then
+                       lose_objectives = lose_objectives .. "\n#" .. 
obj.description
+               else
+                       wesnoth.message "Unknown condition, ignoring."
+               end
+       end
+
+       local summary = cfg.summary
+       if summary then
+               objectives = "*" .. summary .. "\n"
+       end
+       if win_objectives ~= "" then
+               objectives = objectives .. "*" .. win_string .. "\n" .. 
win_objectives .. "\n"
+       end
+       if lose_objectives ~= "" then
+               objectives = objectives .. "*" .. lose_string .. "\n" .. 
lose_objectives .. "\n"
+       end
+
+       local silent = cfg.silent
+       local side = cfg.side or 0
+       if side == 0 then
+               for team in all_teams() do
+                       team.objectives = objectives
+                       if not silent then team.objectives_changed = true end
+               end
+       else
+               local team = wesnoth.get_side(side)
+               team.objectives = objectives
+               if not silent then team.objectives_changed = true end
+       end
+end
+
+wesnoth.register_wml_action("objectives", wml_objectives)


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

Reply via email to