1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-28 17:24:47 +01:00

Add plugin API to remove entities (#11702)

This commit is contained in:
Ted John
2020-05-10 18:07:27 +01:00
committed by GitHub
parent ec06a9ca4b
commit b96fdee531
2 changed files with 43 additions and 0 deletions

View File

@@ -698,6 +698,12 @@ declare global {
* The z-coordinate of the entity in game units.
*/
z: number;
/**
* Removes the entity from the map.
* Note: removing vehicles and peeps that are on rides is currently unsupported.
*/
remove(): void;
}
/**

View File

@@ -11,6 +11,7 @@
#ifdef ENABLE_SCRIPTING
# include "../Context.h"
# include "../common.h"
# include "../world/Sprite.h"
# include "Duktape.hpp"
@@ -119,6 +120,41 @@ namespace OpenRCT2::Scripting
}
}
void remove()
{
auto ctx = GetContext()->GetScriptEngine().GetContext();
auto entity = GetEntity();
if (entity != nullptr)
{
invalidate_sprite_2(entity);
switch (entity->sprite_identifier)
{
case SPRITE_IDENTIFIER_VEHICLE:
duk_error(ctx, DUK_ERR_ERROR, "Removing a vehicle is currently unsupported.");
break;
case SPRITE_IDENTIFIER_PEEP:
{
auto peep = static_cast<Peep*>(entity);
// We can't remove a single peep from a ride at the moment as this can cause complications with the
// vehicle car having an unsupported peep capacity.
if (peep->state == PEEP_STATE_ON_RIDE || peep->state == PEEP_STATE_ENTERING_RIDE)
{
duk_error(ctx, DUK_ERR_ERROR, "Removing a peep that is on a ride is currently unsupported.");
}
else
{
peep->Remove();
}
break;
}
case SPRITE_IDENTIFIER_MISC:
case SPRITE_IDENTIFIER_LITTER:
sprite_remove(entity);
break;
}
}
}
SpriteBase* GetEntity() const
{
return &get_sprite(_id)->generic;
@@ -132,6 +168,7 @@ namespace OpenRCT2::Scripting
dukglue_register_property(ctx, &ScEntity::x_get, &ScEntity::x_set, "x");
dukglue_register_property(ctx, &ScEntity::y_get, &ScEntity::y_set, "y");
dukglue_register_property(ctx, &ScEntity::z_get, &ScEntity::z_set, "z");
dukglue_register_method(ctx, &ScEntity::remove, "remove");
}
};