summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2012-07-29 16:45:11 +0000
committerfrosch <frosch@openttd.org>2012-07-29 16:45:11 +0000
commit48e0d9901fba132ee532252f75ee00b242af5a31 (patch)
treee57d0ca87ba1ba06b47124f2ba9c7e6bfaec2717
parent4c9f65800be7f5a05722c18c559d74e3c1fe6711 (diff)
downloadopenttd-48e0d9901fba132ee532252f75ee00b242af5a31.tar.xz
(svn r24443) -Codechange: Move Vehicle::name to BaseConsist.
-rw-r--r--src/autoreplace_cmd.cpp5
-rw-r--r--src/base_consist.cpp8
-rw-r--r--src/base_consist.h4
-rw-r--r--src/vehicle.cpp2
-rw-r--r--src/vehicle_base.h2
5 files changed, 12 insertions, 9 deletions
diff --git a/src/autoreplace_cmd.cpp b/src/autoreplace_cmd.cpp
index 1f1717f98..de4bcb00f 100644
--- a/src/autoreplace_cmd.cpp
+++ b/src/autoreplace_cmd.cpp
@@ -357,11 +357,6 @@ static CommandCost CopyHeadSpecificThings(Vehicle *old_head, Vehicle *new_head,
/* Last do those things which do never fail (resp. we do not care about), but which are not undo-able */
if (cost.Succeeded() && old_head != new_head && (flags & DC_EXEC) != 0) {
- /* Copy vehicle name */
- if (old_head->name != NULL) {
- DoCommand(0, new_head->index, 0, DC_EXEC | DC_AUTOREPLACE, CMD_RENAME_VEHICLE, old_head->name);
- }
-
/* Copy other things which cannot be copied by a command and which shall not stay resetted from the build vehicle command */
new_head->CopyVehicleConfigAndStatistics(old_head);
diff --git a/src/base_consist.cpp b/src/base_consist.cpp
index def120fe1..93b97e10e 100644
--- a/src/base_consist.cpp
+++ b/src/base_consist.cpp
@@ -12,6 +12,11 @@
#include "stdafx.h"
#include "base_consist.h"
+BaseConsist::~BaseConsist()
+{
+ free(this->name);
+}
+
/**
* Copy properties of other BaseConsist.
* @param src Source for copying
@@ -20,6 +25,9 @@ void BaseConsist::CopyConsistPropertiesFrom(const BaseConsist *src)
{
if (this == src) return;
+ free(this->name);
+ this->name = src->name != NULL ? strdup(src->name) : NULL;
+
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
index 3c1366a6d..68303f4d8 100644
--- a/src/base_consist.h
+++ b/src/base_consist.h
@@ -17,9 +17,13 @@
/** Various front vehicle properties that are preserved when autoreplacing, using order-backup or switching front engines within a consist. */
struct BaseConsist {
+ char *name; ///< Name of vehicle
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
+ BaseConsist() : name(NULL) {}
+ virtual ~BaseConsist();
+
void CopyConsistPropertiesFrom(const BaseConsist *src);
};
diff --git a/src/vehicle.cpp b/src/vehicle.cpp
index 8a3d4fe68..be5cf0cdb 100644
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -781,8 +781,6 @@ void Vehicle::PreDestructor()
Vehicle::~Vehicle()
{
- free(this->name);
-
if (CleaningPool()) {
this->cargo.OnCleanPool();
return;
diff --git a/src/vehicle_base.h b/src/vehicle_base.h
index 545b3404c..98d741948 100644
--- a/src/vehicle_base.h
+++ b/src/vehicle_base.h
@@ -136,8 +136,6 @@ public:
friend void AfterLoadVehicles(bool part_of_load); ///< So we can set the #previous and #first pointers while loading
friend bool LoadOldVehicle(LoadgameState *ls, int num); ///< So we can set the proper next pointer while loading
- char *name; ///< Name of vehicle
-
TileIndex tile; ///< Current tile index
/**