expose a function to trigger a unit transformation from a script

This commit is contained in:
Tim Felgentreff 2015-09-02 14:27:00 +02:00
parent b9ac622b74
commit b8a4a7c43d

View file

@ -703,6 +703,26 @@ static int CclCreateUnit(lua_State *l)
}
}
/**
** 'Upgrade' a unit in place to a unit of different type.
**
** @param l Lua state.
**
** @return Returns success.
*/
static int CclTransformUnit(lua_State *l)
{
lua_pushvalue(l, 1);
CUnit *targetUnit = CclGetUnit(l);
lua_pop(l, 1);
lua_pushvalue(l, 2);
const CUnitType *unittype = TriggerGetUnitType(l);
lua_pop(l, 1);
CommandUpgradeTo(*targetUnit, *(CUnitType*)unittype, 1);
lua_pushvalue(l, 1);
return 1;
}
/**
** Damages unit, additionally using another unit as first's attacker
**
@ -1192,6 +1212,7 @@ void UnitCclRegister()
lua_register(Lua, "MoveUnit", CclMoveUnit);
lua_register(Lua, "RemoveUnit", CclRemoveUnit);
lua_register(Lua, "CreateUnit", CclCreateUnit);
lua_register(Lua, "TransformUnit", CclTransformUnit);
lua_register(Lua, "DamageUnit", CclDamageUnit);
lua_register(Lua, "SetResourcesHeld", CclSetResourcesHeld);
lua_register(Lua, "SetTeleportDestination", CclSetTeleportDestination);