Add more peep stats for plugins

This commit is contained in:
Ted John
2020-05-08 12:39:47 +01:00
parent 49e062ae5d
commit fa0dd4e0d6
2 changed files with 334 additions and 0 deletions

View File

@@ -654,6 +654,10 @@ declare global {
* Represents an object "entity" on the map that can typically moves and has a sub-tile coordinate.
*/
interface Entity {
/**
* The entity index within the entity list.
*/
readonly id: number;
/**
* The type of entity, e.g. car, duck, litter, or peep.
*/
@@ -676,14 +680,90 @@ declare global {
* Represents a guest or staff member.
*/
interface Peep extends Entity {
/**
* Name of the peep.
*/
name: string;
/**
* Colour of the peep's t-shirt.
*/
tshirtColour: number;
/**
* Colour of the peep's trousers.
*/
trousersColour: number;
/**
* How tired the guest is between 32 and 128 where lower is more tired.
*/
energy: number;
/**
* The target energy value. Energy will increase / decrease slowly towards this value.
*/
energyTarget: number;
/**
* How happy the guest is between 0 and 255.
*/
happiness: number;
/**
* The target happiness value. Happiness will increase / decrease slowly towards this value.
*/
happinessTarget: number;
/**
* How nauseated the guest is between 0 and 255.
*/
nausea: number;
/**
* The target nausea value. Nausea will increase / decrease slowly towards this value.
*/
nauseaTarget: number;
/**
* How hungry the guest is between 0 and 255. Lower is more hungry.
*/
hunger: number;
/**
* How thirsty the guest is between 0 and 255. Lower is more thirsty.
*/
thirst: number;
/**
* How much the guest requires the need to go to the toilet between 0 and 255.
*/
toilet: number;
/**
* The mass of the guest. Affects vehicle mass.
*/
mass: number;
/**
* The guest's minimum preferred intensity between 0 and 15.
*/
minIntensity: number;
/**
* The guest's maximum preferred intensity between 0 and 15.
*/
maxIntensity: number;
/**
* The guest's tolerance to nauseating rides between 0 and 3.
*/
nauseaTolerance: number;
/**
* Amount of cash in the guest's pocket.
*/
cash: number;
}
/**

View File

@@ -16,6 +16,8 @@
# include "Duktape.hpp"
# include "ScriptEngine.h"
# include <algorithm>
namespace OpenRCT2::Scripting
{
class ScEntity
@@ -30,6 +32,12 @@ namespace OpenRCT2::Scripting
}
private:
int32_t id_get() const
{
auto entity = GetEntity();
return entity != nullptr ? entity->sprite_index : 0;
}
std::string type_get() const
{
auto entity = GetEntity();
@@ -113,6 +121,7 @@ namespace OpenRCT2::Scripting
public:
static void Register(duk_context* ctx)
{
dukglue_register_property(ctx, &ScEntity::id_get, nullptr, "id");
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");
@@ -129,6 +138,21 @@ namespace OpenRCT2::Scripting
}
private:
std::string name_get() const
{
auto peep = GetPeep();
return peep != nullptr ? peep->GetName() : std::string();
}
void name_set(const std::string& value)
{
ThrowIfGameStateNotMutable();
auto peep = GetPeep();
if (peep != nullptr)
{
peep->SetName(value);
}
}
uint8_t tshirtColour_get() const
{
auto peep = GetPeep();
@@ -143,6 +167,7 @@ namespace OpenRCT2::Scripting
peep->tshirt_colour = value;
}
}
uint8_t trousersColour_get() const
{
auto peep = GetPeep();
@@ -158,6 +183,220 @@ namespace OpenRCT2::Scripting
}
}
uint8_t energy_get() const
{
auto peep = GetPeep();
return peep != nullptr ? peep->energy : 0;
}
void energy_set(uint8_t value)
{
ThrowIfGameStateNotMutable();
auto peep = GetPeep();
if (peep != nullptr)
{
peep->energy = value;
}
}
uint8_t energyTarget_get() const
{
auto peep = GetPeep();
return peep != nullptr ? peep->energy_target : 0;
}
void energyTarget_set(uint8_t value)
{
ThrowIfGameStateNotMutable();
auto peep = GetPeep();
if (peep != nullptr)
{
peep->energy_target = value;
}
}
uint8_t happiness_get() const
{
auto peep = GetPeep();
return peep != nullptr ? peep->happiness : 0;
}
void happiness_set(uint8_t value)
{
ThrowIfGameStateNotMutable();
auto peep = GetPeep();
if (peep != nullptr)
{
peep->happiness = value;
}
}
uint8_t happinessTarget_get() const
{
auto peep = GetPeep();
return peep != nullptr ? peep->happiness_target : 0;
}
void happinessTarget_set(uint8_t value)
{
ThrowIfGameStateNotMutable();
auto peep = GetPeep();
if (peep != nullptr)
{
peep->happiness_target = value;
}
}
uint8_t nausea_get() const
{
auto peep = GetPeep();
return peep != nullptr ? peep->nausea : 0;
}
void nausea_set(uint8_t value)
{
ThrowIfGameStateNotMutable();
auto peep = GetPeep();
if (peep != nullptr)
{
peep->nausea = value;
}
}
uint8_t nauseaTarget_get() const
{
auto peep = GetPeep();
return peep != nullptr ? peep->nausea_target : 0;
}
void nauseaTarget_set(uint8_t value)
{
ThrowIfGameStateNotMutable();
auto peep = GetPeep();
if (peep != nullptr)
{
peep->nausea_target = value;
}
}
uint8_t hunger_get() const
{
auto peep = GetPeep();
return peep != nullptr ? peep->hunger : 0;
}
void hunger_set(uint8_t value)
{
ThrowIfGameStateNotMutable();
auto peep = GetPeep();
if (peep != nullptr)
{
peep->hunger = value;
}
}
uint8_t thirst_get() const
{
auto peep = GetPeep();
return peep != nullptr ? peep->thirst : 0;
}
void thirst_set(uint8_t value)
{
ThrowIfGameStateNotMutable();
auto peep = GetPeep();
if (peep != nullptr)
{
peep->thirst = value;
}
}
uint8_t toilet_get() const
{
auto peep = GetPeep();
return peep != nullptr ? peep->toilet : 0;
}
void toilet_set(uint8_t value)
{
ThrowIfGameStateNotMutable();
auto peep = GetPeep();
if (peep != nullptr)
{
peep->toilet = value;
}
}
uint8_t mass_get() const
{
auto peep = GetPeep();
return peep != nullptr ? peep->mass : 0;
}
void mass_set(uint8_t value)
{
ThrowIfGameStateNotMutable();
auto peep = GetPeep();
if (peep != nullptr)
{
peep->mass = value;
}
}
uint8_t minIntensity_get() const
{
auto peep = GetPeep();
return peep != nullptr ? peep->intensity & 0x0F : 0;
}
void minIntensity_set(uint8_t value)
{
ThrowIfGameStateNotMutable();
auto peep = GetPeep();
if (peep != nullptr)
{
auto minIntensity = std::min<uint8_t>(value, 15);
auto maxIntensity = peep->intensity >> 4;
peep->intensity = (maxIntensity << 4) | minIntensity;
}
}
uint8_t maxIntensity_get() const
{
auto peep = GetPeep();
return peep != nullptr ? peep->intensity >> 4 : 0;
}
void maxIntensity_set(uint8_t value)
{
ThrowIfGameStateNotMutable();
auto peep = GetPeep();
if (peep != nullptr)
{
auto minIntensity = peep->intensity & 0x0F;
auto maxIntensity = std::min<uint8_t>(value, 15);
peep->intensity = (maxIntensity << 4) | minIntensity;
}
}
uint8_t nauseaTolerance_get() const
{
auto peep = GetPeep();
return peep != nullptr ? peep->nausea_tolerance : 0;
}
void nauseaTolerance_set(uint8_t value)
{
ThrowIfGameStateNotMutable();
auto peep = GetPeep();
if (peep != nullptr)
{
peep->nausea_tolerance = std::min<uint8_t>(value, 3);
}
}
int32_t cash_get() const
{
auto peep = GetPeep();
return peep != nullptr ? peep->cash_in_pocket : 0;
}
void cash_set(int32_t value)
{
ThrowIfGameStateNotMutable();
auto peep = GetPeep();
if (peep != nullptr)
{
peep->cash_in_pocket = std::max(0, value);
}
}
Peep* GetPeep() const
{
return get_sprite(_id)->AsPeep();
@@ -167,8 +406,23 @@ namespace OpenRCT2::Scripting
static void Register(duk_context* ctx)
{
dukglue_set_base_class<ScEntity, ScPeep>(ctx);
dukglue_register_property(ctx, &ScPeep::name_get, &ScPeep::name_set, "name");
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");
dukglue_register_property(ctx, &ScPeep::energyTarget_get, &ScPeep::energyTarget_set, "energyTarget");
dukglue_register_property(ctx, &ScPeep::happiness_get, &ScPeep::happiness_set, "happiness");
dukglue_register_property(ctx, &ScPeep::happinessTarget_get, &ScPeep::happinessTarget_set, "happinessTarget");
dukglue_register_property(ctx, &ScPeep::nausea_get, &ScPeep::nausea_set, "nausea");
dukglue_register_property(ctx, &ScPeep::nauseaTarget_get, &ScPeep::nauseaTarget_set, "nauseaTarget");
dukglue_register_property(ctx, &ScPeep::hunger_get, &ScPeep::hunger_set, "hunger");
dukglue_register_property(ctx, &ScPeep::thirst_get, &ScPeep::thirst_set, "thirst");
dukglue_register_property(ctx, &ScPeep::toilet_get, &ScPeep::toilet_set, "toilet");
dukglue_register_property(ctx, &ScPeep::mass_get, &ScPeep::mass_set, "mass");
dukglue_register_property(ctx, &ScPeep::minIntensity_get, &ScPeep::minIntensity_set, "minIntensity");
dukglue_register_property(ctx, &ScPeep::maxIntensity_get, &ScPeep::maxIntensity_set, "maxIntensity");
dukglue_register_property(ctx, &ScPeep::nauseaTolerance_get, &ScPeep::nauseaTolerance_set, "nauseaTolerance");
dukglue_register_property(ctx, &ScPeep::cash_get, &ScPeep::cash_set, "cash");
}
};