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

Method ConsistChanged

src/train_cmd.cpp:107–251  ·  view source on GitHub ↗

* Recalculates the cached stuff of a train. Should be called each time a vehicle is added * to/removed from the chain, and when the game is loaded. * Note: this needs to be called too for 'wagon chains' (in the depot, without an engine) * @param allowed_changes Stuff that is allowed to change. */

Source from the content-addressed store, hash-verified

105 * @param allowed_changes Stuff that is allowed to change.
106 */
107void Train::ConsistChanged(ConsistChangeFlags allowed_changes)
108{
109 uint16_t max_speed = UINT16_MAX;
110
111 assert(this->IsFrontEngine() || this->IsFreeWagon());
112
113 const RailVehicleInfo *rvi_v = RailVehInfo(this->engine_type);
114 EngineID first_engine = this->IsFrontEngine() ? this->engine_type : EngineID::Invalid();
115 this->gcache.cached_total_length = 0;
116 this->compatible_railtypes = {};
117
118 bool train_can_tilt = true;
119 int16_t min_curve_speed_mod = INT16_MAX;
120
121 for (Train *u = this; u != nullptr; u = u->Next()) {
122 const RailVehicleInfo *rvi_u = RailVehInfo(u->engine_type);
123
124 /* Check the this->first cache. */
125 assert(u->First() == this);
126
127 /* update the 'first engine' */
128 u->gcache.first_engine = this == u ? EngineID::Invalid() : first_engine;
129 u->railtypes = rvi_u->railtypes;
130
131 if (u->IsEngine()) first_engine = u->engine_type;
132
133 /* Set user defined data to its default value */
134 u->tcache.user_def_data = rvi_u->user_def_data;
135 this->InvalidateNewGRFCache();
136 u->InvalidateNewGRFCache();
137 }
138
139 for (Train *u = this; u != nullptr; u = u->Next()) {
140 /* Update user defined data (must be done before other properties) */
141 u->tcache.user_def_data = GetVehicleProperty(u, PROP_TRAIN_USER_DATA, u->tcache.user_def_data);
142 this->InvalidateNewGRFCache();
143 u->InvalidateNewGRFCache();
144 }
145
146 for (Train *u = this; u != nullptr; u = u->Next()) {
147 const Engine *e_u = u->GetEngine();
148 const RailVehicleInfo *rvi_u = &e_u->VehInfo<RailVehicleInfo>();
149
150 if (!e_u->info.misc_flags.Test(EngineMiscFlag::RailTilts)) train_can_tilt = false;
151 min_curve_speed_mod = std::min(min_curve_speed_mod, u->GetCurveSpeedModifier());
152
153 /* Cache wagon override sprite group. nullptr is returned if there is none */
154 u->tcache.cached_override = GetWagonOverrideSpriteSet(u->engine_type, u->cargo_type, u->gcache.first_engine);
155
156 /* Reset colour map */
157 u->colourmap = PAL_NONE;
158
159 /* Update powered-wagon-status and visual effect */
160 u->UpdateVisualEffect(true);
161
162 if (rvi_v->pow_wag_power != 0 && rvi_u->railveh_type == RAILVEH_WAGON &&
163 UsesWagonOverride(u) && !HasBit(u->vcache.cached_vis_effect, VE_DISABLE_WAGON_POWER)) {
164 /* wagon is powered */

Callers 15

TransferCargoFunction · 0.80
CmdConvertRailFunction · 0.80
CmdBuildRailWagonFunction · 0.80
CmdBuildRailVehicleFunction · 0.80
NormaliseTrainHeadFunction · 0.80
ReverseTrainDirectionFunction · 0.80
CmdReverseTrainDirectionFunction · 0.80
TrainControllerFunction · 0.80
DeleteLastWagonFunction · 0.80
VehicleEnterDepotFunction · 0.80
CmdRefitVehicleFunction · 0.80

Calls 15

GetCurveSpeedLimitMethod · 0.95
UpdateAccelerationMethod · 0.95
RailVehInfoFunction · 0.85
InvalidFunction · 0.85
GetVehiclePropertyFunction · 0.85
UsesWagonOverrideFunction · 0.85
HasBitFunction · 0.85
GetAllPoweredRailTypesFunction · 0.85
ShowNewGrfVehicleErrorFunction · 0.85
GetVehicleCallbackFunction · 0.85

Tested by

no test coverage detected