Mercurial > hg > openttd
comparison src/train_cmd.cpp @ 14261:2e1e5f37e2fb draft
(svn r18812) -Codechange: make some functions in train.h functions of Train.
author | rubidium <rubidium@openttd.org> |
---|---|
date | Fri, 15 Jan 2010 18:23:52 +0000 |
parents | a899d4e5ee1a |
children | fc532d11eb85 |
comparison
equal
deleted
inserted
replaced
14260:6a3f213b2573 | 14261:2e1e5f37e2fb |
---|---|
89 } | 89 } |
90 | 90 |
91 | 91 |
92 /** | 92 /** |
93 * Recalculates the cached total power of a train. Should be called when the consist is changed | 93 * Recalculates the cached total power of a train. Should be called when the consist is changed |
94 * @param v First vehicle of the consist. | 94 */ |
95 */ | 95 void Train::PowerChanged() |
96 void TrainPowerChanged(Train *v) | 96 { |
97 { | 97 assert(this->First() == this); |
98 | |
98 uint32 total_power = 0; | 99 uint32 total_power = 0; |
99 uint32 max_te = 0; | 100 uint32 max_te = 0; |
100 | 101 |
101 for (const Train *u = v; u != NULL; u = u->Next()) { | 102 for (const Train *u = this; u != NULL; u = u->Next()) { |
102 RailType railtype = GetRailType(u->tile); | 103 RailType railtype = GetRailType(u->tile); |
103 | 104 |
104 /* Power is not added for articulated parts */ | 105 /* Power is not added for articulated parts */ |
105 if (!u->IsArticulatedPart()) { | 106 if (!u->IsArticulatedPart()) { |
106 bool engine_has_power = HasPowerOnRail(u->railtype, railtype); | 107 bool engine_has_power = HasPowerOnRail(u->railtype, railtype); |
118 max_te += (u->tcache.cached_veh_weight * 10000 * GetVehicleProperty(u, PROP_TRAIN_TRACTIVE_EFFORT, rvi_u->tractive_effort)) / 256; | 119 max_te += (u->tcache.cached_veh_weight * 10000 * GetVehicleProperty(u, PROP_TRAIN_TRACTIVE_EFFORT, rvi_u->tractive_effort)) / 256; |
119 } | 120 } |
120 } | 121 } |
121 } | 122 } |
122 | 123 |
123 if (HasBit(u->flags, VRF_POWEREDWAGON) && HasPowerOnRail(v->railtype, railtype)) { | 124 if (HasBit(u->flags, VRF_POWEREDWAGON) && HasPowerOnRail(this->railtype, railtype)) { |
124 total_power += RailVehInfo(u->tcache.first_engine)->pow_wag_power; | 125 total_power += RailVehInfo(u->tcache.first_engine)->pow_wag_power; |
125 } | 126 } |
126 } | 127 } |
127 | 128 |
128 if (v->tcache.cached_power != total_power || v->tcache.cached_max_te != max_te) { | 129 if (this->tcache.cached_power != total_power || this->tcache.cached_max_te != max_te) { |
129 /* If it has no power (no catenary), stop the train */ | 130 /* If it has no power (no catenary), stop the train */ |
130 if (total_power == 0) v->vehstatus |= VS_STOPPED; | 131 if (total_power == 0) this->vehstatus |= VS_STOPPED; |
131 | 132 |
132 v->tcache.cached_power = total_power; | 133 this->tcache.cached_power = total_power; |
133 v->tcache.cached_max_te = max_te; | 134 this->tcache.cached_max_te = max_te; |
134 SetWindowDirty(WC_VEHICLE_DETAILS, v->index); | 135 SetWindowDirty(WC_VEHICLE_DETAILS, this->index); |
135 SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH); | 136 SetWindowWidgetDirty(WC_VEHICLE_VIEW, this->index, VVW_WIDGET_START_STOP_VEH); |
136 } | 137 } |
137 } | 138 } |
138 | 139 |
139 | 140 |
140 /** | 141 /** |
141 * Recalculates the cached weight of a train and its vehicles. Should be called each time the cargo on | 142 * Recalculates the cached weight of a train and its vehicles. Should be called each time the cargo on |
142 * the consist changes. | 143 * the consist changes. |
143 * @param v First vehicle of the consist. | 144 * @param v First vehicle of the consist. |
144 */ | 145 */ |
145 static void TrainCargoChanged(Train *v) | 146 void Train::CargoChanged() |
146 { | 147 { |
148 assert(this->First() == this); | |
147 uint32 weight = 0; | 149 uint32 weight = 0; |
148 | 150 |
149 for (Train *u = v; u != NULL; u = u->Next()) { | 151 for (Train *u = this; u != NULL; u = u->Next()) { |
150 uint32 vweight = CargoSpec::Get(u->cargo_type)->weight * u->cargo.Count() * FreightWagonMult(u->cargo_type) / 16; | 152 uint32 vweight = CargoSpec::Get(u->cargo_type)->weight * u->cargo.Count() * FreightWagonMult(u->cargo_type) / 16; |
151 | 153 |
152 /* Vehicle weight is not added for articulated parts. */ | 154 /* Vehicle weight is not added for articulated parts. */ |
153 if (!u->IsArticulatedPart()) { | 155 if (!u->IsArticulatedPart()) { |
154 /* vehicle weight is the sum of the weight of the vehicle and the weight of its cargo */ | 156 /* vehicle weight is the sum of the weight of the vehicle and the weight of its cargo */ |
166 /* store vehicle weight in cache */ | 168 /* store vehicle weight in cache */ |
167 u->tcache.cached_veh_weight = vweight; | 169 u->tcache.cached_veh_weight = vweight; |
168 } | 170 } |
169 | 171 |
170 /* store consist weight in cache */ | 172 /* store consist weight in cache */ |
171 v->tcache.cached_weight = weight; | 173 this->tcache.cached_weight = weight; |
172 | 174 |
173 /* Now update train power (tractive effort is dependent on weight) */ | 175 /* Now update train power (tractive effort is dependent on weight) */ |
174 TrainPowerChanged(v); | 176 this->PowerChanged(); |
175 } | 177 } |
176 | 178 |
177 | 179 |
178 /** Logs a bug in GRF and shows a warning message if this | 180 /** Logs a bug in GRF and shows a warning message if this |
179 * is for the first time this happened. | 181 * is for the first time this happened. |
216 | 218 |
217 /** | 219 /** |
218 * Recalculates the cached stuff of a train. Should be called each time a vehicle is added | 220 * Recalculates the cached stuff of a train. Should be called each time a vehicle is added |
219 * to/removed from the chain, and when the game is loaded. | 221 * to/removed from the chain, and when the game is loaded. |
220 * Note: this needs to be called too for 'wagon chains' (in the depot, without an engine) | 222 * Note: this needs to be called too for 'wagon chains' (in the depot, without an engine) |
221 * @param v First vehicle of the chain. | |
222 * @param same_length should length of vehicles stay the same? | 223 * @param same_length should length of vehicles stay the same? |
223 */ | 224 */ |
224 void TrainConsistChanged(Train *v, bool same_length) | 225 void Train::ConsistChanged(bool same_length) |
225 { | 226 { |
226 uint16 max_speed = UINT16_MAX; | 227 uint16 max_speed = UINT16_MAX; |
227 | 228 |
228 assert(v->IsFrontEngine() || v->IsFreeWagon()); | 229 assert(this->IsFrontEngine() || this->IsFreeWagon()); |
229 | 230 |
230 const RailVehicleInfo *rvi_v = RailVehInfo(v->engine_type); | 231 const RailVehicleInfo *rvi_v = RailVehInfo(this->engine_type); |
231 EngineID first_engine = v->IsFrontEngine() ? v->engine_type : INVALID_ENGINE; | 232 EngineID first_engine = this->IsFrontEngine() ? this->engine_type : INVALID_ENGINE; |
232 v->tcache.cached_total_length = 0; | 233 this->tcache.cached_total_length = 0; |
233 v->compatible_railtypes = RAILTYPES_NONE; | 234 this->compatible_railtypes = RAILTYPES_NONE; |
234 | 235 |
235 bool train_can_tilt = true; | 236 bool train_can_tilt = true; |
236 | 237 |
237 for (Train *u = v; u != NULL; u = u->Next()) { | 238 for (Train *u = this; u != NULL; u = u->Next()) { |
238 const RailVehicleInfo *rvi_u = RailVehInfo(u->engine_type); | 239 const RailVehicleInfo *rvi_u = RailVehInfo(u->engine_type); |
239 | 240 |
240 /* Check the v->first cache. */ | 241 /* Check the this->first cache. */ |
241 assert(u->First() == v); | 242 assert(u->First() == this); |
242 | 243 |
243 /* update the 'first engine' */ | 244 /* update the 'first engine' */ |
244 u->tcache.first_engine = v == u ? INVALID_ENGINE : first_engine; | 245 u->tcache.first_engine = this == u ? INVALID_ENGINE : first_engine; |
245 u->railtype = rvi_u->railtype; | 246 u->railtype = rvi_u->railtype; |
246 | 247 |
247 if (u->IsEngine()) first_engine = u->engine_type; | 248 if (u->IsEngine()) first_engine = u->engine_type; |
248 | 249 |
249 /* Set user defined data to its default value */ | 250 /* Set user defined data to its default value */ |
250 u->tcache.user_def_data = rvi_u->user_def_data; | 251 u->tcache.user_def_data = rvi_u->user_def_data; |
251 v->InvalidateNewGRFCache(); | 252 this->InvalidateNewGRFCache(); |
252 u->InvalidateNewGRFCache(); | 253 u->InvalidateNewGRFCache(); |
253 } | 254 } |
254 | 255 |
255 for (Train *u = v; u != NULL; u = u->Next()) { | 256 for (Train *u = this; u != NULL; u = u->Next()) { |
256 /* Update user defined data (must be done before other properties) */ | 257 /* Update user defined data (must be done before other properties) */ |
257 u->tcache.user_def_data = GetVehicleProperty(u, PROP_TRAIN_USER_DATA, u->tcache.user_def_data); | 258 u->tcache.user_def_data = GetVehicleProperty(u, PROP_TRAIN_USER_DATA, u->tcache.user_def_data); |
258 v->InvalidateNewGRFCache(); | 259 this->InvalidateNewGRFCache(); |
259 u->InvalidateNewGRFCache(); | 260 u->InvalidateNewGRFCache(); |
260 } | 261 } |
261 | 262 |
262 for (Train *u = v; u != NULL; u = u->Next()) { | 263 for (Train *u = this; u != NULL; u = u->Next()) { |
263 const Engine *e_u = Engine::Get(u->engine_type); | 264 const Engine *e_u = Engine::Get(u->engine_type); |
264 const RailVehicleInfo *rvi_u = &e_u->u.rail; | 265 const RailVehicleInfo *rvi_u = &e_u->u.rail; |
265 | 266 |
266 if (!HasBit(e_u->info.misc_flags, EF_RAIL_TILTS)) train_can_tilt = false; | 267 if (!HasBit(e_u->info.misc_flags, EF_RAIL_TILTS)) train_can_tilt = false; |
267 | 268 |
303 | 304 |
304 if (!u->IsArticulatedPart()) { | 305 if (!u->IsArticulatedPart()) { |
305 /* Do not count powered wagons for the compatible railtypes, as wagons always | 306 /* Do not count powered wagons for the compatible railtypes, as wagons always |
306 have railtype normal */ | 307 have railtype normal */ |
307 if (rvi_u->power > 0) { | 308 if (rvi_u->power > 0) { |
308 v->compatible_railtypes |= GetRailTypeInfo(u->railtype)->powered_railtypes; | 309 this->compatible_railtypes |= GetRailTypeInfo(u->railtype)->powered_railtypes; |
309 } | 310 } |
310 | 311 |
311 /* Some electric engines can be allowed to run on normal rail. It happens to all | 312 /* Some electric engines can be allowed to run on normal rail. It happens to all |
312 * existing electric engines when elrails are disabled and then re-enabled */ | 313 * existing electric engines when elrails are disabled and then re-enabled */ |
313 if (HasBit(u->flags, VRF_EL_ENGINE_ALLOWED_NORMAL_RAIL)) { | 314 if (HasBit(u->flags, VRF_EL_ENGINE_ALLOWED_NORMAL_RAIL)) { |
336 if (same_length && veh_len != u->tcache.cached_veh_length) RailVehicleLengthChanged(u); | 337 if (same_length && veh_len != u->tcache.cached_veh_length) RailVehicleLengthChanged(u); |
337 | 338 |
338 /* update vehicle length? */ | 339 /* update vehicle length? */ |
339 if (!same_length) u->tcache.cached_veh_length = veh_len; | 340 if (!same_length) u->tcache.cached_veh_length = veh_len; |
340 | 341 |
341 v->tcache.cached_total_length += u->tcache.cached_veh_length; | 342 this->tcache.cached_total_length += u->tcache.cached_veh_length; |
342 v->InvalidateNewGRFCache(); | 343 this->InvalidateNewGRFCache(); |
343 u->InvalidateNewGRFCache(); | 344 u->InvalidateNewGRFCache(); |
344 } | 345 } |
345 | 346 |
346 /* store consist weight/max speed in cache */ | 347 /* store consist weight/max speed in cache */ |
347 v->tcache.cached_max_speed = max_speed; | 348 this->tcache.cached_max_speed = max_speed; |
348 v->tcache.cached_tilt = train_can_tilt; | 349 this->tcache.cached_tilt = train_can_tilt; |
349 v->tcache.cached_max_curve_speed = GetTrainCurveSpeedLimit(v); | 350 this->tcache.cached_max_curve_speed = this->GetCurveSpeedLimit(); |
350 | 351 |
351 /* 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) */ | 352 /* 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) */ |
352 TrainCargoChanged(v); | 353 this->CargoChanged(); |
353 | 354 |
354 if (v->IsFrontEngine()) { | 355 if (this->IsFrontEngine()) { |
355 UpdateTrainAcceleration(v); | 356 this->UpdateAcceleration(); |
356 SetWindowDirty(WC_VEHICLE_DETAILS, v->index); | 357 SetWindowDirty(WC_VEHICLE_DETAILS, this->index); |
357 } | 358 } |
358 } | 359 } |
359 | 360 |
360 enum AccelType { | 361 enum AccelType { |
361 AM_ACCEL, | 362 AM_ACCEL, |
412 } | 413 } |
413 | 414 |
414 | 415 |
415 /** | 416 /** |
416 * Computes train speed limit caused by curves | 417 * Computes train speed limit caused by curves |
417 * @param v first vehicle of consist | |
418 * @return imposed speed limit | 418 * @return imposed speed limit |
419 */ | 419 */ |
420 int GetTrainCurveSpeedLimit(Train *v) | 420 int Train::GetCurveSpeedLimit() const |
421 { | 421 { |
422 assert(this->First() == this); | |
423 | |
422 static const int absolute_max_speed = UINT16_MAX; | 424 static const int absolute_max_speed = UINT16_MAX; |
423 int max_speed = absolute_max_speed; | 425 int max_speed = absolute_max_speed; |
424 | 426 |
425 if (_settings_game.vehicle.train_acceleration_model == TAM_ORIGINAL) return max_speed; | 427 if (_settings_game.vehicle.train_acceleration_model == TAM_ORIGINAL) return max_speed; |
426 | 428 |
429 /* first find the curve speed limit */ | 431 /* first find the curve speed limit */ |
430 int numcurve = 0; | 432 int numcurve = 0; |
431 int sum = 0; | 433 int sum = 0; |
432 int pos = 0; | 434 int pos = 0; |
433 int lastpos = -1; | 435 int lastpos = -1; |
434 for (const Vehicle *u = v; u->Next() != NULL; u = u->Next(), pos++) { | 436 for (const Vehicle *u = this; u->Next() != NULL; u = u->Next(), pos++) { |
435 Direction this_dir = u->direction; | 437 Direction this_dir = u->direction; |
436 Direction next_dir = u->Next()->direction; | 438 Direction next_dir = u->Next()->direction; |
437 | 439 |
438 DirDiff dirdiff = DirDifference(this_dir, next_dir); | 440 DirDiff dirdiff = DirDifference(this_dir, next_dir); |
439 if (dirdiff == DIRDIFF_SAME) continue; | 441 if (dirdiff == DIRDIFF_SAME) continue; |
466 } | 468 } |
467 } | 469 } |
468 | 470 |
469 if (max_speed != absolute_max_speed) { | 471 if (max_speed != absolute_max_speed) { |
470 /* Apply the engine's rail type curve speed advantage, if it slowed by curves */ | 472 /* Apply the engine's rail type curve speed advantage, if it slowed by curves */ |
471 const RailtypeInfo *rti = GetRailTypeInfo(v->railtype); | 473 const RailtypeInfo *rti = GetRailTypeInfo(this->railtype); |
472 max_speed += (max_speed / 2) * rti->curve_speed; | 474 max_speed += (max_speed / 2) * rti->curve_speed; |
473 | 475 |
474 if (v->tcache.cached_tilt) { | 476 if (this->tcache.cached_tilt) { |
475 /* Apply max_speed bonus of 20% for a tilting train */ | 477 /* Apply max_speed bonus of 20% for a tilting train */ |
476 max_speed += max_speed / 5; | 478 max_speed += max_speed / 5; |
477 } | 479 } |
478 } | 480 } |
479 | 481 |
482 | 484 |
483 /** new acceleration*/ | 485 /** new acceleration*/ |
484 static int GetTrainAcceleration(Train *v, bool mode) | 486 static int GetTrainAcceleration(Train *v, bool mode) |
485 { | 487 { |
486 int max_speed = v->tcache.cached_max_curve_speed; | 488 int max_speed = v->tcache.cached_max_curve_speed; |
487 assert(max_speed == GetTrainCurveSpeedLimit(v)); // safety check, will be removed later | 489 assert(max_speed == v->GetCurveSpeedLimit()); |
488 int speed = v->cur_speed * 10 / 16; // km-ish/h -> mp/h | 490 int speed = v->cur_speed * 10 / 16; // km-ish/h -> mp/h |
489 | 491 |
490 if (IsRailStationTile(v->tile) && v->IsFrontEngine()) { | 492 if (IsRailStationTile(v->tile) && v->IsFrontEngine()) { |
491 StationID sid = GetStationIndex(v->tile); | 493 StationID sid = GetStationIndex(v->tile); |
492 if (v->current_order.ShouldStopAtStation(v, sid)) { | 494 if (v->current_order.ShouldStopAtStation(v, sid)) { |
572 } else { | 574 } else { |
573 return min(-force - resistance, -10000) / mass; | 575 return min(-force - resistance, -10000) / mass; |
574 } | 576 } |
575 } | 577 } |
576 | 578 |
577 void UpdateTrainAcceleration(Train *v) | 579 void Train::UpdateAcceleration() |
578 { | 580 { |
579 assert(v->IsFrontEngine()); | 581 assert(this->IsFrontEngine()); |
580 | 582 |
581 v->max_speed = v->tcache.cached_max_speed; | 583 this->max_speed = this->tcache.cached_max_speed; |
582 | 584 |
583 uint power = v->tcache.cached_power; | 585 uint power = this->tcache.cached_power; |
584 uint weight = v->tcache.cached_weight; | 586 uint weight = this->tcache.cached_weight; |
585 assert(weight != 0); | 587 assert(weight != 0); |
586 v->acceleration = Clamp(power / weight * 4, 1, 255); | 588 this->acceleration = Clamp(power / weight * 4, 1, 255); |
587 } | 589 } |
588 | 590 |
589 /** | 591 /** |
590 * Get the width of a train vehicle image in the GUI. | 592 * Get the width of a train vehicle image in the GUI. |
591 * @param offset Additional offset for positioning the sprite; set to NULL if not needed | 593 * @param offset Additional offset for positioning the sprite; set to NULL if not needed |
747 AddArticulatedParts(v); | 749 AddArticulatedParts(v); |
748 | 750 |
749 _new_vehicle_id = v->index; | 751 _new_vehicle_id = v->index; |
750 | 752 |
751 VehicleMove(v, false); | 753 VehicleMove(v, false); |
752 TrainConsistChanged(v->First(), false); | 754 v->First()->ConsistChanged(false); |
753 UpdateTrainGroupID(v->First()); | 755 UpdateTrainGroupID(v->First()); |
754 | 756 |
755 SetWindowDirty(WC_VEHICLE_DEPOT, v->tile); | 757 SetWindowDirty(WC_VEHICLE_DEPOT, v->tile); |
756 if (IsLocalCompany()) { | 758 if (IsLocalCompany()) { |
757 InvalidateAutoreplaceWindow(v->engine_type, v->group_id); // updates the replace Train window | 759 InvalidateAutoreplaceWindow(v->engine_type, v->group_id); // updates the replace Train window |
928 AddRearEngineToMultiheadedTrain(v); | 930 AddRearEngineToMultiheadedTrain(v); |
929 } else { | 931 } else { |
930 AddArticulatedParts(v); | 932 AddArticulatedParts(v); |
931 } | 933 } |
932 | 934 |
933 TrainConsistChanged(v, false); | 935 v->ConsistChanged(false); |
934 UpdateTrainGroupID(v); | 936 UpdateTrainGroupID(v); |
935 | 937 |
936 if (!HasBit(p2, 1) && !(flags & DC_AUTOREPLACE)) { // check if the cars should be added to the new vehicle | 938 if (!HasBit(p2, 1) && !(flags & DC_AUTOREPLACE)) { // check if the cars should be added to the new vehicle |
937 NormalizeTrainVehInDepot(v); | 939 NormalizeTrainVehInDepot(v); |
938 } | 940 } |
1286 { | 1288 { |
1287 /* Not much to do! */ | 1289 /* Not much to do! */ |
1288 if (head == NULL) return; | 1290 if (head == NULL) return; |
1289 | 1291 |
1290 /* Tell the 'world' the train changed. */ | 1292 /* Tell the 'world' the train changed. */ |
1291 TrainConsistChanged(head, false); | 1293 head->ConsistChanged(false); |
1292 UpdateTrainGroupID(head); | 1294 UpdateTrainGroupID(head); |
1293 | 1295 |
1294 /* Not a front engine, i.e. a free wagon chain. No need to do more. */ | 1296 /* Not a front engine, i.e. a free wagon chain. No need to do more. */ |
1295 if (!head->IsFrontEngine()) return; | 1297 if (!head->IsFrontEngine()) return; |
1296 | 1298 |
1690 | 1692 |
1691 if (a->track != TRACK_BIT_WORMHOLE) VehicleEnterTile(a, a->tile, a->x_pos, a->y_pos); | 1693 if (a->track != TRACK_BIT_WORMHOLE) VehicleEnterTile(a, a->tile, a->x_pos, a->y_pos); |
1692 } | 1694 } |
1693 | 1695 |
1694 /* Update train's power incase tiles were different rail type */ | 1696 /* Update train's power incase tiles were different rail type */ |
1695 TrainPowerChanged(v); | 1697 v->PowerChanged(); |
1696 } | 1698 } |
1697 | 1699 |
1698 | 1700 |
1699 /** | 1701 /** |
1700 * Check if the vehicle is a train | 1702 * Check if the vehicle is a train |
1907 ToggleBit(v->flags, VRF_TOGGLE_REVERSE); | 1909 ToggleBit(v->flags, VRF_TOGGLE_REVERSE); |
1908 | 1910 |
1909 ClrBit(v->flags, VRF_REVERSING); | 1911 ClrBit(v->flags, VRF_REVERSING); |
1910 | 1912 |
1911 /* recalculate cached data */ | 1913 /* recalculate cached data */ |
1912 TrainConsistChanged(v, true); | 1914 v->ConsistChanged(true); |
1913 | 1915 |
1914 /* update all images */ | 1916 /* update all images */ |
1915 for (Vehicle *u = v; u != NULL; u = u->Next()) u->UpdateViewport(false, false); | 1917 for (Vehicle *u = v; u != NULL; u = u->Next()) u->UpdateViewport(false, false); |
1916 | 1918 |
1917 /* update crossing we were approaching */ | 1919 /* update crossing we were approaching */ |
2078 CommandCost cost = RefitVehicle(v, only_this, new_cid, new_subtype, flags); | 2080 CommandCost cost = RefitVehicle(v, only_this, new_cid, new_subtype, flags); |
2079 | 2081 |
2080 /* Update the train's cached variables */ | 2082 /* Update the train's cached variables */ |
2081 if (flags & DC_EXEC) { | 2083 if (flags & DC_EXEC) { |
2082 Train *front = v->First(); | 2084 Train *front = v->First(); |
2083 TrainConsistChanged(front, false); | 2085 front->ConsistChanged(false); |
2084 SetWindowDirty(WC_VEHICLE_DETAILS, front->index); | 2086 SetWindowDirty(WC_VEHICLE_DETAILS, front->index); |
2085 SetWindowDirty(WC_VEHICLE_DEPOT, front->tile); | 2087 SetWindowDirty(WC_VEHICLE_DEPOT, front->tile); |
2086 InvalidateWindowClassesData(WC_TRAINS_LIST, 0); | 2088 InvalidateWindowClassesData(WC_TRAINS_LIST, 0); |
2087 } else { | 2089 } else { |
2088 v->InvalidateNewGRFCacheOfChain(); // always invalidate; querycost might have filled it | 2090 v->InvalidateNewGRFCacheOfChain(); // always invalidate; querycost might have filled it |
2348 | 2350 |
2349 v->UpdateDeltaXY(v->direction); | 2351 v->UpdateDeltaXY(v->direction); |
2350 v->cur_image = v->GetImage(v->direction); | 2352 v->cur_image = v->GetImage(v->direction); |
2351 VehicleMove(v, false); | 2353 VehicleMove(v, false); |
2352 UpdateSignalsOnSegment(v->tile, INVALID_DIAGDIR, v->owner); | 2354 UpdateSignalsOnSegment(v->tile, INVALID_DIAGDIR, v->owner); |
2353 UpdateTrainAcceleration(v); | 2355 v->UpdateAcceleration(); |
2354 InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile); | 2356 InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile); |
2355 | 2357 |
2356 return false; | 2358 return false; |
2357 } | 2359 } |
2358 | 2360 |
2941 do { | 2943 do { |
2942 v->UpdateViewport(false, false); | 2944 v->UpdateViewport(false, false); |
2943 } while ((v = v->Next()) != NULL); | 2945 } while ((v = v->Next()) != NULL); |
2944 | 2946 |
2945 /* need to update acceleration and cached values since the goods on the train changed. */ | 2947 /* need to update acceleration and cached values since the goods on the train changed. */ |
2946 TrainCargoChanged(this); | 2948 this->CargoChanged(); |
2947 UpdateTrainAcceleration(this); | 2949 this->UpdateAcceleration(); |
2948 } | 2950 } |
2949 | 2951 |
2950 /** | 2952 /** |
2951 * This function looks at the vehicle and updates it's speed (cur_speed | 2953 * This function looks at the vehicle and updates it's speed (cur_speed |
2952 * and subspeed) variables. Furthermore, it returns the distance that | 2954 * and subspeed) variables. Furthermore, it returns the distance that |
3461 if (v->Next() == NULL) ClearPathReservation(v, v->tile, v->GetVehicleTrackdir()); | 3463 if (v->Next() == NULL) ClearPathReservation(v, v->tile, v->GetVehicleTrackdir()); |
3462 | 3464 |
3463 v->tile = gp.new_tile; | 3465 v->tile = gp.new_tile; |
3464 | 3466 |
3465 if (GetTileRailType(gp.new_tile) != GetTileRailType(gp.old_tile)) { | 3467 if (GetTileRailType(gp.new_tile) != GetTileRailType(gp.old_tile)) { |
3466 TrainPowerChanged(v->First()); | 3468 v->First()->PowerChanged(); |
3467 } | 3469 } |
3468 | 3470 |
3469 v->track = chosen_track; | 3471 v->track = chosen_track; |
3470 assert(v->track); | 3472 assert(v->track); |
3471 } | 3473 } |
3566 | 3568 |
3567 /* Do not check on every tick to save some computing time. */ | 3569 /* Do not check on every tick to save some computing time. */ |
3568 if (v->IsFrontEngine() && v->tick_counter % _settings_game.pf.path_backoff_interval == 0) CheckNextTrainTile(v); | 3570 if (v->IsFrontEngine() && v->tick_counter % _settings_game.pf.path_backoff_interval == 0) CheckNextTrainTile(v); |
3569 } | 3571 } |
3570 | 3572 |
3571 if (direction_changed) first->tcache.cached_max_curve_speed = GetTrainCurveSpeedLimit(first); | 3573 if (direction_changed) first->tcache.cached_max_curve_speed = first->GetCurveSpeedLimit(); |
3572 | 3574 |
3573 return; | 3575 return; |
3574 | 3576 |
3575 invalid_rail: | 3577 invalid_rail: |
3576 /* We've reached end of line?? */ | 3578 /* We've reached end of line?? */ |
3622 for (; v->Next() != NULL; v = v->Next()) u = v; | 3624 for (; v->Next() != NULL; v = v->Next()) u = v; |
3623 u->SetNext(NULL); | 3625 u->SetNext(NULL); |
3624 | 3626 |
3625 if (first != v) { | 3627 if (first != v) { |
3626 /* Recalculate cached train properties */ | 3628 /* Recalculate cached train properties */ |
3627 TrainConsistChanged(first, false); | 3629 first->ConsistChanged(false); |
3628 /* Update the depot window if the first vehicle is in depot - | 3630 /* Update the depot window if the first vehicle is in depot - |
3629 * if v == first, then it is updated in PreDestructor() */ | 3631 * if v == first, then it is updated in PreDestructor() */ |
3630 if (first->track == TRACK_BIT_DEPOT) { | 3632 if (first->track == TRACK_BIT_DEPOT) { |
3631 SetWindowDirty(WC_VEHICLE_DEPOT, first->tile); | 3633 SetWindowDirty(WC_VEHICLE_DEPOT, first->tile); |
3632 } | 3634 } |