(svn r21841) -Feature: [NewGRF] Allow to define other railtypes that should be introduced if a particular rail type is introduced, e.g. to make sure slow rail is introduced when fast rail gets introduced

pull/155/head
rubidium 14 years ago
parent 2f98ad38ba
commit dc94c94599

@ -614,7 +614,7 @@ static void AcceptEnginePreview(EngineID eid, CompanyID company)
SetBit(e->company_avail, company);
if (e->type == VEH_TRAIN) {
assert(e->u.rail.railtype < RAILTYPE_END);
SetBit(c->avail_railtypes, e->u.rail.railtype);
c->avail_railtypes |= GetRailTypeInfo(e->u.rail.railtype)->introduces_railtypes;
} else if (e->type == VEH_ROAD) {
SetBit(c->avail_roadtypes, HasBit(e->info.misc_flags, EF_ROAD_TRAM) ? ROADTYPE_TRAM : ROADTYPE_ROAD);
}
@ -760,7 +760,7 @@ static void NewVehicleAvailable(Engine *e)
/* maybe make another rail type available */
RailType railtype = e->u.rail.railtype;
assert(railtype < RAILTYPE_END);
FOR_ALL_COMPANIES(c) SetBit(c->avail_railtypes, railtype);
FOR_ALL_COMPANIES(c) c->avail_railtypes |= GetRailTypeInfo(e->u.rail.railtype)->introduces_railtypes;
} else if (e->type == VEH_ROAD) {
/* maybe make another road type available */
FOR_ALL_COMPANIES(c) SetBit(c->avail_roadtypes, HasBit(e->info.misc_flags, EF_ROAD_TRAM) ? ROADTYPE_TRAM : ROADTYPE_ROAD);

@ -3209,6 +3209,7 @@ static ChangeInfoResult RailTypeChangeInfo(uint id, int numinfo, int prop, ByteR
case 0x0E: // Compatible railtype list
case 0x0F: // Powered railtype list
case 0x19: // Introduced railtype list
{
/* Rail type compatibility bits are added to the existing bits
* to allow multiple GRFs to modify compatibility with the
@ -3218,10 +3219,10 @@ static ChangeInfoResult RailTypeChangeInfo(uint id, int numinfo, int prop, ByteR
RailTypeLabel label = buf->ReadDWord();
RailType rt = GetRailTypeByLabel(BSWAP32(label));
if (rt != INVALID_RAILTYPE) {
if (prop == 0x0E) {
SetBit(rti->compatible_railtypes, rt);
} else {
SetBit(rti->powered_railtypes, rt);
switch (prop) {
case 0x0E: SetBit(rti->compatible_railtypes, rt); break;
case 0x0F: SetBit(rti->powered_railtypes, rt); break;
case 0x19: SetBit(rti->introduces_railtypes, rt); break;
}
}
}
@ -3303,6 +3304,7 @@ static ChangeInfoResult RailTypeReserveInfo(uint id, int numinfo, int prop, Byte
case 0x0E: // Compatible railtype list
case 0x0F: // Powered railtype list
case 0x19: // Introduced railtype list
for (int j = buf->ReadByte(); j != 0; j--) buf->ReadDWord();
break;

@ -194,7 +194,7 @@ RailType GetBestRailtype(const CompanyID company)
RailTypes GetCompanyRailtypes(CompanyID company)
{
RailTypes rt = RAILTYPES_NONE;
RailTypes rts = RAILTYPES_NONE;
Engine *e;
FOR_ALL_ENGINES_OF_TYPE(e, VEH_TRAIN) {
@ -206,12 +206,12 @@ RailTypes GetCompanyRailtypes(CompanyID company)
if (rvi->railveh_type != RAILVEH_WAGON) {
assert(rvi->railtype < RAILTYPE_END);
SetBit(rt, rvi->railtype);
rts |= GetRailTypeInfo(rvi->railtype)->introduces_railtypes;
}
}
}
return rt;
return rts;
}
RailType GetRailTypeByLabel(RailTypeLabel label)

@ -216,6 +216,11 @@ struct RailtypeInfo {
*/
byte map_colour;
/**
* Bitmask of which other railtypes are introduced when this railtype is introduced.
*/
RailTypes introduces_railtypes;
/**
* Sprite groups for resolving sprites
*/

@ -97,6 +97,9 @@ RailType AllocateRailType(RailTypeLabel label)
/* Make us compatible with ourself. */
rti->powered_railtypes = (RailTypes)(1 << rt);
rti->compatible_railtypes = (RailTypes)(1 << rt);
/* We also introduce ourself. */
rti->introduces_railtypes = (RailTypes)(1 << rt);
return rt;
}
}

@ -95,6 +95,9 @@ static const RailtypeInfo _original_railtypes[] = {
/* map colour */
0x0A,
/* introduction rail types */
RAILTYPES_RAIL,
{ NULL },
},
@ -178,6 +181,9 @@ static const RailtypeInfo _original_railtypes[] = {
/* map colour */
0x0A,
/* introduction rail types */
RAILTYPES_ELECTRIC,
{ NULL },
},
@ -257,6 +263,9 @@ static const RailtypeInfo _original_railtypes[] = {
/* map colour */
0x0A,
/* introduction rail types */
RAILTYPES_MONO,
{ NULL },
},
@ -336,6 +345,9 @@ static const RailtypeInfo _original_railtypes[] = {
/* map colour */
0x0A,
/* introduction rail types */
RAILTYPES_MAGLEV,
{ NULL },
},
};

@ -693,22 +693,21 @@ static CallBackFunction ToolbarZoomOutClick(Window *w)
static CallBackFunction ToolbarBuildRailClick(Window *w)
{
/* Use C++ spec to zero whole array. */
bool used_railtype[RAILTYPE_END] = { false };
RailTypes used_railtypes = RAILTYPES_NONE;
/* Find the used railtypes. */
Engine *e;
FOR_ALL_ENGINES_OF_TYPE(e, VEH_TRAIN) {
if (!HasBit(e->info.climates, _settings_game.game_creation.landscape)) continue;
used_railtype[e->u.rail.railtype] = true;
used_railtypes |= GetRailTypeInfo(e->u.rail.railtype)->introduces_railtypes;
}
const Company *c = Company::Get(_local_company);
DropDownList *list = new DropDownList();
for (RailType rt = RAILTYPE_BEGIN; rt != RAILTYPE_END; rt++) {
/* If it's not used ever, don't show it to the user. */
if (!used_railtype[rt]) continue;
if (!HasBit(used_railtypes, rt)) continue;
const RailtypeInfo *rti = GetRailTypeInfo(rt);
/* Skip rail type if it has no label */

Loading…
Cancel
Save