From 7c8e7c6b6e16d4a26259a676db32d8776b99817e Mon Sep 17 00:00:00 2001 From: Henry Wilson Date: Wed, 10 Apr 2019 22:07:06 +0100 Subject: Codechange: Use null pointer literal instead of the NULL macro --- src/company_cmd.cpp | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) (limited to 'src/company_cmd.cpp') diff --git a/src/company_cmd.cpp b/src/company_cmd.cpp index df0588f91..3cf55cf1e 100644 --- a/src/company_cmd.cpp +++ b/src/company_cmd.cpp @@ -193,7 +193,7 @@ bool CheckCompanyHasMoney(CommandCost &cost) { if (cost.GetCost() > 0) { const Company *c = Company::GetIfValid(_current_company); - if (c != NULL && cost.GetCost() > c->money) { + if (c != nullptr && cost.GetCost() > c->money) { SetDParam(0, cost.GetCost()); cost.MakeError(STR_ERROR_NOT_ENOUGH_CASH_REQUIRES_CURRENCY); return false; @@ -239,7 +239,7 @@ static void SubtractMoneyFromAnyCompany(Company *c, CommandCost cost) void SubtractMoneyFromCompany(CommandCost cost) { Company *c = Company::GetIfValid(_current_company); - if (c != NULL) SubtractMoneyFromAnyCompany(c, cost); + if (c != nullptr) SubtractMoneyFromAnyCompany(c, cost); } /** @@ -353,7 +353,7 @@ static void GenerateCompanyName(Company *c) StringID str; uint32 strp; - if (t->name == NULL && IsInsideMM(t->townnametype, SPECSTR_TOWNNAME_START, SPECSTR_TOWNNAME_LAST + 1)) { + if (t->name == nullptr && IsInsideMM(t->townnametype, SPECSTR_TOWNNAME_START, SPECSTR_TOWNNAME_LAST + 1)) { str = t->townnametype - SPECSTR_TOWNNAME_START + SPECSTR_COMPANY_NAME_START; strp = t->townnameparts; @@ -539,7 +539,7 @@ void ResetCompanyLivery(Company *c) */ Company *DoStartupNewCompany(bool is_ai, CompanyID company = INVALID_COMPANY) { - if (!Company::CanAllocateItem()) return NULL; + if (!Company::CanAllocateItem()) return nullptr; /* we have to generate colour before this company is valid */ Colours colour = GenerateCompanyColour(); @@ -548,7 +548,7 @@ Company *DoStartupNewCompany(bool is_ai, CompanyID company = INVALID_COMPANY) if (company == INVALID_COMPANY) { c = new Company(STR_SV_UNNAMED, is_ai); } else { - if (Company::IsValidID(company)) return NULL; + if (Company::IsValidID(company)) return nullptr; c = new (company) Company(STR_SV_UNNAMED, is_ai); } @@ -670,7 +670,7 @@ static void HandleBankruptcyTakeover(Company *c) /* Did we ask everyone for bankruptcy? If so, bail out. */ if (c->bankrupt_asked == MAX_UVALUE(CompanyMask)) return; - Company *c2, *best = NULL; + Company *c2, *best = nullptr; int32 best_performance = -1; /* Ask the company with the highest performance history first */ @@ -706,7 +706,7 @@ void OnTick_Companies() if (_game_mode == GM_EDITOR) return; Company *c = Company::GetIfValid(_cur_company_tick_index); - if (c != NULL) { + if (c != nullptr) { if (c->name_1 != 0) GenerateCompanyName(c); if (c->bankrupt_asked != 0) HandleBankruptcyTakeover(c); } @@ -759,14 +759,14 @@ void CompaniesYearlyLoop() /** * Fill the CompanyNewsInformation struct with the required data. * @param c the current company. - * @param other the other company (use \c NULL if not relevant). + * @param other the other company (use \c nullptr if not relevant). */ void CompanyNewsInformation::FillData(const Company *c, const Company *other) { SetDParam(0, c->index); GetString(this->company_name, STR_COMPANY_NAME, lastof(this->company_name)); - if (other == NULL) { + if (other == nullptr) { *this->other_company_name = '\0'; } else { SetDParam(0, other->index); @@ -832,8 +832,8 @@ CommandCost CmdCompanyCtrl(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3 /* When replaying the client ID is not a valid client; there * are actually no clients at all. However, the company has to * be created, otherwise we cannot rerun the game properly. - * So only allow a NULL client info in that case. */ - if (ci == NULL) return CommandCost(); + * So only allow a nullptr client info in that case. */ + if (ci == nullptr) return CommandCost(); #endif /* NOT DEBUG_DUMP_COMMANDS */ /* Delete multiplayer progress bar */ @@ -842,7 +842,7 @@ CommandCost CmdCompanyCtrl(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3 Company *c = DoStartupNewCompany(false); /* A new company could not be created, revert to being a spectator */ - if (c == NULL) { + if (c == nullptr) { if (_network_server) { ci->client_playas = COMPANY_SPECTATOR; NetworkUpdateClientInfo(ci->client_id); @@ -874,7 +874,7 @@ CommandCost CmdCompanyCtrl(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3 if (company_id != INVALID_COMPANY && (company_id >= MAX_COMPANIES || Company::IsValidID(company_id))) return CMD_ERROR; Company *c = DoStartupNewCompany(true, company_id); - if (c != NULL) NetworkServerNewCompany(c, NULL); + if (c != nullptr) NetworkServerNewCompany(c, nullptr); break; } @@ -883,7 +883,7 @@ CommandCost CmdCompanyCtrl(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3 if (reason >= CRR_END) return CMD_ERROR; Company *c = Company::GetIfValid(company_id); - if (c == NULL) return CMD_ERROR; + if (c == nullptr) return CMD_ERROR; if (!(flags & DC_EXEC)) return CommandCost(); @@ -1055,7 +1055,7 @@ static bool IsUniqueCompanyName(const char *name) const Company *c; FOR_ALL_COMPANIES(c) { - if (c->name != NULL && strcmp(c->name, name) == 0) return false; + if (c->name != nullptr && strcmp(c->name, name) == 0) return false; } return true; @@ -1082,7 +1082,7 @@ CommandCost CmdRenameCompany(TileIndex tile, DoCommandFlag flags, uint32 p1, uin if (flags & DC_EXEC) { Company *c = Company::Get(_current_company); free(c->name); - c->name = reset ? NULL : stredup(text); + c->name = reset ? nullptr : stredup(text); MarkWholeScreenDirty(); CompanyAdminUpdate(c); } @@ -1100,7 +1100,7 @@ static bool IsUniquePresidentName(const char *name) const Company *c; FOR_ALL_COMPANIES(c) { - if (c->president_name != NULL && strcmp(c->president_name, name) == 0) return false; + if (c->president_name != nullptr && strcmp(c->president_name, name) == 0) return false; } return true; @@ -1129,11 +1129,11 @@ CommandCost CmdRenamePresident(TileIndex tile, DoCommandFlag flags, uint32 p1, u free(c->president_name); if (reset) { - c->president_name = NULL; + c->president_name = nullptr; } else { c->president_name = stredup(text); - if (c->name_1 == STR_SV_UNNAMED && c->name == NULL) { + if (c->name_1 == STR_SV_UNNAMED && c->name == nullptr) { char buf[80]; seprintf(buf, lastof(buf), "%s Transport", text); @@ -1150,13 +1150,13 @@ CommandCost CmdRenamePresident(TileIndex tile, DoCommandFlag flags, uint32 p1, u /** * Get the service interval for the given company and vehicle type. - * @param c The company, or NULL for client-default settings. + * @param c The company, or nullptr for client-default settings. * @param type The vehicle type to get the interval for. * @return The service interval. */ int CompanyServiceInterval(const Company *c, VehicleType type) { - const VehicleDefaultSettings *vds = (c == NULL) ? &_settings_client.company.vehicle : &c->settings.vehicle; + const VehicleDefaultSettings *vds = (c == nullptr) ? &_settings_client.company.vehicle : &c->settings.vehicle; switch (type) { default: NOT_REACHED(); case VEH_TRAIN: return vds->servint_trains; -- cgit v1.2.3-54-g00ecf