Make Lua's wesnoth.transform_unit() function preserve hit points.

This is actually simpler to implement and is more consistent with the
[transform_unit] tag.  Plus, the wiki documentation for
wesnoth.transform_unit() does not state that the hit points definitely
will be changed (it's a bit vague on that point), so this is
consistent with the existing documentation.
This commit is contained in:
J. Tyne 2013-01-05 14:53:05 +00:00
parent e8796a8279
commit 7b0a480254
3 changed files with 5 additions and 10 deletions

View file

@ -28,6 +28,8 @@ Version 1.11.1+svn:
* Lua API:
* new wesnoth.get_time_stamp() function
* new helper.shuffle() function
* The wesnoth.transform_unit() function no longer performs a full heal when
the type has actually changed.
* Multiplayer:
* Moved new lobby option in Preferences -> Multiplayer to Advanced
Preferences and clarified description

View file

@ -915,26 +915,25 @@ function wml_actions.transform_unit(cfg)
local transform_to = cfg.transform_to
for index, unit in ipairs(wesnoth.get_units(cfg)) do
local hitpoints = unit.hitpoints
if transform_to then
wesnoth.transform_unit( unit, transform_to )
else
local hitpoints = unit.hitpoints
local experience = unit.experience
unit.experience = unit.max_experience
local status = helper.get_child( unit.__cfg, "status" )
unit.experience = unit.max_experience
wml_actions.store_unit { { "filter", { id = unit.id } }, variable = "Lua_store_unit", kill = true }
wml_actions.unstore_unit { variable = "Lua_store_unit", find_vacant = false, advance = true, fire_event = false }
wesnoth.set_variable ( "Lua_store_unit")
unit.hitpoints = hitpoints
unit.experience = experience
for key, value in pairs(status) do unit.status[key] = value end
end
unit.hitpoints = hitpoints
if unit.status.not_living then unit.status.poisoned = nil end
end

View file

@ -2613,16 +2613,10 @@ static int intf_transform_unit(lua_State *L)
{
unit *u = luaW_checkunit(L, 1);
char const *m = luaL_checkstring(L, 2);
const bool full_heal = u->type_id() != m;
const unit_type *utp = unit_types.find(m);
if (!utp) return luaL_argerror(L, 2, "unknown unit type");
u->advance_to(utp);
// This is to exactly preserve the old behavior, but perhaps it should
// be removed?
if ( full_heal )
u->heal_all();
return 0;
}