diff --git a/config/fxdata/lua/bindings/parties.lua b/config/fxdata/lua/bindings/parties.lua index c61f7a18f5..367a5dc997 100644 --- a/config/fxdata/lua/bindings/parties.lua +++ b/config/fxdata/lua/bindings/parties.lua @@ -73,3 +73,7 @@ function AddTunnellerPartyToLevel(owner,party_name,spawn_location,head_for,targe ---@param location location where the party should be spawned ---@return Creature[] party_creatures list of creatures in the party, first entry is the leader function AddPartyToLevel(owner,party_name,location) return {} end + +---@param tunneler Creature the tunneller that should be sent to the location, only works on diggers that are owned by roaming player +---@param location location where the tunneller should start digging towards +function SendTunnellerToLocation(tunneler,location) end diff --git a/config/fxdata/lua/classes/Creature.lua b/config/fxdata/lua/classes/Creature.lua index 39bc3d6257..9149b639d3 100644 --- a/config/fxdata/lua/classes/Creature.lua +++ b/config/fxdata/lua/classes/Creature.lua @@ -13,6 +13,12 @@ function Creature:OnDeath(action) RegisterCreatureDeathEvent(action,self) end +---@param location location where the tunneller should start digging towards +function Creature:tunnel_to_location(location) + SendTunnellerToLocation(self,location) +end + + ----functions below are implemented in C, so they have no body here ---teleports the thing to a new location diff --git a/src/lua_api.c b/src/lua_api.c index 0228282fc6..0356f8e7ea 100644 --- a/src/lua_api.c +++ b/src/lua_api.c @@ -490,6 +490,25 @@ static int lua_Add_party_to_level(lua_State *L) return 1; } +static int lua_Send_tunneller_to_location(lua_State *L) +{ + struct Thing* creatng = luaL_checkThing(L, 1); + TbMapLocation destination_location = luaL_checkLocation(L, 2); + + if(!thing_is_hero(creatng) || !thing_is_creature_digger(creatng)) + { + SYNCERRLOG("Tried to send %s to location %d which is not a tunneller",thing_model_name(creatng),(int)spawn_location); + return 0; + } + + struct Coord3d pos; + get_coords_at_location(&pos, destination_location,0); + send_tunneller_to_point(creatng, &pos); + + return 0; +} + + //Displaying information and affecting interface static int lua_Display_objective(lua_State *L) @@ -1954,6 +1973,7 @@ static const luaL_Reg global_methods[] = { {"DeleteFromParty", lua_Delete_from_party }, {"AddTunnellerPartyToLevel", lua_Add_tunneller_party_to_level }, {"AddPartyToLevel", lua_Add_party_to_level }, + {"SendTunnellerToLocation", lua_Send_tunneller_to_location }, //Displaying information and affecting interface {"DisplayObjective" ,lua_Display_objective },