mirror of https://github.com/OpenTTD/OpenTTD
Compare commits
4 Commits
6aaa8ca93c
...
20b214307a
Author | SHA1 | Date |
---|---|---|
|
20b214307a | |
|
7546c1acab | |
|
a6143eea21 | |
|
b8d966029c |
|
@ -43,26 +43,26 @@ SpriteFontCache::SpriteFontCache(FontSize fs) : FontCache(fs)
|
|||
}
|
||||
|
||||
/**
|
||||
* Get SpriteID associated with a GlyphID.
|
||||
* @param key Glyph to find.
|
||||
* @return SpriteID of glyph, or 0 if not present.
|
||||
* Get SpriteID associated with a character.
|
||||
* @param key Character to find.
|
||||
* @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);
|
||||
if (found == std::end(this->glyph_to_spriteid_map)) return 0;
|
||||
const auto found = this->char_map.find(key);
|
||||
if (found == std::end(this->char_map)) return 0;
|
||||
return found->second;
|
||||
}
|
||||
|
||||
void SpriteFontCache::SetUnicodeGlyph(char32_t key, SpriteID sprite)
|
||||
{
|
||||
this->glyph_to_spriteid_map[key] = sprite;
|
||||
this->char_map[key] = sprite;
|
||||
}
|
||||
|
||||
void SpriteFontCache::InitializeUnicodeGlyphMap()
|
||||
{
|
||||
/* Clear out existing glyph map if it exists */
|
||||
this->glyph_to_spriteid_map.clear();
|
||||
this->char_map.clear();
|
||||
|
||||
SpriteID base;
|
||||
switch (this->fs) {
|
||||
|
|
|
@ -28,8 +28,8 @@ public:
|
|||
bool IsBuiltInFont() override { return true; }
|
||||
|
||||
private:
|
||||
std::unordered_map<GlyphID, SpriteID> glyph_to_spriteid_map{}; ///< Mapping of glyphs to sprite IDs.
|
||||
SpriteID GetUnicodeGlyph(GlyphID key);
|
||||
std::unordered_map<char32_t, SpriteID> char_map{}; ///< Mapping of characters to sprite IDs.
|
||||
SpriteID GetUnicodeGlyph(char32_t key);
|
||||
};
|
||||
|
||||
#endif /* SPRITEFONTCACHE_H */
|
||||
|
|
|
@ -884,11 +884,33 @@ static CommandCost CmdRailTrackHelper(DoCommandFlags flags, TileIndex tile, Tile
|
|||
CommandCost ret = ValidateAutoDrag(&trackdir, tile, end_tile);
|
||||
if (ret.Failed()) return ret;
|
||||
|
||||
int distance_remaining = static_cast<int>(DistanceManhattan(tile, end_tile)) + 1;
|
||||
|
||||
auto advance = [&] {
|
||||
distance_remaining--;
|
||||
tile = TileAddByDiagDir(tile, TrackdirToExitdir(trackdir));
|
||||
trackdir = NextTrackdir(trackdir);
|
||||
};
|
||||
|
||||
bool had_success = false;
|
||||
CommandCost last_error = CMD_ERROR;
|
||||
for (;;) {
|
||||
ret = remove ? Command<CMD_REMOVE_SINGLE_RAIL>::Do(flags, tile, TrackdirToTrack(trackdir)) : Command<CMD_BUILD_SINGLE_RAIL>::Do(flags, tile, railtype, TrackdirToTrack(trackdir), auto_remove_signals);
|
||||
if (!remove && !fail_on_obstacle && last_error.GetErrorMessage() == STR_ERROR_ALREADY_BUILT) had_success = true;
|
||||
for (; distance_remaining > 0; advance()) {
|
||||
if (!remove && !fail_on_obstacle && CheckTileOwnership(tile).Succeeded() && IsCompatibleRail(GetRailType(tile), railtype)) {
|
||||
/* Skip stations and waypoints */
|
||||
if (HasStationTileRail(tile) && GetRailStationTrack(tile) == track) continue;
|
||||
|
||||
/* Skip bridges and tunnels */
|
||||
if (IsTileType(tile, MP_TUNNELBRIDGE) && GetTunnelBridgeTransportType(tile) == TRANSPORT_RAIL
|
||||
&& DiagDirToDiagTrackdir(GetTunnelBridgeDirection(tile)) == trackdir ) {
|
||||
const uint length = GetTunnelBridgeLength(tile, GetOtherTunnelBridgeEnd(tile));
|
||||
for (uint i = 0; i <= length; ++i) advance();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
ret = remove ? Command<CMD_REMOVE_SINGLE_RAIL>::Do(flags, tile, TrackdirToTrack(trackdir))
|
||||
: Command<CMD_BUILD_SINGLE_RAIL>::Do(flags, tile, railtype, TrackdirToTrack(trackdir), auto_remove_signals);
|
||||
if (!remove && !fail_on_obstacle && ret.GetErrorMessage() == STR_ERROR_ALREADY_BUILT) had_success = true;
|
||||
|
||||
if (ret.Failed()) {
|
||||
last_error = std::move(ret);
|
||||
|
@ -903,13 +925,6 @@ static CommandCost CmdRailTrackHelper(DoCommandFlags flags, TileIndex tile, Tile
|
|||
had_success = true;
|
||||
total_cost.AddCost(ret.GetCost());
|
||||
}
|
||||
|
||||
if (tile == end_tile) break;
|
||||
|
||||
tile += ToTileIndexDiff(_trackdelta[trackdir]);
|
||||
|
||||
/* toggle railbit for the non-diagonal tracks */
|
||||
if (!IsDiagonalTrackdir(trackdir)) ToggleBit(trackdir, 0);
|
||||
}
|
||||
|
||||
if (had_success) return total_cost;
|
||||
|
|
|
@ -24,10 +24,12 @@
|
|||
#include "api/script_event.hpp"
|
||||
#include "api/script_log.hpp"
|
||||
|
||||
#include "../company_base.h"
|
||||
#include "../company_func.h"
|
||||
#include "../company_type.h"
|
||||
#include "../fileio_func.h"
|
||||
#include "../goal_type.h"
|
||||
#include "../league_type.h"
|
||||
#include "../signs_type.h"
|
||||
#include "../story_type.h"
|
||||
#include "../misc/endian_buffer.hpp"
|
||||
|
||||
#include "../safeguards.h"
|
||||
|
|
|
@ -12,12 +12,10 @@
|
|||
|
||||
#include <queue>
|
||||
|
||||
#include "../signs_func.h"
|
||||
#include "../vehicle_func.h"
|
||||
#include "../command_type.h"
|
||||
#include "../company_type.h"
|
||||
#include "../rail_type.h"
|
||||
#include "../road_type.h"
|
||||
#include "../group.h"
|
||||
#include "../goal_type.h"
|
||||
#include "../story_type.h"
|
||||
|
||||
#include "script_types.hpp"
|
||||
#include "script_log_types.hpp"
|
||||
|
|
Loading…
Reference in New Issue