From afb45b6f29023b89a63c3030cac3cc0f84869a75 Mon Sep 17 00:00:00 2001 From: peter1138 Date: Mon, 16 Oct 2006 10:26:22 +0000 Subject: (svn r6788) - Codechange: Add and use a function to test if a string ID is a custom name. --- functions.h | 1 + misc.c | 7 ++++++- order_cmd.c | 2 +- vehicle.c | 2 +- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/functions.h b/functions.h index ab91f0734..a7237a778 100644 --- a/functions.h +++ b/functions.h @@ -138,6 +138,7 @@ void PlaceTreesRandomly(void); void InitializeLandscapeVariables(bool only_constants); /* misc.c */ +bool IsCustomName(StringID id); void DeleteName(StringID id); char *GetName(int id, char *buff); diff --git a/misc.c b/misc.c index 7801a2140..80ef97c72 100644 --- a/misc.c +++ b/misc.c @@ -150,9 +150,14 @@ void InitializeGame(int mode, uint size_x, uint size_y) ResetObjectToPlace(); } +bool IsCustomName(StringID id) +{ + return GB(id, 11, 5) == 15; +} + void DeleteName(StringID id) { - if ((id & 0xF800) == 0x7800) { + if (IsCustomName(id)) { memset(_name_array[id & 0x1FF], 0, sizeof(_name_array[id & 0x1FF])); } } diff --git a/order_cmd.c b/order_cmd.c index b872e9ea2..8614bb639 100644 --- a/order_cmd.c +++ b/order_cmd.c @@ -823,7 +823,7 @@ void BackupVehicleOrders(const Vehicle *v, BackuppedOrders *bak) bak->service_interval = v->service_interval; /* Safe custom string, if any */ - if ((v->string_id & 0xF800) != 0x7800) { + if (!IsCustomName(v->string_id)) { bak->name[0] = '\0'; } else { GetName(v->string_id & 0x7FF, bak->name); diff --git a/vehicle.c b/vehicle.c index e4b1ddbf7..bccc9a775 100644 --- a/vehicle.c +++ b/vehicle.c @@ -2073,7 +2073,7 @@ static int32 ReplaceVehicle(Vehicle **w, byte flags, int32 total_cost) MoveVehicleCargo(new_v->type == VEH_Train ? GetFirstVehicleInChain(new_v) : new_v, old_v); // Get the name of the old vehicle if it has a custom name. - if ((old_v->string_id & 0xF800) != 0x7800) { + if (!IsCustomName(old_v->string_id)) { vehicle_name[0] = '\0'; } else { GetName(old_v->string_id & 0x7FF, vehicle_name); -- cgit v1.2.3-54-g00ecf