1
0
Fork 0

Compare commits

...

4 Commits

Author SHA1 Message Date
SamuXarick c2afa18d80
Merge bd9d785695 into 7546c1acab 2025-07-14 08:01:52 +00:00
Peter Nelson 7546c1acab
Codefix f220ed179d: GetUnicodeGlyph takes a unicode character. (#14438)
Previous change erroneously changed type to GlyphID, based on naming. It should actually be char32_t.
2025-07-14 08:01:42 +00:00
Peter Nelson a6143eea21
Codechange: Include more relevant headers for script_storage. (#14437) 2025-07-14 07:49:50 +01:00
SamuXarick bd9d785695 Change: [Script] Remove IsValidBaseStation
Add compatibility functions.
2025-05-22 13:48:54 +01:00
9 changed files with 53 additions and 36 deletions

View File

@ -36,3 +36,8 @@ AITown.FoundTown <- function(tile, size, city, layout, name) { return AITown.Fou
AIVehicle.SetNameCompat14 <- AIVehicle.SetName; AIVehicle.SetNameCompat14 <- AIVehicle.SetName;
AIVehicle.SetName <- function(id, name) { return AIVehicle.SetNameCompat14(id, AICompat14.Text(name)); } AIVehicle.SetName <- function(id, name) { return AIVehicle.SetNameCompat14(id, AICompat14.Text(name)); }
AIBaseStation.IsValidBaseStation <- function(station_id)
{
return AIStation.IsValidStation(station_id) || AIWaypoint.IsValidWaypoint(station_id);
}

View File

@ -81,3 +81,8 @@ GSTown.FoundTown <- function(tile, size, city, layout, name) { return GSTown.Fou
GSVehicle.SetNameCompat14 <- GSVehicle.SetName; GSVehicle.SetNameCompat14 <- GSVehicle.SetName;
GSVehicle.SetName <- function(id, name) { return GSVehicle.SetNameCompat14(id, GSCompat14.Text(name)); } GSVehicle.SetName <- function(id, name) { return GSVehicle.SetNameCompat14(id, GSCompat14.Text(name)); }
GSBaseStation.IsValidBaseStation <- function(station_id)
{
return GSStation.IsValidStation(station_id) || GSWaypoint.IsValidWaypoint(station_id);
}

View File

@ -43,26 +43,26 @@ SpriteFontCache::SpriteFontCache(FontSize fs) : FontCache(fs)
} }
/** /**
* Get SpriteID associated with a GlyphID. * Get SpriteID associated with a character.
* @param key Glyph to find. * @param key Character to find.
* @return SpriteID of glyph, or 0 if not present. * @return SpriteID for character, or 0 if not present.
*/ */
SpriteID SpriteFontCache::GetUnicodeGlyph(GlyphID key) SpriteID SpriteFontCache::GetUnicodeGlyph(char32_t key)
{ {
const auto found = this->glyph_to_spriteid_map.find(key & ~SPRITE_GLYPH); const auto found = this->char_map.find(key);
if (found == std::end(this->glyph_to_spriteid_map)) return 0; if (found == std::end(this->char_map)) return 0;
return found->second; return found->second;
} }
void SpriteFontCache::SetUnicodeGlyph(char32_t key, SpriteID sprite) void SpriteFontCache::SetUnicodeGlyph(char32_t key, SpriteID sprite)
{ {
this->glyph_to_spriteid_map[key] = sprite; this->char_map[key] = sprite;
} }
void SpriteFontCache::InitializeUnicodeGlyphMap() void SpriteFontCache::InitializeUnicodeGlyphMap()
{ {
/* Clear out existing glyph map if it exists */ /* Clear out existing glyph map if it exists */
this->glyph_to_spriteid_map.clear(); this->char_map.clear();
SpriteID base; SpriteID base;
switch (this->fs) { switch (this->fs) {

View File

@ -28,8 +28,8 @@ public:
bool IsBuiltInFont() override { return true; } bool IsBuiltInFont() override { return true; }
private: private:
std::unordered_map<GlyphID, SpriteID> glyph_to_spriteid_map{}; ///< Mapping of glyphs to sprite IDs. std::unordered_map<char32_t, SpriteID> char_map{}; ///< Mapping of characters to sprite IDs.
SpriteID GetUnicodeGlyph(GlyphID key); SpriteID GetUnicodeGlyph(char32_t key);
}; };
#endif /* SPRITEFONTCACHE_H */ #endif /* SPRITEFONTCACHE_H */

View File

@ -29,6 +29,9 @@
* \li AICargo::CC_NON_POTABLE * \li AICargo::CC_NON_POTABLE
* \li AIVehicleList_Waypoint * \li AIVehicleList_Waypoint
* *
* API removals:
* \li AIBaseStation::IsValidBaseStation, use AIStation::IsValidStation or AIWaypoint::IsValidWaypoint instead
*
* Other changes: * Other changes:
* \li AIBridge::GetBridgeID renamed to AIBridge::GetBridgeType * \li AIBridge::GetBridgeID renamed to AIBridge::GetBridgeType
* \li AIWaypoint::GetWaypointID now returns the StationID of any type of waypoint * \li AIWaypoint::GetWaypointID now returns the StationID of any type of waypoint

View File

@ -30,6 +30,9 @@
* \li GSVehicleList_Waypoint * \li GSVehicleList_Waypoint
* \li GSBaseStation::GetOwner * \li GSBaseStation::GetOwner
* *
* API removals:
* \li GSBaseStation::IsValidBaseStation, use GSStation::IsValidStation or GSWaypoint::IsValidWaypoint instead
*
* Other changes: * Other changes:
* \li GSBridge::GetBridgeID renamed to GSBridge::GetBridgeType * \li GSBridge::GetBridgeID renamed to GSBridge::GetBridgeType
* \li GSWaypoint::GetWaypointID now returns the StationID of any type of waypoint * \li GSWaypoint::GetWaypointID now returns the StationID of any type of waypoint

View File

@ -21,15 +21,16 @@
*/ */
class ScriptBaseStation : public ScriptObject { class ScriptBaseStation : public ScriptObject {
public: public:
static constexpr StationID STATION_NEW = ::NEW_STATION; ///< Build a new station static constexpr StationID STATION_NEW = ::NEW_STATION; ///< Build a new station or waypoint
static constexpr StationID STATION_JOIN_ADJACENT = ::ADJACENT_STATION; ///< Join an neighbouring station if one exists static constexpr StationID STATION_JOIN_ADJACENT = ::ADJACENT_STATION; ///< Join a neighbouring station or waypoint if one exists
static constexpr StationID STATION_INVALID = ::StationID::Invalid(); ///< Invalid station id. static constexpr StationID STATION_INVALID = ::StationID::Invalid(); ///< Invalid station or waypoint id.
/** /**
* Checks whether the given basestation is valid and owned by you. * Checks whether the given basestation is valid and owned by you.
* @param station_id The station to check. * @param station_id The station to check.
* @return True if and only if the basestation is valid. * @return True if and only if the basestation is valid.
* @note IsValidBaseStation == (IsValidStation || IsValidWaypoint). * @note IsValidBaseStation == (IsValidStation || IsValidWaypoint).
* @api -all
*/ */
static bool IsValidBaseStation(StationID station_id); static bool IsValidBaseStation(StationID station_id);
@ -43,18 +44,18 @@ public:
static ScriptCompany::CompanyID GetOwner(StationID station_id); static ScriptCompany::CompanyID GetOwner(StationID station_id);
/** /**
* Get the name of a basestation. * Get the name of a station or waypoint.
* @param station_id The basestation to get the name of. * @param station_id The station or waypoint to get the name of.
* @pre IsValidBaseStation(station_id). * @pre IsValidStation(station_id) || IsValidWaypoint(station_id).
* @return The name of the station. * @return The name of the station or waypoint.
*/ */
static std::optional<std::string> GetName(StationID station_id); static std::optional<std::string> GetName(StationID station_id);
/** /**
* Set the name this basestation. * Set the name of a station or waypoint.
* @param station_id The basestation to set the name of. * @param station_id The station or waypoint to set the name of.
* @param name The new name of the station (can be either a raw string, or a ScriptText object). * @param name The new name of the station or waypoint (can be either a raw string, or a ScriptText object).
* @pre IsValidBaseStation(station_id). * @pre IsValidStation(station_id) || IsValidWaypoint(station_id).
* @pre name != null && len(name) != 0. * @pre name != null && len(name) != 0.
* @game @pre ScriptCompanyMode::IsValid(). * @game @pre ScriptCompanyMode::IsValid().
* @exception ScriptError::ERR_NAME_IS_NOT_UNIQUE * @exception ScriptError::ERR_NAME_IS_NOT_UNIQUE
@ -63,19 +64,19 @@ public:
static bool SetName(StationID station_id, Text *name); static bool SetName(StationID station_id, Text *name);
/** /**
* Get the current location of a basestation. * Get the current location of a station or waypoint.
* @param station_id The basestation to get the location of. * @param station_id The station or waypoint to get the location of.
* @pre IsValidBaseStation(station_id). * @pre IsValidStation(station_id) || IsValidWaypoint(station_id).
* @return The tile the basestation sign above it. * @return The tile with the station or waypoint sign above it.
* @note The tile is not necessarily a station tile (and if it is, it could also belong to another station). * @note The tile is not necessarily a station or waypoint tile (and if it is, it could also belong to another station or waypoint).
* @see ScriptTileList_StationType. * @see ScriptTileList_StationType.
*/ */
static TileIndex GetLocation(StationID station_id); static TileIndex GetLocation(StationID station_id);
/** /**
* Get the last calendar-date a station part was added to this station. * Get the last calendar-date a station or waypoint part was added to this station or waypoint.
* @param station_id The station to look at. * @param station_id The station or waypoint to look at.
* @return The last calendar-date some part of this station was build. * @return The last calendar-date some part of this station or waypoint was built.
* @see \ref ScriptCalendarTime * @see \ref ScriptCalendarTime
*/ */
static ScriptDate::Date GetConstructionDate(StationID station_id); static ScriptDate::Date GetConstructionDate(StationID station_id);

View File

@ -24,10 +24,12 @@
#include "api/script_event.hpp" #include "api/script_event.hpp"
#include "api/script_log.hpp" #include "api/script_log.hpp"
#include "../company_base.h" #include "../company_type.h"
#include "../company_func.h"
#include "../fileio_func.h" #include "../fileio_func.h"
#include "../goal_type.h"
#include "../league_type.h" #include "../league_type.h"
#include "../signs_type.h"
#include "../story_type.h"
#include "../misc/endian_buffer.hpp" #include "../misc/endian_buffer.hpp"
#include "../safeguards.h" #include "../safeguards.h"

View File

@ -12,12 +12,10 @@
#include <queue> #include <queue>
#include "../signs_func.h" #include "../command_type.h"
#include "../vehicle_func.h" #include "../company_type.h"
#include "../rail_type.h"
#include "../road_type.h" #include "../road_type.h"
#include "../group.h"
#include "../goal_type.h"
#include "../story_type.h"
#include "script_types.hpp" #include "script_types.hpp"
#include "script_log_types.hpp" #include "script_log_types.hpp"