src/train_cmd.cpp
changeset 8178 28e437261743
parent 8175 4d10031a5495
child 8197 3af783256580
equal deleted inserted replaced
8177:d3b340b0bdfe 8178:28e437261743
   162 	const RailVehicleInfo *rvi_v = RailVehInfo(v->engine_type);
   162 	const RailVehicleInfo *rvi_v = RailVehInfo(v->engine_type);
   163 	EngineID first_engine = IsFrontEngine(v) ? v->engine_type : INVALID_ENGINE;
   163 	EngineID first_engine = IsFrontEngine(v) ? v->engine_type : INVALID_ENGINE;
   164 	v->u.rail.cached_total_length = 0;
   164 	v->u.rail.cached_total_length = 0;
   165 	v->u.rail.compatible_railtypes = 0;
   165 	v->u.rail.compatible_railtypes = 0;
   166 
   166 
       
   167 	bool train_can_tilt = true;
       
   168 
   167 	for (Vehicle *u = v; u != NULL; u = u->Next()) {
   169 	for (Vehicle *u = v; u != NULL; u = u->Next()) {
   168 		const RailVehicleInfo *rvi_u = RailVehInfo(u->engine_type);
   170 		const RailVehicleInfo *rvi_u = RailVehInfo(u->engine_type);
   169 
   171 
   170 		/* Check the v->first cache. */
   172 		/* Check the v->first cache. */
   171 		assert(u->First() == v);
   173 		assert(u->First() == v);
       
   174 
       
   175 		if (!HasBit(EngInfo(u->engine_type)->misc_flags, EF_RAIL_TILTS)) train_can_tilt = false;
   172 
   176 
   173 		/* update the 'first engine' */
   177 		/* update the 'first engine' */
   174 		u->u.rail.first_engine = v == u ? INVALID_ENGINE : first_engine;
   178 		u->u.rail.first_engine = v == u ? INVALID_ENGINE : first_engine;
   175 		u->u.rail.railtype = rvi_u->railtype;
   179 		u->u.rail.railtype = rvi_u->railtype;
   176 
   180 
   251 		v->u.rail.cached_total_length += u->u.rail.cached_veh_length;
   255 		v->u.rail.cached_total_length += u->u.rail.cached_veh_length;
   252 	}
   256 	}
   253 
   257 
   254 	/* store consist weight/max speed in cache */
   258 	/* store consist weight/max speed in cache */
   255 	v->u.rail.cached_max_speed = max_speed;
   259 	v->u.rail.cached_max_speed = max_speed;
       
   260 	v->u.rail.cached_tilt = train_can_tilt;
   256 
   261 
   257 	/* recalculate cached weights and power too (we do this *after* the rest, so it is known which wagons are powered and need extra weight added) */
   262 	/* recalculate cached weights and power too (we do this *after* the rest, so it is known which wagons are powered and need extra weight added) */
   258 	TrainCargoChanged(v);
   263 	TrainCargoChanged(v);
   259 }
   264 }
   260 
   265 
   336 
   341 
   337 	if (max_speed != absolute_max_speed) {
   342 	if (max_speed != absolute_max_speed) {
   338 		/* Apply the engine's rail type curve speed advantage, if it slowed by curves */
   343 		/* Apply the engine's rail type curve speed advantage, if it slowed by curves */
   339 		const RailtypeInfo *rti = GetRailTypeInfo(v->u.rail.railtype);
   344 		const RailtypeInfo *rti = GetRailTypeInfo(v->u.rail.railtype);
   340 		max_speed += (max_speed / 2) * rti->curve_speed;
   345 		max_speed += (max_speed / 2) * rti->curve_speed;
       
   346 
       
   347 		if (v->u.rail.cached_tilt) {
       
   348 			/* Apply max_speed bonus of 20% for a tilting train */
       
   349 			max_speed += max_speed / 5;
       
   350 		}
   341 	}
   351 	}
   342 
   352 
   343 	if (IsTileType(v->tile, MP_STATION) && IsFrontEngine(v)) {
   353 	if (IsTileType(v->tile, MP_STATION) && IsFrontEngine(v)) {
   344 		if (TrainShouldStop(v, v->tile)) {
   354 		if (TrainShouldStop(v, v->tile)) {
   345 			int station_length = GetStationByTile(v->tile)->GetPlatformLength(v->tile, DirToDiagDir(v->direction));
   355 			int station_length = GetStationByTile(v->tile)->GetPlatformLength(v->tile, DirToDiagDir(v->direction));