MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / RoadVehUpdateCache

Function RoadVehUpdateCache

src/roadveh_cmd.cpp:219–252  ·  view source on GitHub ↗

* Update the cache of a road vehicle. * @param v Road vehicle needing an update of its cache. * @param same_length should length of vehicles stay the same? * @pre \a v must be first road vehicle. */

Source from the content-addressed store, hash-verified

217 * @pre \a v must be first road vehicle.
218 */
219void RoadVehUpdateCache(RoadVehicle *v, bool same_length)
220{
221 assert(v->type == VEH_ROAD);
222 assert(v->IsFrontEngine());
223
224 v->InvalidateNewGRFCacheOfChain();
225
226 v->gcache.cached_total_length = 0;
227
228 for (RoadVehicle *u = v; u != nullptr; u = u->Next()) {
229 /* Check the v->first cache. */
230 assert(u->First() == v);
231
232 /* Update the 'first engine' */
233 u->gcache.first_engine = (v == u) ? EngineID::Invalid() : v->engine_type;
234
235 /* Update the length of the vehicle. */
236 uint veh_len = GetRoadVehLength(u);
237 /* Verify length hasn't changed. */
238 if (same_length && veh_len != u->gcache.cached_veh_length) VehicleLengthChanged(u);
239
240 u->gcache.cached_veh_length = veh_len;
241 v->gcache.cached_total_length += u->gcache.cached_veh_length;
242
243 /* Update visual effect */
244 u->UpdateVisualEffect();
245
246 /* Update cargo aging period. */
247 u->vcache.cached_cargo_age_period = GetVehicleProperty(u, PROP_ROADVEH_CARGO_AGE_PERIOD, EngInfo(u->engine_type)->cargo_age_period);
248 }
249
250 uint max_speed = GetVehicleProperty(v, PROP_ROADVEH_SPEED, 0);
251 v->vcache.cached_max_speed = (max_speed != 0) ? max_speed * 4 : RoadVehInfo(v->engine_type)->max_speed;
252}
253
254/**
255 * Build a road vehicle.

Callers 5

CmdRefitVehicleFunction · 0.85
CmdBuildRoadVehicleFunction · 0.85
CheckCachesFunction · 0.85
AfterLoadVehiclesPhase2Function · 0.85

Calls 11

InvalidFunction · 0.85
GetRoadVehLengthFunction · 0.85
VehicleLengthChangedFunction · 0.85
GetVehiclePropertyFunction · 0.85
EngInfoFunction · 0.85
RoadVehInfoFunction · 0.85
IsFrontEngineMethod · 0.80
UpdateVisualEffectMethod · 0.80
NextMethod · 0.45
FirstMethod · 0.45

Tested by

no test coverage detected