(svn r21842) -Feature [FS#4393]: [NewGRF] Introduction dates/required types for rail types; e.g. introduce a particular rail type in 1960 (or when a vehicle using it is introduced), but also allow limiting its introduction to only happen when the required railtypes are available

This commit is contained in:
rubidium
2011-01-18 21:30:59 +00:00
parent dc94c94599
commit abc1828d30
6 changed files with 135 additions and 3 deletions

View File

@@ -44,6 +44,11 @@ EngineOverrideManager _engine_mngr;
*/
static Year _year_engine_aging_stops;
/**
* The railtypes that have been or never will be introduced, or
* an inverse bitmap of rail types that have to be introduced. */
static uint16 _introduced_railtypes;
/** Number of engines of each vehicle type in original engine data */
const uint8 _engine_counts[4] = {
lengthof(_orig_rail_vehicle_info),
@@ -474,8 +479,30 @@ void SetupEngines()
const Engine *e = new Engine(eid->type, eid->internal_id);
assert(e->index == index);
}
_introduced_railtypes = 0;
}
/**
* Check whether the railtypes should be introduced.
*/
static void CheckRailIntroduction()
{
/* All railtypes have been introduced. */
if (_introduced_railtypes == UINT16_MAX || Company::GetPoolSize() == 0) return;
/* We need to find the railtypes that are known to all companies. */
RailTypes rts = (RailTypes)UINT16_MAX;
/* We are at, or past the introduction date of the rail. */
Company *c;
FOR_ALL_COMPANIES(c) {
c->avail_railtypes = AddDateIntroducedRailTypes(c->avail_railtypes, _date);
rts &= c->avail_railtypes;
}
_introduced_railtypes |= rts;
}
void ShowEnginePreviewWindow(EngineID engine);
@@ -602,6 +629,19 @@ void StartupEngines()
c->avail_roadtypes = GetCompanyRoadtypes(c->index);
}
/* Rail types that are invalid or never introduced are marked as
* being introduced upon start. That way we can easily check whether
* there is any date related introduction that is still going to
* happen somewhere in the future. */
for (RailType rt = RAILTYPE_BEGIN; rt != RAILTYPE_END; rt++) {
const RailtypeInfo *rti = GetRailTypeInfo(rt);
if (rti->label != 0 && IsInsideMM(rti->introduction_date, 0, MAX_DAY)) continue;
SetBit(_introduced_railtypes, rt);
}
CheckRailIntroduction();
/* Invalidate any open purchase lists */
InvalidateWindowClassesData(WC_BUILD_VEHICLE);
}
@@ -614,7 +654,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);
c->avail_railtypes |= GetRailTypeInfo(e->u.rail.railtype)->introduces_railtypes;
c->avail_railtypes = AddDateIntroducedRailTypes(c->avail_railtypes | GetRailTypeInfo(e->u.rail.railtype)->introduces_railtypes, _date);
} else if (e->type == VEH_ROAD) {
SetBit(c->avail_roadtypes, HasBit(e->info.misc_flags, EF_ROAD_TRAM) ? ROADTYPE_TRAM : ROADTYPE_ROAD);
}
@@ -663,6 +703,8 @@ static CompanyID GetBestCompany(uint8 pp)
/** Daily check to offer an exclusive engine preview to the companies. */
void EnginesDailyLoop()
{
CheckRailIntroduction();
if (_cur_year >= _year_engine_aging_stops) return;
Engine *e;
@@ -760,7 +802,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) c->avail_railtypes |= GetRailTypeInfo(e->u.rail.railtype)->introduces_railtypes;
FOR_ALL_COMPANIES(c) c->avail_railtypes = AddDateIntroducedRailTypes(c->avail_railtypes | GetRailTypeInfo(e->u.rail.railtype)->introduces_railtypes, _date);
} 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);