OpenTTD

base_consist.cpp
Go to the documentation of this file.
1 /* $Id: base_consist.cpp 27280 2015-05-11 16:40:06Z frosch $ */
2
3 /*
4 * This file is part of OpenTTD.
5 * 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.
6 * 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.
7 * 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 <http://www.gnu.org/licenses/>.
8 */
9
12 #include "stdafx.h"
13 #include "base_consist.h"
14 #include "vehicle_base.h"
15 #include "string_func.h"
16
17 #include "safeguards.h"
18
19 BaseConsist::~BaseConsist()
20 {
21 free(this->name);
22 }
23
28 void BaseConsist::CopyConsistPropertiesFrom(const BaseConsist *src)
29 {
30 if (this == src) return;
31
32 free(this->name);
33 this->name = src->name != NULL ? stredup(src->name) : NULL;
34
35 this->current_order_time = src->current_order_time;
36 this->lateness_counter = src->lateness_counter;
37 this->timetable_start = src->timetable_start;
38
39 this->service_interval = src->service_interval;
40
41 this->cur_real_order_index = src->cur_real_order_index;
42 this->cur_implicit_order_index = src->cur_implicit_order_index;
43
44 if (HasBit(src->vehicle_flags, VF_TIMETABLE_STARTED)) SetBit(this->vehicle_flags, VF_TIMETABLE_STARTED);
45 if (HasBit(src->vehicle_flags, VF_AUTOFILL_TIMETABLE)) SetBit(this->vehicle_flags, VF_AUTOFILL_TIMETABLE);
46 if (HasBit(src->vehicle_flags, VF_AUTOFILL_PRES_WAIT_TIME)) SetBit(this->vehicle_flags, VF_AUTOFILL_PRES_WAIT_TIME);
47 if (HasBit(src->vehicle_flags, VF_SERVINT_IS_PERCENT) != HasBit(this->vehicle_flags, VF_SERVINT_IS_PERCENT)) {
48 ToggleBit(this->vehicle_flags, VF_SERVINT_IS_PERCENT);
49 }
50 if (HasBit(src->vehicle_flags, VF_SERVINT_IS_CUSTOM)) SetBit(this->vehicle_flags, VF_SERVINT_IS_CUSTOM);
51 }
VF_TIMETABLE_STARTED
Whether the vehicle has started running on the timetable yet.
Definition: vehicle_base.h:47
ToggleBit
static T ToggleBit(T &x, const uint8 y)
Toggles a bit in a variable.
Definition: bitmath_func.hpp:183
SetBit
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
Definition: bitmath_func.hpp:123
BaseConsist::current_order_time
uint32 current_order_time
How many ticks have passed since this order started.
Definition: base_consist.h:23
BaseConsist::lateness_counter
int32 lateness_counter
How many ticks late (or early if negative) this vehicle is.
Definition: base_consist.h:24
BaseConsist::service_interval
uint16 service_interval
The interval for (automatic) servicing; either in days or %.
Definition: base_consist.h:27
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:19
stdafx.h
Definition of base types and functions in a cross-platform compatible way.
BaseConsist::CopyConsistPropertiesFrom
void CopyConsistPropertiesFrom(const BaseConsist *src)
Copy properties of other BaseConsist.
Definition: base_consist.cpp:28
safeguards.h
A number of safeguards to prevent using unsafe methods.
VF_SERVINT_IS_CUSTOM
Service interval is custom.
Definition: vehicle_base.h:52
stredup
char * stredup(const char *s, const char *last)
Create a duplicate of the given string.
Definition: string.cpp:126
VF_AUTOFILL_TIMETABLE
Whether the vehicle should fill in the timetable automatically.
Definition: vehicle_base.h:48
base_consist.h
Properties for front vehicles/consists.
BaseConsist::timetable_start
Date timetable_start
When the vehicle is supposed to start the timetable.
Definition: base_consist.h:25
BaseConsist::name
char * name
Name of vehicle.
Definition: base_consist.h:20
vehicle_base.h
Base class for all vehicles.
free
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
Definition: depend.cpp:114
BaseConsist::vehicle_flags
uint16 vehicle_flags
Used for gradual loading and other miscellaneous things (.
Definition: base_consist.h:32
HasBit
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:105
VF_AUTOFILL_PRES_WAIT_TIME
Whether non-destructive auto-fill should preserve waiting times.
Definition: vehicle_base.h:49
BaseConsist::cur_implicit_order_index
VehicleOrderID cur_implicit_order_index
The index to the current implicit order.
Definition: base_consist.h:30
BaseConsist::cur_real_order_index
VehicleOrderID cur_real_order_index
The index to the current real (non-implicit) order.
Definition: base_consist.h:29
VF_SERVINT_IS_PERCENT
Service interval is percent.
Definition: vehicle_base.h:53