URL:
  <http://gna.org/patch/?2031>

                 Summary: fixing [store_unit]mode=replace and adding [kill] -
tag functionality
                 Project: Battle for Wesnoth
            Submitted by: anonymissimus
            Submitted on: Dienstag 05.10.2010 um 19:49
                Priority: 5 - Normal
                  Status: None
                 Privacy: Public
             Assigned to: silene
        Originator Email: 
             Open/Closed: Open
         Discussion Lock: Any

    _______________________________________________________

Details:

1. There was a small bug; [store_unit]mode=replace wasn't handled, resulting
in the variable being cleared even though no unit was found.
2. This adds fire_event=, animate= and [secondary_unit] functionality to
[store_unit].

I construct the table passed to wml_actions.kill manually since the wml
author could put keys into [store_unit] that would break kill=yes. Also, I
think it's better to use the existing wml_actions.kill instead of "rewriting"
it for [store_unit]kill=yes.
see also: http://forums.wesnoth.org/viewtopic.php?f=21&t=31822&start=0

current_code:

function wml_actions.store_unit(cfg)
        local filter = helper.get_child(cfg, "filter") or
                helper.wml_error "[store_unit] missing required [filter] tag"
        local kill_units = cfg.kill
        local fire_event = kill_units and cfg.fire_event

        local secondary_unit = helper.get_child(cfg, "secondary_unit")
        if secondary_unit then secondary_unit = { "secondary_unit", 
secondary_unit }
end

        local var = cfg.variable or "unit"
        local mode = cfg.mode

        local idx = 0
        local units = wesnoth.get_units(filter)
        local recall_units
        if (not cfg.x or cfg.x == "recall") and (not cfg.y or cfg.y == "recall")
then
                recall_units = wesnoth.get_recall_units(filter)
        end

        if mode == "append" then
                idx = wesnoth.get_variable(var .. ".length")
        else
                if mode ~= "replace" or units[1] or recall_units[1] then
                        wesnoth.set_variable(var)
                end
        end

        for i,u in ipairs(units) do
                if not fire_event or u.valid then
                        wesnoth.set_variable(string.format("%s[%d]", var, idx), 
u.__cfg)
                        idx = idx + 1
                        if kill_units then
                                wml_actions.kill({ id = u.id, fire_event = 
fire_event, animate =
cfg.animate, secondary_unit })
                        end
                end
        end

        for i,u in ipairs(recall_units) do
                if not fire_event or u.valid then
                        local ucfg = u.__cfg
                        ucfg.x = "recall"
                        ucfg.y = "recall"
                        wesnoth.set_variable(string.format("%s[%d]", var, idx), 
ucfg)
                        idx = idx + 1
                        if kill_units then wesnoth.extract_unit(u) end
                end
        end
end





    _______________________________________________________

File Attachments:


-------------------------------------------------------
Date: Dienstag 05.10.2010 um 19:49  Name: kill.patch  Size: 2kB   By:
anonymissimus

<http://gna.org/patch/download.php?file_id=10633>

    _______________________________________________________

Reply to this item at:

  <http://gna.org/patch/?2031>

_______________________________________________
  Nachricht geschickt von/durch Gna!
  http://gna.org/


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

Reply via email to