OpenTTD Source: src/base_consist.cpp Source File

OpenTTD Source 15.3

base_consist.cpp
Go to the documentation of this file.
1/*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
10#include "stdafx.h"
11#include "base_consist.h"
12#include "vehicle_base.h"
13#include "string_func.h"
14
15#include "safeguards.h"
16
17
22 void BaseConsist::CopyConsistPropertiesFrom(const BaseConsist *src)
23{
24 if (this == src) return;
25
26 this->name = src->name;
27
28 this->current_order_time = src->current_order_time;
29 this->lateness_counter = src->lateness_counter;
30 this->timetable_start = src->timetable_start;
31
32 this->service_interval = src->service_interval;
33
34 this->cur_real_order_index = src->cur_real_order_index;
35 this->cur_implicit_order_index = src->cur_implicit_order_index;
36
37 if (src->vehicle_flags.Test(VehicleFlag::TimetableStarted)) this->vehicle_flags.Set(VehicleFlag::TimetableStarted);
38 if (src->vehicle_flags.Test(VehicleFlag::AutofillTimetable)) this->vehicle_flags.Set(VehicleFlag::AutofillTimetable);
39 if (src->vehicle_flags.Test(VehicleFlag::AutofillPreserveWaitTime)) this->vehicle_flags.Set(VehicleFlag::AutofillPreserveWaitTime);
40 if (src->vehicle_flags.Test(VehicleFlag::ServiceIntervalIsPercent) != this->vehicle_flags.Test(VehicleFlag::ServiceIntervalIsPercent)) {
41 this->vehicle_flags.Flip(VehicleFlag::ServiceIntervalIsPercent);
42 }
43 if (src->vehicle_flags.Test(VehicleFlag::ServiceIntervalIsCustom)) this->vehicle_flags.Set(VehicleFlag::ServiceIntervalIsCustom);
44}
45
49 void BaseConsist::ResetDepotUnbunching()
50{
51 this->depot_unbunching_last_departure = 0;
52 this->depot_unbunching_next_departure = 0;
53 this->round_trip_time = 0;
54}
base_consist.h
Properties for front vehicles/consists.
VehicleFlag::AutofillTimetable
@ AutofillTimetable
Whether the vehicle should fill in the timetable automatically.
VehicleFlag::ServiceIntervalIsCustom
@ ServiceIntervalIsCustom
Service interval is custom.
VehicleFlag::ServiceIntervalIsPercent
@ ServiceIntervalIsPercent
Service interval is percent.
VehicleFlag::TimetableStarted
@ TimetableStarted
Whether the vehicle has started running on the timetable yet.
VehicleFlag::AutofillPreserveWaitTime
@ AutofillPreserveWaitTime
Whether non-destructive auto-fill should preserve waiting times.
BaseBitSet::Test
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
Definition base_bitset_type.hpp:141
BaseBitSet::Flip
constexpr Timpl & Flip(Tvalue_type value)
Flip the value-th bit.
Definition base_bitset_type.hpp:116
BaseBitSet::Set
constexpr Timpl & Set()
Set all bits.
Definition base_bitset_type.hpp:40
safeguards.h
A number of safeguards to prevent using unsafe methods.
stdafx.h
Definition of base types and functions in a cross-platform compatible way.
string_func.h
Functions related to low-level strings.
BaseConsist
Various front vehicle properties that are preserved when autoreplacing, using order-backup or switchi...
Definition base_consist.h:33
BaseConsist::name
std::string name
Name of vehicle.
Definition base_consist.h:34
BaseConsist::current_order_time
TimerGameTick::Ticks current_order_time
How many ticks have passed since this order started.
Definition base_consist.h:37
BaseConsist::depot_unbunching_next_departure
TimerGameTick::TickCounter depot_unbunching_next_departure
When the vehicle will next try to leave its unbunching depot.
Definition base_consist.h:42
BaseConsist::cur_real_order_index
VehicleOrderID cur_real_order_index
The index to the current real (non-implicit) order.
Definition base_consist.h:47
BaseConsist::round_trip_time
TimerGameTick::Ticks round_trip_time
How many ticks for a single circumnavigation of the orders.
Definition base_consist.h:43
BaseConsist::vehicle_flags
VehicleFlags vehicle_flags
Used for gradual loading and other miscellaneous things (.
Definition base_consist.h:50
BaseConsist::depot_unbunching_last_departure
TimerGameTick::TickCounter depot_unbunching_last_departure
When the vehicle last left its unbunching depot.
Definition base_consist.h:41
BaseConsist::cur_implicit_order_index
VehicleOrderID cur_implicit_order_index
The index to the current implicit order.
Definition base_consist.h:48
BaseConsist::timetable_start
TimerGameTick::TickCounter timetable_start
At what tick of TimerGameTick::counter the vehicle should start its timetable.
Definition base_consist.h:39
BaseConsist::lateness_counter
TimerGameTick::Ticks lateness_counter
How many ticks late (or early if negative) this vehicle is.
Definition base_consist.h:38
BaseConsist::service_interval
uint16_t service_interval
The interval for (automatic) servicing; either in days or %.
Definition base_consist.h:45
BaseConsist::CopyConsistPropertiesFrom
void CopyConsistPropertiesFrom(const BaseConsist *src)
Copy properties of other BaseConsist.
Definition base_consist.cpp:22
BaseConsist::ResetDepotUnbunching
void ResetDepotUnbunching()
Resets all the data used for depot unbunching.
Definition base_consist.cpp:49
vehicle_base.h
Base class for all vehicles.