changeset 19540:37eb005bbc66 draft

(svn r24443) -Codechange: Move Vehicle::name to BaseConsist.
author frosch <frosch@openttd.org>
date Sun, 29 Jul 2012 16:45:11 +0000
parents 1fff5d73a6ca
children 30c84259268d
files src/autoreplace_cmd.cpp src/base_consist.cpp src/base_consist.h src/vehicle.cpp src/vehicle_base.h
diffstat 5 files changed, 12 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/autoreplace_cmd.cpp
+++ b/src/autoreplace_cmd.cpp
@@ -357,11 +357,6 @@
 
 	/* 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);
 
--- 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 @@
 {
 	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;
 }
--- 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);
 };
 
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -781,8 +781,6 @@
 
 Vehicle::~Vehicle()
 {
-	free(this->name);
-
 	if (CleaningPool()) {
 		this->cargo.OnCleanPool();
 		return;
--- a/src/vehicle_base.h
+++ b/src/vehicle_base.h
@@ -136,8 +136,6 @@
 	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
 
 	/**