(svn r23758) -Feature: [NewGRF] Alternate rail type label list.

This commit is contained in:
michi_cc
2012-01-05 19:40:34 +00:00
parent 69e197c87f
commit ee0fcb2567
5 changed files with 54 additions and 4 deletions

View File

@@ -277,9 +277,10 @@ RailTypes GetCompanyRailtypes(CompanyID company)
/**
* Get the rail type for a given label.
* @param label the railtype label.
* @param allow_alternate_labels Search in the alternate label lists as well.
* @return the railtype.
*/
RailType GetRailTypeByLabel(RailTypeLabel label)
RailType GetRailTypeByLabel(RailTypeLabel label, bool allow_alternate_labels)
{
/* Loop through each rail type until the label is found */
for (RailType r = RAILTYPE_BEGIN; r != RAILTYPE_END; r++) {
@@ -287,6 +288,14 @@ RailType GetRailTypeByLabel(RailTypeLabel label)
if (rti->label == label) return r;
}
if (allow_alternate_labels) {
/* Test if any rail type defines the label as an alternate. */
for (RailType r = RAILTYPE_BEGIN; r != RAILTYPE_END; r++) {
const RailtypeInfo *rti = GetRailTypeInfo(r);
if (rti->alternate_labels.Contains(label)) return r;
}
}
/* No matching label was found, so it is invalid */
return INVALID_RAILTYPE;
}