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

Function TrainEnterStation

src/train_cmd.cpp:3036–3061  ·  view source on GitHub ↗

* Trains enters a station, send out a news item if it is the first train, and start loading. * @param v Train that entered the station. * @param station Station visited. */

Source from the content-addressed store, hash-verified

3034 * @param station Station visited.
3035 */
3036static void TrainEnterStation(Train *v, StationID station)
3037{
3038 v->last_station_visited = station;
3039
3040 /* check if a train ever visited this station before */
3041 Station *st = Station::Get(station);
3042 if (!(st->had_vehicle_of_type & HVOT_TRAIN)) {
3043 st->had_vehicle_of_type |= HVOT_TRAIN;
3044 AddVehicleNewsItem(
3045 GetEncodedString(STR_NEWS_FIRST_TRAIN_ARRIVAL, st->index),
3046 v->owner == _local_company ? NewsType::ArrivalCompany : NewsType::ArrivalOther,
3047 v->index,
3048 st->index
3049 );
3050 AI::NewEvent(v->owner, new ScriptEventStationFirstVehicle(st->index, v->index));
3051 Game::NewEvent(new ScriptEventStationFirstVehicle(st->index, v->index));
3052 }
3053
3054 v->force_proceed = TFP_NONE;
3055 SetWindowDirty(WC_VEHICLE_VIEW, v->index);
3056
3057 v->BeginLoading();
3058
3059 TriggerStationRandomisation(st, v->tile, StationRandomTrigger::VehicleArrives);
3060 TriggerStationAnimation(st, v->tile, StationAnimationTrigger::VehicleArrives);
3061}
3062
3063/* Check if the vehicle is compatible with the specified tile */
3064static inline bool CheckCompatibleRail(const Train *v, TileIndex tile)

Callers 1

TrainControllerFunction · 0.85

Calls 6

AddVehicleNewsItemFunction · 0.85
SetWindowDirtyFunction · 0.85
TriggerStationAnimationFunction · 0.85
BeginLoadingMethod · 0.80
GetEncodedStringFunction · 0.70

Tested by

no test coverage detected