Skip to content

Commit

Permalink
add destroy_grid_entity overload with position, detect player by ent-…
Browse files Browse the repository at this point in the history
…>is_player()
  • Loading branch information
estebanfer committed Oct 8, 2023
1 parent 15a769f commit 80cc987
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 2 deletions.
7 changes: 7 additions & 0 deletions docs/game_data/spel2.lua

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions docs/src/includes/_globals.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/game_api/layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
11 changes: 11 additions & 0 deletions src/game_api/rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Movable>();
Expand Down
1 change: 1 addition & 0 deletions src/game_api/rpc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion src/game_api/script/lua_vm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<void (*)(int32_t uid)>(::destroy_grid_entity),
static_cast<void (*)(float x, float y, LAYER layer)>(::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).
Expand Down

0 comments on commit 80cc987

Please sign in to comment.