mirror of https://github.com/OpenTTD/OpenTTD
(svn r15417) -Codechange: Add default rail type labels and support for per-GRF translation table.
parent
986224519a
commit
a68e0ee42f
|
@ -479,6 +479,17 @@ static ChangeInfoResult RailVehicleChangeInfo(uint engine, int numinfo, int prop
|
||||||
case 0x05: { // Track type
|
case 0x05: { // Track type
|
||||||
uint8 tracktype = grf_load_byte(&buf);
|
uint8 tracktype = grf_load_byte(&buf);
|
||||||
|
|
||||||
|
if (tracktype < _cur_grffile->railtype_max) {
|
||||||
|
RailType railtype = GetRailTypeByLabel(_cur_grffile->railtype_list[tracktype]);
|
||||||
|
if (railtype == INVALID_RAILTYPE) {
|
||||||
|
/* Rail type is not available, so disable this engine */
|
||||||
|
ei[i].climates = 0x80;
|
||||||
|
} else {
|
||||||
|
rvi[i].railtype = railtype;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
switch (tracktype) {
|
switch (tracktype) {
|
||||||
case 0: rvi->railtype = rvi->engclass >= 2 ? RAILTYPE_ELECTRIC : RAILTYPE_RAIL; break;
|
case 0: rvi->railtype = rvi->engclass >= 2 ? RAILTYPE_ELECTRIC : RAILTYPE_RAIL; break;
|
||||||
case 1: rvi->railtype = RAILTYPE_MONO; break;
|
case 1: rvi->railtype = RAILTYPE_MONO; break;
|
||||||
|
@ -610,8 +621,13 @@ static ChangeInfoResult RailVehicleChangeInfo(uint engine, int numinfo, int prop
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_cur_grffile->railtype_max == 0) {
|
||||||
|
/* Use traction type to select between normal and electrified
|
||||||
|
* rail only when no translation list is in place. */
|
||||||
if (rvi->railtype == RAILTYPE_RAIL && engclass >= EC_ELECTRIC) rvi->railtype = RAILTYPE_ELECTRIC;
|
if (rvi->railtype == RAILTYPE_RAIL && engclass >= EC_ELECTRIC) rvi->railtype = RAILTYPE_ELECTRIC;
|
||||||
if (rvi->railtype == RAILTYPE_ELECTRIC && engclass < EC_ELECTRIC) rvi->railtype = RAILTYPE_RAIL;
|
if (rvi->railtype == RAILTYPE_ELECTRIC && engclass < EC_ELECTRIC) rvi->railtype = RAILTYPE_RAIL;
|
||||||
|
}
|
||||||
|
|
||||||
rvi->engclass = engclass;
|
rvi->engclass = engclass;
|
||||||
} break;
|
} break;
|
||||||
|
@ -1749,6 +1765,12 @@ static ChangeInfoResult GlobalVarChangeInfo(uint gvid, int numinfo, int prop, by
|
||||||
buf += 8;
|
buf += 8;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 0x12: // Rail type translation table
|
||||||
|
/* This is loaded during the reservation stage, so just skip it here. */
|
||||||
|
/* Each entry is 4 bytes. */
|
||||||
|
buf += 4;
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
ret = CIR_UNKNOWN;
|
ret = CIR_UNKNOWN;
|
||||||
break;
|
break;
|
||||||
|
@ -1810,6 +1832,23 @@ static ChangeInfoResult GlobalVarReserveInfo(uint gvid, int numinfo, int prop, b
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case 0x12: { // Rail type translation table
|
||||||
|
if (i == 0) {
|
||||||
|
if (gvid != 0) {
|
||||||
|
grfmsg(1, "ReserveChangeInfo: Rail type translation table must start at zero");
|
||||||
|
return CIR_INVALID_ID;
|
||||||
|
}
|
||||||
|
|
||||||
|
free(_cur_grffile->railtype_list);
|
||||||
|
_cur_grffile->railtype_max = numinfo;
|
||||||
|
_cur_grffile->railtype_list = MallocT<RailTypeLabel>(numinfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
RailTypeLabel rtl = grf_load_dword(&buf);
|
||||||
|
_cur_grffile->railtype_list[i] = BSWAP32(rtl);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
ret = CIR_UNKNOWN;
|
ret = CIR_UNKNOWN;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include "cargotype.h"
|
#include "cargotype.h"
|
||||||
#include "industry_type.h"
|
#include "industry_type.h"
|
||||||
#include "station_type.h"
|
#include "station_type.h"
|
||||||
|
#include "rail_type.h"
|
||||||
|
|
||||||
enum GrfLoadingStage {
|
enum GrfLoadingStage {
|
||||||
GLS_FILESCAN,
|
GLS_FILESCAN,
|
||||||
|
@ -98,6 +99,9 @@ struct GRFFile {
|
||||||
uint8 cargo_max;
|
uint8 cargo_max;
|
||||||
CargoLabel *cargo_list;
|
CargoLabel *cargo_list;
|
||||||
uint8 cargo_map[NUM_CARGO];
|
uint8 cargo_map[NUM_CARGO];
|
||||||
|
|
||||||
|
uint8 railtype_max;
|
||||||
|
RailTypeLabel *railtype_list;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern GRFFile *_first_grffile;
|
extern GRFFile *_first_grffile;
|
||||||
|
|
12
src/rail.cpp
12
src/rail.cpp
|
@ -207,3 +207,15 @@ RailTypes GetCompanyRailtypes(CompanyID company)
|
||||||
|
|
||||||
return rt;
|
return rt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RailType GetRailTypeByLabel(RailTypeLabel label)
|
||||||
|
{
|
||||||
|
/* Loop through each rail type until the label is found */
|
||||||
|
for (RailType r = RAILTYPE_BEGIN; r != RAILTYPE_END; r++) {
|
||||||
|
const RailtypeInfo *rti = GetRailTypeInfo(r);
|
||||||
|
if (rti->label == label) return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* No matching label was found, so it is invalid */
|
||||||
|
return INVALID_RAILTYPE;
|
||||||
|
}
|
||||||
|
|
12
src/rail.h
12
src/rail.h
|
@ -132,6 +132,11 @@ struct RailtypeInfo {
|
||||||
* Cost multiplier for building this rail type
|
* Cost multiplier for building this rail type
|
||||||
*/
|
*/
|
||||||
uint8 cost_multiplier;
|
uint8 cost_multiplier;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unique 32 bit rail type identifier
|
||||||
|
*/
|
||||||
|
RailTypeLabel label;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -254,6 +259,13 @@ RailType GetBestRailtype(const CompanyID company);
|
||||||
*/
|
*/
|
||||||
RailTypes GetCompanyRailtypes(const CompanyID c);
|
RailTypes GetCompanyRailtypes(const CompanyID c);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the rail type for a given label.
|
||||||
|
* @param label the railtype label.
|
||||||
|
* @return the railtype.
|
||||||
|
*/
|
||||||
|
RailType GetRailTypeByLabel(RailTypeLabel label);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reset all rail type information to its default values.
|
* Reset all rail type information to its default values.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -7,6 +7,8 @@
|
||||||
|
|
||||||
#include "core/enum_type.hpp"
|
#include "core/enum_type.hpp"
|
||||||
|
|
||||||
|
typedef uint32 RailTypeLabel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enumeration for all possible railtypes.
|
* Enumeration for all possible railtypes.
|
||||||
*
|
*
|
||||||
|
|
|
@ -73,6 +73,9 @@ static const RailtypeInfo _original_railtypes[] = {
|
||||||
|
|
||||||
/* cost multiplier */
|
/* cost multiplier */
|
||||||
8,
|
8,
|
||||||
|
|
||||||
|
/* rail type label */
|
||||||
|
'RAIL',
|
||||||
},
|
},
|
||||||
|
|
||||||
/** Electrified railway */
|
/** Electrified railway */
|
||||||
|
@ -142,6 +145,9 @@ static const RailtypeInfo _original_railtypes[] = {
|
||||||
|
|
||||||
/* cost multiplier */
|
/* cost multiplier */
|
||||||
12,
|
12,
|
||||||
|
|
||||||
|
/* rail type label */
|
||||||
|
'ELRL',
|
||||||
},
|
},
|
||||||
|
|
||||||
/** Monorail */
|
/** Monorail */
|
||||||
|
@ -207,6 +213,9 @@ static const RailtypeInfo _original_railtypes[] = {
|
||||||
|
|
||||||
/* cost multiplier */
|
/* cost multiplier */
|
||||||
16,
|
16,
|
||||||
|
|
||||||
|
/* rail type label */
|
||||||
|
'MONO',
|
||||||
},
|
},
|
||||||
|
|
||||||
/** Maglev */
|
/** Maglev */
|
||||||
|
@ -272,6 +281,9 @@ static const RailtypeInfo _original_railtypes[] = {
|
||||||
|
|
||||||
/* cost multiplier */
|
/* cost multiplier */
|
||||||
24,
|
24,
|
||||||
|
|
||||||
|
/* rail type label */
|
||||||
|
'MGLV',
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue