1
0
Fork 0

(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

release/1.1
rubidium 2011-01-18 21:28:07 +00:00
parent 5f28591610
commit 6371b75bcc
7 changed files with 34 additions and 13 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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