mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-16 11:33:03 +01:00
Add peep flags and destination
This commit is contained in:
@@ -51,22 +51,6 @@ namespace OpenRCT2::Scripting
|
||||
return CURSOR_UNDEFINED;
|
||||
}
|
||||
|
||||
template<> DukValue ToDuk(duk_context* ctx, const CoordsXY& coords)
|
||||
{
|
||||
DukObject dukCoords(ctx);
|
||||
dukCoords.Set("x", coords.x);
|
||||
dukCoords.Set("y", coords.y);
|
||||
return dukCoords.Take();
|
||||
}
|
||||
|
||||
template<> DukValue ToDuk(duk_context* ctx, const ScreenCoordsXY& coords)
|
||||
{
|
||||
DukObject dukCoords(ctx);
|
||||
dukCoords.Set("x", coords.x);
|
||||
dukCoords.Set("y", coords.y);
|
||||
return dukCoords.Take();
|
||||
}
|
||||
|
||||
static void RemoveMenuItemsAndTool(std::shared_ptr<Plugin> owner)
|
||||
{
|
||||
if (ActiveCustomTool)
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
|
||||
#ifdef ENABLE_SCRIPTING
|
||||
|
||||
# include "../world/Map.h"
|
||||
|
||||
# include <cstdio>
|
||||
# include <dukglue/dukglue.h>
|
||||
# include <duktape.h>
|
||||
@@ -232,6 +234,39 @@ namespace OpenRCT2::Scripting
|
||||
return value ? ToDuk(ctx, *value) : ToDuk(ctx, nullptr);
|
||||
}
|
||||
|
||||
template<> CoordsXY inline FromDuk(const DukValue& d)
|
||||
{
|
||||
CoordsXY result;
|
||||
result.x = AsOrDefault(d["x"], 0);
|
||||
result.y = AsOrDefault(d["y"], 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
template<> DukValue inline ToDuk(duk_context* ctx, const CoordsXY& coords)
|
||||
{
|
||||
DukObject dukCoords(ctx);
|
||||
dukCoords.Set("x", coords.x);
|
||||
dukCoords.Set("y", coords.y);
|
||||
return dukCoords.Take();
|
||||
}
|
||||
|
||||
template<> DukValue inline ToDuk(duk_context* ctx, const CoordsXYZ& coords)
|
||||
{
|
||||
DukObject dukCoords(ctx);
|
||||
dukCoords.Set("x", coords.x);
|
||||
dukCoords.Set("y", coords.y);
|
||||
dukCoords.Set("z", coords.z);
|
||||
return dukCoords.Take();
|
||||
}
|
||||
|
||||
template<> DukValue inline ToDuk(duk_context* ctx, const ScreenCoordsXY& coords)
|
||||
{
|
||||
DukObject dukCoords(ctx);
|
||||
dukCoords.Set("x", coords.x);
|
||||
dukCoords.Set("y", coords.y);
|
||||
return dukCoords.Take();
|
||||
}
|
||||
|
||||
} // namespace OpenRCT2::Scripting
|
||||
|
||||
#endif
|
||||
|
||||
@@ -196,6 +196,72 @@ namespace OpenRCT2::Scripting
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t flags_get() const
|
||||
{
|
||||
auto peep = GetPeep();
|
||||
return peep != nullptr ? peep->peep_flags : 0;
|
||||
}
|
||||
|
||||
void flags_set(uint32_t value)
|
||||
{
|
||||
ThrowIfGameStateNotMutable();
|
||||
auto peep = GetPeep();
|
||||
if (peep != nullptr)
|
||||
{
|
||||
peep->peep_flags = value;
|
||||
peep->Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
DukValue destination_get() const
|
||||
{
|
||||
auto ctx = GetContext()->GetScriptEngine().GetContext();
|
||||
auto peep = GetPeep();
|
||||
if (peep != nullptr)
|
||||
{
|
||||
return ToDuk(ctx, CoordsXY(peep->destination_x, peep->destination_y));
|
||||
}
|
||||
return ToDuk(ctx, nullptr);
|
||||
}
|
||||
|
||||
void destination_set(const DukValue& value)
|
||||
{
|
||||
ThrowIfGameStateNotMutable();
|
||||
auto peep = GetPeep();
|
||||
if (peep != nullptr)
|
||||
{
|
||||
auto pos = FromDuk<CoordsXY>(value);
|
||||
peep->destination_x = pos.x;
|
||||
peep->destination_y = pos.y;
|
||||
peep->Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
DukValue pathfindGoal_get() const
|
||||
{
|
||||
auto ctx = GetContext()->GetScriptEngine().GetContext();
|
||||
auto peep = GetPeep();
|
||||
if (peep != nullptr)
|
||||
{
|
||||
return ToDuk(ctx, CoordsXY(peep->destination_x, peep->destination_y));
|
||||
}
|
||||
return ToDuk(ctx, nullptr);
|
||||
}
|
||||
|
||||
void pathfindGoal_set(const DukValue& value)
|
||||
{
|
||||
ThrowIfGameStateNotMutable();
|
||||
auto peep = GetPeep();
|
||||
if (peep != nullptr)
|
||||
{
|
||||
auto pos = FromDuk<CoordsXY>(value);
|
||||
peep->pathfind_goal.x = pos.x;
|
||||
peep->pathfind_goal.y = pos.y;
|
||||
peep->pathfind_goal.z = pos.z;
|
||||
peep->Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t tshirtColour_get() const
|
||||
{
|
||||
auto peep = GetPeep();
|
||||
@@ -448,6 +514,8 @@ namespace OpenRCT2::Scripting
|
||||
{
|
||||
dukglue_set_base_class<ScEntity, ScPeep>(ctx);
|
||||
dukglue_register_property(ctx, &ScPeep::name_get, &ScPeep::name_set, "name");
|
||||
dukglue_register_property(ctx, &ScPeep::flags_get, &ScPeep::flags_set, "flags");
|
||||
dukglue_register_property(ctx, &ScPeep::destination_get, &ScPeep::destination_set, "destination");
|
||||
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::energy_get, &ScPeep::energy_set, "energy");
|
||||
|
||||
@@ -772,20 +772,6 @@ std::unique_ptr<GameActionResult> ScriptEngine::DukToGameActionResult(const DukV
|
||||
return result;
|
||||
}
|
||||
|
||||
DukValue ScriptEngine::PositionToDuk(const CoordsXYZ& position)
|
||||
{
|
||||
DukStackFrame frame(_context);
|
||||
duk_context* ctx = _context;
|
||||
auto obj = duk_push_object(ctx);
|
||||
duk_push_int(ctx, position.x);
|
||||
duk_put_prop_string(ctx, obj, "x");
|
||||
duk_push_int(ctx, position.y);
|
||||
duk_put_prop_string(ctx, obj, "y");
|
||||
duk_push_int(ctx, position.z);
|
||||
duk_put_prop_string(ctx, obj, "z");
|
||||
return DukValue::take_from_stack(ctx);
|
||||
}
|
||||
|
||||
constexpr static const char* ExpenditureTypes[] = {
|
||||
"ride_construction",
|
||||
"ride_runningcosts",
|
||||
@@ -839,7 +825,7 @@ DukValue ScriptEngine::GameActionResultToDuk(const GameAction& action, const std
|
||||
}
|
||||
if (!result->Position.isNull())
|
||||
{
|
||||
obj.Set("position", PositionToDuk(result->Position));
|
||||
obj.Set("position", ToDuk(_context, result->Position));
|
||||
}
|
||||
|
||||
if (result->Expenditure != ExpenditureType::Count)
|
||||
|
||||
@@ -201,7 +201,6 @@ namespace OpenRCT2::Scripting
|
||||
void RemoveCustomGameActions(const std::shared_ptr<Plugin>& plugin);
|
||||
std::unique_ptr<GameActionResult> DukToGameActionResult(const DukValue& d);
|
||||
DukValue GameActionResultToDuk(const GameAction& action, const std::unique_ptr<GameActionResult>& result);
|
||||
DukValue PositionToDuk(const CoordsXYZ& position);
|
||||
static std::string_view ExpenditureTypeToString(ExpenditureType expenditureType);
|
||||
static ExpenditureType StringToExpenditureType(const std::string_view& expenditureType);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user