1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2025-12-21 14:53:02 +01:00

Get the plugin branch building again

This commit is contained in:
Ted John
2019-07-23 23:21:42 +01:00
parent e8468e71bb
commit 5bd58118b5
15 changed files with 118 additions and 111 deletions

View File

@@ -9,12 +9,12 @@
#pragma once
#include "../Context.h"
#include "../common.h"
#include "ScWindow.hpp"
#include <dukglue/dukglue.h>
#include <memory>
#include <openrct2/Context.h>
#include <openrct2/common.h>
#include <openrct2/scripting/Duktape.hpp>
#include <openrct2/scripting/ScriptEngine.h>
#include <string>
@@ -93,12 +93,12 @@ namespace OpenRCT2::Scripting
std::shared_ptr<ScWindow> getWindow(int32_t index)
{
for (int32_t i = 0; i < g_window_list.size(); i++)
int32_t i = 0;
for (auto w : g_window_list)
{
if (i == index)
{
auto w = g_window_list[i].get();
return std::make_shared<ScWindow>(w);
return std::make_shared<ScWindow>(w.get());
}
i++;
}

View File

@@ -9,11 +9,10 @@
#pragma once
#include "../common.h"
#include "../interface/Window.h"
#include "../interface/Window_internal.h"
#include <dukglue/dukglue.h>
#include <openrct2/common.h>
#include <openrct2/interface/Window.h>
#include <openrct2/interface/Window_internal.h>
#include <openrct2/scripting/Duktape.hpp>
namespace OpenRCT2::Scripting
{

View File

@@ -11,10 +11,9 @@
#include "../OpenRCT2.h"
#include "../platform/Platform2.h"
#include "../scripting/ScriptEngine.h"
#include "../thirdparty/linenoise.hpp"
#include "InteractiveConsole.h"
#include <linenoise.hpp>
using namespace OpenRCT2;
void StdInOutConsole::Start()

View File

@@ -0,0 +1,4 @@
#pragma once
#include "../thirdparty/dukglue/dukglue.h"
#include <duktape.h>

View File

@@ -10,8 +10,8 @@
#pragma once
#include "../common.h"
#include "Duktape.hpp"
#include <dukglue/dukglue.h>
#include <memory>
#include <string>
#include <vector>

View File

@@ -9,9 +9,9 @@
#include "Plugin.h"
#include "Duktape.hpp"
#include <algorithm>
#include <dukglue/dukglue.h>
#include <duktape.h>
#include <fstream>
#include <memory>

View File

@@ -9,7 +9,8 @@
#pragma once
#include <dukglue/dukglue.h>
#include "Duktape.hpp"
#include <memory>
#include <string>
#include <vector>

View File

@@ -9,10 +9,8 @@
#pragma once
#include "../core/Math.hpp"
#include "../interface/InteractiveConsole.h"
#include <dukglue/dukglue.h>
#include "Duktape.hpp"
namespace OpenRCT2::Scripting
{
@@ -50,7 +48,7 @@ namespace OpenRCT2::Scripting
{
const auto d = val.as_double();
const duk_int_t i = val.as_int();
if (Math::AlmostEqual<double>(d, i))
if (AlmostEqual<double>(d, i))
{
str = std::to_string(i);
}
@@ -84,5 +82,18 @@ namespace OpenRCT2::Scripting
dukglue_register_method(ctx, &ScConsole::clear, "clear");
dukglue_register_method(ctx, &ScConsole::log, "log");
}
private:
// Taken from http://en.cppreference.com/w/cpp/types/numeric_limits/epsilon
template<class T>
static typename std::enable_if<!std::numeric_limits<T>::is_integer, bool>::type AlmostEqual(T x, T y, int32_t ulp = 20)
{
// the machine epsilon has to be scaled to the magnitude of the values used
// and multiplied by the desired precision in ULPs (units in the last place)
return std::abs(x - y) <= std::numeric_limits<T>::epsilon() * std::abs(x + y) * ulp
// unless the result is subnormal
|| std::abs(x - y)
< (std::numeric_limits<T>::min)(); // TODO: Remove parentheses around min once the macro is removed
}
};
} // namespace OpenRCT2::Scripting

View File

@@ -9,12 +9,12 @@
#pragma once
#include "Duktape.hpp"
#include "HookEngine.h"
#include "ScDisposable.hpp"
#include "ScriptEngine.h"
#include <cstdio>
#include <dukglue/dukglue.h>
#include <memory>
namespace OpenRCT2::Scripting

View File

@@ -9,7 +9,8 @@
#pragma once
#include <dukglue/dukglue.h>
#include "Duktape.hpp"
#include <functional>
namespace OpenRCT2::Scripting

View File

@@ -12,11 +12,10 @@
#include "../common.h"
#include "../ride/Ride.h"
#include "../world/Map.h"
#include "Duktape.hpp"
#include "ScThing.hpp"
#include "ScTile.hpp"
#include <dukglue/dukglue.h>
namespace OpenRCT2::Scripting
{
class ScMap
@@ -62,7 +61,7 @@ namespace OpenRCT2::Scripting
if (id >= 0 && id < MAX_SPRITES)
{
auto sprite = get_sprite(id);
if (sprite != nullptr && sprite->unknown.sprite_identifier != SPRITE_IDENTIFIER_NULL)
if (sprite != nullptr && sprite->generic.sprite_identifier != SPRITE_IDENTIFIER_NULL)
{
return std::make_shared<ScThing>(sprite);
}

View File

@@ -15,9 +15,9 @@
#include "../management/NewsItem.h"
#include "../windows/Intent.h"
#include "../world/Park.h"
#include "Duktape.hpp"
#include <algorithm>
#include <dukglue/dukglue.h>
namespace OpenRCT2::Scripting
{

View File

@@ -11,8 +11,7 @@
#include "../common.h"
#include "../world/Sprite.h"
#include <dukglue/dukglue.h>
#include "Duktape.hpp"
namespace OpenRCT2::Scripting
{
@@ -29,7 +28,7 @@ namespace OpenRCT2::Scripting
std::string type_get()
{
if (_sprite->unknown.sprite_identifier == SPRITE_IDENTIFIER_PEEP)
if (_sprite->generic.sprite_identifier == SPRITE_IDENTIFIER_PEEP)
{
return "peep";
}
@@ -39,31 +38,31 @@ namespace OpenRCT2::Scripting
// x getter and setter
int32_t x_get()
{
return _sprite->unknown.x;
return _sprite->generic.x;
}
void x_set(int32_t value)
{
_sprite->unknown.x = value;
_sprite->generic.x = value;
}
// y getter and setter
int32_t y_get()
{
return _sprite->unknown.y;
return _sprite->generic.y;
}
void y_set(int32_t value)
{
_sprite->unknown.y = value;
_sprite->generic.y = value;
}
// z getter and setter
int16_t z_get()
{
return _sprite->unknown.z;
return _sprite->generic.z;
}
void z_set(int16_t value)
{
_sprite->unknown.z = value;
_sprite->generic.z = value;
}
uint8_t tshirtColour_get()

View File

@@ -14,19 +14,19 @@
#include "../world/Scenery.h"
#include "../world/Sprite.h"
#include "../world/Surface.h"
#include "Duktape.hpp"
#include <cstdio>
#include <dukglue/dukglue.h>
namespace OpenRCT2::Scripting
{
class ScTileElement
{
protected:
rct_tile_element* _element;
TileElement* _element;
public:
ScTileElement(rct_tile_element* element)
ScTileElement(TileElement* element)
: _element(element)
{
}
@@ -105,63 +105,59 @@ namespace OpenRCT2::Scripting
{
uint8_t slope_get()
{
return _element->properties.surface.slope & TILE_ELEMENT_SURFACE_SLOPE_MASK;
return _element->AsSurface()->GetSlope();
}
void slope_set(uint8_t value)
{
// TODO: Give warning when value > TILE_ELEMENT_SURFACE_SLOPE_MASK
_element->properties.surface.slope &= ~TILE_ELEMENT_SURFACE_SLOPE_MASK;
_element->properties.surface.slope |= value & TILE_ELEMENT_SURFACE_SLOPE_MASK;
_element->AsSurface()->SetSlope(value);
}
uint8_t terrain_get()
{
return surface_get_terrain(_element);
return _element->AsSurface()->GetSurfaceStyle();
}
void terrain_set(uint8_t value)
{
surface_set_terrain(_element, value);
_element->AsSurface()->SetSurfaceStyle(value);
}
uint8_t waterHeight_get()
{
return surface_get_water_height(_element);
return _element->AsSurface()->GetWaterHeight();
}
void waterHeight_set(uint8_t value)
{
// TODO: Give warning when value > TILE_ELEMENT_SURFACE_WATER_HEIGHT_MASK
_element->properties.surface.terrain &= ~TILE_ELEMENT_SURFACE_WATER_HEIGHT_MASK;
_element->properties.surface.terrain |= value & TILE_ELEMENT_SURFACE_WATER_HEIGHT_MASK;
_element->AsSurface()->SetWaterHeight(value);
}
uint8_t grassLength_get()
{
return _element->properties.surface.grass_length;
return _element->AsSurface()->GetGrassLength();
}
void grassLength_set(uint8_t value)
{
// TODO: Give warning when value > GRASS_LENGTH_CLUMPS_2
_element->properties.surface.grass_length = value;
return _element->AsSurface()->SetGrassLength(value);
}
uint8_t ownership_get()
{
return _element->properties.surface.ownership & 0xF0;
return _element->AsSurface()->GetOwnership();
}
void ownership_set(uint8_t flags)
{
_element->properties.surface.ownership &= ~0xF0;
_element->properties.surface.ownership |= flags << 4;
_element->AsSurface()->SetOwnership(flags);
}
uint8_t parkFences_get()
{
return _element->properties.surface.ownership & 0xF0;
return _element->AsSurface()->GetParkFences();
}
void parkFences_set(uint8_t flags)
{
_element->properties.surface.ownership &= ~0x0F;
_element->properties.surface.ownership |= flags & 0x0F;
return _element->AsSurface()->SetParkFences(flags);
}
public:
@@ -184,52 +180,60 @@ namespace OpenRCT2::Scripting
class ScFootpathAdditionStatus
{
protected:
rct_tile_element* _element;
TileElement* _element;
public:
ScFootpathAdditionStatus(rct_tile_element* element)
ScFootpathAdditionStatus(TileElement* element)
: _element(element)
{
}
uint8_t north_get()
{
return _element->properties.path.addition_status & 3;
return _element->AsPath()->GetAdditionStatus() & 3;
}
void north_set(uint8_t value)
{
_element->properties.path.addition_status &= ~3;
_element->properties.path.addition_status |= value & 3;
auto addition = _element->AsPath()->GetAdditionStatus();
addition &= ~3;
addition |= value & 3;
_element->AsPath()->SetAdditionStatus(addition);
}
uint8_t east_get()
{
return _element->properties.path.addition_status & 3;
return _element->AsPath()->GetAdditionStatus() & 3;
}
void east_set(uint8_t value)
{
_element->properties.path.addition_status &= ~(3 << 2);
_element->properties.path.addition_status |= (value & 3) << 2;
auto addition = _element->AsPath()->GetAdditionStatus();
addition &= ~(3 << 2);
addition |= (value & 3) << 2;
_element->AsPath()->SetAdditionStatus(addition);
}
uint8_t south_get()
{
return _element->properties.path.addition_status & 3;
return _element->AsPath()->GetAdditionStatus() & 3;
}
void south_set(uint8_t value)
{
_element->properties.path.addition_status &= ~(3 << 4);
_element->properties.path.addition_status |= (value & 3) << 4;
auto addition = _element->AsPath()->GetAdditionStatus();
addition &= ~(3 << 4);
addition |= (value & 3) << 4;
_element->AsPath()->SetAdditionStatus(addition);
}
uint8_t west_get()
{
return _element->properties.path.addition_status & 3;
return _element->AsPath()->GetAdditionStatus() & 3;
}
void west_set(uint8_t value)
{
_element->properties.path.addition_status &= ~(3 << 6);
_element->properties.path.addition_status |= (value & 3) << 6;
auto addition = _element->AsPath()->GetAdditionStatus();
addition &= ~(3 << 6);
addition |= (value & 3) << 6;
_element->AsPath()->SetAdditionStatus(addition);
}
static void Register(duk_context* ctx)
@@ -242,10 +246,10 @@ namespace OpenRCT2::Scripting
};
protected:
rct_tile_element* _element;
TileElement* _element;
bool VerifyPathAdditionExists()
{
if (!footpath_element_has_path_scenery(_element))
if (!_element->AsPath()->HasAddition())
{
// TODO: Show warning in console that the path addition has been removed
return false;
@@ -254,25 +258,25 @@ namespace OpenRCT2::Scripting
}
public:
ScFootpathAddition(rct_tile_element* element)
ScFootpathAddition(TileElement* element)
: _element(element)
{
}
void Remove()
{
footpath_element_set_path_scenery(_element, 0);
_element->AsPath()->SetAddition(0);
}
uint8_t type_get()
{
if (!VerifyPathAdditionExists())
return 0;
return footpath_element_get_path_scenery(_element);
return _element->AsPath()->GetAddition();
}
void type_set(uint8_t value)
{
footpath_element_set_path_scenery(_element, value);
_element->AsPath()->SetAddition(value);
}
bool isBin_get()
@@ -280,8 +284,7 @@ namespace OpenRCT2::Scripting
if (!VerifyPathAdditionExists())
return false;
auto index = footpath_element_get_path_scenery_index(_element);
auto sceneryEntry = get_footpath_item_entry(index);
auto sceneryEntry = _element->AsPath()->GetAdditionEntry();
return sceneryEntry->path_bit.flags & PATH_BIT_FLAG_IS_BIN;
}
bool isBench_get()
@@ -289,8 +292,7 @@ namespace OpenRCT2::Scripting
if (!VerifyPathAdditionExists())
return false;
auto index = footpath_element_get_path_scenery_index(_element);
auto sceneryEntry = get_footpath_item_entry(index);
auto sceneryEntry = _element->AsPath()->GetAdditionEntry();
return sceneryEntry->path_bit.flags & PATH_BIT_FLAG_IS_BENCH;
}
bool isLamp_get()
@@ -298,8 +300,7 @@ namespace OpenRCT2::Scripting
if (!VerifyPathAdditionExists())
return false;
auto index = footpath_element_get_path_scenery_index(_element);
auto sceneryEntry = get_footpath_item_entry(index);
auto sceneryEntry = _element->AsPath()->GetAdditionEntry();
return sceneryEntry->path_bit.flags & PATH_BIT_FLAG_LAMP;
}
bool isBreakable_get()
@@ -307,8 +308,7 @@ namespace OpenRCT2::Scripting
if (!VerifyPathAdditionExists())
return false;
auto index = footpath_element_get_path_scenery_index(_element);
auto sceneryEntry = get_footpath_item_entry(index);
auto sceneryEntry = _element->AsPath()->GetAdditionEntry();
return sceneryEntry->path_bit.flags & PATH_BIT_FLAG_BREAKABLE;
}
bool isJumpingFountainWater_get()
@@ -316,8 +316,7 @@ namespace OpenRCT2::Scripting
if (!VerifyPathAdditionExists())
return false;
auto index = footpath_element_get_path_scenery_index(_element);
auto sceneryEntry = get_footpath_item_entry(index);
auto sceneryEntry = _element->AsPath()->GetAdditionEntry();
return sceneryEntry->path_bit.flags & PATH_BIT_FLAG_JUMPING_FOUNTAIN_WATER;
}
bool isJumpingFountainSnow_get()
@@ -325,8 +324,7 @@ namespace OpenRCT2::Scripting
if (!VerifyPathAdditionExists())
return false;
auto index = footpath_element_get_path_scenery_index(_element);
auto sceneryEntry = get_footpath_item_entry(index);
auto sceneryEntry = _element->AsPath()->GetAdditionEntry();
return sceneryEntry->path_bit.flags & PATH_BIT_FLAG_JUMPING_FOUNTAIN_SNOW;
}
bool allowedOnQueue_get()
@@ -334,8 +332,7 @@ namespace OpenRCT2::Scripting
if (!VerifyPathAdditionExists())
return false;
auto index = footpath_element_get_path_scenery_index(_element);
auto sceneryEntry = get_footpath_item_entry(index);
auto sceneryEntry = _element->AsPath()->GetAdditionEntry();
return sceneryEntry->path_bit.flags & PATH_BIT_FLAG_DONT_ALLOW_ON_QUEUE;
}
bool allowedOnSlope_get()
@@ -343,8 +340,7 @@ namespace OpenRCT2::Scripting
if (!VerifyPathAdditionExists())
return false;
auto index = footpath_element_get_path_scenery_index(_element);
auto sceneryEntry = get_footpath_item_entry(index);
auto sceneryEntry = _element->AsPath()->GetAdditionEntry();
return sceneryEntry->path_bit.flags & PATH_BIT_FLAG_DONT_ALLOW_ON_SLOPE;
}
bool isQueueScreen_get()
@@ -352,8 +348,7 @@ namespace OpenRCT2::Scripting
if (!VerifyPathAdditionExists())
return false;
auto index = footpath_element_get_path_scenery_index(_element);
auto sceneryEntry = get_footpath_item_entry(index);
auto sceneryEntry = _element->AsPath()->GetAdditionEntry();
return sceneryEntry->path_bit.flags & PATH_BIT_FLAG_IS_QUEUE_SCREEN;
}
@@ -387,36 +382,36 @@ namespace OpenRCT2::Scripting
uint8_t footpathType_get()
{
return footpath_element_get_type(_element);
return _element->AsPath()->GetPathEntryIndex();
}
void type_set(uint8_t index)
{
auto entry = get_footpath_entry(index);
auto entry = get_path_surface_entry(index);
if (entry == nullptr)
{
// TODO: Give warning (most likely only happens when index > MAX_PATH_OBJECTS)
return;
}
footpath_element_set_type(_element, index);
_element->AsPath()->SetPathEntryIndex(index);
}
bool isSloped_get()
{
return footpath_element_is_sloped(_element);
return _element->AsPath()->IsSloped();
}
void isSlope_set(bool value)
{
footpath_element_set_sloped(_element, value);
_element->AsPath()->SetSloped(value);
}
bool isQueue_get()
{
return footpath_element_is_queue(_element);
return _element->AsPath()->IsQueue();
}
std::shared_ptr<ScFootpathAddition> addition_get()
{
if (!footpath_element_has_path_scenery(_element))
if (!_element->AsPath()->HasAddition())
return nullptr;
return std::make_shared<ScFootpathAddition>(_element);
@@ -424,29 +419,29 @@ namespace OpenRCT2::Scripting
uint8_t edges_get()
{
return footpath_element_get_edges(_element);
return _element->AsPath()->GetEdges();
}
void edges_set(uint8_t value)
{
footpath_element_set_edges(_element, value);
_element->AsPath()->SetEdges(value);
}
uint8_t corners_get()
{
return footpath_element_get_corners(_element);
return _element->AsPath()->GetCorners();
}
void corners_set(uint8_t value)
{
footpath_element_set_corners(_element, value);
_element->AsPath()->SetCorners(value);
}
uint8_t rideIndex_get()
{
if (!footpath_element_is_queue(_element))
if (!_element->AsPath()->IsQueue())
{
// TODO: Show warning that "path is not a queue"
}
return _element->properties.path.ride_index;
return _element->AsPath()->GetRideIndex();
}
public:
@@ -473,7 +468,7 @@ namespace OpenRCT2::Scripting
{
auto track_ride_index_get() const
{
return _element->properties.track.ride_index;
return _element->AsTrack()->GetRideIndex();
}
public:
@@ -575,11 +570,11 @@ namespace OpenRCT2::Scripting
class ScTile
{
private:
rct_tile_element* _first;
TileElement* _first;
size_t _count = 0;
public:
ScTile(rct_tile_element* first)
ScTile(TileElement* first)
: _first(first)
{
_count = 0;

View File

@@ -14,6 +14,7 @@
#include "../core/Path.hpp"
#include "../interface/InteractiveConsole.h"
#include "../platform/Platform2.h"
#include "Duktape.hpp"
#include "ScConsole.hpp"
#include "ScContext.hpp"
#include "ScDisposable.hpp"
@@ -22,8 +23,6 @@
#include "ScThing.hpp"
#include "ScTile.hpp"
#include <dukglue/dukglue.h>
#include <duktape.h>
#include <iostream>
#include <stdexcept>