mirror of https://github.com/OpenTTD/OpenTTD
Compare commits
7 Commits
d7d23e6684
...
a8f7def711
Author | SHA1 | Date |
---|---|---|
|
a8f7def711 | |
|
1d38cbafcb | |
|
992d58d799 | |
|
8f34b7a821 | |
|
bf6d0c4934 | |
|
3c4fb21a5e | |
|
13f24c25ca |
|
@ -90,7 +90,7 @@ template <> SQInteger PushClassName<AIInfo, ScriptType::AI>(HSQUIRRELVM vm) { sq
|
|||
/* Remove the link to the real instance, else it might get deleted by RegisterAI() */
|
||||
sq_setinstanceup(vm, 2, nullptr);
|
||||
/* Register the AI to the base system */
|
||||
info->GetScanner()->RegisterScript(info);
|
||||
info->GetScanner()->RegisterScript(std::unique_ptr<AIInfo>{info});
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -136,22 +136,21 @@ bool AIInfo::CanLoadFromVersion(int version) const
|
|||
/* static */ SQInteger AILibrary::Constructor(HSQUIRRELVM vm)
|
||||
{
|
||||
/* Create a new library */
|
||||
AILibrary *library = new AILibrary();
|
||||
auto library = std::make_unique<AILibrary>();
|
||||
|
||||
SQInteger res = ScriptInfo::Constructor(vm, *library);
|
||||
if (res != 0) {
|
||||
delete library;
|
||||
return res;
|
||||
}
|
||||
|
||||
/* Cache the category */
|
||||
if (!library->CheckMethod("GetCategory") || !library->engine->CallStringMethod(library->SQ_instance, "GetCategory", &library->category, MAX_GET_OPS)) {
|
||||
delete library;
|
||||
return SQ_ERROR;
|
||||
}
|
||||
|
||||
/* Register the Library to the base system */
|
||||
library->GetScanner()->RegisterScript(library);
|
||||
ScriptScanner *scanner = library->GetScanner();
|
||||
scanner->RegisterScript(std::move(library));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ void AIScannerInfo::Initialize()
|
|||
{
|
||||
ScriptScanner::Initialize("AIScanner");
|
||||
|
||||
ScriptAllocatorScope alloc_scope(this->engine);
|
||||
ScriptAllocatorScope alloc_scope(this->engine.get());
|
||||
|
||||
/* Create the dummy AI */
|
||||
this->main_script = "%_dummy";
|
||||
|
|
|
@ -22,9 +22,10 @@
|
|||
|
||||
#include "safeguards.h"
|
||||
|
||||
/** Default heights for the different sizes of fonts. */
|
||||
static const int _default_font_height[FS_END] = {10, 6, 18, 10};
|
||||
static const int _default_font_ascender[FS_END] = { 8, 5, 15, 8};
|
||||
/** Default unscaled heights for the different sizes of fonts. */
|
||||
/* static */ const int FontCache::DEFAULT_FONT_HEIGHT[FS_END] = {10, 6, 18, 10};
|
||||
/** Default unscaled ascenders for the different sizes of fonts. */
|
||||
/* static */ const int FontCache::DEFAULT_FONT_ASCENDER[FS_END] = {8, 5, 15, 8};
|
||||
|
||||
FontCacheSettings _fcsettings;
|
||||
|
||||
|
@ -32,8 +33,7 @@ FontCacheSettings _fcsettings;
|
|||
* Create a new font cache.
|
||||
* @param fs The size of the font.
|
||||
*/
|
||||
FontCache::FontCache(FontSize fs) : parent(FontCache::Get(fs)), fs(fs), height(_default_font_height[fs]),
|
||||
ascender(_default_font_ascender[fs]), descender(_default_font_ascender[fs] - _default_font_height[fs])
|
||||
FontCache::FontCache(FontSize fs) : parent(FontCache::Get(fs)), fs(fs)
|
||||
{
|
||||
assert(this->parent == nullptr || this->fs == this->parent->fs);
|
||||
FontCache::caches[this->fs] = this;
|
||||
|
@ -50,7 +50,7 @@ FontCache::~FontCache()
|
|||
|
||||
int FontCache::GetDefaultFontHeight(FontSize fs)
|
||||
{
|
||||
return _default_font_height[fs];
|
||||
return FontCache::DEFAULT_FONT_HEIGHT[fs];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -23,9 +23,9 @@ protected:
|
|||
static FontCache *caches[FS_END]; ///< All the font caches.
|
||||
FontCache *parent; ///< The parent of this font cache.
|
||||
const FontSize fs; ///< The size of the font.
|
||||
int height; ///< The height of the font.
|
||||
int ascender; ///< The ascender value of the font.
|
||||
int descender; ///< The descender value of the font.
|
||||
int height = 0; ///< The height of the font.
|
||||
int ascender = 0; ///< The ascender value of the font.
|
||||
int descender = 0; ///< The descender value of the font.
|
||||
|
||||
public:
|
||||
FontCache(FontSize fs);
|
||||
|
@ -33,6 +33,11 @@ public:
|
|||
|
||||
static void InitializeFontCaches();
|
||||
|
||||
/** Default unscaled font heights. */
|
||||
static const int DEFAULT_FONT_HEIGHT[FS_END];
|
||||
/** Default unscaled font ascenders. */
|
||||
static const int DEFAULT_FONT_ASCENDER[FS_END];
|
||||
|
||||
static int GetDefaultFontHeight(FontSize fs);
|
||||
|
||||
/**
|
||||
|
|
|
@ -78,7 +78,7 @@ template <> SQInteger PushClassName<GameInfo, ScriptType::GS>(HSQUIRRELVM vm) {
|
|||
/* Remove the link to the real instance, else it might get deleted by RegisterGame() */
|
||||
sq_setinstanceup(vm, 2, nullptr);
|
||||
/* Register the Game to the base system */
|
||||
info->GetScanner()->RegisterScript(info);
|
||||
info->GetScanner()->RegisterScript(std::unique_ptr<GameInfo>{info});
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -106,22 +106,21 @@ bool GameInfo::CanLoadFromVersion(int version) const
|
|||
/* static */ SQInteger GameLibrary::Constructor(HSQUIRRELVM vm)
|
||||
{
|
||||
/* Create a new library */
|
||||
GameLibrary *library = new GameLibrary();
|
||||
auto library = std::make_unique<GameLibrary>();
|
||||
|
||||
SQInteger res = ScriptInfo::Constructor(vm, *library);
|
||||
if (res != 0) {
|
||||
delete library;
|
||||
return res;
|
||||
}
|
||||
|
||||
/* Cache the category */
|
||||
if (!library->CheckMethod("GetCategory") || !library->engine->CallStringMethod(library->SQ_instance, "GetCategory", &library->category, MAX_GET_OPS)) {
|
||||
delete library;
|
||||
return SQ_ERROR;
|
||||
}
|
||||
|
||||
/* Register the Library to the base system */
|
||||
library->GetScanner()->RegisterScript(library);
|
||||
ScriptScanner *scanner = library->GetScanner();
|
||||
scanner->RegisterScript(std::move(library));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -92,8 +92,8 @@ GameLibrary *GameScannerLibrary::FindLibrary(const std::string &library, int ver
|
|||
std::string library_name = fmt::format("{}.{}", library, version);
|
||||
|
||||
/* Check if the library + version exists */
|
||||
ScriptInfoList::iterator it = this->info_list.find(library_name);
|
||||
auto it = this->info_list.find(library_name);
|
||||
if (it == this->info_list.end()) return nullptr;
|
||||
|
||||
return static_cast<GameLibrary *>((*it).second);
|
||||
return static_cast<GameLibrary *>(it->second);
|
||||
}
|
||||
|
|
|
@ -193,6 +193,7 @@ static uint32_t GetAirportTileIDAtOffset(TileIndex tile, const Station *st, uint
|
|||
/* Get airport tile ID at offset */
|
||||
case 0x62: return GetAirportTileIDAtOffset(GetNearbyTile(parameter, this->tile), this->st, this->ro.grffile->grfid);
|
||||
|
||||
case 0x79: return GetNearbyBadgeVariableResult(*this->ro.grffile, GetNearbyTile(parameter, this->tile), this->ro);
|
||||
case 0x7A: return GetBadgeVariableResult(*this->ro.grffile, this->ats->badges, parameter);
|
||||
}
|
||||
|
||||
|
|
|
@ -8,13 +8,25 @@
|
|||
/** @file newgrf_badge.cpp Functionality for NewGRF badges. */
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "house.h"
|
||||
#include "industry_map.h"
|
||||
#include "newgrf.h"
|
||||
#include "newgrf_airporttiles.h"
|
||||
#include "newgrf_badge.h"
|
||||
#include "newgrf_badge_type.h"
|
||||
#include "newgrf_object.h"
|
||||
#include "newgrf_roadstop.h"
|
||||
#include "newgrf_station.h"
|
||||
#include "newgrf_spritegroup.h"
|
||||
#include "rail.h"
|
||||
#include "rail_map.h"
|
||||
#include "station_map.h"
|
||||
#include "stringfilter_type.h"
|
||||
#include "strings_func.h"
|
||||
#include "tile_map.h"
|
||||
#include "timer/timer_game_calendar.h"
|
||||
#include "town_map.h"
|
||||
#include "tunnelbridge_map.h"
|
||||
|
||||
#include "table/strings.h"
|
||||
|
||||
|
@ -216,7 +228,173 @@ BadgeResolverObject::BadgeResolverObject(const Badge &badge, GrfSpecFeature feat
|
|||
}
|
||||
|
||||
/**
|
||||
* Test for a matching badge in a list of badges, returning the number of matching bits.
|
||||
* Test if a list of badges contains a badge.
|
||||
* @param badges List of badges.
|
||||
* @param badge Badge to find.
|
||||
* @returns true iff the badge appears in the list.
|
||||
*/
|
||||
static bool BadgesContains(std::span<const BadgeID> badges, BadgeID badge)
|
||||
{
|
||||
return std::ranges::find(badges, badge) != std::end(badges);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a rail type has a badge.
|
||||
* @param rt Rail type to test.
|
||||
* @param badge Badge to find.
|
||||
* @returns true iff the rail type has the badge.
|
||||
*/
|
||||
static bool RailTypeHasBadge(RailType rt, BadgeID badge)
|
||||
{
|
||||
return rt != INVALID_RAILTYPE && BadgesContains(GetRailTypeInfo(rt)->badges, badge);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a road type has a badge.
|
||||
* @param rt Road type to test.
|
||||
* @param badge Badge to find.
|
||||
* @returns true iff the road type has the badge.
|
||||
*/
|
||||
static bool RoadTypeHasBadge(RoadType rt, BadgeID badge)
|
||||
{
|
||||
return rt != INVALID_ROADTYPE && BadgesContains(GetRoadTypeInfo(rt)->badges, badge);
|
||||
}
|
||||
|
||||
using TileHasBadgeProc = bool(*)(TileIndex tile, BadgeID badge, GrfSpecFeatures features);
|
||||
|
||||
static bool TileHasBadge_Rail(TileIndex tile, BadgeID badge, GrfSpecFeatures features)
|
||||
{
|
||||
if (features.Test(GrfSpecFeature::GSF_RAILTYPES) && RailTypeHasBadge(GetRailType(tile), badge)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool TileHasBadge_Road(TileIndex tile, BadgeID badge, GrfSpecFeatures features)
|
||||
{
|
||||
if (features.Test(GrfSpecFeature::GSF_ROADTYPES) && RoadTypeHasBadge(GetRoadTypeRoad(tile), badge)) return true;
|
||||
if (features.Test(GrfSpecFeature::GSF_TRAMTYPES) && RoadTypeHasBadge(GetRoadTypeTram(tile), badge)) return true;
|
||||
if (features.Test(GrfSpecFeature::GSF_RAILTYPES) && IsLevelCrossing(tile) && RailTypeHasBadge(GetRailType(tile), badge)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool TileHasBadge_Town(TileIndex tile, BadgeID badge, GrfSpecFeatures features)
|
||||
{
|
||||
if (features.Test(GrfSpecFeature::GSF_HOUSES) && BadgesContains(HouseSpec::Get(GetHouseType(tile))->badges, badge)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool TileHasBadge_Station(TileIndex tile, BadgeID badge, GrfSpecFeatures features)
|
||||
{
|
||||
switch (GetStationType(tile)) {
|
||||
case StationType::Rail:
|
||||
case StationType::RailWaypoint:
|
||||
if (features.Test(GrfSpecFeature::GSF_STATIONS)) {
|
||||
if (const StationSpec *spec = GetStationSpec(tile); spec != nullptr && BadgesContains(spec->badges, badge)) return true;
|
||||
}
|
||||
if (features.Test(GrfSpecFeature::GSF_RAILTYPES) && RailTypeHasBadge(GetRailType(tile), badge)) return true;
|
||||
return false;
|
||||
|
||||
case StationType::Bus:
|
||||
case StationType::Truck:
|
||||
case StationType::RoadWaypoint:
|
||||
if (features.Test(GrfSpecFeature::GSF_ROADSTOPS)) {
|
||||
if (const RoadStopSpec *spec = GetRoadStopSpec(tile); spec != nullptr && BadgesContains(spec->badges, badge)) return true;
|
||||
}
|
||||
if (features.Test(GrfSpecFeature::GSF_ROADTYPES) && RoadTypeHasBadge(GetRoadTypeRoad(tile), badge)) return true;
|
||||
if (features.Test(GrfSpecFeature::GSF_TRAMTYPES) && RoadTypeHasBadge(GetRoadTypeTram(tile), badge)) return true;
|
||||
return false;
|
||||
|
||||
case StationType::Airport:
|
||||
if (features.Test(GrfSpecFeature::GSF_AIRPORTTILES) && BadgesContains(AirportTileSpec::GetByTile(tile)->badges, badge)) return true;
|
||||
return false;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static bool TileHasBadge_Industry(TileIndex tile, BadgeID badge, GrfSpecFeatures features)
|
||||
{
|
||||
if (features.Test(GrfSpecFeature::GSF_INDUSTRYTILES) && BadgesContains(GetIndustryTileSpec(GetIndustryGfx(tile))->badges, badge)) return true;
|
||||
if (features.Test(GrfSpecFeature::GSF_INDUSTRIES) && BadgesContains(GetIndustrySpec(GetIndustryType(tile))->badges, badge)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool TileHasBadge_TunnelBridge(TileIndex tile, BadgeID badge, GrfSpecFeatures features)
|
||||
{
|
||||
switch (GetTunnelBridgeTransportType(tile)) {
|
||||
case TransportType::TRANSPORT_RAIL:
|
||||
if (features.Test(GrfSpecFeature::GSF_RAILTYPES) && RailTypeHasBadge(GetRailType(tile), badge)) return true;
|
||||
return false;
|
||||
|
||||
case TransportType::TRANSPORT_ROAD:
|
||||
if (features.Test(GrfSpecFeature::GSF_ROADTYPES) && RoadTypeHasBadge(GetRoadTypeRoad(tile), badge)) return true;
|
||||
if (features.Test(GrfSpecFeature::GSF_TRAMTYPES) && RoadTypeHasBadge(GetRoadTypeTram(tile), badge)) return true;
|
||||
return false;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static bool TileHasBadge_Object(TileIndex tile, BadgeID badge, GrfSpecFeatures features)
|
||||
{
|
||||
if (features.Test(GrfSpecFeature::GSF_OBJECTS) && BadgesContains(ObjectSpec::GetByTile(tile)->badges, badge)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a tile has an item containing the specified badge.
|
||||
* @param tile Tile to query.
|
||||
* @param badge Badge to search for.
|
||||
* @param features GRF features to include in the test.
|
||||
* @returns true iff the badge 'is on' the tile.
|
||||
*/
|
||||
static bool TileHasBadge(TileIndex tile, BadgeID badge, GrfSpecFeatures features)
|
||||
{
|
||||
/* Per-tiletype functions for badge testing. Like _tile_type_procs, this is 16 entries as GetTileType() reads 4 bits. */
|
||||
static constexpr std::array<TileHasBadgeProc, 16> tile_procs = {
|
||||
nullptr,
|
||||
TileHasBadge_Rail,
|
||||
TileHasBadge_Road,
|
||||
TileHasBadge_Town,
|
||||
nullptr,
|
||||
TileHasBadge_Station,
|
||||
nullptr,
|
||||
nullptr,
|
||||
TileHasBadge_Industry,
|
||||
TileHasBadge_TunnelBridge,
|
||||
TileHasBadge_Object,
|
||||
};
|
||||
|
||||
TileHasBadgeProc proc = tile_procs[GetTileType(tile)];
|
||||
return proc != nullptr && proc(tile, badge, features);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for a matching badge 'on' a specific map tile.
|
||||
* @param grffile GRF file of the current varaction.
|
||||
* @param tile Tile to test.
|
||||
* @param parameter GRF-local badge index.
|
||||
* @param features GRF features to include in the test.
|
||||
* @returns true iff the badge is present.
|
||||
*/
|
||||
uint32_t GetNearbyBadgeVariableResult(const GRFFile &grffile, TileIndex tile, const ResolverObject &object)
|
||||
{
|
||||
GrfSpecFeatures features = static_cast<GrfSpecFeatures>(object.GetRegister(0x101));
|
||||
if (features.None()) return 0;
|
||||
|
||||
uint32_t parameter = object.GetRegister(0x100);
|
||||
if (parameter >= std::size(grffile.badge_list)) return UINT_MAX;
|
||||
|
||||
/* NewGRF cannot be expected to know the bounds of the map. If the tile is invalid it doesn't have the queried badge. */
|
||||
if (!IsValidTile(tile)) return 0;
|
||||
|
||||
BadgeID index = grffile.badge_list[parameter];
|
||||
return TileHasBadge(tile, index, features);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for a matching badge in a list of badges.
|
||||
* @param grffile GRF file of the current varaction.
|
||||
* @param badges List of badges to test.
|
||||
* @param parameter GRF-local badge index.
|
||||
|
@ -227,7 +405,7 @@ uint32_t GetBadgeVariableResult(const GRFFile &grffile, std::span<const BadgeID>
|
|||
if (parameter >= std::size(grffile.badge_list)) return UINT_MAX;
|
||||
|
||||
BadgeID index = grffile.badge_list[parameter];
|
||||
return std::ranges::find(badges, index) != std::end(badges);
|
||||
return BadgesContains(badges, index);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -64,6 +64,7 @@ Badge *GetBadgeByLabel(std::string_view label);
|
|||
Badge *GetClassBadge(BadgeClassID class_index);
|
||||
std::span<const BadgeID> GetClassBadges();
|
||||
|
||||
uint32_t GetNearbyBadgeVariableResult(const GRFFile &grffile, TileIndex tile, const ResolverObject &object);
|
||||
uint32_t GetBadgeVariableResult(const struct GRFFile &grffile, std::span<const BadgeID> badges, uint32_t parameter);
|
||||
|
||||
PalSpriteID GetBadgeSprite(const Badge &badge, GrfSpecFeature feature, std::optional<TimerGameCalendar::Date> introduction_date, PaletteID remap);
|
||||
|
|
|
@ -444,6 +444,7 @@ static uint32_t GetDistanceFromNearbyHouse(uint8_t parameter, TileIndex start_ti
|
|||
return _house_mngr.GetGRFID(house_id);
|
||||
}
|
||||
|
||||
case 0x79: return GetNearbyBadgeVariableResult(*this->ro.grffile, GetNearbyTile(parameter, this->tile), this->ro);
|
||||
case 0x7A: return GetBadgeVariableResult(*this->ro.grffile, HouseSpec::Get(this->house_id)->badges, parameter);
|
||||
}
|
||||
|
||||
|
|
|
@ -168,6 +168,7 @@ static uint32_t GetCountAndDistanceOfClosestInstance(const ResolverObject &objec
|
|||
/* Variables available during construction check. */
|
||||
|
||||
switch (variable) {
|
||||
case 0x79: return GetNearbyBadgeVariableResult(*this->ro.grffile, GetNearbyTile(parameter, this->tile), this->ro);
|
||||
case 0x7A: return GetBadgeVariableResult(*this->ro.grffile, GetIndustrySpec(this->type)->badges, parameter);
|
||||
|
||||
case 0x80: return this->tile.base();
|
||||
|
@ -354,6 +355,7 @@ static uint32_t GetCountAndDistanceOfClosestInstance(const ResolverObject &objec
|
|||
NOT_REACHED();
|
||||
}
|
||||
|
||||
case 0x79: return GetNearbyBadgeVariableResult(*this->ro.grffile, GetNearbyTile(parameter, this->tile), this->ro);
|
||||
case 0x7A: return GetBadgeVariableResult(*this->ro.grffile, GetIndustrySpec(this->type)->badges, parameter);
|
||||
|
||||
/* Get a variable from the persistent storage */
|
||||
|
|
|
@ -93,6 +93,7 @@ uint32_t GetRelativePosition(TileIndex tile, TileIndex ind_tile)
|
|||
/* Get industry tile ID at offset */
|
||||
case 0x62: return GetIndustryIDAtOffset(GetNearbyTile(parameter, this->tile), this->industry, this->ro.grffile->grfid);
|
||||
|
||||
case 0x79: return GetNearbyBadgeVariableResult(*this->ro.grffile, GetNearbyTile(parameter, this->tile), this->ro);
|
||||
case 0x7A: return GetBadgeVariableResult(*this->ro.grffile, GetIndustryTileSpec(GetIndustryGfx(this->tile))->badges, parameter);
|
||||
}
|
||||
|
||||
|
|
|
@ -291,6 +291,7 @@ static uint32_t GetCountAndDistanceOfClosestInstance(const ResolverObject &objec
|
|||
/* Object view */
|
||||
case 0x48: return this->view;
|
||||
|
||||
case 0x79: return GetNearbyBadgeVariableResult(*this->ro.grffile, GetNearbyTile(parameter, this->tile), this->ro);
|
||||
case 0x7A: return GetBadgeVariableResult(*this->ro.grffile, this->spec->badges, parameter);
|
||||
|
||||
/*
|
||||
|
@ -364,6 +365,7 @@ static uint32_t GetCountAndDistanceOfClosestInstance(const ResolverObject &objec
|
|||
/* Count of object, distance of closest instance */
|
||||
case 0x64: return GetCountAndDistanceOfClosestInstance(this->ro, parameter, this->ro.grffile->grfid, this->tile, this->obj);
|
||||
|
||||
case 0x79: return GetNearbyBadgeVariableResult(*this->ro.grffile, GetNearbyTile(parameter, this->tile), this->ro);
|
||||
case 0x7A: return GetBadgeVariableResult(*this->ro.grffile, this->spec->badges, parameter);
|
||||
}
|
||||
|
||||
|
|
|
@ -205,6 +205,7 @@ uint32_t RoadStopScopeResolver::GetVariable(uint8_t variable, [[maybe_unused]] u
|
|||
return 0xFFFE;
|
||||
}
|
||||
|
||||
case 0x79: return GetNearbyBadgeVariableResult(*this->ro.grffile, GetNearbyTile(parameter, this->tile), this->ro);
|
||||
case 0x7A: return GetBadgeVariableResult(*this->ro.grffile, this->roadstopspec->badges, parameter);
|
||||
|
||||
case 0xF0: return this->st == nullptr ? 0 : this->st->facilities.base(); // facilities
|
||||
|
|
|
@ -295,6 +295,12 @@ TownScopeResolver *StationResolverObject::GetTown()
|
|||
}
|
||||
break;
|
||||
|
||||
case 0x79:
|
||||
if (this->axis != INVALID_AXIS && this->tile != INVALID_TILE) {
|
||||
return GetNearbyBadgeVariableResult(*this->ro.grffile, GetNearbyTile(parameter, this->tile, true, this->axis), this->ro);
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x7A: return GetBadgeVariableResult(*this->ro.grffile, this->statspec->badges, parameter);
|
||||
|
||||
case 0xFA: return ClampTo<uint16_t>(TimerGameCalendar::date - CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR); // Build date, clamped to a 16 bit value
|
||||
|
@ -398,6 +404,7 @@ TownScopeResolver *StationResolverObject::GetTown()
|
|||
return 0xFFFE;
|
||||
}
|
||||
|
||||
case 0x79: return GetNearbyBadgeVariableResult(*this->ro.grffile, GetNearbyTile(parameter, this->tile), this->ro);
|
||||
case 0x7A: return GetBadgeVariableResult(*this->ro.grffile, this->statspec->badges, parameter);
|
||||
|
||||
/* General station variables */
|
||||
|
|
|
@ -44,10 +44,7 @@ bool ScriptScanner::AddFile(const std::string &filename, size_t, const std::stri
|
|||
return true;
|
||||
}
|
||||
|
||||
ScriptScanner::ScriptScanner() :
|
||||
engine(nullptr)
|
||||
{
|
||||
}
|
||||
ScriptScanner::ScriptScanner() = default;
|
||||
|
||||
void ScriptScanner::ResetEngine()
|
||||
{
|
||||
|
@ -58,7 +55,7 @@ void ScriptScanner::ResetEngine()
|
|||
|
||||
void ScriptScanner::Initialize(std::string_view name)
|
||||
{
|
||||
this->engine = new Squirrel(name);
|
||||
this->engine = std::make_unique<Squirrel>(name);
|
||||
|
||||
this->RescanDir();
|
||||
|
||||
|
@ -68,8 +65,6 @@ void ScriptScanner::Initialize(std::string_view name)
|
|||
ScriptScanner::~ScriptScanner()
|
||||
{
|
||||
this->Reset();
|
||||
|
||||
delete this->engine;
|
||||
}
|
||||
|
||||
void ScriptScanner::RescanDir()
|
||||
|
@ -83,15 +78,12 @@ void ScriptScanner::RescanDir()
|
|||
|
||||
void ScriptScanner::Reset()
|
||||
{
|
||||
for (const auto &item : this->info_list) {
|
||||
delete item.second;
|
||||
}
|
||||
|
||||
this->info_list.clear();
|
||||
this->info_single_list.clear();
|
||||
this->info_vector.clear();
|
||||
}
|
||||
|
||||
void ScriptScanner::RegisterScript(ScriptInfo *info)
|
||||
void ScriptScanner::RegisterScript(std::unique_ptr<ScriptInfo> &&info)
|
||||
{
|
||||
std::string script_original_name = this->GetScriptName(*info);
|
||||
std::string script_name = fmt::format("{}.{}", script_original_name, info->GetVersion());
|
||||
|
@ -99,7 +91,6 @@ void ScriptScanner::RegisterScript(ScriptInfo *info)
|
|||
/* Check if GetShortName follows the rules */
|
||||
if (info->GetShortName().size() != 4) {
|
||||
Debug(script, 0, "The script '{}' returned a string from GetShortName() which is not four characters. Unable to load the script.", info->GetName());
|
||||
delete info;
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -111,7 +102,6 @@ void ScriptScanner::RegisterScript(ScriptInfo *info)
|
|||
#else
|
||||
if (it->second->GetMainScript() == info->GetMainScript()) {
|
||||
#endif
|
||||
delete info;
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -120,20 +110,20 @@ void ScriptScanner::RegisterScript(ScriptInfo *info)
|
|||
Debug(script, 1, " 2: {}", info->GetMainScript());
|
||||
Debug(script, 1, "The first is taking precedence.");
|
||||
|
||||
delete info;
|
||||
return;
|
||||
}
|
||||
|
||||
this->info_list[script_name] = info;
|
||||
ScriptInfo *script_info = this->info_vector.emplace_back(std::move(info)).get();
|
||||
this->info_list[script_name] = script_info;
|
||||
|
||||
if (!info->IsDeveloperOnly() || _settings_client.gui.ai_developer_tools) {
|
||||
if (!script_info->IsDeveloperOnly() || _settings_client.gui.ai_developer_tools) {
|
||||
/* Add the script to the 'unique' script list, where only the highest version
|
||||
* of the script is registered. */
|
||||
auto it = this->info_single_list.find(script_original_name);
|
||||
if (it == this->info_single_list.end()) {
|
||||
this->info_single_list[script_original_name] = info;
|
||||
} else if (it->second->GetVersion() < info->GetVersion()) {
|
||||
it->second = info;
|
||||
this->info_single_list[script_original_name] = script_info;
|
||||
} else if (it->second->GetVersion() < script_info->GetVersion()) {
|
||||
it->second = script_info;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -195,17 +185,17 @@ struct ScriptFileChecksumCreator : FileScanner {
|
|||
* @param info The script to get the shortname and md5 sum from.
|
||||
* @return True iff they're the same.
|
||||
*/
|
||||
static bool IsSameScript(const ContentInfo &ci, bool md5sum, ScriptInfo *info, Subdirectory dir)
|
||||
static bool IsSameScript(const ContentInfo &ci, bool md5sum, const ScriptInfo &info, Subdirectory dir)
|
||||
{
|
||||
uint32_t id = 0;
|
||||
auto str = std::string_view{info->GetShortName()}.substr(0, 4);
|
||||
auto str = std::string_view{info.GetShortName()}.substr(0, 4);
|
||||
for (size_t j = 0; j < str.size(); j++) id |= static_cast<uint8_t>(str[j]) << (8 * j);
|
||||
|
||||
if (id != ci.unique_id) return false;
|
||||
if (!md5sum) return true;
|
||||
|
||||
ScriptFileChecksumCreator checksum(dir);
|
||||
const auto &tar_filename = info->GetTarFile();
|
||||
const auto &tar_filename = info.GetTarFile();
|
||||
TarList::iterator iter;
|
||||
if (!tar_filename.empty() && (iter = _tar_list[dir].find(tar_filename)) != _tar_list[dir].end()) {
|
||||
/* The main script is in a tar file, so find all files that
|
||||
|
@ -224,7 +214,7 @@ static bool IsSameScript(const ContentInfo &ci, bool md5sum, ScriptInfo *info, S
|
|||
/* There'll always be at least 1 path separator character in a script
|
||||
* main script name as the search algorithm requires the main script to
|
||||
* be in a subdirectory of the script directory; so <dir>/<path>/main.nut. */
|
||||
const std::string &main_script = info->GetMainScript();
|
||||
const std::string &main_script = info.GetMainScript();
|
||||
std::string path = main_script.substr(0, main_script.find_last_of(PATHSEPCHAR));
|
||||
checksum.Scan(".nut", path);
|
||||
}
|
||||
|
@ -235,7 +225,7 @@ static bool IsSameScript(const ContentInfo &ci, bool md5sum, ScriptInfo *info, S
|
|||
bool ScriptScanner::HasScript(const ContentInfo &ci, bool md5sum)
|
||||
{
|
||||
for (const auto &item : this->info_list) {
|
||||
if (IsSameScript(ci, md5sum, item.second, this->GetDirectory())) return true;
|
||||
if (IsSameScript(ci, md5sum, *item.second, this->GetDirectory())) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -243,7 +233,7 @@ bool ScriptScanner::HasScript(const ContentInfo &ci, bool md5sum)
|
|||
std::optional<std::string_view> ScriptScanner::FindMainScript(const ContentInfo &ci, bool md5sum)
|
||||
{
|
||||
for (const auto &item : this->info_list) {
|
||||
if (IsSameScript(ci, md5sum, item.second, this->GetDirectory())) return item.second->GetMainScript();
|
||||
if (IsSameScript(ci, md5sum, *item.second, this->GetDirectory())) return item.second->GetMainScript();
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
#include "../fileio_func.h"
|
||||
#include "../string_func.h"
|
||||
|
||||
typedef std::map<std::string, class ScriptInfo *, CaseInsensitiveComparator> ScriptInfoList; ///< Type for the list of scripts.
|
||||
using ScriptInfoList = std::map<std::string, class ScriptInfo *, CaseInsensitiveComparator>; ///< Type for the list of scripts.
|
||||
|
||||
/** Scanner to help finding scripts. */
|
||||
class ScriptScanner : public FileScanner {
|
||||
|
@ -26,7 +26,7 @@ public:
|
|||
/**
|
||||
* Get the engine of the main squirrel handler (it indexes all available scripts).
|
||||
*/
|
||||
class Squirrel *GetEngine() { return this->engine; }
|
||||
class Squirrel *GetEngine() { return this->engine.get(); }
|
||||
|
||||
/**
|
||||
* Get the current main script the ScanDir is currently tracking.
|
||||
|
@ -51,7 +51,7 @@ public:
|
|||
/**
|
||||
* Register a ScriptInfo to the scanner.
|
||||
*/
|
||||
void RegisterScript(class ScriptInfo *info);
|
||||
void RegisterScript(std::unique_ptr<class ScriptInfo> &&info);
|
||||
|
||||
/**
|
||||
* Get the list of registered scripts to print on the console.
|
||||
|
@ -84,11 +84,13 @@ public:
|
|||
void RescanDir();
|
||||
|
||||
protected:
|
||||
class Squirrel *engine; ///< The engine we're scanning with.
|
||||
std::unique_ptr<class Squirrel> engine; ///< The engine we're scanning with.
|
||||
std::string main_script; ///< The full path of the script.
|
||||
std::string tar_file; ///< If, which tar file the script was in.
|
||||
|
||||
ScriptInfoList info_list; ///< The list of all script.
|
||||
std::vector<std::unique_ptr<ScriptInfo>> info_vector;
|
||||
|
||||
ScriptInfoList info_list; ///< The list of all script.
|
||||
ScriptInfoList info_single_list; ///< The list of all unique script. The best script (highest version) is shown.
|
||||
|
||||
/**
|
||||
|
|
|
@ -401,6 +401,40 @@ static void CancelIMEComposition(HWND hwnd)
|
|||
HandleTextInput({}, true);
|
||||
}
|
||||
|
||||
#if defined(_MSC_VER) && defined(NTDDI_WIN10_RS4)
|
||||
/* We only use WinRT functions on Windows 10 or later. Unfortunately, newer Windows SDKs are now
|
||||
* linking the two functions below directly instead of using dynamic linking as previously.
|
||||
* To avoid any runtime linking errors on Windows 7 or older, we stub in our own dynamic
|
||||
* linking trampoline. */
|
||||
|
||||
static LibraryLoader _combase("combase.dll");
|
||||
|
||||
extern "C" int32_t __stdcall WINRT_IMPL_RoOriginateLanguageException(int32_t error, void *message, void *languageException) noexcept
|
||||
{
|
||||
typedef BOOL(WINAPI *PFNRoOriginateLanguageException)(int32_t, void *, void *);
|
||||
static PFNRoOriginateLanguageException RoOriginateLanguageException = _combase.GetFunction("RoOriginateLanguageException");
|
||||
|
||||
if (RoOriginateLanguageException != nullptr) {
|
||||
return RoOriginateLanguageException(error, message, languageException);
|
||||
} else {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" int32_t __stdcall WINRT_IMPL_RoGetActivationFactory(void *classId, winrt::guid const &iid, void **factory) noexcept
|
||||
{
|
||||
typedef BOOL(WINAPI *PFNRoGetActivationFactory)(void *, winrt::guid const &, void **);
|
||||
static PFNRoGetActivationFactory RoGetActivationFactory = _combase.GetFunction("RoGetActivationFactory");
|
||||
|
||||
if (RoGetActivationFactory != nullptr) {
|
||||
return RoGetActivationFactory(classId, iid, factory);
|
||||
} else {
|
||||
*factory = nullptr;
|
||||
return winrt::impl::error_class_not_available;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static bool IsDarkModeEnabled()
|
||||
{
|
||||
/* Only build if SDK is Windows 10 1803 or later. */
|
||||
|
|
Loading…
Reference in New Issue