mirror of https://github.com/OpenTTD/OpenTTD
Compare commits
8 Commits
a59ab9b195
...
8361e662c3
Author | SHA1 | Date |
---|---|---|
|
8361e662c3 | |
|
9ce2aca949 | |
|
55098a2f2e | |
|
7ff0c67f77 | |
|
b2de1ff66f | |
|
fc924161ab | |
|
61a299bc99 | |
|
13f24c25ca |
|
@ -103,14 +103,14 @@ void SpriteFontCache::ClearFontCache()
|
|||
|
||||
const Sprite *SpriteFontCache::GetGlyph(GlyphID key)
|
||||
{
|
||||
SpriteID sprite = this->GetUnicodeGlyph(static_cast<char32_t>(key & ~SPRITE_GLYPH));
|
||||
SpriteID sprite = static_cast<SpriteID>(key & ~SPRITE_GLYPH);
|
||||
if (sprite == 0) sprite = this->GetUnicodeGlyph('?');
|
||||
return GetSprite(sprite, SpriteType::Font);
|
||||
}
|
||||
|
||||
uint SpriteFontCache::GetGlyphWidth(GlyphID key)
|
||||
{
|
||||
SpriteID sprite = this->GetUnicodeGlyph(static_cast<char32_t>(key & ~SPRITE_GLYPH));
|
||||
SpriteID sprite = static_cast<SpriteID>(key & ~SPRITE_GLYPH);
|
||||
if (sprite == 0) sprite = this->GetUnicodeGlyph('?');
|
||||
return SpriteExists(sprite) ? GetSprite(sprite, SpriteType::Font)->width + ScaleFontTrad(this->fs != FS_NORMAL ? 1 : 0) : 0;
|
||||
}
|
||||
|
@ -120,7 +120,7 @@ GlyphID SpriteFontCache::MapCharToGlyph(char32_t key, [[maybe_unused]] bool allo
|
|||
assert(IsPrintable(key));
|
||||
SpriteID sprite = this->GetUnicodeGlyph(key);
|
||||
if (sprite == 0) return 0;
|
||||
return SPRITE_GLYPH | key;
|
||||
return SPRITE_GLYPH | sprite;
|
||||
}
|
||||
|
||||
bool SpriteFontCache::GetDrawGlyphShadow()
|
||||
|
|
|
@ -105,8 +105,8 @@ static ChangeInfoResult RoadStopChangeInfo(uint first, uint last, int prop, Byte
|
|||
AddStringForMapping(GRFStringID{buf.ReadWord()}, [rs = rs.get()](StringID str) { RoadStopClass::Get(rs->class_index)->name = str; });
|
||||
break;
|
||||
|
||||
case 0x0C: // The draw mode
|
||||
rs->draw_mode = static_cast<RoadStopDrawMode>(buf.ReadByte());
|
||||
case 0x0C: // The draw modes
|
||||
rs->draw_mode = static_cast<RoadStopDrawModes>(buf.ReadByte());
|
||||
break;
|
||||
|
||||
case 0x0D: // Cargo types for random triggers
|
||||
|
|
|
@ -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
|
||||
|
@ -298,7 +299,7 @@ void DrawRoadStopTile(int x, int y, RoadType roadtype, const RoadStopSpec *spec,
|
|||
|
||||
RoadStopDrawModes draw_mode;
|
||||
if (spec->flags.Test(RoadStopSpecFlag::DrawModeRegister)) {
|
||||
draw_mode = static_cast<RoadStopDrawMode>(object.GetRegister(0x100));
|
||||
draw_mode = static_cast<RoadStopDrawModes>(object.GetRegister(0x100));
|
||||
} else {
|
||||
draw_mode = spec->draw_mode;
|
||||
}
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -76,7 +76,7 @@ ScriptController::ScriptController(::CompanyID company) :
|
|||
|
||||
/* static */ uint ScriptController::GetTick()
|
||||
{
|
||||
return ScriptObject::GetActiveInstance().GetController()->ticks;
|
||||
return ScriptObject::GetActiveInstance().GetController().ticks;
|
||||
}
|
||||
|
||||
/* static */ int ScriptController::GetOpsTillSuspend()
|
||||
|
@ -96,9 +96,9 @@ ScriptController::ScriptController(::CompanyID company) :
|
|||
|
||||
/* static */ HSQOBJECT ScriptController::Import(const std::string &library, const std::string &class_name, int version)
|
||||
{
|
||||
ScriptController *controller = ScriptObject::GetActiveInstance().GetController();
|
||||
Squirrel *engine = ScriptObject::GetActiveInstance().engine;
|
||||
HSQUIRRELVM vm = engine->GetVM();
|
||||
ScriptController &controller = ScriptObject::GetActiveInstance().GetController();
|
||||
Squirrel &engine = *ScriptObject::GetActiveInstance().engine;
|
||||
HSQUIRRELVM vm = engine.GetVM();
|
||||
|
||||
ScriptInfo *lib = ScriptObject::GetActiveInstance().FindLibrary(library, version);
|
||||
if (lib == nullptr) {
|
||||
|
@ -114,11 +114,11 @@ ScriptController::ScriptController(::CompanyID company) :
|
|||
|
||||
std::string fake_class;
|
||||
|
||||
LoadedLibraryList::iterator it = controller->loaded_library.find(library_name);
|
||||
if (it != controller->loaded_library.end()) {
|
||||
LoadedLibraryList::iterator it = controller.loaded_library.find(library_name);
|
||||
if (it != controller.loaded_library.end()) {
|
||||
fake_class = (*it).second;
|
||||
} else {
|
||||
int next_number = ++controller->loaded_library_count;
|
||||
int next_number = ++controller.loaded_library_count;
|
||||
|
||||
/* Create a new fake internal name */
|
||||
fake_class = fmt::format("_internalNA{}", next_number);
|
||||
|
@ -128,14 +128,14 @@ ScriptController::ScriptController(::CompanyID company) :
|
|||
sq_pushstring(vm, fake_class);
|
||||
sq_newclass(vm, SQFalse);
|
||||
/* Load the library */
|
||||
if (!engine->LoadScript(vm, lib->GetMainScript(), false)) {
|
||||
if (!engine.LoadScript(vm, lib->GetMainScript(), false)) {
|
||||
throw sq_throwerror(vm, fmt::format("there was a compile error when importing '{}' version {}", library, version));
|
||||
}
|
||||
/* Create the fake class */
|
||||
sq_newslot(vm, -3, SQFalse);
|
||||
sq_pop(vm, 1);
|
||||
|
||||
controller->loaded_library[library_name] = fake_class;
|
||||
controller.loaded_library[library_name] = fake_class;
|
||||
}
|
||||
|
||||
/* Find the real class inside the fake class (like 'sets.Vector') */
|
||||
|
|
|
@ -45,7 +45,7 @@ void SimpleCountedObject::Release()
|
|||
* Get the storage associated with the current ScriptInstance.
|
||||
* @return The storage.
|
||||
*/
|
||||
static ScriptStorage *GetStorage()
|
||||
static ScriptStorage &GetStorage()
|
||||
{
|
||||
return ScriptObject::GetActiveInstance().GetStorage();
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ ScriptObject::ActiveInstance::~ActiveInstance()
|
|||
}
|
||||
|
||||
ScriptObject::DisableDoCommandScope::DisableDoCommandScope()
|
||||
: AutoRestoreBackup(GetStorage()->allow_do_command, false)
|
||||
: AutoRestoreBackup(GetStorage().allow_do_command, false)
|
||||
{}
|
||||
|
||||
/* static */ ScriptInstance &ScriptObject::GetActiveInstance()
|
||||
|
@ -78,181 +78,181 @@ ScriptObject::DisableDoCommandScope::DisableDoCommandScope()
|
|||
/* static */ void ScriptObject::SetDoCommandDelay(uint ticks)
|
||||
{
|
||||
assert(ticks > 0);
|
||||
GetStorage()->delay = ticks;
|
||||
GetStorage().delay = ticks;
|
||||
}
|
||||
|
||||
/* static */ uint ScriptObject::GetDoCommandDelay()
|
||||
{
|
||||
return GetStorage()->delay;
|
||||
return GetStorage().delay;
|
||||
}
|
||||
|
||||
/* static */ void ScriptObject::SetDoCommandMode(ScriptModeProc *proc, ScriptObject *instance)
|
||||
{
|
||||
GetStorage()->mode = proc;
|
||||
GetStorage()->mode_instance = instance;
|
||||
GetStorage().mode = proc;
|
||||
GetStorage().mode_instance = instance;
|
||||
}
|
||||
|
||||
/* static */ ScriptModeProc *ScriptObject::GetDoCommandMode()
|
||||
{
|
||||
return GetStorage()->mode;
|
||||
return GetStorage().mode;
|
||||
}
|
||||
|
||||
/* static */ ScriptObject *ScriptObject::GetDoCommandModeInstance()
|
||||
{
|
||||
return GetStorage()->mode_instance;
|
||||
return GetStorage().mode_instance;
|
||||
}
|
||||
|
||||
/* static */ void ScriptObject::SetDoCommandAsyncMode(ScriptAsyncModeProc *proc, ScriptObject *instance)
|
||||
{
|
||||
GetStorage()->async_mode = proc;
|
||||
GetStorage()->async_mode_instance = instance;
|
||||
GetStorage().async_mode = proc;
|
||||
GetStorage().async_mode_instance = instance;
|
||||
}
|
||||
|
||||
/* static */ ScriptAsyncModeProc *ScriptObject::GetDoCommandAsyncMode()
|
||||
{
|
||||
return GetStorage()->async_mode;
|
||||
return GetStorage().async_mode;
|
||||
}
|
||||
|
||||
/* static */ ScriptObject *ScriptObject::GetDoCommandAsyncModeInstance()
|
||||
{
|
||||
return GetStorage()->async_mode_instance;
|
||||
return GetStorage().async_mode_instance;
|
||||
}
|
||||
|
||||
/* static */ void ScriptObject::SetLastCommand(const CommandDataBuffer &data, Commands cmd)
|
||||
{
|
||||
ScriptStorage *s = GetStorage();
|
||||
Debug(script, 6, "SetLastCommand company={:02d} cmd={} data={}", s->root_company, cmd, FormatArrayAsHex(data));
|
||||
s->last_data = data;
|
||||
s->last_cmd = cmd;
|
||||
ScriptStorage &s = GetStorage();
|
||||
Debug(script, 6, "SetLastCommand company={:02d} cmd={} data={}", s.root_company, cmd, FormatArrayAsHex(data));
|
||||
s.last_data = data;
|
||||
s.last_cmd = cmd;
|
||||
}
|
||||
|
||||
/* static */ bool ScriptObject::CheckLastCommand(const CommandDataBuffer &data, Commands cmd)
|
||||
{
|
||||
ScriptStorage *s = GetStorage();
|
||||
Debug(script, 6, "CheckLastCommand company={:02d} cmd={} data={}", s->root_company, cmd, FormatArrayAsHex(data));
|
||||
if (s->last_cmd != cmd) return false;
|
||||
if (s->last_data != data) return false;
|
||||
ScriptStorage &s = GetStorage();
|
||||
Debug(script, 6, "CheckLastCommand company={:02d} cmd={} data={}", s.root_company, cmd, FormatArrayAsHex(data));
|
||||
if (s.last_cmd != cmd) return false;
|
||||
if (s.last_data != data) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/* static */ void ScriptObject::SetDoCommandCosts(Money value)
|
||||
{
|
||||
GetStorage()->costs = CommandCost(INVALID_EXPENSES, value); // Expense type is never read.
|
||||
GetStorage().costs = CommandCost(INVALID_EXPENSES, value); // Expense type is never read.
|
||||
}
|
||||
|
||||
/* static */ void ScriptObject::IncreaseDoCommandCosts(Money value)
|
||||
{
|
||||
GetStorage()->costs.AddCost(value);
|
||||
GetStorage().costs.AddCost(value);
|
||||
}
|
||||
|
||||
/* static */ Money ScriptObject::GetDoCommandCosts()
|
||||
{
|
||||
return GetStorage()->costs.GetCost();
|
||||
return GetStorage().costs.GetCost();
|
||||
}
|
||||
|
||||
/* static */ void ScriptObject::SetLastError(ScriptErrorType last_error)
|
||||
{
|
||||
GetStorage()->last_error = last_error;
|
||||
GetStorage().last_error = last_error;
|
||||
}
|
||||
|
||||
/* static */ ScriptErrorType ScriptObject::GetLastError()
|
||||
{
|
||||
return GetStorage()->last_error;
|
||||
return GetStorage().last_error;
|
||||
}
|
||||
|
||||
/* static */ void ScriptObject::SetLastCost(Money last_cost)
|
||||
{
|
||||
GetStorage()->last_cost = last_cost;
|
||||
GetStorage().last_cost = last_cost;
|
||||
}
|
||||
|
||||
/* static */ Money ScriptObject::GetLastCost()
|
||||
{
|
||||
return GetStorage()->last_cost;
|
||||
return GetStorage().last_cost;
|
||||
}
|
||||
|
||||
/* static */ void ScriptObject::SetRoadType(RoadType road_type)
|
||||
{
|
||||
GetStorage()->road_type = road_type;
|
||||
GetStorage().road_type = road_type;
|
||||
}
|
||||
|
||||
/* static */ RoadType ScriptObject::GetRoadType()
|
||||
{
|
||||
return GetStorage()->road_type;
|
||||
return GetStorage().road_type;
|
||||
}
|
||||
|
||||
/* static */ void ScriptObject::SetRailType(RailType rail_type)
|
||||
{
|
||||
GetStorage()->rail_type = rail_type;
|
||||
GetStorage().rail_type = rail_type;
|
||||
}
|
||||
|
||||
/* static */ RailType ScriptObject::GetRailType()
|
||||
{
|
||||
return GetStorage()->rail_type;
|
||||
return GetStorage().rail_type;
|
||||
}
|
||||
|
||||
/* static */ void ScriptObject::SetLastCommandRes(bool res)
|
||||
{
|
||||
GetStorage()->last_command_res = res;
|
||||
GetStorage().last_command_res = res;
|
||||
}
|
||||
|
||||
/* static */ bool ScriptObject::GetLastCommandRes()
|
||||
{
|
||||
return GetStorage()->last_command_res;
|
||||
return GetStorage().last_command_res;
|
||||
}
|
||||
|
||||
/* static */ void ScriptObject::SetLastCommandResData(CommandDataBuffer data)
|
||||
{
|
||||
GetStorage()->last_cmd_ret = std::move(data);
|
||||
GetStorage().last_cmd_ret = std::move(data);
|
||||
}
|
||||
|
||||
/* static */ const CommandDataBuffer &ScriptObject::GetLastCommandResData()
|
||||
{
|
||||
return GetStorage()->last_cmd_ret;
|
||||
return GetStorage().last_cmd_ret;
|
||||
}
|
||||
|
||||
/* static */ void ScriptObject::SetCompany(::CompanyID company)
|
||||
{
|
||||
if (GetStorage()->root_company == INVALID_OWNER) GetStorage()->root_company = company;
|
||||
GetStorage()->company = company;
|
||||
if (GetStorage().root_company == INVALID_OWNER) GetStorage().root_company = company;
|
||||
GetStorage().company = company;
|
||||
|
||||
_current_company = company;
|
||||
}
|
||||
|
||||
/* static */ ::CompanyID ScriptObject::GetCompany()
|
||||
{
|
||||
return GetStorage()->company;
|
||||
return GetStorage().company;
|
||||
}
|
||||
|
||||
/* static */ ::CompanyID ScriptObject::GetRootCompany()
|
||||
{
|
||||
return GetStorage()->root_company;
|
||||
return GetStorage().root_company;
|
||||
}
|
||||
|
||||
/* static */ bool ScriptObject::CanSuspend()
|
||||
{
|
||||
Squirrel *squirrel = ScriptObject::GetActiveInstance().engine;
|
||||
return GetStorage()->allow_do_command && squirrel->CanSuspend();
|
||||
return GetStorage().allow_do_command && squirrel->CanSuspend();
|
||||
}
|
||||
|
||||
/* static */ ScriptEventQueue &ScriptObject::GetEventQueue()
|
||||
{
|
||||
return GetStorage()->event_queue;
|
||||
return GetStorage().event_queue;
|
||||
}
|
||||
|
||||
/* static */ ScriptLogTypes::LogData &ScriptObject::GetLogData()
|
||||
{
|
||||
return GetStorage()->log_data;
|
||||
return GetStorage().log_data;
|
||||
}
|
||||
|
||||
/* static */ void ScriptObject::SetCallbackVariable(int index, int value)
|
||||
{
|
||||
if (static_cast<size_t>(index) >= GetStorage()->callback_value.size()) GetStorage()->callback_value.resize(index + 1);
|
||||
GetStorage()->callback_value[index] = value;
|
||||
if (static_cast<size_t>(index) >= GetStorage().callback_value.size()) GetStorage().callback_value.resize(index + 1);
|
||||
GetStorage().callback_value[index] = value;
|
||||
}
|
||||
|
||||
/* static */ int ScriptObject::GetCallbackVariable(int index)
|
||||
{
|
||||
return GetStorage()->callback_value[index];
|
||||
return GetStorage().callback_value[index];
|
||||
}
|
||||
|
||||
/* static */ CommandCallbackData *ScriptObject::GetDoCommandCallback()
|
||||
|
@ -310,8 +310,8 @@ ScriptObject::DisableDoCommandScope::DisableDoCommandScope()
|
|||
IncreaseDoCommandCosts(res.GetCost());
|
||||
if (!_generating_world) {
|
||||
/* Charge a nominal fee for asynchronously executed commands */
|
||||
Squirrel *engine = ScriptObject::GetActiveInstance().engine;
|
||||
Squirrel::DecreaseOps(engine->GetVM(), 100);
|
||||
Squirrel &engine = *ScriptObject::GetActiveInstance().engine;
|
||||
Squirrel::DecreaseOps(engine.GetVM(), 100);
|
||||
}
|
||||
if (callback != nullptr) {
|
||||
/* Insert return value into to stack and throw a control code that
|
||||
|
|
|
@ -100,7 +100,7 @@ void ScriptInstance::Initialize(const std::string &main_script, const std::strin
|
|||
|
||||
void ScriptInstance::RegisterAPI()
|
||||
{
|
||||
squirrel_register_std(this->engine);
|
||||
squirrel_register_std(*this->engine);
|
||||
}
|
||||
|
||||
bool ScriptInstance::LoadCompatibilityScript(std::string_view api_version, Subdirectory dir)
|
||||
|
@ -318,9 +318,10 @@ void ScriptInstance::CollectGarbage()
|
|||
}
|
||||
|
||||
|
||||
ScriptStorage *ScriptInstance::GetStorage()
|
||||
ScriptStorage &ScriptInstance::GetStorage()
|
||||
{
|
||||
return this->storage;
|
||||
assert(this->storage != nullptr);
|
||||
return *this->storage;
|
||||
}
|
||||
|
||||
ScriptLogTypes::LogData &ScriptInstance::GetLogData()
|
||||
|
|
|
@ -91,7 +91,7 @@ public:
|
|||
/**
|
||||
* Get the storage of this script.
|
||||
*/
|
||||
class ScriptStorage *GetStorage();
|
||||
class ScriptStorage &GetStorage();
|
||||
|
||||
/**
|
||||
* Get the log pointer of this script.
|
||||
|
@ -146,7 +146,11 @@ public:
|
|||
/**
|
||||
* Get the controller attached to the instance.
|
||||
*/
|
||||
class ScriptController *GetController() { return controller; }
|
||||
class ScriptController &GetController()
|
||||
{
|
||||
assert(this->controller != nullptr);
|
||||
return *this->controller;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the "this script died" value
|
||||
|
|
|
@ -536,7 +536,7 @@ void Squirrel::Initialize()
|
|||
sq_setforeignptr(this->vm, this);
|
||||
|
||||
sq_pushroottable(this->vm);
|
||||
squirrel_register_global_std(this);
|
||||
squirrel_register_global_std(*this);
|
||||
|
||||
/* Set consts table as delegate of root table, so consts/enums defined via require() are accessible */
|
||||
sq_pushconsttable(this->vm);
|
||||
|
|
|
@ -82,20 +82,20 @@ SQInteger SquirrelStd::notifyallexceptions(HSQUIRRELVM vm)
|
|||
return SQ_ERROR;
|
||||
}
|
||||
|
||||
void squirrel_register_global_std(Squirrel *engine)
|
||||
void squirrel_register_global_std(Squirrel &engine)
|
||||
{
|
||||
/* We don't use squirrel_helper here, as we want to register to the global
|
||||
* scope and not to a class. */
|
||||
engine->AddMethod("require", &SquirrelStd::require, ".s");
|
||||
engine->AddMethod("notifyallexceptions", &SquirrelStd::notifyallexceptions, ".b");
|
||||
engine.AddMethod("require", &SquirrelStd::require, ".s");
|
||||
engine.AddMethod("notifyallexceptions", &SquirrelStd::notifyallexceptions, ".b");
|
||||
}
|
||||
|
||||
void squirrel_register_std(Squirrel *engine)
|
||||
void squirrel_register_std(Squirrel &engine)
|
||||
{
|
||||
/* We don't use squirrel_helper here, as we want to register to the global
|
||||
* scope and not to a class. */
|
||||
engine->AddMethod("min", &SquirrelStd::min, ".ii");
|
||||
engine->AddMethod("max", &SquirrelStd::max, ".ii");
|
||||
engine.AddMethod("min", &SquirrelStd::min, ".ii");
|
||||
engine.AddMethod("max", &SquirrelStd::max, ".ii");
|
||||
|
||||
sqstd_register_mathlib(engine->GetVM());
|
||||
sqstd_register_mathlib(engine.GetVM());
|
||||
}
|
||||
|
|
|
@ -52,12 +52,12 @@ public:
|
|||
/**
|
||||
* Register all standard functions we want to give to a script.
|
||||
*/
|
||||
void squirrel_register_std(Squirrel *engine);
|
||||
void squirrel_register_std(Squirrel &engine);
|
||||
|
||||
/**
|
||||
* Register all standard functions that are available on first startup.
|
||||
* @note this set is very limited, and is only meant to load other scripts and things like that.
|
||||
*/
|
||||
void squirrel_register_global_std(Squirrel *engine);
|
||||
void squirrel_register_global_std(Squirrel &engine);
|
||||
|
||||
#endif /* SQUIRREL_STD_HPP */
|
||||
|
|
|
@ -3331,7 +3331,7 @@ draw_default_foundation:
|
|||
auto result = GetRoadStopLayout(ti, stopspec, st, type, view, regs100);
|
||||
if (result.has_value()) {
|
||||
if (stopspec->flags.Test(RoadStopSpecFlag::DrawModeRegister)) {
|
||||
stop_draw_mode = static_cast<RoadStopDrawMode>(regs100[0]);
|
||||
stop_draw_mode = static_cast<RoadStopDrawModes>(regs100[0]);
|
||||
}
|
||||
if (type == StationType::RoadWaypoint && stop_draw_mode.Test(RoadStopDrawMode::WaypGround)) {
|
||||
draw_ground = true;
|
||||
|
|
|
@ -427,6 +427,7 @@ struct TimetableWindow : Window {
|
|||
void DrawTimetablePanel(const Rect &r) const
|
||||
{
|
||||
const Vehicle *v = this->vehicle;
|
||||
if (v->GetNumOrders() == 0) return;
|
||||
Rect tr = r.Shrink(WidgetDimensions::scaled.framerect);
|
||||
int i = this->vscroll->GetPosition();
|
||||
VehicleOrderID order_id = (i + 1) / 2;
|
||||
|
|
Loading…
Reference in New Issue