mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-04 13:42:55 +01:00
Add function to get all entities on a tile to plugin api
Co-authored-by: Hielke Morsink <hielke.morsink@gmail.com>
This commit is contained in:
@@ -93,7 +93,7 @@ The following people are not part of the development team, but have been contrib
|
||||
* Keith Stellyes (keithstellyes) - Misc.
|
||||
* Bas Cantrijn (Basssiiie) - Various plugin additions, misc.
|
||||
* Adrian Zdanowicz (CookiePLMonster) - Misc.
|
||||
* Andrew Pratt (andrewpratt64) - Added api hook for vehicle crashes
|
||||
* Andrew Pratt (andrewpratt64) - Added api hook for vehicle crashes, api function to get entities on a tile
|
||||
|
||||
## Bug fixes
|
||||
* (KirilAngelov)
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
- Feature: [#13858] Flatride bases can be made invisible.
|
||||
- Feature: [#14676] [Plugin] Allow plugins to store data in .park files.
|
||||
- Feature: [#15367] Individual track elements can now be drawn as another ride type.
|
||||
- Feature: [#15901] [Plugin] Add map.getAllEntitiesOnTile to API.
|
||||
- Feature: [#16029] [Plugin] Add TrackElement.rideType to API.
|
||||
- Feature: [#16097] The Looping Roller Coaster can now draw all elements from the LIM Launched Roller Coaster.
|
||||
- Feature: [#16132, #16389] The Corkscrew, Twister and Vertical Drop Roller Coasters can now draw inline twists.
|
||||
|
||||
5
distribution/openrct2.d.ts
vendored
5
distribution/openrct2.d.ts
vendored
@@ -604,6 +604,11 @@ declare global {
|
||||
getAllEntities(type: "staff"): Staff[];
|
||||
getAllEntities(type: "car"): Car[];
|
||||
getAllEntities(type: "litter"): Litter[];
|
||||
getAllEntitiesOnTile(type: EntityType, tilePos: CoordsXY): Entity[];
|
||||
getAllEntitiesOnTile(type: "guest", tilePos: CoordsXY): Guest[];
|
||||
getAllEntitiesOnTile(type: "staff", tilePos: CoordsXY): Staff[];
|
||||
getAllEntitiesOnTile(type: "car", tilePos: CoordsXY): Car[];
|
||||
getAllEntitiesOnTile(type: "litter", tilePos: CoordsXY): Litter[];
|
||||
createEntity(type: EntityType, initializer: object): Entity;
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ namespace OpenRCT2
|
||||
|
||||
namespace OpenRCT2::Scripting
|
||||
{
|
||||
static constexpr int32_t OPENRCT2_PLUGIN_API_VERSION = 48;
|
||||
static constexpr int32_t OPENRCT2_PLUGIN_API_VERSION = 49;
|
||||
|
||||
// Versions marking breaking changes.
|
||||
static constexpr int32_t API_VERSION_33_PEEP_DEPRECATION = 33;
|
||||
|
||||
@@ -167,6 +167,67 @@ namespace OpenRCT2::Scripting
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<DukValue> OpenRCT2::Scripting::ScMap::getAllEntitiesOnTile(
|
||||
const std::string& type, const DukValue& tilePos) const
|
||||
{
|
||||
// Get the tile position
|
||||
const auto pos = FromDuk<CoordsXY>(tilePos);
|
||||
|
||||
// Declare a vector that will hold the result to return
|
||||
std::vector<DukValue> result;
|
||||
|
||||
// Use EntityTileList to iterate all entities of the given type on the tile, and push them to result
|
||||
if (type == "balloon")
|
||||
{
|
||||
for (auto sprite : EntityTileList<Balloon>(pos))
|
||||
{
|
||||
result.push_back(GetObjectAsDukValue(_context, std::make_shared<ScEntity>(sprite->sprite_index)));
|
||||
}
|
||||
}
|
||||
else if (type == "car")
|
||||
{
|
||||
for (auto sprite : EntityTileList<Vehicle>(pos))
|
||||
{
|
||||
result.push_back(GetObjectAsDukValue(_context, std::make_shared<ScVehicle>(sprite->sprite_index)));
|
||||
}
|
||||
}
|
||||
else if (type == "litter")
|
||||
{
|
||||
for (auto sprite : EntityTileList<Litter>(pos))
|
||||
{
|
||||
result.push_back(GetObjectAsDukValue(_context, std::make_shared<ScLitter>(sprite->sprite_index)));
|
||||
}
|
||||
}
|
||||
else if (type == "duck")
|
||||
{
|
||||
for (auto sprite : EntityTileList<Duck>(pos))
|
||||
{
|
||||
result.push_back(GetObjectAsDukValue(_context, std::make_shared<ScEntity>(sprite->sprite_index)));
|
||||
}
|
||||
}
|
||||
else if (type == "guest")
|
||||
{
|
||||
for (auto sprite : EntityTileList<Guest>(pos))
|
||||
{
|
||||
result.push_back(GetObjectAsDukValue(_context, std::make_shared<ScGuest>(sprite->sprite_index)));
|
||||
}
|
||||
}
|
||||
else if (type == "staff")
|
||||
{
|
||||
for (auto sprite : EntityTileList<Staff>(pos))
|
||||
{
|
||||
result.push_back(GetObjectAsDukValue(_context, std::make_shared<ScStaff>(sprite->sprite_index)));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// If the given type isn't valid, throw an error
|
||||
duk_error(_context, DUK_ERR_ERROR, "Invalid entity type: %s", type.c_str());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
template<typename TEntityType, typename TScriptType>
|
||||
DukValue createEntityType(duk_context* ctx, const DukValue& initializer)
|
||||
{
|
||||
@@ -252,6 +313,7 @@ namespace OpenRCT2::Scripting
|
||||
dukglue_register_method(ctx, &ScMap::getTile, "getTile");
|
||||
dukglue_register_method(ctx, &ScMap::getEntity, "getEntity");
|
||||
dukglue_register_method(ctx, &ScMap::getAllEntities, "getAllEntities");
|
||||
dukglue_register_method(ctx, &ScMap::getAllEntitiesOnTile, "getAllEntitiesOnTile");
|
||||
dukglue_register_method(ctx, &ScMap::createEntity, "createEntity");
|
||||
}
|
||||
|
||||
|
||||
@@ -42,6 +42,8 @@ namespace OpenRCT2::Scripting
|
||||
|
||||
std::vector<DukValue> getAllEntities(const std::string& type) const;
|
||||
|
||||
std::vector<DukValue> getAllEntitiesOnTile(const std::string& type, const DukValue& tilePos) const;
|
||||
|
||||
DukValue createEntity(const std::string& type, const DukValue& initializer);
|
||||
|
||||
static void Register(duk_context* ctx);
|
||||
|
||||
Reference in New Issue
Block a user