summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2012-07-29 16:44:39 +0000
committerfrosch <frosch@openttd.org>2012-07-29 16:44:39 +0000
commit4c9f65800be7f5a05722c18c559d74e3c1fe6711 (patch)
treebe8dd6b362953262d278218bb8569cf13e158fa1
parent77b5e7254118049bb5d7332b67a151f402ec31c9 (diff)
downloadopenttd-4c9f65800be7f5a05722c18c559d74e3c1fe6711.tar.xz
(svn r24442) -Codechange: Split some members of Vehicle into a new class BaseConsist.
-rw-r--r--projects/openttd_vs100.vcxproj2
-rw-r--r--projects/openttd_vs100.vcxproj.filters6
-rw-r--r--projects/openttd_vs80.vcproj8
-rw-r--r--projects/openttd_vs90.vcproj8
-rw-r--r--source.list2
-rw-r--r--src/base_consist.cpp25
-rw-r--r--src/base_consist.h26
-rw-r--r--src/vehicle_base.h10
8 files changed, 81 insertions, 6 deletions
diff --git a/projects/openttd_vs100.vcxproj b/projects/openttd_vs100.vcxproj
index 0da604efd..4ab6f45e7 100644
--- a/projects/openttd_vs100.vcxproj
+++ b/projects/openttd_vs100.vcxproj
@@ -317,6 +317,7 @@
<ClCompile Include="..\src\fileio.cpp" />
<ClCompile Include="..\src\fios.cpp" />
<ClCompile Include="..\src\fontcache.cpp" />
+ <ClCompile Include="..\src\base_consist.cpp" />
<ClCompile Include="..\src\gamelog.cpp" />
<ClCompile Include="..\src\genworld.cpp" />
<ClCompile Include="..\src\gfx.cpp" />
@@ -439,6 +440,7 @@
<ClInclude Include="..\src\fileio_type.h" />
<ClInclude Include="..\src\fios.h" />
<ClInclude Include="..\src\fontcache.h" />
+ <ClInclude Include="..\src\base_consist.h" />
<ClInclude Include="..\src\gamelog.h" />
<ClInclude Include="..\src\gamelog_internal.h" />
<ClInclude Include="..\src\genworld.h" />
diff --git a/projects/openttd_vs100.vcxproj.filters b/projects/openttd_vs100.vcxproj.filters
index d1e9d7971..34a8b4d00 100644
--- a/projects/openttd_vs100.vcxproj.filters
+++ b/projects/openttd_vs100.vcxproj.filters
@@ -180,6 +180,9 @@
<ClCompile Include="..\src\fontcache.cpp">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="..\src\base_consist.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
<ClCompile Include="..\src\gamelog.cpp">
<Filter>Source Files</Filter>
</ClCompile>
@@ -546,6 +549,9 @@
<ClInclude Include="..\src\fontcache.h">
<Filter>Header Files</Filter>
</ClInclude>
+ <ClInclude Include="..\src\base_consist.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
<ClInclude Include="..\src\gamelog.h">
<Filter>Header Files</Filter>
</ClInclude>
diff --git a/projects/openttd_vs80.vcproj b/projects/openttd_vs80.vcproj
index 310b64dc8..c6e3e595f 100644
--- a/projects/openttd_vs80.vcproj
+++ b/projects/openttd_vs80.vcproj
@@ -539,6 +539,10 @@
>
</File>
<File
+ RelativePath=".\..\src\base_consist.cpp"
+ >
+ </File>
+ <File
RelativePath=".\..\src\gamelog.cpp"
>
</File>
@@ -1031,6 +1035,10 @@
>
</File>
<File
+ RelativePath=".\..\src\base_consist.h"
+ >
+ </File>
+ <File
RelativePath=".\..\src\gamelog.h"
>
</File>
diff --git a/projects/openttd_vs90.vcproj b/projects/openttd_vs90.vcproj
index 4be6956f6..b5155a469 100644
--- a/projects/openttd_vs90.vcproj
+++ b/projects/openttd_vs90.vcproj
@@ -536,6 +536,10 @@
>
</File>
<File
+ RelativePath=".\..\src\base_consist.cpp"
+ >
+ </File>
+ <File
RelativePath=".\..\src\gamelog.cpp"
>
</File>
@@ -1028,6 +1032,10 @@
>
</File>
<File
+ RelativePath=".\..\src\base_consist.h"
+ >
+ </File>
+ <File
RelativePath=".\..\src\gamelog.h"
>
</File>
diff --git a/source.list b/source.list
index bd6dd04ce..83dc19e83 100644
--- a/source.list
+++ b/source.list
@@ -25,6 +25,7 @@ engine.cpp
fileio.cpp
fios.cpp
fontcache.cpp
+base_consist.cpp
gamelog.cpp
genworld.cpp
gfx.cpp
@@ -172,6 +173,7 @@ fileio_func.h
fileio_type.h
fios.h
fontcache.h
+base_consist.h
gamelog.h
gamelog_internal.h
genworld.h
diff --git a/src/base_consist.cpp b/src/base_consist.cpp
new file mode 100644
index 000000000..def120fe1
--- /dev/null
+++ b/src/base_consist.cpp
@@ -0,0 +1,25 @@
+/* $Id$ */
+
+/*
+ * This file is part of OpenTTD.
+ * 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.
+ * 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.
+ * 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/>.
+ */
+
+/** @file base_consist.cpp Properties for front vehicles/consists. */
+
+#include "stdafx.h"
+#include "base_consist.h"
+
+/**
+ * Copy properties of other BaseConsist.
+ * @param src Source for copying
+ */
+void BaseConsist::CopyConsistPropertiesFrom(const BaseConsist *src)
+{
+ if (this == src) return;
+
+ this->service_interval = src->service_interval;
+ this->cur_real_order_index = src->cur_real_order_index;
+}
diff --git a/src/base_consist.h b/src/base_consist.h
new file mode 100644
index 000000000..3c1366a6d
--- /dev/null
+++ b/src/base_consist.h
@@ -0,0 +1,26 @@
+/* $Id$ */
+
+/*
+ * This file is part of OpenTTD.
+ * 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.
+ * 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.
+ * 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/>.
+ */
+
+/** @file base_consist.h Properties for front vehicles/consists. */
+
+#ifndef BASE_CONSIST_H
+#define BASE_CONSIST_H
+
+#include "order_type.h"
+#include "date_type.h"
+
+/** Various front vehicle properties that are preserved when autoreplacing, using order-backup or switching front engines within a consist. */
+struct BaseConsist {
+ Date service_interval; ///< The interval for (automatic) servicing; either in days or %.
+ VehicleOrderID cur_real_order_index;///< The index to the current real (non-implicit) order
+
+ void CopyConsistPropertiesFrom(const BaseConsist *src);
+};
+
+#endif /* BASE_CONSIST_H */
diff --git a/src/vehicle_base.h b/src/vehicle_base.h
index fa06519e0..545b3404c 100644
--- a/src/vehicle_base.h
+++ b/src/vehicle_base.h
@@ -21,6 +21,7 @@
#include "order_func.h"
#include "transport_type.h"
#include "group_type.h"
+#include "base_consist.h"
/** Vehicle status bits in #Vehicle::vehstatus. */
enum VehStatus {
@@ -121,7 +122,7 @@ extern void FixOldVehicles();
struct GRFFile;
/** %Vehicle data structure. */
-struct Vehicle : VehiclePool::PoolItem<&_vehicle_pool>, BaseVehicle {
+struct Vehicle : VehiclePool::PoolItem<&_vehicle_pool>, BaseVehicle, BaseConsist {
private:
Vehicle *next; ///< pointer to the next vehicle in the chain
Vehicle *previous; ///< NOSAVE: pointer to the previous vehicle in the chain
@@ -173,7 +174,6 @@ public:
Date age; ///< Age in days
Date max_age; ///< Maximum age
Date date_of_last_service; ///< Last date the vehicle had a service at a depot.
- Date service_interval; ///< The interval for (automatic) servicing; either in days or %.
uint16 reliability; ///< Reliability.
uint16 reliability_spd_dec; ///< Reliability decrease speed.
byte breakdown_ctr; ///< Counter for managing breakdown events. @see Vehicle::HandleBreakdown
@@ -229,7 +229,6 @@ public:
byte vehstatus; ///< Status
Order current_order; ///< The current order (+ status, like: loading)
- VehicleOrderID cur_real_order_index;///< The index to the current real (non-implicit) order
VehicleOrderID cur_implicit_order_index;///< The index to the current implicit order
union {
@@ -597,9 +596,10 @@ public:
*/
inline void CopyVehicleConfigAndStatistics(const Vehicle *src)
{
+ this->CopyConsistPropertiesFrom(src);
+
this->unitnumber = src->unitnumber;
- this->cur_real_order_index = src->cur_real_order_index;
this->cur_implicit_order_index = src->cur_implicit_order_index;
this->current_order = src->current_order;
this->dest_tile = src->dest_tile;
@@ -614,8 +614,6 @@ public:
if (HasBit(src->vehicle_flags, VF_TIMETABLE_STARTED)) SetBit(this->vehicle_flags, VF_TIMETABLE_STARTED);
if (HasBit(src->vehicle_flags, VF_AUTOFILL_TIMETABLE)) SetBit(this->vehicle_flags, VF_AUTOFILL_TIMETABLE);
if (HasBit(src->vehicle_flags, VF_AUTOFILL_PRES_WAIT_TIME)) SetBit(this->vehicle_flags, VF_AUTOFILL_PRES_WAIT_TIME);
-
- this->service_interval = src->service_interval;
}