Files
@ r28396:ef195b601c72
Branch filter:
Location: cpp/openttd-patchpack/source/src/newgrf_railtype.cpp - annotation
r28396:ef195b601c72
6.4 KiB
text/x-c
Fix: Pass townnameparts as parameter when testing townname based companyname. (#11685)
Length of returned string could vary and pass/fail the length check with a different
string than the final selection.
Length of returned string could vary and pass/fail the length check with a different
string than the final selection.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 | r15534:64974155b7a6 r15534:64974155b7a6 r15534:64974155b7a6 r15534:64974155b7a6 r15534:64974155b7a6 r15534:64974155b7a6 r15534:64974155b7a6 r14477:752d803ed3be r14477:752d803ed3be r14477:752d803ed3be r27400:742251af6ade r14477:752d803ed3be r19730:2c33854b291a r27148:4e041ae27b9d r15350:38997da618b5 r19000:dcf7cc74e44b r14477:752d803ed3be r21383:942c32fb8b0e r21383:942c32fb8b0e r27737:728d55b97775 r14477:752d803ed3be r28112:bca7556a6bb6 r14646:051de492031c r14477:752d803ed3be r14477:752d803ed3be r27942:f7389062d120 r14477:752d803ed3be r19730:2c33854b291a r14477:752d803ed3be r14477:752d803ed3be r14477:752d803ed3be r14477:752d803ed3be r28112:bca7556a6bb6 r19000:dcf7cc74e44b r14477:752d803ed3be r14477:752d803ed3be r14477:752d803ed3be r14477:752d803ed3be r19730:2c33854b291a r14477:752d803ed3be r19730:2c33854b291a r15350:38997da618b5 r28112:bca7556a6bb6 r28112:bca7556a6bb6 r19000:dcf7cc74e44b r23607:36c15679007d r19730:2c33854b291a r19730:2c33854b291a r19730:2c33854b291a r19730:2c33854b291a r19000:dcf7cc74e44b r23607:36c15679007d r19000:dcf7cc74e44b r14477:752d803ed3be r14477:752d803ed3be r25655:1030dcb7eb52 r14477:752d803ed3be r14477:752d803ed3be r14477:752d803ed3be r14477:752d803ed3be r14477:752d803ed3be r24069:49625df81342 r24069:49625df81342 r24069:49625df81342 r24069:49625df81342 r24069:49625df81342 r27737:728d55b97775 r24069:49625df81342 r24069:49625df81342 r24069:49625df81342 r24069:49625df81342 r19738:837a139219f0 r19738:837a139219f0 r23607:36c15679007d r19738:837a139219f0 r19738:837a139219f0 r21299:8973364c4b52 r19738:837a139219f0 r19738:837a139219f0 r19738:837a139219f0 r27896:3f48fccebe5f r24069:49625df81342 r19730:2c33854b291a r23607:36c15679007d r14477:752d803ed3be r14477:752d803ed3be r17629:21e9dfd343cd r17629:21e9dfd343cd r17629:21e9dfd343cd r17629:21e9dfd343cd r17629:21e9dfd343cd r23023:7b8669afd1db r23607:36c15679007d r17629:21e9dfd343cd r17629:21e9dfd343cd r27896:3f48fccebe5f r14477:752d803ed3be r14477:752d803ed3be r14477:752d803ed3be r23607:36c15679007d r14477:752d803ed3be r21299:8973364c4b52 r21299:8973364c4b52 r23607:36c15679007d r14477:752d803ed3be r22169:671a08e8e50e r22169:671a08e8e50e r14477:752d803ed3be r14477:752d803ed3be r14477:752d803ed3be r17629:21e9dfd343cd r19450:89a0bcc12737 r19450:89a0bcc12737 r19450:89a0bcc12737 r19450:89a0bcc12737 r19450:89a0bcc12737 r19450:89a0bcc12737 r19450:89a0bcc12737 r19450:89a0bcc12737 r19450:89a0bcc12737 r27896:3f48fccebe5f r19450:89a0bcc12737 r23607:36c15679007d r19450:89a0bcc12737 r27737:728d55b97775 r27737:728d55b97775 r21299:8973364c4b52 r19450:89a0bcc12737 r21299:8973364c4b52 r23607:36c15679007d r19450:89a0bcc12737 r19450:89a0bcc12737 r19450:89a0bcc12737 r19450:89a0bcc12737 r19450:89a0bcc12737 r24635:c539e338e87f r24635:c539e338e87f r24635:c539e338e87f r24635:c539e338e87f r24635:c539e338e87f r27737:728d55b97775 r24635:c539e338e87f r28025:9116d6e411b0 r24635:c539e338e87f r24635:c539e338e87f r24635:c539e338e87f r24635:c539e338e87f r24635:c539e338e87f r24635:c539e338e87f r24635:c539e338e87f r24635:c539e338e87f r24635:c539e338e87f r24635:c539e338e87f r24635:c539e338e87f r24635:c539e338e87f r24635:c539e338e87f r24635:c539e338e87f r17629:21e9dfd343cd r17629:21e9dfd343cd r17629:21e9dfd343cd r17629:21e9dfd343cd r17629:21e9dfd343cd r27737:728d55b97775 r14477:752d803ed3be r14477:752d803ed3be r28025:9116d6e411b0 r14477:752d803ed3be r14477:752d803ed3be r14477:752d803ed3be r23534:ced2648be38e r23534:ced2648be38e r23534:ced2648be38e r14477:752d803ed3be r14477:752d803ed3be r14477:752d803ed3be r14477:752d803ed3be | /*
* This file is part of OpenTTD.
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file newgrf_railtype.cpp NewGRF handling of rail types. */
#include "stdafx.h"
#include "core/container_func.hpp"
#include "debug.h"
#include "newgrf_railtype.h"
#include "timer/timer_game_calendar.h"
#include "depot_base.h"
#include "town.h"
#include "safeguards.h"
/* virtual */ uint32_t RailTypeScopeResolver::GetRandomBits() const
{
uint tmp = CountBits(this->tile.base() + (TileX(this->tile) + TileY(this->tile)) * TILE_SIZE);
return GB(tmp, 0, 2);
}
/* virtual */ uint32_t RailTypeScopeResolver::GetVariable(byte variable, [[maybe_unused]] uint32_t parameter, bool *available) const
{
if (this->tile == INVALID_TILE) {
switch (variable) {
case 0x40: return 0;
case 0x41: return 0;
case 0x42: return 0;
case 0x43: return TimerGameCalendar::date.base();
case 0x44: return HZB_TOWN_EDGE;
}
}
switch (variable) {
case 0x40: return GetTerrainType(this->tile, this->context);
case 0x41: return 0;
case 0x42: return IsLevelCrossingTile(this->tile) && IsCrossingBarred(this->tile);
case 0x43:
if (IsRailDepotTile(this->tile)) return Depot::GetByTile(this->tile)->build_date.base();
return TimerGameCalendar::date.base();
case 0x44: {
const Town *t = nullptr;
if (IsRailDepotTile(this->tile)) {
t = Depot::GetByTile(this->tile)->town;
} else if (IsLevelCrossingTile(this->tile)) {
t = ClosestTownFromTile(this->tile, UINT_MAX);
}
return t != nullptr ? GetTownRadiusGroup(t, this->tile) : HZB_TOWN_EDGE;
}
}
Debug(grf, 1, "Unhandled rail type tile variable 0x{:X}", variable);
*available = false;
return UINT_MAX;
}
GrfSpecFeature RailTypeResolverObject::GetFeature() const
{
return GSF_RAILTYPES;
}
uint32_t RailTypeResolverObject::GetDebugID() const
{
return this->railtype_scope.rti->label;
}
/**
* Resolver object for rail types.
* @param rti Railtype. nullptr in NewGRF Inspect window.
* @param tile %Tile containing the track. For track on a bridge this is the southern bridgehead.
* @param context Are we resolving sprites for the upper halftile, or on a bridge?
* @param rtsg Railpart of interest
* @param param1 Extra parameter (first parameter of the callback, except railtypes do not have callbacks).
* @param param2 Extra parameter (second parameter of the callback, except railtypes do not have callbacks).
*/
RailTypeResolverObject::RailTypeResolverObject(const RailTypeInfo *rti, TileIndex tile, TileContext context, RailTypeSpriteGroup rtsg, uint32_t param1, uint32_t param2)
: ResolverObject(rti != nullptr ? rti->grffile[rtsg] : nullptr, CBID_NO_CALLBACK, param1, param2), railtype_scope(*this, rti, tile, context)
{
this->root_spritegroup = rti != nullptr ? rti->group[rtsg] : nullptr;
}
/**
* Get the sprite to draw for the given tile.
* @param rti The rail type data (spec).
* @param tile The tile to get the sprite for.
* @param rtsg The type of sprite to draw.
* @param context Where are we drawing the tile?
* @param[out] num_results If not nullptr, return the number of sprites in the spriteset.
* @return The sprite to draw.
*/
SpriteID GetCustomRailSprite(const RailTypeInfo *rti, TileIndex tile, RailTypeSpriteGroup rtsg, TileContext context, uint *num_results)
{
assert(rtsg < RTSG_END);
if (rti->group[rtsg] == nullptr) return 0;
RailTypeResolverObject object(rti, tile, context, rtsg);
const SpriteGroup *group = object.Resolve();
if (group == nullptr || group->GetNumResults() == 0) return 0;
if (num_results) *num_results = group->GetNumResults();
return group->GetResult();
}
/**
* Get the sprite to draw for a given signal.
* @param rti The rail type data (spec).
* @param tile The tile to get the sprite for.
* @param type Signal type.
* @param var Signal variant.
* @param state Signal state.
* @param gui Is the sprite being used on the map or in the GUI?
* @return The sprite to draw.
*/
SpriteID GetCustomSignalSprite(const RailTypeInfo *rti, TileIndex tile, SignalType type, SignalVariant var, SignalState state, bool gui)
{
if (rti->group[RTSG_SIGNALS] == nullptr) return 0;
uint32_t param1 = gui ? 0x10 : 0x00;
uint32_t param2 = (type << 16) | (var << 8) | state;
RailTypeResolverObject object(rti, tile, TCX_NORMAL, RTSG_SIGNALS, param1, param2);
const SpriteGroup *group = object.Resolve();
if (group == nullptr || group->GetNumResults() == 0) return 0;
return group->GetResult();
}
/**
* Translate an index to the GRF-local railtype-translation table into a RailType.
* @param railtype Index into GRF-local translation table.
* @param grffile Originating GRF file.
* @return RailType or INVALID_RAILTYPE if the railtype is unknown.
*/
RailType GetRailTypeTranslation(uint8_t railtype, const GRFFile *grffile)
{
if (grffile == nullptr || grffile->railtype_list.empty()) {
/* No railtype table present. Return railtype as-is (if valid), so it works for original railtypes. */
if (railtype >= RAILTYPE_END || GetRailTypeInfo(static_cast<RailType>(railtype))->label == 0) return INVALID_RAILTYPE;
return static_cast<RailType>(railtype);
} else {
/* Railtype table present, but invalid index, return invalid type. */
if (railtype >= grffile->railtype_list.size()) return INVALID_RAILTYPE;
/* Look up railtype including alternate labels. */
return GetRailTypeByLabel(grffile->railtype_list[railtype]);
}
}
/**
* Perform a reverse railtype lookup to get the GRF internal ID.
* @param railtype The global (OpenTTD) railtype.
* @param grffile The GRF to do the lookup for.
* @return the GRF internal ID.
*/
uint8_t GetReverseRailTypeTranslation(RailType railtype, const GRFFile *grffile)
{
/* No rail type table present, return rail type as-is */
if (grffile == nullptr || grffile->railtype_list.empty()) return railtype;
/* Look for a matching rail type label in the table */
RailTypeLabel label = GetRailTypeInfo(railtype)->label;
int idx = find_index(grffile->railtype_list, label);
if (idx >= 0) return idx;
/* If not found, return as invalid */
return 0xFF;
}
|