mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2025-12-20 06:12:57 +01:00
Rename thing to entity
This commit is contained in:
24
distribution/openrct2.d.ts
vendored
24
distribution/openrct2.d.ts
vendored
@@ -295,13 +295,13 @@ declare global {
|
|||||||
interface GameMap {
|
interface GameMap {
|
||||||
readonly size: Coord2;
|
readonly size: Coord2;
|
||||||
readonly numRides: number;
|
readonly numRides: number;
|
||||||
readonly numThings: number;
|
readonly numEntities: number;
|
||||||
readonly rides: Ride[];
|
readonly rides: Ride[];
|
||||||
|
|
||||||
getRide(id: number): Ride;
|
getRide(id: number): Ride;
|
||||||
getTile(x: number, y: number): Tile;
|
getTile(x: number, y: number): Tile;
|
||||||
getThing(id: number): Thing;
|
getEntity(id: number): Entity;
|
||||||
getAllThings(type: ThingType);
|
getAllEntities(type: EntityType);
|
||||||
}
|
}
|
||||||
|
|
||||||
type TileElementType =
|
type TileElementType =
|
||||||
@@ -491,27 +491,27 @@ declare global {
|
|||||||
totalCustomers: number;
|
totalCustomers: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
type ThingType =
|
type EntityType =
|
||||||
"car" | "duck" | "peep";
|
"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;
|
x: number;
|
||||||
/**
|
/**
|
||||||
* The y-coordinate of the thing in game units.
|
* The y-coordinate of the entity in game units.
|
||||||
*/
|
*/
|
||||||
y: number;
|
y: number;
|
||||||
/**
|
/**
|
||||||
* The z-coordinate of the thing in game units.
|
* The z-coordinate of the entity in game units.
|
||||||
*/
|
*/
|
||||||
z: number;
|
z: number;
|
||||||
}
|
}
|
||||||
@@ -519,7 +519,7 @@ declare global {
|
|||||||
/**
|
/**
|
||||||
* Represents a guest or staff member.
|
* Represents a guest or staff member.
|
||||||
*/
|
*/
|
||||||
interface Peep extends Thing {
|
interface Peep extends Entity {
|
||||||
/**
|
/**
|
||||||
* Colour of the peep's t-shirt.
|
* Colour of the peep's t-shirt.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -18,13 +18,13 @@
|
|||||||
|
|
||||||
namespace OpenRCT2::Scripting
|
namespace OpenRCT2::Scripting
|
||||||
{
|
{
|
||||||
class ScThing
|
class ScEntity
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
uint16_t _id = SPRITE_INDEX_NULL;
|
uint16_t _id = SPRITE_INDEX_NULL;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ScThing(uint16_t id)
|
ScEntity(uint16_t id)
|
||||||
: _id(id)
|
: _id(id)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -32,17 +32,17 @@ namespace OpenRCT2::Scripting
|
|||||||
private:
|
private:
|
||||||
std::string type_get()
|
std::string type_get()
|
||||||
{
|
{
|
||||||
auto thing = GetThing();
|
auto entity = GetEntity();
|
||||||
if (thing != nullptr)
|
if (entity != nullptr)
|
||||||
{
|
{
|
||||||
switch (thing->sprite_identifier)
|
switch (entity->sprite_identifier)
|
||||||
{
|
{
|
||||||
case SPRITE_IDENTIFIER_VEHICLE:
|
case SPRITE_IDENTIFIER_VEHICLE:
|
||||||
return "car";
|
return "car";
|
||||||
case SPRITE_IDENTIFIER_PEEP:
|
case SPRITE_IDENTIFIER_PEEP:
|
||||||
return "peep";
|
return "peep";
|
||||||
case SPRITE_IDENTIFIER_MISC:
|
case SPRITE_IDENTIFIER_MISC:
|
||||||
switch (thing->type)
|
switch (entity->type)
|
||||||
{
|
{
|
||||||
case SPRITE_MISC_BALLOON:
|
case SPRITE_MISC_BALLOON:
|
||||||
return "balloon";
|
return "balloon";
|
||||||
@@ -60,52 +60,52 @@ namespace OpenRCT2::Scripting
|
|||||||
// x getter and setter
|
// x getter and setter
|
||||||
int32_t x_get()
|
int32_t x_get()
|
||||||
{
|
{
|
||||||
auto thing = GetThing();
|
auto entity = GetEntity();
|
||||||
return thing != nullptr ? thing->x : 0;
|
return entity != nullptr ? entity->x : 0;
|
||||||
}
|
}
|
||||||
void x_set(int32_t value)
|
void x_set(int32_t value)
|
||||||
{
|
{
|
||||||
ThrowIfGameStateNotMutable();
|
ThrowIfGameStateNotMutable();
|
||||||
auto thing = GetThing();
|
auto entity = GetEntity();
|
||||||
if (thing != nullptr)
|
if (entity != nullptr)
|
||||||
{
|
{
|
||||||
sprite_move(value, thing->y, thing->z, thing);
|
sprite_move(value, entity->y, entity->z, entity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// y getter and setter
|
// y getter and setter
|
||||||
int32_t y_get()
|
int32_t y_get()
|
||||||
{
|
{
|
||||||
auto thing = GetThing();
|
auto entity = GetEntity();
|
||||||
return thing != nullptr ? thing->y : 0;
|
return entity != nullptr ? entity->y : 0;
|
||||||
}
|
}
|
||||||
void y_set(int32_t value)
|
void y_set(int32_t value)
|
||||||
{
|
{
|
||||||
ThrowIfGameStateNotMutable();
|
ThrowIfGameStateNotMutable();
|
||||||
auto thing = GetThing();
|
auto entity = GetEntity();
|
||||||
if (thing != nullptr)
|
if (entity != nullptr)
|
||||||
{
|
{
|
||||||
sprite_move(thing->x, value, thing->z, thing);
|
sprite_move(entity->x, value, entity->z, entity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// z getter and setter
|
// z getter and setter
|
||||||
int16_t z_get()
|
int16_t z_get()
|
||||||
{
|
{
|
||||||
auto thing = GetThing();
|
auto entity = GetEntity();
|
||||||
return thing != nullptr ? thing->z : 0;
|
return entity != nullptr ? entity->z : 0;
|
||||||
}
|
}
|
||||||
void z_set(int16_t value)
|
void z_set(int16_t value)
|
||||||
{
|
{
|
||||||
ThrowIfGameStateNotMutable();
|
ThrowIfGameStateNotMutable();
|
||||||
auto thing = GetThing();
|
auto entity = GetEntity();
|
||||||
if (thing != nullptr)
|
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;
|
return &get_sprite(_id)->generic;
|
||||||
}
|
}
|
||||||
@@ -113,18 +113,18 @@ namespace OpenRCT2::Scripting
|
|||||||
public:
|
public:
|
||||||
static void Register(duk_context* ctx)
|
static void Register(duk_context* ctx)
|
||||||
{
|
{
|
||||||
dukglue_register_property(ctx, &ScThing::type_get, nullptr, "type");
|
dukglue_register_property(ctx, &ScEntity::type_get, nullptr, "type");
|
||||||
dukglue_register_property(ctx, &ScThing::x_get, &ScThing::x_set, "x");
|
dukglue_register_property(ctx, &ScEntity::x_get, &ScEntity::x_set, "x");
|
||||||
dukglue_register_property(ctx, &ScThing::y_get, &ScThing::y_set, "y");
|
dukglue_register_property(ctx, &ScEntity::y_get, &ScEntity::y_set, "y");
|
||||||
dukglue_register_property(ctx, &ScThing::z_get, &ScThing::z_set, "z");
|
dukglue_register_property(ctx, &ScEntity::z_get, &ScEntity::z_set, "z");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class ScPeep : public ScThing
|
class ScPeep : public ScEntity
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ScPeep(uint16_t id)
|
ScPeep(uint16_t id)
|
||||||
: ScThing(id)
|
: ScEntity(id)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -166,7 +166,7 @@ namespace OpenRCT2::Scripting
|
|||||||
public:
|
public:
|
||||||
static void Register(duk_context* ctx)
|
static void Register(duk_context* ctx)
|
||||||
{
|
{
|
||||||
dukglue_set_base_class<ScThing, ScPeep>(ctx);
|
dukglue_set_base_class<ScEntity, ScPeep>(ctx);
|
||||||
dukglue_register_property(ctx, &ScPeep::tshirtColour_get, &ScPeep::tshirtColour_set, "tshirtColour");
|
dukglue_register_property(ctx, &ScPeep::tshirtColour_get, &ScPeep::tshirtColour_set, "tshirtColour");
|
||||||
dukglue_register_property(ctx, &ScPeep::trousersColour_get, &ScPeep::trousersColour_set, "trousersColour");
|
dukglue_register_property(ctx, &ScPeep::trousersColour_get, &ScPeep::trousersColour_set, "trousersColour");
|
||||||
}
|
}
|
||||||
@@ -15,8 +15,8 @@
|
|||||||
# include "../ride/Ride.h"
|
# include "../ride/Ride.h"
|
||||||
# include "../world/Map.h"
|
# include "../world/Map.h"
|
||||||
# include "Duktape.hpp"
|
# include "Duktape.hpp"
|
||||||
|
# include "ScEntity.hpp"
|
||||||
# include "ScRide.hpp"
|
# include "ScRide.hpp"
|
||||||
# include "ScThing.hpp"
|
|
||||||
# include "ScTile.hpp"
|
# include "ScTile.hpp"
|
||||||
|
|
||||||
namespace OpenRCT2::Scripting
|
namespace OpenRCT2::Scripting
|
||||||
@@ -48,7 +48,7 @@ namespace OpenRCT2::Scripting
|
|||||||
return static_cast<int32_t>(GetRideManager().size());
|
return static_cast<int32_t>(GetRideManager().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t numThings_get()
|
int32_t numEntities_get()
|
||||||
{
|
{
|
||||||
return MAX_SPRITES;
|
return MAX_SPRITES;
|
||||||
}
|
}
|
||||||
@@ -84,7 +84,7 @@ namespace OpenRCT2::Scripting
|
|||||||
return std::make_shared<ScTile>(coords);
|
return std::make_shared<ScTile>(coords);
|
||||||
}
|
}
|
||||||
|
|
||||||
DukValue getThing(int32_t id)
|
DukValue getEntity(int32_t id)
|
||||||
{
|
{
|
||||||
if (id >= 0 && id < MAX_SPRITES)
|
if (id >= 0 && id < MAX_SPRITES)
|
||||||
{
|
{
|
||||||
@@ -92,14 +92,14 @@ namespace OpenRCT2::Scripting
|
|||||||
auto sprite = get_sprite(spriteId);
|
auto sprite = get_sprite(spriteId);
|
||||||
if (sprite != nullptr && sprite->generic.sprite_identifier != SPRITE_IDENTIFIER_NULL)
|
if (sprite != nullptr && sprite->generic.sprite_identifier != SPRITE_IDENTIFIER_NULL)
|
||||||
{
|
{
|
||||||
return GetThingAsDukValue(sprite);
|
return GetEntityAsDukValue(sprite);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
duk_push_null(_context);
|
duk_push_null(_context);
|
||||||
return DukValue::take_from_stack(_context);
|
return DukValue::take_from_stack(_context);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<DukValue> getAllThings(const std::string& type)
|
std::vector<DukValue> getAllEntities(const std::string& type)
|
||||||
{
|
{
|
||||||
SPRITE_LIST targetList{};
|
SPRITE_LIST targetList{};
|
||||||
uint8_t targetType{};
|
uint8_t targetType{};
|
||||||
@@ -127,7 +127,7 @@ namespace OpenRCT2::Scripting
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
duk_error(_context, DUK_ERR_ERROR, "Invalid thing type.");
|
duk_error(_context, DUK_ERR_ERROR, "Invalid entity type.");
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<DukValue> result;
|
std::vector<DukValue> result;
|
||||||
@@ -160,14 +160,14 @@ namespace OpenRCT2::Scripting
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
result.push_back(GetObjectAsDukValue(_context, std::make_shared<ScThing>(carId)));
|
result.push_back(GetObjectAsDukValue(_context, std::make_shared<ScEntity>(carId)));
|
||||||
carId = car->vehicle.next_vehicle_on_train;
|
carId = car->vehicle.next_vehicle_on_train;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
result.push_back(GetObjectAsDukValue(_context, std::make_shared<ScThing>(spriteId)));
|
result.push_back(GetObjectAsDukValue(_context, std::make_shared<ScEntity>(spriteId)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
spriteId = sprite->generic.next;
|
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::size_get, nullptr, "size");
|
||||||
dukglue_register_property(ctx, &ScMap::numRides_get, nullptr, "numRides");
|
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_property(ctx, &ScMap::rides_get, nullptr, "rides");
|
||||||
dukglue_register_method(ctx, &ScMap::getRide, "getRide");
|
dukglue_register_method(ctx, &ScMap::getRide, "getRide");
|
||||||
dukglue_register_method(ctx, &ScMap::getTile, "getTile");
|
dukglue_register_method(ctx, &ScMap::getTile, "getTile");
|
||||||
dukglue_register_method(ctx, &ScMap::getThing, "getThing");
|
dukglue_register_method(ctx, &ScMap::getEntity, "getEntity");
|
||||||
dukglue_register_method(ctx, &ScMap::getAllThings, "getAllThings");
|
dukglue_register_method(ctx, &ScMap::getAllEntities, "getAllEntities");
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DukValue GetThingAsDukValue(const rct_sprite* sprite)
|
DukValue GetEntityAsDukValue(const rct_sprite* sprite)
|
||||||
{
|
{
|
||||||
auto spriteId = sprite->generic.sprite_index;
|
auto spriteId = sprite->generic.sprite_index;
|
||||||
switch (sprite->generic.sprite_identifier)
|
switch (sprite->generic.sprite_identifier)
|
||||||
@@ -197,7 +197,7 @@ namespace OpenRCT2::Scripting
|
|||||||
case SPRITE_IDENTIFIER_PEEP:
|
case SPRITE_IDENTIFIER_PEEP:
|
||||||
return GetObjectAsDukValue(_context, std::make_shared<ScPeep>(spriteId));
|
return GetObjectAsDukValue(_context, std::make_shared<ScPeep>(spriteId));
|
||||||
default:
|
default:
|
||||||
return GetObjectAsDukValue(_context, std::make_shared<ScThing>(spriteId));
|
return GetObjectAsDukValue(_context, std::make_shared<ScEntity>(spriteId));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -25,12 +25,12 @@
|
|||||||
# include "ScContext.hpp"
|
# include "ScContext.hpp"
|
||||||
# include "ScDate.hpp"
|
# include "ScDate.hpp"
|
||||||
# include "ScDisposable.hpp"
|
# include "ScDisposable.hpp"
|
||||||
|
# include "ScEntity.hpp"
|
||||||
# include "ScMap.hpp"
|
# include "ScMap.hpp"
|
||||||
# include "ScNetwork.hpp"
|
# include "ScNetwork.hpp"
|
||||||
# include "ScObject.hpp"
|
# include "ScObject.hpp"
|
||||||
# include "ScPark.hpp"
|
# include "ScPark.hpp"
|
||||||
# include "ScRide.hpp"
|
# include "ScRide.hpp"
|
||||||
# include "ScThing.hpp"
|
|
||||||
# include "ScTile.hpp"
|
# include "ScTile.hpp"
|
||||||
|
|
||||||
# include <iostream>
|
# include <iostream>
|
||||||
@@ -382,7 +382,7 @@ void ScriptEngine::Initialise()
|
|||||||
ScRideObject::Register(ctx);
|
ScRideObject::Register(ctx);
|
||||||
ScTile::Register(ctx);
|
ScTile::Register(ctx);
|
||||||
ScTileElement::Register(ctx);
|
ScTileElement::Register(ctx);
|
||||||
ScThing::Register(ctx);
|
ScEntity::Register(ctx);
|
||||||
ScPeep::Register(ctx);
|
ScPeep::Register(ctx);
|
||||||
|
|
||||||
dukglue_register_global(ctx, std::make_shared<ScConsole>(_console), "console");
|
dukglue_register_global(ctx, std::make_shared<ScConsole>(_console), "console");
|
||||||
|
|||||||
Reference in New Issue
Block a user