From 82b434b589b087bc75247ddbb01b79a1e7a4b2ef Mon Sep 17 00:00:00 2001 From: Rubidium Date: Sun, 11 Jun 2023 21:48:07 +0200 Subject: [PATCH] Codechange: rename function to better describe what it is doing --- src/company_cmd.cpp | 10 +++++----- src/company_func.h | 3 ++- src/error_gui.cpp | 3 ++- src/misc_gui.cpp | 2 +- src/road_cmd.cpp | 4 ++-- 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/company_cmd.cpp b/src/company_cmd.cpp index 5d186d831b..0cf65688f9 100644 --- a/src/company_cmd.cpp +++ b/src/company_cmd.cpp @@ -285,14 +285,14 @@ void UpdateLandscapingLimits() } /** - * Set the right DParams to get the name of an owner. + * Set the right DParams for STR_ERROR_OWNED_BY. * @param owner the owner to get the name of. * @param tile optional tile to get the right town. * @pre if tile == 0, then owner can't be OWNER_TOWN. */ -void GetNameOfOwner(Owner owner, TileIndex tile) +void SetDParamsForOwnedBy(Owner owner, TileIndex tile) { - SetDParam(2, owner); + SetDParam(OWNED_BY_OWNER_IN_PARAMETERS_OFFSET, owner); if (owner != OWNER_TOWN) { if (!Company::IsValidID(owner)) { @@ -326,7 +326,7 @@ CommandCost CheckOwnership(Owner owner, TileIndex tile) if (owner == _current_company) return CommandCost(); - GetNameOfOwner(owner, tile); + SetDParamsForOwnedBy(owner, tile); return_cmd_error(STR_ERROR_OWNED_BY); } @@ -346,7 +346,7 @@ CommandCost CheckTileOwnership(TileIndex tile) if (owner == _current_company) return CommandCost(); /* no need to get the name of the owner unless we're the local company (saves some time) */ - if (IsLocalCompany()) GetNameOfOwner(owner, tile); + if (IsLocalCompany()) SetDParamsForOwnedBy(owner, tile); return_cmd_error(STR_ERROR_OWNED_BY); } diff --git a/src/company_func.h b/src/company_func.h index 1212c4aa6a..60b70fbf97 100644 --- a/src/company_func.h +++ b/src/company_func.h @@ -17,7 +17,8 @@ bool MayCompanyTakeOver(CompanyID cbig, CompanyID small); void ChangeOwnershipOfCompanyItems(Owner old_owner, Owner new_owner); -void GetNameOfOwner(Owner owner, TileIndex tile); +static const int OWNED_BY_OWNER_IN_PARAMETERS_OFFSET = 2; ///< The index in the parameters for the owner information. +void SetDParamsForOwnedBy(Owner owner, TileIndex tile); void SetLocalCompany(CompanyID new_company); void ShowBuyCompanyDialog(CompanyID company, bool hostile_takeover); void CompanyAdminUpdate(const Company *company); diff --git a/src/error_gui.cpp b/src/error_gui.cpp index b7b5fe75bd..1d7107bec4 100644 --- a/src/error_gui.cpp +++ b/src/error_gui.cpp @@ -16,6 +16,7 @@ #include "gfx_func.h" #include "string_func.h" #include "company_base.h" +#include "company_func.h" #include "company_manager_face.h" #include "strings_func.h" #include "zoom_func.h" @@ -141,7 +142,7 @@ void ErrorMessageData::CopyOutDParams() if (this->textref_stack_size > 0) StopTextRefStackUsage(); if (this->detailed_msg == STR_ERROR_OWNED_BY) { - CompanyID company = (CompanyID)GetDParamX(this->decode_params, 2); + CompanyID company = (CompanyID)GetDParamX(this->decode_params, OWNED_BY_OWNER_IN_PARAMETERS_OFFSET); if (company < MAX_COMPANIES) face = company; } } diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp index 315964dada..42cd589761 100644 --- a/src/misc_gui.cpp +++ b/src/misc_gui.cpp @@ -182,7 +182,7 @@ public: if (td.owner_type[i] == STR_NULL) continue; SetDParam(0, STR_LAND_AREA_INFORMATION_OWNER_N_A); - if (td.owner[i] != OWNER_NONE && td.owner[i] != OWNER_WATER) GetNameOfOwner(td.owner[i], tile); + if (td.owner[i] != OWNER_NONE && td.owner[i] != OWNER_WATER) SetDParamsForOwnedBy(td.owner[i], tile); this->landinfo_data.push_back(GetString(td.owner_type[i])); } diff --git a/src/road_cmd.cpp b/src/road_cmd.cpp index c29fef09e7..b7049ebac4 100644 --- a/src/road_cmd.cpp +++ b/src/road_cmd.cpp @@ -2463,8 +2463,8 @@ CommandCost CmdConvertRoad(DoCommandFlag flags, TileIndex tile, TileIndex area_s } if (rtt == RTT_ROAD && owner == OWNER_TOWN) { + SetDParamsForOwnedBy(OWNER_TOWN, tile); error.MakeError(STR_ERROR_OWNED_BY); - GetNameOfOwner(OWNER_TOWN, tile); continue; } } @@ -2516,8 +2516,8 @@ CommandCost CmdConvertRoad(DoCommandFlag flags, TileIndex tile, TileIndex area_s } if (rtt == RTT_ROAD && owner == OWNER_TOWN) { + SetDParamsForOwnedBy(OWNER_TOWN, tile); error.MakeError(STR_ERROR_OWNED_BY); - GetNameOfOwner(OWNER_TOWN, tile); continue; } }