From 0f7392bd616e0bd256b5ec241ad52d7230bcc454 Mon Sep 17 00:00:00 2001 From: peter1138 Date: Sat, 12 Jan 2008 19:58:06 +0000 Subject: (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is no limit to the amount of names. -Fix: NewGRF engines could not be renamed. --- src/vehicle.cpp | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) (limited to 'src/vehicle.cpp') diff --git a/src/vehicle.cpp b/src/vehicle.cpp index 6631a064a..88c771f9f 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -570,7 +570,7 @@ void Vehicle::PreDestructor() Vehicle::~Vehicle() { - DeleteName(this->string_id); + free(this->name); if (CleaningPool()) return; @@ -2308,7 +2308,6 @@ static bool IsUniqueVehicleName(const char *name) CommandCost CmdNameVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) { Vehicle *v; - StringID str; if (!IsValidVehicleID(p1) || StrEmpty(_cmd_text)) return CMD_ERROR; @@ -2318,17 +2317,11 @@ CommandCost CmdNameVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) if (!IsUniqueVehicleName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE); - str = AllocateName(_cmd_text, 2); - if (str == 0) return CMD_ERROR; - if (flags & DC_EXEC) { - StringID old_str = v->string_id; - v->string_id = str; - DeleteName(old_str); + free(v->name); + v->name = strdup(_cmd_text); ResortVehicleLists(); MarkWholeScreenDirty(); - } else { - DeleteName(str); } return CommandCost(); @@ -2741,7 +2734,8 @@ static const SaveLoad _common_veh_desc[] = { SLE_VAR(Vehicle, subtype, SLE_UINT8), SLE_REF(Vehicle, next, REF_VEHICLE_OLD), - SLE_VAR(Vehicle, string_id, SLE_STRINGID), + SLE_CONDVAR(Vehicle, name, SLE_NAME, 0, 83), + SLE_CONDSTR(Vehicle, name, SLE_STR, 0, 84, SL_MAX_VERSION), SLE_CONDVAR(Vehicle, unitnumber, SLE_FILE_U8 | SLE_VAR_U16, 0, 7), SLE_CONDVAR(Vehicle, unitnumber, SLE_UINT16, 8, SL_MAX_VERSION), SLE_VAR(Vehicle, owner, SLE_UINT8), -- cgit v1.2.3-54-g00ecf