diff --git a/docs/game_data/spel2.lua b/docs/game_data/spel2.lua index 630d603f4..7208b1954 100644 --- a/docs/game_data/spel2.lua +++ b/docs/game_data/spel2.lua @@ -469,6 +469,13 @@ function move_grid_entity(uid, x, y, layer) end ---@param uid integer ---@return nil function destroy_grid_entity(uid) end +---Destroy the grid entity, and its item entities, removing them from the grid without dropping particles or gold. +---Will also destroy monsters or items that are standing on a linked activefloor or chain, though excludes MASK.PLAYER to prevent crashes +---@param x number +---@param y number +---@param layer LAYER +---@return nil +function destroy_grid_entity(x, y, layer) end ---Make an ENT_TYPE.FLOOR_DOOR_EXIT go to world `w`, level `l`, theme `t` ---@param uid integer ---@param w integer diff --git a/docs/src/includes/_globals.md b/docs/src/includes/_globals.md index 37cbc536f..7fa5fe884 100644 --- a/docs/src/includes/_globals.md +++ b/docs/src/includes/_globals.md @@ -466,6 +466,8 @@ Use empty table as argument to reset to the game default #### nil destroy_grid_entity(int uid) +#### nil destroy_grid_entity(float x, float y, [LAYER](#LAYER) layer) + Destroy the grid entity, and its item entities, removing them from the grid without dropping particles or gold. Will also destroy monsters or items that are standing on a linked activefloor or chain, though excludes [MASK](#MASK).PLAYER to prevent crashes diff --git a/src/game_api/layer.cpp b/src/game_api/layer.cpp index 4e9541b4a..39a0ca999 100644 --- a/src/game_api/layer.cpp +++ b/src/game_api/layer.cpp @@ -225,7 +225,7 @@ void Layer::destroy_grid_entity(Entity* ent) { ptr--; Entity* item_ent = *ptr; - if (item_ent->type->search_flags & ~1) // if not player + if (!item_ent->is_player()) // if not player { destroy_grid_entity(item_ent); } diff --git a/src/game_api/rpc.cpp b/src/game_api/rpc.cpp index 82b027738..eaae42487 100644 --- a/src/game_api/rpc.cpp +++ b/src/game_api/rpc.cpp @@ -1682,6 +1682,17 @@ void destroy_grid_entity(int32_t uid) } } +void destroy_grid_entity(float x, float y, LAYER layer) +{ + auto state = State::get(); + uint8_t actual_layer = enum_to_layer(layer); + + if (Entity* entity = state.layer(actual_layer)->get_grid_entity_at(x, y)) + { + state.layer(entity->layer)->destroy_grid_entity(entity); + } +} + void add_item_to_shop(int32_t item_uid, int32_t shop_owner_uid) { Movable* item = get_entity_ptr(item_uid)->as(); diff --git a/src/game_api/rpc.hpp b/src/game_api/rpc.hpp index b82693414..5013d4cee 100644 --- a/src/game_api/rpc.hpp +++ b/src/game_api/rpc.hpp @@ -126,6 +126,7 @@ void poison_entity(int32_t entity_uid); void modify_ankh_health_gain(uint8_t max_health, uint8_t beat_add_health); void move_grid_entity(int32_t uid, float x, float y, LAYER layer); void destroy_grid_entity(int32_t uid); +void destroy_grid_entity(float x, float y, LAYER layer); void add_item_to_shop(int32_t item_uid, int32_t shop_owner_uid); void change_poison_timer(int16_t frames); void set_adventure_seed(int64_t first, int64_t second); diff --git a/src/game_api/script/lua_vm.cpp b/src/game_api/script/lua_vm.cpp index e40164f63..643093d5d 100644 --- a/src/game_api/script/lua_vm.cpp +++ b/src/game_api/script/lua_vm.cpp @@ -968,7 +968,9 @@ end lua["move_grid_entity"] = move_grid_entity; /// Destroy the grid entity, and its item entities, removing them from the grid without dropping particles or gold. /// Will also destroy monsters or items that are standing on a linked activefloor or chain, though excludes MASK.PLAYER to prevent crashes - lua["destroy_grid_entity"] = destroy_grid_entity; + lua["destroy_grid_entity"] = sol::overload( + static_cast(::destroy_grid_entity), + static_cast(::destroy_grid_entity)); /// Make an ENT_TYPE.FLOOR_DOOR_EXIT go to world `w`, level `l`, theme `t` lua["set_door_target"] = set_door_target; /// Short for [set_door_target](#set_door_target).