diff --git a/distribution/openrct2.d.ts b/distribution/openrct2.d.ts index 219ee8ead4..954a28a481 100644 --- a/distribution/openrct2.d.ts +++ b/distribution/openrct2.d.ts @@ -295,13 +295,13 @@ declare global { interface GameMap { readonly size: Coord2; readonly numRides: number; - readonly numThings: number; + readonly numEntities: number; readonly rides: Ride[]; getRide(id: number): Ride; getTile(x: number, y: number): Tile; - getThing(id: number): Thing; - getAllThings(type: ThingType); + getEntity(id: number): Entity; + getAllEntities(type: EntityType); } type TileElementType = @@ -491,27 +491,27 @@ declare global { totalCustomers: number; } - type ThingType = + type EntityType = "car" | "duck" | "peep"; /** - * Represents an object "thing" on the map that can typically moves and has a sub-tile coordinate. + * Represents an object "entity" on the map that can typically moves and has a sub-tile coordinate. */ - interface Thing { + interface Entity { /** - * The type of thing, e.g. car, duck, litter, or peep. + * The type of entity, e.g. car, duck, litter, or peep. */ - readonly type: ThingType; + readonly type: EntityType; /** - * The x-coordinate of the thing in game units. + * The x-coordinate of the entity in game units. */ x: number; /** - * The y-coordinate of the thing in game units. + * The y-coordinate of the entity in game units. */ y: number; /** - * The z-coordinate of the thing in game units. + * The z-coordinate of the entity in game units. */ z: number; } @@ -519,7 +519,7 @@ declare global { /** * Represents a guest or staff member. */ - interface Peep extends Thing { + interface Peep extends Entity { /** * Colour of the peep's t-shirt. */ diff --git a/src/openrct2/scripting/ScThing.hpp b/src/openrct2/scripting/ScEntity.hpp similarity index 71% rename from src/openrct2/scripting/ScThing.hpp rename to src/openrct2/scripting/ScEntity.hpp index 5320af6825..eb8192e92a 100644 --- a/src/openrct2/scripting/ScThing.hpp +++ b/src/openrct2/scripting/ScEntity.hpp @@ -18,13 +18,13 @@ namespace OpenRCT2::Scripting { - class ScThing + class ScEntity { protected: uint16_t _id = SPRITE_INDEX_NULL; public: - ScThing(uint16_t id) + ScEntity(uint16_t id) : _id(id) { } @@ -32,17 +32,17 @@ namespace OpenRCT2::Scripting private: std::string type_get() { - auto thing = GetThing(); - if (thing != nullptr) + auto entity = GetEntity(); + if (entity != nullptr) { - switch (thing->sprite_identifier) + switch (entity->sprite_identifier) { case SPRITE_IDENTIFIER_VEHICLE: return "car"; case SPRITE_IDENTIFIER_PEEP: return "peep"; case SPRITE_IDENTIFIER_MISC: - switch (thing->type) + switch (entity->type) { case SPRITE_MISC_BALLOON: return "balloon"; @@ -60,52 +60,52 @@ namespace OpenRCT2::Scripting // x getter and setter int32_t x_get() { - auto thing = GetThing(); - return thing != nullptr ? thing->x : 0; + auto entity = GetEntity(); + return entity != nullptr ? entity->x : 0; } void x_set(int32_t value) { ThrowIfGameStateNotMutable(); - auto thing = GetThing(); - if (thing != nullptr) + auto entity = GetEntity(); + if (entity != nullptr) { - sprite_move(value, thing->y, thing->z, thing); + sprite_move(value, entity->y, entity->z, entity); } } // y getter and setter int32_t y_get() { - auto thing = GetThing(); - return thing != nullptr ? thing->y : 0; + auto entity = GetEntity(); + return entity != nullptr ? entity->y : 0; } void y_set(int32_t value) { ThrowIfGameStateNotMutable(); - auto thing = GetThing(); - if (thing != nullptr) + auto entity = GetEntity(); + if (entity != nullptr) { - sprite_move(thing->x, value, thing->z, thing); + sprite_move(entity->x, value, entity->z, entity); } } // z getter and setter int16_t z_get() { - auto thing = GetThing(); - return thing != nullptr ? thing->z : 0; + auto entity = GetEntity(); + return entity != nullptr ? entity->z : 0; } void z_set(int16_t value) { ThrowIfGameStateNotMutable(); - auto thing = GetThing(); - if (thing != nullptr) + auto entity = GetEntity(); + if (entity != nullptr) { - sprite_move(thing->x, thing->y, value, thing); + sprite_move(entity->x, entity->y, value, entity); } } - SpriteBase* GetThing() + SpriteBase* GetEntity() { return &get_sprite(_id)->generic; } @@ -113,18 +113,18 @@ namespace OpenRCT2::Scripting public: static void Register(duk_context* ctx) { - dukglue_register_property(ctx, &ScThing::type_get, nullptr, "type"); - dukglue_register_property(ctx, &ScThing::x_get, &ScThing::x_set, "x"); - dukglue_register_property(ctx, &ScThing::y_get, &ScThing::y_set, "y"); - dukglue_register_property(ctx, &ScThing::z_get, &ScThing::z_set, "z"); + dukglue_register_property(ctx, &ScEntity::type_get, nullptr, "type"); + 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"); } }; - class ScPeep : public ScThing + class ScPeep : public ScEntity { public: ScPeep(uint16_t id) - : ScThing(id) + : ScEntity(id) { } @@ -166,7 +166,7 @@ namespace OpenRCT2::Scripting public: static void Register(duk_context* ctx) { - dukglue_set_base_class(ctx); + dukglue_set_base_class(ctx); dukglue_register_property(ctx, &ScPeep::tshirtColour_get, &ScPeep::tshirtColour_set, "tshirtColour"); dukglue_register_property(ctx, &ScPeep::trousersColour_get, &ScPeep::trousersColour_set, "trousersColour"); } diff --git a/src/openrct2/scripting/ScMap.hpp b/src/openrct2/scripting/ScMap.hpp index fa293b713a..1013e5bc79 100644 --- a/src/openrct2/scripting/ScMap.hpp +++ b/src/openrct2/scripting/ScMap.hpp @@ -15,8 +15,8 @@ # include "../ride/Ride.h" # include "../world/Map.h" # include "Duktape.hpp" +# include "ScEntity.hpp" # include "ScRide.hpp" -# include "ScThing.hpp" # include "ScTile.hpp" namespace OpenRCT2::Scripting @@ -48,7 +48,7 @@ namespace OpenRCT2::Scripting return static_cast(GetRideManager().size()); } - int32_t numThings_get() + int32_t numEntities_get() { return MAX_SPRITES; } @@ -84,7 +84,7 @@ namespace OpenRCT2::Scripting return std::make_shared(coords); } - DukValue getThing(int32_t id) + DukValue getEntity(int32_t id) { if (id >= 0 && id < MAX_SPRITES) { @@ -92,14 +92,14 @@ namespace OpenRCT2::Scripting auto sprite = get_sprite(spriteId); if (sprite != nullptr && sprite->generic.sprite_identifier != SPRITE_IDENTIFIER_NULL) { - return GetThingAsDukValue(sprite); + return GetEntityAsDukValue(sprite); } } duk_push_null(_context); return DukValue::take_from_stack(_context); } - std::vector getAllThings(const std::string& type) + std::vector getAllEntities(const std::string& type) { SPRITE_LIST targetList{}; uint8_t targetType{}; @@ -127,7 +127,7 @@ namespace OpenRCT2::Scripting } else { - duk_error(_context, DUK_ERR_ERROR, "Invalid thing type."); + duk_error(_context, DUK_ERR_ERROR, "Invalid entity type."); } std::vector result; @@ -160,14 +160,14 @@ namespace OpenRCT2::Scripting } else { - result.push_back(GetObjectAsDukValue(_context, std::make_shared(carId))); + result.push_back(GetObjectAsDukValue(_context, std::make_shared(carId))); carId = car->vehicle.next_vehicle_on_train; } } } else { - result.push_back(GetObjectAsDukValue(_context, std::make_shared(spriteId))); + result.push_back(GetObjectAsDukValue(_context, std::make_shared(spriteId))); } } spriteId = sprite->generic.next; @@ -180,16 +180,16 @@ namespace OpenRCT2::Scripting { dukglue_register_property(ctx, &ScMap::size_get, nullptr, "size"); dukglue_register_property(ctx, &ScMap::numRides_get, nullptr, "numRides"); - dukglue_register_property(ctx, &ScMap::numThings_get, nullptr, "numThings"); + dukglue_register_property(ctx, &ScMap::numEntities_get, nullptr, "numEntities"); dukglue_register_property(ctx, &ScMap::rides_get, nullptr, "rides"); dukglue_register_method(ctx, &ScMap::getRide, "getRide"); dukglue_register_method(ctx, &ScMap::getTile, "getTile"); - dukglue_register_method(ctx, &ScMap::getThing, "getThing"); - dukglue_register_method(ctx, &ScMap::getAllThings, "getAllThings"); + dukglue_register_method(ctx, &ScMap::getEntity, "getEntity"); + dukglue_register_method(ctx, &ScMap::getAllEntities, "getAllEntities"); } private: - DukValue GetThingAsDukValue(const rct_sprite* sprite) + DukValue GetEntityAsDukValue(const rct_sprite* sprite) { auto spriteId = sprite->generic.sprite_index; switch (sprite->generic.sprite_identifier) @@ -197,7 +197,7 @@ namespace OpenRCT2::Scripting case SPRITE_IDENTIFIER_PEEP: return GetObjectAsDukValue(_context, std::make_shared(spriteId)); default: - return GetObjectAsDukValue(_context, std::make_shared(spriteId)); + return GetObjectAsDukValue(_context, std::make_shared(spriteId)); } } }; diff --git a/src/openrct2/scripting/ScriptEngine.cpp b/src/openrct2/scripting/ScriptEngine.cpp index 5ca0c0b990..9a7d38dd80 100644 --- a/src/openrct2/scripting/ScriptEngine.cpp +++ b/src/openrct2/scripting/ScriptEngine.cpp @@ -25,12 +25,12 @@ # include "ScContext.hpp" # include "ScDate.hpp" # include "ScDisposable.hpp" +# include "ScEntity.hpp" # include "ScMap.hpp" # include "ScNetwork.hpp" # include "ScObject.hpp" # include "ScPark.hpp" # include "ScRide.hpp" -# include "ScThing.hpp" # include "ScTile.hpp" # include @@ -382,7 +382,7 @@ void ScriptEngine::Initialise() ScRideObject::Register(ctx); ScTile::Register(ctx); ScTileElement::Register(ctx); - ScThing::Register(ctx); + ScEntity::Register(ctx); ScPeep::Register(ctx); dukglue_register_global(ctx, std::make_shared(_console), "console");