* The train vehicle crashed! * Update its status and other parts around it. * @param flooded Crash was caused by flooding. * @return Number of people killed. */
| 3140 | * @return Number of people killed. |
| 3141 | */ |
| 3142 | uint Train::Crash(bool flooded) |
| 3143 | { |
| 3144 | uint victims = 0; |
| 3145 | if (this->IsFrontEngine()) { |
| 3146 | victims += 2; // driver |
| 3147 | |
| 3148 | /* Remove the reserved path in front of the train if it is not stuck. |
| 3149 | * Also clear all reserved tracks the train is currently on. */ |
| 3150 | if (!this->flags.Test(VehicleRailFlag::Stuck)) FreeTrainTrackReservation(this); |
| 3151 | for (const Train *v = this; v != nullptr; v = v->Next()) { |
| 3152 | ClearPathReservation(v, v->tile, v->GetVehicleTrackdir()); |
| 3153 | if (IsTileType(v->tile, MP_TUNNELBRIDGE)) { |
| 3154 | /* ClearPathReservation will not free the wormhole exit |
| 3155 | * if the train has just entered the wormhole. */ |
| 3156 | SetTunnelBridgeReservation(GetOtherTunnelBridgeEnd(v->tile), false); |
| 3157 | } |
| 3158 | } |
| 3159 | |
| 3160 | /* we may need to update crossing we were approaching, |
| 3161 | * but must be updated after the train has been marked crashed */ |
| 3162 | TileIndex crossing = TrainApproachingCrossingTile(this); |
| 3163 | if (crossing != INVALID_TILE) UpdateLevelCrossing(crossing); |
| 3164 | |
| 3165 | /* Remove the loading indicators (if any) */ |
| 3166 | HideFillingPercent(&this->fill_percent_te_id); |
| 3167 | } |
| 3168 | |
| 3169 | victims += this->GroundVehicleBase::Crash(flooded); |
| 3170 | |
| 3171 | this->crash_anim_pos = flooded ? 4000 : 1; // max 4440, disappear pretty fast when flooded |
| 3172 | return victims; |
| 3173 | } |
| 3174 | |
| 3175 | /** |
| 3176 | * Marks train as crashed and creates an AI event. |
no test coverage detected