Codechange: rename function to better describe what it is doing

This commit is contained in:
Rubidium 2023-06-11 21:48:07 +02:00 committed by rubidium42
parent f86500df92
commit 82b434b589
5 changed files with 12 additions and 10 deletions

View File

@ -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);
}

View File

@ -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);

View File

@ -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;
}
}

View File

@ -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]));
}

View File

@ -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;
}
}