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/script/api/script_basestation.cpp | 6 +++--- src/script/api/script_basestation.hpp | 2 +- src/script/api/script_bridge.cpp | 8 ++++---- src/script/api/script_cargo.cpp | 2 +- src/script/api/script_client.cpp | 14 +++++++------- src/script/api/script_company.cpp | 10 +++++----- src/script/api/script_company.hpp | 4 ++-- src/script/api/script_controller.cpp | 4 ++-- src/script/api/script_engine.cpp | 6 +++--- src/script/api/script_error.hpp | 2 +- src/script/api/script_event.cpp | 10 +++++----- src/script/api/script_event_types.cpp | 24 ++++++++++++------------ src/script/api/script_gamesettings.cpp | 2 +- src/script/api/script_goal.cpp | 18 +++++++++--------- src/script/api/script_goal.hpp | 10 +++++----- src/script/api/script_group.cpp | 8 ++++---- src/script/api/script_group.hpp | 2 +- src/script/api/script_industry.cpp | 2 +- src/script/api/script_industrytype.cpp | 6 +++--- src/script/api/script_list.cpp | 12 ++++++------ src/script/api/script_list.hpp | 4 ++-- src/script/api/script_log.cpp | 4 ++-- src/script/api/script_marine.cpp | 6 +++--- src/script/api/script_news.cpp | 2 +- src/script/api/script_news.hpp | 2 +- src/script/api/script_object.cpp | 12 ++++++------ src/script/api/script_object.hpp | 2 +- src/script/api/script_order.cpp | 26 +++++++++++++------------- src/script/api/script_rail.cpp | 12 ++++++------ src/script/api/script_road.cpp | 8 ++++---- src/script/api/script_sign.cpp | 8 ++++---- src/script/api/script_sign.hpp | 4 ++-- src/script/api/script_station.cpp | 6 +++--- src/script/api/script_stationlist.cpp | 12 ++++++------ src/script/api/script_story_page.cpp | 14 +++++++------- src/script/api/script_story_page.hpp | 4 ++-- src/script/api/script_text.cpp | 20 ++++++++++---------- src/script/api/script_text.hpp | 4 ++-- src/script/api/script_tile.cpp | 20 ++++++++++---------- src/script/api/script_town.cpp | 14 +++++++------- src/script/api/script_town.hpp | 4 ++-- src/script/api/script_tunnel.cpp | 4 ++-- src/script/api/script_vehicle.cpp | 24 ++++++++++++------------ src/script/api/script_vehicle.hpp | 2 +- src/script/api/script_vehiclelist.cpp | 2 +- src/script/api/script_waypoint.cpp | 2 +- src/script/api/script_waypointlist.cpp | 2 +- src/script/api/script_window.cpp | 6 +++--- 48 files changed, 191 insertions(+), 191 deletions(-) (limited to 'src/script/api') diff --git a/src/script/api/script_basestation.cpp b/src/script/api/script_basestation.cpp index 229abf865..c51fa867a 100644 --- a/src/script/api/script_basestation.cpp +++ b/src/script/api/script_basestation.cpp @@ -22,12 +22,12 @@ /* static */ bool ScriptBaseStation::IsValidBaseStation(StationID station_id) { const BaseStation *st = ::BaseStation::GetIfValid(station_id); - return st != NULL && (st->owner == ScriptObject::GetCompany() || ScriptObject::GetCompany() == OWNER_DEITY || st->owner == OWNER_NONE); + return st != nullptr && (st->owner == ScriptObject::GetCompany() || ScriptObject::GetCompany() == OWNER_DEITY || st->owner == OWNER_NONE); } /* static */ char *ScriptBaseStation::GetName(StationID station_id) { - if (!IsValidBaseStation(station_id)) return NULL; + if (!IsValidBaseStation(station_id)) return nullptr; ::SetDParam(0, station_id); return GetString(::Station::IsValidID(station_id) ? STR_STATION_NAME : STR_WAYPOINT_NAME); @@ -39,7 +39,7 @@ EnforcePrecondition(false, ScriptObject::GetCompany() != OWNER_DEITY); EnforcePrecondition(false, IsValidBaseStation(station_id)); - EnforcePrecondition(false, name != NULL); + EnforcePrecondition(false, name != nullptr); const char *text = name->GetDecodedText(); EnforcePreconditionEncodedText(false, text); EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_STATION_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG); diff --git a/src/script/api/script_basestation.hpp b/src/script/api/script_basestation.hpp index 9676829f6..5bfd9ac84 100644 --- a/src/script/api/script_basestation.hpp +++ b/src/script/api/script_basestation.hpp @@ -52,7 +52,7 @@ public: * @param station_id The basestation to set the name of. * @param name The new name of the station (can be either a raw string, or a ScriptText object). * @pre IsValidBaseStation(station_id). - * @pre name != NULL && len(name) != 0. + * @pre name != nullptr && len(name) != 0. * @game @pre Valid ScriptCompanyMode active in scope. * @exception ScriptError::ERR_NAME_IS_NOT_UNIQUE * @return True if the name was changed. diff --git a/src/script/api/script_bridge.cpp b/src/script/api/script_bridge.cpp index f532f11b7..03787be2a 100644 --- a/src/script/api/script_bridge.cpp +++ b/src/script/api/script_bridge.cpp @@ -102,7 +102,7 @@ static void _DoCommandReturnBuildBridge1(class ScriptInstance *instance) ScriptObject::SetCallbackVariable(0, start); ScriptObject::SetCallbackVariable(1, end); - return ScriptObject::DoCommand(end, start, type | bridge_id, CMD_BUILD_BRIDGE, NULL, &::_DoCommandReturnBuildBridge1); + return ScriptObject::DoCommand(end, start, type | bridge_id, CMD_BUILD_BRIDGE, nullptr, &::_DoCommandReturnBuildBridge1); } /* static */ bool ScriptBridge::_BuildBridgeRoad1() @@ -114,7 +114,7 @@ static void _DoCommandReturnBuildBridge1(class ScriptInstance *instance) DiagDirection dir_1 = ::DiagdirBetweenTiles(end, start); DiagDirection dir_2 = ::ReverseDiagDir(dir_1); - return ScriptObject::DoCommand(start + ::TileOffsByDiagDir(dir_1), ::DiagDirToRoadBits(dir_2) | (ScriptObject::GetRoadType() << 4), 0, CMD_BUILD_ROAD, NULL, &::_DoCommandReturnBuildBridge2); + return ScriptObject::DoCommand(start + ::TileOffsByDiagDir(dir_1), ::DiagDirToRoadBits(dir_2) | (ScriptObject::GetRoadType() << 4), 0, CMD_BUILD_ROAD, nullptr, &::_DoCommandReturnBuildBridge2); } /* static */ bool ScriptBridge::_BuildBridgeRoad2() @@ -138,8 +138,8 @@ static void _DoCommandReturnBuildBridge1(class ScriptInstance *instance) /* static */ char *ScriptBridge::GetName(BridgeID bridge_id, ScriptVehicle::VehicleType vehicle_type) { - EnforcePrecondition(NULL, vehicle_type == ScriptVehicle::VT_ROAD || vehicle_type == ScriptVehicle::VT_RAIL || vehicle_type == ScriptVehicle::VT_WATER); - if (!IsValidBridge(bridge_id)) return NULL; + EnforcePrecondition(nullptr, vehicle_type == ScriptVehicle::VT_ROAD || vehicle_type == ScriptVehicle::VT_RAIL || vehicle_type == ScriptVehicle::VT_WATER); + if (!IsValidBridge(bridge_id)) return nullptr; return GetString(vehicle_type == ScriptVehicle::VT_WATER ? STR_LAI_BRIDGE_DESCRIPTION_AQUEDUCT : ::GetBridgeSpec(bridge_id)->transport_name[vehicle_type]); } diff --git a/src/script/api/script_cargo.cpp b/src/script/api/script_cargo.cpp index a2643f897..9e83daa08 100644 --- a/src/script/api/script_cargo.cpp +++ b/src/script/api/script_cargo.cpp @@ -29,7 +29,7 @@ /* static */ char *ScriptCargo::GetCargoLabel(CargoID cargo_type) { - if (!IsValidCargo(cargo_type)) return NULL; + if (!IsValidCargo(cargo_type)) return nullptr; const CargoSpec *cargo = ::CargoSpec::Get(cargo_type); /* cargo->label is a uint32 packing a 4 character non-terminated string, diff --git a/src/script/api/script_client.cpp b/src/script/api/script_client.cpp index 855ad86a0..247cac98c 100644 --- a/src/script/api/script_client.cpp +++ b/src/script/api/script_client.cpp @@ -20,37 +20,37 @@ * Finds NetworkClientInfo given client-identifier, * is used by other methods to resolve client-identifier. * @param client The client to get info structure for - * @return A pointer to corresponding CI struct or NULL when not found. + * @return A pointer to corresponding CI struct or nullptr when not found. */ static NetworkClientInfo *FindClientInfo(ScriptClient::ClientID client) { - if (client == ScriptClient::CLIENT_INVALID) return NULL; - if (!_networking) return NULL; + if (client == ScriptClient::CLIENT_INVALID) return nullptr; + if (!_networking) return nullptr; return NetworkClientInfo::GetByClientID((::ClientID)client); } /* static */ ScriptClient::ClientID ScriptClient::ResolveClientID(ScriptClient::ClientID client) { - return (FindClientInfo(client) == NULL ? ScriptClient::CLIENT_INVALID : client); + return (FindClientInfo(client) == nullptr ? ScriptClient::CLIENT_INVALID : client); } /* static */ char *ScriptClient::GetName(ScriptClient::ClientID client) { NetworkClientInfo *ci = FindClientInfo(client); - if (ci == NULL) return NULL; + if (ci == nullptr) return nullptr; return stredup(ci->client_name); } /* static */ ScriptCompany::CompanyID ScriptClient::GetCompany(ScriptClient::ClientID client) { NetworkClientInfo *ci = FindClientInfo(client); - if (ci == NULL) return ScriptCompany::COMPANY_INVALID; + if (ci == nullptr) return ScriptCompany::COMPANY_INVALID; return (ScriptCompany::CompanyID)ci->client_playas; } /* static */ ScriptDate::Date ScriptClient::GetJoinDate(ScriptClient::ClientID client) { NetworkClientInfo *ci = FindClientInfo(client); - if (ci == NULL) return ScriptDate::DATE_INVALID; + if (ci == nullptr) return ScriptDate::DATE_INVALID; return (ScriptDate::Date)ci->join_date; } diff --git a/src/script/api/script_company.cpp b/src/script/api/script_company.cpp index 54888c33c..59f4fa43e 100644 --- a/src/script/api/script_company.cpp +++ b/src/script/api/script_company.cpp @@ -45,7 +45,7 @@ { CCountedPtr counter(name); - EnforcePrecondition(false, name != NULL); + EnforcePrecondition(false, name != nullptr); const char *text = name->GetDecodedText(); EnforcePreconditionEncodedText(false, text); EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_COMPANY_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG); @@ -56,7 +56,7 @@ /* static */ char *ScriptCompany::GetName(ScriptCompany::CompanyID company) { company = ResolveCompanyID(company); - if (company == COMPANY_INVALID) return NULL; + if (company == COMPANY_INVALID) return nullptr; ::SetDParam(0, company); return GetString(STR_COMPANY_NAME); @@ -66,7 +66,7 @@ { CCountedPtr counter(name); - EnforcePrecondition(false, name != NULL); + EnforcePrecondition(false, name != nullptr); const char *text = name->GetDecodedText(); EnforcePreconditionEncodedText(false, text); EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_PRESIDENT_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG); @@ -312,7 +312,7 @@ if ((::LiveryScheme)scheme < LS_BEGIN || (::LiveryScheme)scheme >= LS_END) return COLOUR_INVALID; const Company *c = ::Company::GetIfValid(_current_company); - if (c == NULL) return COLOUR_INVALID; + if (c == nullptr) return COLOUR_INVALID; return (ScriptCompany::Colours)c->livery[scheme].colour1; } @@ -322,7 +322,7 @@ if ((::LiveryScheme)scheme < LS_BEGIN || (::LiveryScheme)scheme >= LS_END) return COLOUR_INVALID; const Company *c = ::Company::GetIfValid(_current_company); - if (c == NULL) return COLOUR_INVALID; + if (c == nullptr) return COLOUR_INVALID; return (ScriptCompany::Colours)c->livery[scheme].colour2; } diff --git a/src/script/api/script_company.hpp b/src/script/api/script_company.hpp index 55cb7a930..e3be24e55 100644 --- a/src/script/api/script_company.hpp +++ b/src/script/api/script_company.hpp @@ -139,7 +139,7 @@ public: /** * Set the name of your company. * @param name The new name of the company (can be either a raw string, or a ScriptText object). - * @pre name != NULL && len(name) != 0. + * @pre name != nullptr && len(name) != 0. * @exception ScriptError::ERR_NAME_IS_NOT_UNIQUE * @return True if the name was changed. */ @@ -156,7 +156,7 @@ public: /** * Set the name of your president. * @param name The new name of the president (can be either a raw string, or a ScriptText object). - * @pre name != NULL && len(name) != 0. + * @pre name != nullptr && len(name) != 0. * @exception ScriptError::ERR_NAME_IS_NOT_UNIQUE * @return True if the name was changed. */ diff --git a/src/script/api/script_controller.cpp b/src/script/api/script_controller.cpp index a42c8ede9..beb9b155f 100644 --- a/src/script/api/script_controller.cpp +++ b/src/script/api/script_controller.cpp @@ -43,7 +43,7 @@ ticks = 1; } - throw Script_Suspend(ticks, NULL); + throw Script_Suspend(ticks, nullptr); } /* static */ void ScriptController::Break(const char* message) @@ -119,7 +119,7 @@ ScriptController::~ScriptController() strtolower(library_name); ScriptInfo *lib = ScriptObject::GetActiveInstance()->FindLibrary(library, version); - if (lib == NULL) { + if (lib == nullptr) { char error[1024]; seprintf(error, lastof(error), "couldn't find library '%s' with version %d", library, version); throw sq_throwerror(vm, error); diff --git a/src/script/api/script_engine.cpp b/src/script/api/script_engine.cpp index c564cee97..dfd15bee4 100644 --- a/src/script/api/script_engine.cpp +++ b/src/script/api/script_engine.cpp @@ -25,7 +25,7 @@ /* static */ bool ScriptEngine::IsValidEngine(EngineID engine_id) { const Engine *e = ::Engine::GetIfValid(engine_id); - if (e == NULL || !e->IsEnabled()) return false; + if (e == nullptr || !e->IsEnabled()) return false; /* AIs have only access to engines they can purchase or still have in use. * Deity has access to all engined that will be or were available ever. */ @@ -36,12 +36,12 @@ /* static */ bool ScriptEngine::IsBuildable(EngineID engine_id) { const Engine *e = ::Engine::GetIfValid(engine_id); - return e != NULL && ::IsEngineBuildable(engine_id, e->type, ScriptObject::GetCompany()); + return e != nullptr && ::IsEngineBuildable(engine_id, e->type, ScriptObject::GetCompany()); } /* static */ char *ScriptEngine::GetName(EngineID engine_id) { - if (!IsValidEngine(engine_id)) return NULL; + if (!IsValidEngine(engine_id)) return nullptr; ::SetDParam(0, engine_id); return GetString(STR_ENGINE_NAME); diff --git a/src/script/api/script_error.hpp b/src/script/api/script_error.hpp index 1817cdb7d..346298d2c 100644 --- a/src/script/api/script_error.hpp +++ b/src/script/api/script_error.hpp @@ -44,7 +44,7 @@ * @param string The string that is checked. */ #define EnforcePreconditionEncodedText(returnval, string) \ - if ((string) == NULL) { \ + if ((string) == nullptr) { \ ScriptObject::SetLastError(ScriptError::ERR_PRECONDITION_TOO_MANY_PARAMETERS); \ return returnval; \ } \ diff --git a/src/script/api/script_event.cpp b/src/script/api/script_event.cpp index 0e711ca41..2d364e8d2 100644 --- a/src/script/api/script_event.cpp +++ b/src/script/api/script_event.cpp @@ -23,7 +23,7 @@ struct ScriptEventData { /* static */ void ScriptEventController::CreateEventPointer() { - assert(ScriptObject::GetEventPointer() == NULL); + assert(ScriptObject::GetEventPointer() == nullptr); ScriptObject::GetEventPointer() = new ScriptEventData(); } @@ -45,7 +45,7 @@ struct ScriptEventData { /* static */ bool ScriptEventController::IsEventWaiting() { - if (ScriptObject::GetEventPointer() == NULL) ScriptEventController::CreateEventPointer(); + if (ScriptObject::GetEventPointer() == nullptr) ScriptEventController::CreateEventPointer(); ScriptEventData *data = (ScriptEventData *)ScriptObject::GetEventPointer(); return !data->stack.empty(); @@ -53,10 +53,10 @@ struct ScriptEventData { /* static */ ScriptEvent *ScriptEventController::GetNextEvent() { - if (ScriptObject::GetEventPointer() == NULL) ScriptEventController::CreateEventPointer(); + if (ScriptObject::GetEventPointer() == nullptr) ScriptEventController::CreateEventPointer(); ScriptEventData *data = (ScriptEventData *)ScriptObject::GetEventPointer(); - if (data->stack.empty()) return NULL; + if (data->stack.empty()) return nullptr; ScriptEvent *e = data->stack.front(); data->stack.pop(); @@ -65,7 +65,7 @@ struct ScriptEventData { /* static */ void ScriptEventController::InsertEvent(ScriptEvent *event) { - if (ScriptObject::GetEventPointer() == NULL) ScriptEventController::CreateEventPointer(); + if (ScriptObject::GetEventPointer() == nullptr) ScriptEventController::CreateEventPointer(); ScriptEventData *data = (ScriptEventData *)ScriptObject::GetEventPointer(); event->AddRef(); diff --git a/src/script/api/script_event_types.cpp b/src/script/api/script_event_types.cpp index d424e6fef..e997f2320 100644 --- a/src/script/api/script_event_types.cpp +++ b/src/script/api/script_event_types.cpp @@ -25,12 +25,12 @@ bool ScriptEventEnginePreview::IsEngineValid() const { const Engine *e = ::Engine::GetIfValid(this->engine); - return e != NULL && e->IsEnabled(); + return e != nullptr && e->IsEnabled(); } char *ScriptEventEnginePreview::GetName() { - if (!this->IsEngineValid()) return NULL; + if (!this->IsEngineValid()) return nullptr; ::SetDParam(0, this->engine); return GetString(STR_ENGINE_NAME); @@ -132,13 +132,13 @@ ScriptEventAdminPort::~ScriptEventAdminPort() } #define SKIP_EMPTY(p) while (*(p) == ' ' || *(p) == '\n' || *(p) == '\r') (p)++; -#define RETURN_ERROR(stack) { ScriptLog::Error("Received invalid JSON data from AdminPort."); if (stack != 0) sq_pop(vm, stack); return NULL; } +#define RETURN_ERROR(stack) { ScriptLog::Error("Received invalid JSON data from AdminPort."); if (stack != 0) sq_pop(vm, stack); return nullptr; } SQInteger ScriptEventAdminPort::GetObject(HSQUIRRELVM vm) { char *p = this->json; - if (this->ReadTable(vm, p) == NULL) { + if (this->ReadTable(vm, p) == nullptr) { sq_pushnull(vm); return 1; } @@ -189,18 +189,18 @@ char *ScriptEventAdminPort::ReadTable(HSQUIRRELVM vm, char *p) if (*p++ != '"') RETURN_ERROR(1); p = ReadString(vm, p); - if (p == NULL) { + if (p == nullptr) { sq_pop(vm, 1); - return NULL; + return nullptr; } SKIP_EMPTY(p); if (*p++ != ':') RETURN_ERROR(2); p = this->ReadValue(vm, p); - if (p == NULL) { + if (p == nullptr) { sq_pop(vm, 2); - return NULL; + return nullptr; } sq_rawset(vm, -3); @@ -241,7 +241,7 @@ char *ScriptEventAdminPort::ReadValue(HSQUIRRELVM vm, char *p) case '"': { /* String */ p = ReadString(vm, ++p); - if (p == NULL) return NULL; + if (p == nullptr) return nullptr; break; } @@ -249,7 +249,7 @@ char *ScriptEventAdminPort::ReadValue(HSQUIRRELVM vm, char *p) case '{': { /* Table */ p = this->ReadTable(vm, p); - if (p == NULL) return NULL; + if (p == nullptr) return nullptr; break; } @@ -268,9 +268,9 @@ char *ScriptEventAdminPort::ReadValue(HSQUIRRELVM vm, char *p) while (*p++ != ']') { p = this->ReadValue(vm, p); - if (p == NULL) { + if (p == nullptr) { sq_pop(vm, 1); - return NULL; + return nullptr; } sq_arrayappend(vm, -2); diff --git a/src/script/api/script_gamesettings.cpp b/src/script/api/script_gamesettings.cpp index 1f8ded877..490e6eee0 100644 --- a/src/script/api/script_gamesettings.cpp +++ b/src/script/api/script_gamesettings.cpp @@ -21,7 +21,7 @@ { uint i; const SettingDesc *sd = GetSettingFromName(setting, &i); - return sd != NULL && sd->desc.cmd != SDT_STRING; + return sd != nullptr && sd->desc.cmd != SDT_STRING; } /* static */ int32 ScriptGameSettings::GetValue(const char *setting) diff --git a/src/script/api/script_goal.cpp b/src/script/api/script_goal.cpp index 54312cd9d..b5f6ccef2 100644 --- a/src/script/api/script_goal.cpp +++ b/src/script/api/script_goal.cpp @@ -34,14 +34,14 @@ CCountedPtr counter(goal); EnforcePrecondition(GOAL_INVALID, ScriptObject::GetCompany() == OWNER_DEITY); - EnforcePrecondition(GOAL_INVALID, goal != NULL); + EnforcePrecondition(GOAL_INVALID, goal != nullptr); const char *text = goal->GetEncodedText(); EnforcePreconditionEncodedText(GOAL_INVALID, text); EnforcePrecondition(GOAL_INVALID, company == ScriptCompany::COMPANY_INVALID || ScriptCompany::ResolveCompanyID(company) != ScriptCompany::COMPANY_INVALID); uint8 c = company; if (company == ScriptCompany::COMPANY_INVALID) c = INVALID_COMPANY; - StoryPage *story_page = NULL; + StoryPage *story_page = nullptr; if (type == GT_STORY_PAGE && ScriptStoryPage::IsValidStoryPage((ScriptStoryPage::StoryPageID)destination)) story_page = ::StoryPage::Get((ScriptStoryPage::StoryPageID)destination); EnforcePrecondition(GOAL_INVALID, (type == GT_NONE && destination == 0) || @@ -49,7 +49,7 @@ (type == GT_INDUSTRY && ScriptIndustry::IsValidIndustry(destination)) || (type == GT_TOWN && ScriptTown::IsValidTown(destination)) || (type == GT_COMPANY && ScriptCompany::ResolveCompanyID((ScriptCompany::CompanyID)destination) != ScriptCompany::COMPANY_INVALID) || - (type == GT_STORY_PAGE && story_page != NULL && (c == INVALID_COMPANY ? story_page->company == INVALID_COMPANY : story_page->company == INVALID_COMPANY || story_page->company == c))); + (type == GT_STORY_PAGE && story_page != nullptr && (c == INVALID_COMPANY ? story_page->company == INVALID_COMPANY : story_page->company == INVALID_COMPANY || story_page->company == c))); if (!ScriptObject::DoCommand(0, type | (c << 8), destination, CMD_CREATE_GOAL, text, &ScriptInstance::DoCommandReturnGoalID)) return GOAL_INVALID; @@ -71,7 +71,7 @@ EnforcePrecondition(false, IsValidGoal(goal_id)); EnforcePrecondition(false, ScriptObject::GetCompany() == OWNER_DEITY); - EnforcePrecondition(false, goal != NULL); + EnforcePrecondition(false, goal != nullptr); EnforcePrecondition(false, !StrEmpty(goal->GetEncodedText())); return ScriptObject::DoCommand(0, goal_id, 0, CMD_SET_GOAL_TEXT, goal->GetEncodedText()); @@ -85,11 +85,11 @@ EnforcePrecondition(false, ScriptObject::GetCompany() == OWNER_DEITY); /* Ensure null as used for emtpy string. */ - if (progress != NULL && StrEmpty(progress->GetEncodedText())) { - progress = NULL; + if (progress != nullptr && StrEmpty(progress->GetEncodedText())) { + progress = nullptr; } - return ScriptObject::DoCommand(0, goal_id, 0, CMD_SET_GOAL_PROGRESS, progress != NULL ? progress->GetEncodedText() : NULL); + return ScriptObject::DoCommand(0, goal_id, 0, CMD_SET_GOAL_PROGRESS, progress != nullptr ? progress->GetEncodedText() : nullptr); } /* static */ bool ScriptGoal::SetCompleted(GoalID goal_id, bool completed) @@ -106,7 +106,7 @@ EnforcePrecondition(false, ScriptObject::GetCompany() == OWNER_DEITY); Goal *g = Goal::Get(goal_id); - return g != NULL && g->completed; + return g != nullptr && g->completed; } /* static */ bool ScriptGoal::DoQuestion(uint16 uniqueid, uint8 target, bool is_client, Text *question, QuestionType type, int buttons) @@ -114,7 +114,7 @@ CCountedPtr counter(question); EnforcePrecondition(false, ScriptObject::GetCompany() == OWNER_DEITY); - EnforcePrecondition(false, question != NULL); + EnforcePrecondition(false, question != nullptr); const char *text = question->GetEncodedText(); EnforcePreconditionEncodedText(false, text); EnforcePrecondition(false, CountBits(buttons) >= 1 && CountBits(buttons) <= 3); diff --git a/src/script/api/script_goal.hpp b/src/script/api/script_goal.hpp index f5dfba095..b8c0873a2 100644 --- a/src/script/api/script_goal.hpp +++ b/src/script/api/script_goal.hpp @@ -99,7 +99,7 @@ public: * @param destination The destination of the \a type type. * @return The new GoalID, or GOAL_INVALID if it failed. * @pre No ScriptCompanyMode may be in scope. - * @pre goal != NULL && len(goal) != 0. + * @pre goal != nullptr && len(goal) != 0. * @pre company == COMPANY_INVALID || ResolveCompanyID(company) != COMPANY_INVALID. * @pre if type is GT_STORY_PAGE, the company of the goal and the company of the story page need to match: * \li Global goals can only reference global story pages. @@ -122,7 +122,7 @@ public: * @param goal The new goal text (can be either a raw string, or a ScriptText object). * @return True if the action succeeded. * @pre No ScriptCompanyMode may be in scope. - * @pre goal != NULL && len(goal) != 0. + * @pre goal != nullptr && len(goal) != 0. * @pre IsValidGoal(goal_id). */ static bool SetText(GoalID goal_id, Text *goal); @@ -133,7 +133,7 @@ public: * the progress string short. * @param goal_id The goal to update. * @param progress The new progress text for the goal (can be either a raw string, - * or a ScriptText object). To clear the progress string you can pass NULL or an + * or a ScriptText object). To clear the progress string you can pass nullptr or an * empty string. * @return True if the action succeeded. * @pre No ScriptCompanyMode may be in scope. @@ -169,7 +169,7 @@ public: * @param buttons Any combinations (at least 1, up to 3) of buttons defined in QuestionButton. Like BUTTON_YES + BUTTON_NO. * @return True if the action succeeded. * @pre No ScriptCompanyMode may be in scope. - * @pre question != NULL && len(question) != 0. + * @pre question != nullptr && len(question) != 0. * @pre company == COMPANY_INVALID || ResolveCompanyID(company) != COMPANY_INVALID. * @pre CountBits(buttons) >= 1 && CountBits(buttons) <= 3. * @note Replies to the question are given by you via the event ScriptEvent_GoalQuestionAnswer. @@ -187,7 +187,7 @@ public: * @return True if the action succeeded. * @pre No ScriptCompanyMode may be in scope. * @pre ScriptGame::IsMultiplayer() - * @pre question != NULL && len(question) != 0. + * @pre question != nullptr && len(question) != 0. * @pre ResolveClientID(client) != CLIENT_INVALID. * @pre CountBits(buttons) >= 1 && CountBits(buttons) <= 3. * @note Replies to the question are given by you via the event ScriptEvent_GoalQuestionAnswer. diff --git a/src/script/api/script_group.cpp b/src/script/api/script_group.cpp index fcae6c3d2..55f5ffdeb 100644 --- a/src/script/api/script_group.cpp +++ b/src/script/api/script_group.cpp @@ -25,12 +25,12 @@ /* static */ bool ScriptGroup::IsValidGroup(GroupID group_id) { const Group *g = ::Group::GetIfValid(group_id); - return g != NULL && g->owner == ScriptObject::GetCompany(); + return g != nullptr && g->owner == ScriptObject::GetCompany(); } /* static */ ScriptGroup::GroupID ScriptGroup::CreateGroup(ScriptVehicle::VehicleType vehicle_type, GroupID parent_group_id) { - if (!ScriptObject::DoCommand(0, (::VehicleType)vehicle_type, parent_group_id, CMD_CREATE_GROUP, NULL, &ScriptInstance::DoCommandReturnGroupID)) return GROUP_INVALID; + if (!ScriptObject::DoCommand(0, (::VehicleType)vehicle_type, parent_group_id, CMD_CREATE_GROUP, nullptr, &ScriptInstance::DoCommandReturnGroupID)) return GROUP_INVALID; /* In case of test-mode, we return GroupID 0 */ return (ScriptGroup::GroupID)0; @@ -55,7 +55,7 @@ CCountedPtr counter(name); EnforcePrecondition(false, IsValidGroup(group_id)); - EnforcePrecondition(false, name != NULL); + EnforcePrecondition(false, name != nullptr); const char *text = name->GetDecodedText(); EnforcePreconditionEncodedText(false, text); EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_GROUP_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG); @@ -65,7 +65,7 @@ /* static */ char *ScriptGroup::GetName(GroupID group_id) { - if (!IsValidGroup(group_id)) return NULL; + if (!IsValidGroup(group_id)) return nullptr; ::SetDParam(0, group_id); return GetString(STR_GROUP_NAME); diff --git a/src/script/api/script_group.hpp b/src/script/api/script_group.hpp index 6e7deb0b7..f44163bba 100644 --- a/src/script/api/script_group.hpp +++ b/src/script/api/script_group.hpp @@ -71,7 +71,7 @@ public: * @param group_id The group to set the name for. * @param name The name for the group (can be either a raw string, or a ScriptText object). * @pre IsValidGroup(group_id). - * @pre name != NULL && len(name) != 0 + * @pre name != nullptr && len(name) != 0 * @exception ScriptError::ERR_NAME_IS_NOT_UNIQUE * @return True if and only if the name was changed. */ diff --git a/src/script/api/script_industry.cpp b/src/script/api/script_industry.cpp index 68bb9003d..e72f9955b 100644 --- a/src/script/api/script_industry.cpp +++ b/src/script/api/script_industry.cpp @@ -39,7 +39,7 @@ /* static */ char *ScriptIndustry::GetName(IndustryID industry_id) { - if (!IsValidIndustry(industry_id)) return NULL; + if (!IsValidIndustry(industry_id)) return nullptr; ::SetDParam(0, industry_id); return GetString(STR_INDUSTRY_NAME); diff --git a/src/script/api/script_industrytype.cpp b/src/script/api/script_industrytype.cpp index 1ac59975d..e154705bb 100644 --- a/src/script/api/script_industrytype.cpp +++ b/src/script/api/script_industrytype.cpp @@ -59,14 +59,14 @@ /* static */ char *ScriptIndustryType::GetName(IndustryType industry_type) { - if (!IsValidIndustryType(industry_type)) return NULL; + if (!IsValidIndustryType(industry_type)) return nullptr; return GetString(::GetIndustrySpec(industry_type)->name); } /* static */ ScriptList *ScriptIndustryType::GetProducedCargo(IndustryType industry_type) { - if (!IsValidIndustryType(industry_type)) return NULL; + if (!IsValidIndustryType(industry_type)) return nullptr; const IndustrySpec *ins = ::GetIndustrySpec(industry_type); @@ -80,7 +80,7 @@ /* static */ ScriptList *ScriptIndustryType::GetAcceptedCargo(IndustryType industry_type) { - if (!IsValidIndustryType(industry_type)) return NULL; + if (!IsValidIndustryType(industry_type)) return nullptr; const IndustrySpec *ins = ::GetIndustrySpec(industry_type); diff --git a/src/script/api/script_list.cpp b/src/script/api/script_list.cpp index d0c72b5bb..13545c422 100644 --- a/src/script/api/script_list.cpp +++ b/src/script/api/script_list.cpp @@ -109,7 +109,7 @@ public: void End() { - this->bucket_list = NULL; + this->bucket_list = nullptr; this->has_no_more_items = true; this->item_next = 0; } @@ -119,7 +119,7 @@ public: */ void FindNext() { - if (this->bucket_list == NULL) { + if (this->bucket_list == nullptr) { this->has_no_more_items = true; return; } @@ -128,7 +128,7 @@ public: if (this->bucket_list_iter == this->bucket_list->end()) { this->bucket_iter++; if (this->bucket_iter == this->list->buckets.end()) { - this->bucket_list = NULL; + this->bucket_list = nullptr; return; } this->bucket_list = &(*this->bucket_iter).second; @@ -203,7 +203,7 @@ public: void End() { - this->bucket_list = NULL; + this->bucket_list = nullptr; this->has_no_more_items = true; this->item_next = 0; } @@ -213,14 +213,14 @@ public: */ void FindNext() { - if (this->bucket_list == NULL) { + if (this->bucket_list == nullptr) { this->has_no_more_items = true; return; } if (this->bucket_list_iter == this->bucket_list->begin()) { if (this->bucket_iter == this->list->buckets.begin()) { - this->bucket_list = NULL; + this->bucket_list = nullptr; return; } this->bucket_iter--; diff --git a/src/script/api/script_list.hpp b/src/script/api/script_list.hpp index 1fbafe3d9..b32ebc463 100644 --- a/src/script/api/script_list.hpp +++ b/src/script/api/script_list.hpp @@ -198,7 +198,7 @@ public: /** * Remove everything that is in the given list from this list (same item index that is). * @param list the list of items to remove. - * @pre list != NULL + * @pre list != nullptr */ void RemoveList(ScriptList *list); @@ -242,7 +242,7 @@ public: /** * Keeps everything that is in the given list from this list (same item index that is). * @param list the list of items to keep. - * @pre list != NULL + * @pre list != nullptr */ void KeepList(ScriptList *list); diff --git a/src/script/api/script_log.cpp b/src/script/api/script_log.cpp index d9fbbde98..b40ed97aa 100644 --- a/src/script/api/script_log.cpp +++ b/src/script/api/script_log.cpp @@ -35,7 +35,7 @@ /* static */ void ScriptLog::Log(ScriptLog::ScriptLogType level, const char *message) { - if (ScriptObject::GetLogPointer() == NULL) { + if (ScriptObject::GetLogPointer() == nullptr) { ScriptObject::GetLogPointer() = new LogData(); LogData *log = (LogData *)ScriptObject::GetLogPointer(); @@ -59,7 +59,7 @@ /* Cut string after first \n */ char *p; - while ((p = strchr(log->lines[log->pos], '\n')) != NULL) { + while ((p = strchr(log->lines[log->pos], '\n')) != nullptr) { *p = '\0'; break; } diff --git a/src/script/api/script_marine.cpp b/src/script/api/script_marine.cpp index 434ec11ac..bba361cec 100644 --- a/src/script/api/script_marine.cpp +++ b/src/script/api/script_marine.cpp @@ -166,9 +166,9 @@ /* static */ Money ScriptMarine::GetBuildCost(BuildType build_type) { switch (build_type) { - case BT_DOCK: return ::GetPrice(PR_BUILD_STATION_DOCK, 1, NULL); - case BT_DEPOT: return ::GetPrice(PR_BUILD_DEPOT_SHIP, 1, NULL); - case BT_BUOY: return ::GetPrice(PR_BUILD_WAYPOINT_BUOY, 1, NULL); + case BT_DOCK: return ::GetPrice(PR_BUILD_STATION_DOCK, 1, nullptr); + case BT_DEPOT: return ::GetPrice(PR_BUILD_DEPOT_SHIP, 1, nullptr); + case BT_BUOY: return ::GetPrice(PR_BUILD_WAYPOINT_BUOY, 1, nullptr); default: return -1; } } diff --git a/src/script/api/script_news.cpp b/src/script/api/script_news.cpp index 5f84f96d6..0c2ca3792 100644 --- a/src/script/api/script_news.cpp +++ b/src/script/api/script_news.cpp @@ -25,7 +25,7 @@ { CCountedPtr counter(text); - EnforcePrecondition(false, text != NULL); + EnforcePrecondition(false, text != nullptr); const char *encoded = text->GetEncodedText(); EnforcePreconditionEncodedText(false, encoded); EnforcePrecondition(false, type == NT_ECONOMY || type == NT_SUBSIDIES || type == NT_GENERAL); diff --git a/src/script/api/script_news.hpp b/src/script/api/script_news.hpp index ca0656608..441419338 100644 --- a/src/script/api/script_news.hpp +++ b/src/script/api/script_news.hpp @@ -61,7 +61,7 @@ public: * - For #NR_TOWN this parameter should be a valid townID (ScriptTown::IsValidTown). * @return True if the action succeeded. * @pre type must be #NT_ECONOMY, #NT_SUBSIDIES, or #NT_GENERAL. - * @pre text != NULL. + * @pre text != nullptr. * @pre company == COMPANY_INVALID || ResolveCompanyID(company) != COMPANY_INVALID. * @pre The \a reference condition must be fulfilled. */ diff --git a/src/script/api/script_object.cpp b/src/script/api/script_object.cpp index 7a22e3ab7..67ab7e40d 100644 --- a/src/script/api/script_object.cpp +++ b/src/script/api/script_object.cpp @@ -36,7 +36,7 @@ static ScriptStorage *GetStorage() } -/* static */ ScriptInstance *ScriptObject::ActiveInstance::active = NULL; +/* static */ ScriptInstance *ScriptObject::ActiveInstance::active = nullptr; ScriptObject::ActiveInstance::ActiveInstance(ScriptInstance *instance) { @@ -51,7 +51,7 @@ ScriptObject::ActiveInstance::~ActiveInstance() /* static */ ScriptInstance *ScriptObject::GetActiveInstance() { - assert(ScriptObject::ActiveInstance::active != NULL); + assert(ScriptObject::ActiveInstance::active != nullptr); return ScriptObject::ActiveInstance::active; } @@ -296,16 +296,16 @@ ScriptObject::ActiveInstance::~ActiveInstance() } /* Set the default callback to return a true/false result of the DoCommand */ - if (callback == NULL) callback = &ScriptInstance::DoCommandReturn; + if (callback == nullptr) callback = &ScriptInstance::DoCommandReturn; /* Are we only interested in the estimate costs? */ - bool estimate_only = GetDoCommandMode() != NULL && !GetDoCommandMode()(); + bool estimate_only = GetDoCommandMode() != nullptr && !GetDoCommandMode()(); /* Only set p2 when the command does not come from the network. */ if (GetCommandFlags(cmd) & CMD_CLIENT_ID && p2 == 0) p2 = UINT32_MAX; /* Try to perform the command. */ - CommandCost res = ::DoCommandPInternal(tile, p1, p2, cmd, (_networking && !_generating_world) ? ScriptObject::GetActiveInstance()->GetDoCommandCallback() : NULL, text, false, estimate_only); + CommandCost res = ::DoCommandPInternal(tile, p1, p2, cmd, (_networking && !_generating_world) ? ScriptObject::GetActiveInstance()->GetDoCommandCallback() : nullptr, text, false, estimate_only); /* We failed; set the error and bail out */ if (res.Failed()) { @@ -328,7 +328,7 @@ ScriptObject::ActiveInstance::~ActiveInstance() if (_generating_world) { IncreaseDoCommandCosts(res.GetCost()); - if (callback != NULL) { + if (callback != nullptr) { /* Insert return value into to stack and throw a control code that * the return value in the stack should be used. */ callback(GetActiveInstance()); diff --git a/src/script/api/script_object.hpp b/src/script/api/script_object.hpp index 482e76f66..6725f0ed1 100644 --- a/src/script/api/script_object.hpp +++ b/src/script/api/script_object.hpp @@ -69,7 +69,7 @@ protected: /** * Executes a raw DoCommand for the script. */ - static bool DoCommand(TileIndex tile, uint32 p1, uint32 p2, uint cmd, const char *text = NULL, Script_SuspendCallbackProc *callback = NULL); + static bool DoCommand(TileIndex tile, uint32 p1, uint32 p2, uint cmd, const char *text = nullptr, Script_SuspendCallbackProc *callback = nullptr); /** * Sets the DoCommand costs counter to a value. diff --git a/src/script/api/script_order.cpp b/src/script/api/script_order.cpp index a1390bf8f..04f7c69f4 100644 --- a/src/script/api/script_order.cpp +++ b/src/script/api/script_order.cpp @@ -66,7 +66,7 @@ static const Order *ResolveOrder(VehicleID vehicle_id, ScriptOrder::OrderPositio const Order *order = &v->current_order; if (order->GetType() == OT_GOTO_DEPOT && !(order->GetDepotOrderType() & ODTFB_PART_OF_ORDERS)) return order; order_position = ScriptOrder::ResolveOrderPosition(vehicle_id, order_position); - if (order_position == ScriptOrder::ORDER_INVALID) return NULL; + if (order_position == ScriptOrder::ORDER_INVALID) return nullptr; } const Order *order = v->GetFirstOrder(); while (order->GetType() == OT_IMPLICIT) order = order->next; @@ -108,7 +108,7 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr if (!IsValidVehicleOrder(vehicle_id, order_position)) return false; const Order *order = ::ResolveOrder(vehicle_id, order_position); - return order != NULL && order->GetType() == OT_GOTO_STATION; + return order != nullptr && order->GetType() == OT_GOTO_STATION; } /* static */ bool ScriptOrder::IsGotoDepotOrder(VehicleID vehicle_id, OrderPosition order_position) @@ -116,7 +116,7 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr if (!IsValidVehicleOrder(vehicle_id, order_position)) return false; const Order *order = ::ResolveOrder(vehicle_id, order_position); - return order != NULL && order->GetType() == OT_GOTO_DEPOT; + return order != nullptr && order->GetType() == OT_GOTO_DEPOT; } /* static */ bool ScriptOrder::IsGotoWaypointOrder(VehicleID vehicle_id, OrderPosition order_position) @@ -124,7 +124,7 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr if (!IsValidVehicleOrder(vehicle_id, order_position)) return false; const Order *order = ::ResolveOrder(vehicle_id, order_position); - return order != NULL && order->GetType() == OT_GOTO_WAYPOINT; + return order != nullptr && order->GetType() == OT_GOTO_WAYPOINT; } /* static */ bool ScriptOrder::IsConditionalOrder(VehicleID vehicle_id, OrderPosition order_position) @@ -150,7 +150,7 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr if (!IsValidVehicleOrder(vehicle_id, order_position)) return false; const Order *order = ::ResolveOrder(vehicle_id, order_position); - return order != NULL && order->IsRefit(); + return order != nullptr && order->IsRefit(); } /* static */ bool ScriptOrder::IsCurrentOrderPartOfOrderList(VehicleID vehicle_id) @@ -240,7 +240,7 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr if (!IsValidVehicleOrder(vehicle_id, order_position)) return INVALID_TILE; const Order *order = ::ResolveOrder(vehicle_id, order_position); - if (order == NULL || order->GetType() == OT_CONDITIONAL) return INVALID_TILE; + if (order == nullptr || order->GetType() == OT_CONDITIONAL) return INVALID_TILE; const Vehicle *v = ::Vehicle::Get(vehicle_id); switch (order->GetType()) { @@ -263,9 +263,9 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr } } else if (st->dock_tile != INVALID_TILE) { return st->dock_tile; - } else if (st->bus_stops != NULL) { + } else if (st->bus_stops != nullptr) { return st->bus_stops->xy; - } else if (st->truck_stops != NULL) { + } else if (st->truck_stops != nullptr) { return st->truck_stops->xy; } else if (st->airport.tile != INVALID_TILE) { TILE_AREA_LOOP(tile, st->airport) { @@ -294,7 +294,7 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr if (!IsValidVehicleOrder(vehicle_id, order_position)) return OF_INVALID; const Order *order = ::ResolveOrder(vehicle_id, order_position); - if (order == NULL || order->GetType() == OT_CONDITIONAL || order->GetType() == OT_DUMMY) return OF_INVALID; + if (order == nullptr || order->GetType() == OT_CONDITIONAL || order->GetType() == OT_DUMMY) return OF_INVALID; ScriptOrderFlags order_flags = OF_NONE; order_flags |= (ScriptOrderFlags)order->GetNonStopType(); @@ -586,7 +586,7 @@ static void _DoCommandReturnSetOrderFlags(class ScriptInstance *instance) EnforcePrecondition(false, (order_flags & OF_GOTO_NEAREST_DEPOT) == (current & OF_GOTO_NEAREST_DEPOT)); if ((current & OF_NON_STOP_FLAGS) != (order_flags & OF_NON_STOP_FLAGS)) { - return ScriptObject::DoCommand(0, vehicle_id | (order_pos << 20), (order_flags & OF_NON_STOP_FLAGS) << 4 | MOF_NON_STOP, CMD_MODIFY_ORDER, NULL, &::_DoCommandReturnSetOrderFlags); + return ScriptObject::DoCommand(0, vehicle_id | (order_pos << 20), (order_flags & OF_NON_STOP_FLAGS) << 4 | MOF_NON_STOP, CMD_MODIFY_ORDER, nullptr, &::_DoCommandReturnSetOrderFlags); } switch (order->GetType()) { @@ -595,16 +595,16 @@ static void _DoCommandReturnSetOrderFlags(class ScriptInstance *instance) uint data = DA_ALWAYS_GO; if (order_flags & OF_SERVICE_IF_NEEDED) data = DA_SERVICE; if (order_flags & OF_STOP_IN_DEPOT) data = DA_STOP; - return ScriptObject::DoCommand(0, vehicle_id | (order_pos << 20), (data << 4) | MOF_DEPOT_ACTION, CMD_MODIFY_ORDER, NULL, &::_DoCommandReturnSetOrderFlags); + return ScriptObject::DoCommand(0, vehicle_id | (order_pos << 20), (data << 4) | MOF_DEPOT_ACTION, CMD_MODIFY_ORDER, nullptr, &::_DoCommandReturnSetOrderFlags); } break; case OT_GOTO_STATION: if ((current & OF_UNLOAD_FLAGS) != (order_flags & OF_UNLOAD_FLAGS)) { - return ScriptObject::DoCommand(0, vehicle_id | (order_pos << 20), (order_flags & OF_UNLOAD_FLAGS) << 2 | MOF_UNLOAD, CMD_MODIFY_ORDER, NULL, &::_DoCommandReturnSetOrderFlags); + return ScriptObject::DoCommand(0, vehicle_id | (order_pos << 20), (order_flags & OF_UNLOAD_FLAGS) << 2 | MOF_UNLOAD, CMD_MODIFY_ORDER, nullptr, &::_DoCommandReturnSetOrderFlags); } if ((current & OF_LOAD_FLAGS) != (order_flags & OF_LOAD_FLAGS)) { - return ScriptObject::DoCommand(0, vehicle_id | (order_pos << 20), (order_flags & OF_LOAD_FLAGS) >> 1 | MOF_LOAD, CMD_MODIFY_ORDER, NULL, &::_DoCommandReturnSetOrderFlags); + return ScriptObject::DoCommand(0, vehicle_id | (order_pos << 20), (order_flags & OF_LOAD_FLAGS) >> 1 | MOF_LOAD, CMD_MODIFY_ORDER, nullptr, &::_DoCommandReturnSetOrderFlags); } break; diff --git a/src/script/api/script_rail.cpp b/src/script/api/script_rail.cpp index f7682cfd8..d4580fc32 100644 --- a/src/script/api/script_rail.cpp +++ b/src/script/api/script_rail.cpp @@ -25,7 +25,7 @@ /* static */ char *ScriptRail::GetName(RailType rail_type) { - if (!IsRailTypeAvailable(rail_type)) return NULL; + if (!IsRailTypeAvailable(rail_type)) return nullptr; return GetString(GetRailTypeInfo((::RailType)rail_type)->strings.menu_text); } @@ -185,7 +185,7 @@ if (res != CALLBACK_FAILED) { int index = 0; const StationSpec *spec = StationClass::GetByGrf(file->grfid, res, &index); - if (spec == NULL) { + if (spec == nullptr) { DEBUG(grf, 1, "%s returned an invalid station ID for 'AI construction/purchase selection (18)' callback", file->filename); } else { /* We might have gotten an usable station spec. Try to build it, but if it fails we'll fall back to the original station. */ @@ -487,10 +487,10 @@ static bool IsValidSignalType(int signal_type) switch (build_type) { case BT_TRACK: return ::RailBuildCost((::RailType)railtype); - case BT_SIGNAL: return ::GetPrice(PR_BUILD_SIGNALS, 1, NULL); - case BT_DEPOT: return ::GetPrice(PR_BUILD_DEPOT_TRAIN, 1, NULL); - case BT_STATION: return ::GetPrice(PR_BUILD_STATION_RAIL, 1, NULL) + ::GetPrice(PR_BUILD_STATION_RAIL_LENGTH, 1, NULL); - case BT_WAYPOINT: return ::GetPrice(PR_BUILD_WAYPOINT_RAIL, 1, NULL); + case BT_SIGNAL: return ::GetPrice(PR_BUILD_SIGNALS, 1, nullptr); + case BT_DEPOT: return ::GetPrice(PR_BUILD_DEPOT_TRAIN, 1, nullptr); + case BT_STATION: return ::GetPrice(PR_BUILD_STATION_RAIL, 1, nullptr) + ::GetPrice(PR_BUILD_STATION_RAIL_LENGTH, 1, nullptr); + case BT_WAYPOINT: return ::GetPrice(PR_BUILD_WAYPOINT_RAIL, 1, nullptr); default: return -1; } } diff --git a/src/script/api/script_road.cpp b/src/script/api/script_road.cpp index 44972cdea..74899f8bb 100644 --- a/src/script/api/script_road.cpp +++ b/src/script/api/script_road.cpp @@ -588,10 +588,10 @@ static bool NeighbourHasReachableRoad(::RoadTypes rts, TileIndex start_tile, Dia if (!ScriptRoad::IsRoadTypeAvailable(roadtype)) return -1; switch (build_type) { - case BT_ROAD: return ::GetPrice(PR_BUILD_ROAD, 1, NULL); - case BT_DEPOT: return ::GetPrice(PR_BUILD_DEPOT_ROAD, 1, NULL); - case BT_BUS_STOP: return ::GetPrice(PR_BUILD_STATION_BUS, 1, NULL); - case BT_TRUCK_STOP: return ::GetPrice(PR_BUILD_STATION_TRUCK, 1, NULL); + case BT_ROAD: return ::GetPrice(PR_BUILD_ROAD, 1, nullptr); + case BT_DEPOT: return ::GetPrice(PR_BUILD_DEPOT_ROAD, 1, nullptr); + case BT_BUS_STOP: return ::GetPrice(PR_BUILD_STATION_BUS, 1, nullptr); + case BT_TRUCK_STOP: return ::GetPrice(PR_BUILD_STATION_TRUCK, 1, nullptr); default: return -1; } } diff --git a/src/script/api/script_sign.cpp b/src/script/api/script_sign.cpp index 236e1df7e..33c8e9a28 100644 --- a/src/script/api/script_sign.cpp +++ b/src/script/api/script_sign.cpp @@ -23,7 +23,7 @@ /* static */ bool ScriptSign::IsValidSign(SignID sign_id) { const Sign *si = ::Sign::GetIfValid(sign_id); - return si != NULL && (si->owner == ScriptObject::GetCompany() || si->owner == OWNER_DEITY); + return si != nullptr && (si->owner == ScriptObject::GetCompany() || si->owner == OWNER_DEITY); } /* static */ ScriptCompany::CompanyID ScriptSign::GetOwner(SignID sign_id) @@ -38,7 +38,7 @@ CCountedPtr counter(name); EnforcePrecondition(false, IsValidSign(sign_id)); - EnforcePrecondition(false, name != NULL); + EnforcePrecondition(false, name != nullptr); const char *text = name->GetDecodedText(); EnforcePreconditionEncodedText(false, text); EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_SIGN_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG); @@ -48,7 +48,7 @@ /* static */ char *ScriptSign::GetName(SignID sign_id) { - if (!IsValidSign(sign_id)) return NULL; + if (!IsValidSign(sign_id)) return nullptr; ::SetDParam(0, sign_id); return GetString(STR_SIGN_NAME); @@ -73,7 +73,7 @@ CCountedPtr counter(name); EnforcePrecondition(INVALID_SIGN, ::IsValidTile(location)); - EnforcePrecondition(INVALID_SIGN, name != NULL); + EnforcePrecondition(INVALID_SIGN, name != nullptr); const char *text = name->GetDecodedText(); EnforcePreconditionEncodedText(INVALID_SIGN, text); EnforcePreconditionCustomError(INVALID_SIGN, ::Utf8StringLength(text) < MAX_LENGTH_SIGN_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG); diff --git a/src/script/api/script_sign.hpp b/src/script/api/script_sign.hpp index e5c2164da..4b0483e98 100644 --- a/src/script/api/script_sign.hpp +++ b/src/script/api/script_sign.hpp @@ -45,7 +45,7 @@ public: * @param sign_id The sign to set the name for. * @param name The name for the sign (can be either a raw string, or a ScriptText object). * @pre IsValidSign(sign_id). - * @pre name != NULL && len(name) != 0. + * @pre name != nullptr && len(name) != 0. * @exception ScriptError::ERR_NAME_IS_NOT_UNIQUE * @return True if and only if the name was changed. */ @@ -81,7 +81,7 @@ public: * @param location The place to build the sign. * @param name The text to place on the sign (can be either a raw string, or a ScriptText object). * @pre ScriptMap::IsValidTile(location). - * @pre name != NULL && len(name) != 0. + * @pre name != nullptr && len(name) != 0. * @exception ScriptSign::ERR_SIGN_TOO_MANY_SIGNS * @return The SignID of the build sign (use IsValidSign() to check for validity). * In test-mode it returns 0 if successful, or any other value to indicate diff --git a/src/script/api/script_station.cpp b/src/script/api/script_station.cpp index 5ed43e0a6..3b3bae33c 100644 --- a/src/script/api/script_station.cpp +++ b/src/script/api/script_station.cpp @@ -23,7 +23,7 @@ /* static */ bool ScriptStation::IsValidStation(StationID station_id) { const Station *st = ::Station::GetIfValid(station_id); - return st != NULL && (st->owner == ScriptObject::GetCompany() || ScriptObject::GetCompany() == OWNER_DEITY || st->owner == OWNER_NONE); + return st != nullptr && (st->owner == ScriptObject::GetCompany() || ScriptObject::GetCompany() == OWNER_DEITY || st->owner == OWNER_NONE); } /* static */ ScriptCompany::CompanyID ScriptStation::GetOwner(StationID station_id) @@ -213,10 +213,10 @@ template ::RoadTypes r = RoadTypeToRoadTypes((::RoadType)road_type); - for (const RoadStop *rs = ::Station::Get(station_id)->GetPrimaryRoadStop(ROADSTOP_BUS); rs != NULL; rs = rs->next) { + for (const RoadStop *rs = ::Station::Get(station_id)->GetPrimaryRoadStop(ROADSTOP_BUS); rs != nullptr; rs = rs->next) { if ((::GetRoadTypes(rs->xy) & r) != 0) return true; } - for (const RoadStop *rs = ::Station::Get(station_id)->GetPrimaryRoadStop(ROADSTOP_TRUCK); rs != NULL; rs = rs->next) { + for (const RoadStop *rs = ::Station::Get(station_id)->GetPrimaryRoadStop(ROADSTOP_TRUCK); rs != nullptr; rs = rs->next) { if ((::GetRoadTypes(rs->xy) & r) != 0) return true; } diff --git a/src/script/api/script_stationlist.cpp b/src/script/api/script_stationlist.cpp index 51a06b5a7..4bbb5fa67 100644 --- a/src/script/api/script_stationlist.cpp +++ b/src/script/api/script_stationlist.cpp @@ -32,7 +32,7 @@ ScriptStationList_Vehicle::ScriptStationList_Vehicle(VehicleID vehicle_id) Vehicle *v = ::Vehicle::Get(vehicle_id); - for (Order *o = v->GetFirstOrder(); o != NULL; o = o->next) { + for (Order *o = v->GetFirstOrder(); o != nullptr; o = o->next) { if (o->IsType(OT_GOTO_STATION)) this->AddItem(o->GetDestination()); } } @@ -120,7 +120,7 @@ private: CargoCollector::CargoCollector(ScriptStationList_Cargo *parent, StationID station_id, CargoID cargo, StationID other) : - list(parent), ge(NULL), other_station(other), last_key(INVALID_STATION), amount(0) + list(parent), ge(nullptr), other_station(other), last_key(INVALID_STATION), amount(0) { if (!ScriptStation::IsValidStation(station_id)) return; if (!ScriptCargo::IsValidCargo(cargo)) return; @@ -176,7 +176,7 @@ template void ScriptStationList_CargoWaiting::Add(StationID station_id, CargoID cargo, StationID other_station) { CargoCollector collector(this, station_id, cargo, other_station); - if (collector.GE() == NULL) return; + if (collector.GE() == nullptr) return; StationCargoList::ConstIterator iter = collector.GE()->cargo.Packets()->begin(); StationCargoList::ConstIterator end = collector.GE()->cargo.Packets()->end(); @@ -190,7 +190,7 @@ template void ScriptStationList_CargoPlanned::Add(StationID station_id, CargoID cargo, StationID other_station) { CargoCollector collector(this, station_id, cargo, other_station); - if (collector.GE() == NULL) return; + if (collector.GE() == nullptr) return; FlowStatMap::const_iterator iter = collector.GE()->flows.begin(); FlowStatMap::const_iterator end = collector.GE()->flows.end(); @@ -215,7 +215,7 @@ ScriptStationList_CargoWaitingViaByFrom::ScriptStationList_CargoWaitingViaByFrom StationID station_id, CargoID cargo, StationID via) { CargoCollector collector(this, station_id, cargo, via); - if (collector.GE() == NULL) return; + if (collector.GE() == nullptr) return; std::pair range = collector.GE()->cargo.Packets()->equal_range(via); @@ -261,7 +261,7 @@ ScriptStationList_CargoPlannedFromByVia::ScriptStationList_CargoPlannedFromByVia StationID station_id, CargoID cargo, StationID from) { CargoCollector collector(this, station_id, cargo, from); - if (collector.GE() == NULL) return; + if (collector.GE() == nullptr) return; FlowStatMap::const_iterator iter = collector.GE()->flows.find(from); if (iter == collector.GE()->flows.end()) return; diff --git a/src/script/api/script_story_page.cpp b/src/script/api/script_story_page.cpp index 11820ec3f..e31ad71c3 100644 --- a/src/script/api/script_story_page.cpp +++ b/src/script/api/script_story_page.cpp @@ -48,7 +48,7 @@ c, 0, CMD_CREATE_STORY_PAGE, - title != NULL? title->GetEncodedText() : NULL, + title != nullptr? title->GetEncodedText() : nullptr, &ScriptInstance::DoCommandReturnStoryPageID)) return STORY_PAGE_INVALID; /* In case of test-mode, we return StoryPageID 0 */ @@ -61,7 +61,7 @@ EnforcePrecondition(STORY_PAGE_ELEMENT_INVALID, ScriptObject::GetCompany() == OWNER_DEITY); EnforcePrecondition(STORY_PAGE_ELEMENT_INVALID, IsValidStoryPage(story_page_id)); - EnforcePrecondition(STORY_PAGE_ELEMENT_INVALID, (type != SPET_TEXT && type != SPET_LOCATION) || (text != NULL && !StrEmpty(text->GetEncodedText()))); + EnforcePrecondition(STORY_PAGE_ELEMENT_INVALID, (type != SPET_TEXT && type != SPET_LOCATION) || (text != nullptr && !StrEmpty(text->GetEncodedText()))); EnforcePrecondition(STORY_PAGE_ELEMENT_INVALID, type != SPET_LOCATION || ::IsValidTile(reference)); EnforcePrecondition(STORY_PAGE_ELEMENT_INVALID, type != SPET_GOAL || ScriptGoal::IsValidGoal((ScriptGoal::GoalID)reference)); EnforcePrecondition(STORY_PAGE_ELEMENT_INVALID, type != SPET_GOAL || !(StoryPage::Get(story_page_id)->company == INVALID_COMPANY && Goal::Get(reference)->company != INVALID_COMPANY)); @@ -70,7 +70,7 @@ story_page_id + (type << 16), type == SPET_GOAL ? reference : 0, CMD_CREATE_STORY_PAGE_ELEMENT, - type == SPET_TEXT || type == SPET_LOCATION ? text->GetEncodedText() : NULL, + type == SPET_TEXT || type == SPET_LOCATION ? text->GetEncodedText() : nullptr, &ScriptInstance::DoCommandReturnStoryPageElementID)) return STORY_PAGE_ELEMENT_INVALID; /* In case of test-mode, we return StoryPageElementID 0 */ @@ -88,7 +88,7 @@ StoryPage *p = StoryPage::Get(pe->page); ::StoryPageElementType type = pe->type; - EnforcePrecondition(false, (type != ::SPET_TEXT && type != ::SPET_LOCATION) || (text != NULL && !StrEmpty(text->GetEncodedText()))); + EnforcePrecondition(false, (type != ::SPET_TEXT && type != ::SPET_LOCATION) || (text != nullptr && !StrEmpty(text->GetEncodedText()))); EnforcePrecondition(false, type != ::SPET_LOCATION || ::IsValidTile(reference)); EnforcePrecondition(false, type != ::SPET_GOAL || ScriptGoal::IsValidGoal((ScriptGoal::GoalID)reference)); EnforcePrecondition(false, type != ::SPET_GOAL || !(p->company == INVALID_COMPANY && Goal::Get(reference)->company != INVALID_COMPANY)); @@ -97,7 +97,7 @@ story_page_element_id, type == ::SPET_GOAL ? reference : 0, CMD_UPDATE_STORY_PAGE_ELEMENT, - type == ::SPET_TEXT || type == ::SPET_LOCATION ? text->GetEncodedText() : NULL); + type == ::SPET_TEXT || type == ::SPET_LOCATION ? text->GetEncodedText() : nullptr); } /* static */ uint32 ScriptStoryPage::GetPageSortValue(StoryPageID story_page_id) @@ -121,7 +121,7 @@ EnforcePrecondition(false, IsValidStoryPage(story_page_id)); EnforcePrecondition(false, ScriptObject::GetCompany() == OWNER_DEITY); - return ScriptObject::DoCommand(0, story_page_id, 0, CMD_SET_STORY_PAGE_TITLE, title != NULL? title->GetEncodedText() : NULL); + return ScriptObject::DoCommand(0, story_page_id, 0, CMD_SET_STORY_PAGE_TITLE, title != nullptr? title->GetEncodedText() : nullptr); } /* static */ ScriptCompany::CompanyID ScriptStoryPage::GetCompany(StoryPageID story_page_id) @@ -147,7 +147,7 @@ EnforcePrecondition(false, IsValidStoryPage(story_page_id)); EnforcePrecondition(false, ScriptObject::GetCompany() == OWNER_DEITY); - return ScriptObject::DoCommand(0, story_page_id, date, CMD_SET_STORY_PAGE_DATE, NULL); + return ScriptObject::DoCommand(0, story_page_id, date, CMD_SET_STORY_PAGE_DATE, nullptr); } diff --git a/src/script/api/script_story_page.hpp b/src/script/api/script_story_page.hpp index c22d4c198..772c16200 100644 --- a/src/script/api/script_story_page.hpp +++ b/src/script/api/script_story_page.hpp @@ -97,7 +97,7 @@ public: * @return The new StoryPageElementID, or STORY_PAGE_ELEMENT_INVALID if it failed. * @pre No ScriptCompanyMode may be in scope. * @pre IsValidStoryPage(story_page). - * @pre (type != SPET_TEXT && type != SPET_LOCATION) || (text != NULL && len(text) != 0). + * @pre (type != SPET_TEXT && type != SPET_LOCATION) || (text != nullptr && len(text) != 0). * @pre type != SPET_LOCATION || ScriptMap::IsValidTile(reference). * @pre type != SPET_GOAL || ScriptGoal::IsValidGoal(reference). * @pre if type is SPET_GOAL and story_page is a global page, then referenced goal must be global. @@ -112,7 +112,7 @@ public: * @return True if the action succeeded. * @pre No ScriptCompanyMode may be in scope. * @pre IsValidStoryPage(story_page). - * @pre (type != SPET_TEXT && type != SPET_LOCATION) || (text != NULL && len(text) != 0). + * @pre (type != SPET_TEXT && type != SPET_LOCATION) || (text != nullptr && len(text) != 0). * @pre type != SPET_LOCATION || ScriptMap::IsValidTile(reference). * @pre type != SPET_GOAL || ScriptGoal::IsValidGoal(reference). * @pre if type is SPET_GOAL and story_page is a global page, then referenced goal must be global. diff --git a/src/script/api/script_text.cpp b/src/script/api/script_text.cpp index e692be0ae..bfc866ac4 100644 --- a/src/script/api/script_text.cpp +++ b/src/script/api/script_text.cpp @@ -63,7 +63,7 @@ ScriptText::~ScriptText() { for (int i = 0; i < SCRIPT_TEXT_MAX_PARAMETERS; i++) { free(this->params[i]); - if (this->paramt[i] != NULL) this->paramt[i]->Release(); + if (this->paramt[i] != nullptr) this->paramt[i]->Release(); } } @@ -72,11 +72,11 @@ SQInteger ScriptText::_SetParam(int parameter, HSQUIRRELVM vm) if (parameter >= SCRIPT_TEXT_MAX_PARAMETERS) return SQ_ERROR; free(this->params[parameter]); - if (this->paramt[parameter] != NULL) this->paramt[parameter]->Release(); + if (this->paramt[parameter] != nullptr) this->paramt[parameter]->Release(); this->parami[parameter] = 0; - this->params[parameter] = NULL; - this->paramt[parameter] = NULL; + this->params[parameter] = nullptr; + this->paramt[parameter] = nullptr; switch (sq_gettype(vm, -1)) { case OT_STRING: { @@ -97,7 +97,7 @@ SQInteger ScriptText::_SetParam(int parameter, HSQUIRRELVM vm) } case OT_INSTANCE: { - SQUserPointer real_instance = NULL; + SQUserPointer real_instance = nullptr; HSQOBJECT instance; sq_getstackobj(vm, -1, &instance); @@ -112,7 +112,7 @@ SQInteger ScriptText::_SetParam(int parameter, HSQUIRRELVM vm) /* Get the 'real' instance of this class */ sq_getinstanceup(vm, -1, &real_instance, 0); - if (real_instance == NULL) return SQ_ERROR; + if (real_instance == nullptr) return SQ_ERROR; ScriptText *value = static_cast(real_instance); value->AddRef(); @@ -183,7 +183,7 @@ const char *ScriptText::GetEncodedText() static char buf[1024]; int param_count = 0; this->_GetEncodedText(buf, lastof(buf), param_count); - return (param_count > SCRIPT_TEXT_MAX_PARAMETERS) ? NULL : buf; + return (param_count > SCRIPT_TEXT_MAX_PARAMETERS) ? nullptr : buf; } char *ScriptText::_GetEncodedText(char *p, char *lastofp, int ¶m_count) @@ -191,12 +191,12 @@ char *ScriptText::_GetEncodedText(char *p, char *lastofp, int ¶m_count) p += Utf8Encode(p, SCC_ENCODED); p += seprintf(p, lastofp, "%X", this->string); for (int i = 0; i < this->paramc; i++) { - if (this->params[i] != NULL) { + if (this->params[i] != nullptr) { p += seprintf(p, lastofp, ":\"%s\"", this->params[i]); param_count++; continue; } - if (this->paramt[i] != NULL) { + if (this->paramt[i] != nullptr) { p += seprintf(p, lastofp, ":"); p = this->paramt[i]->_GetEncodedText(p, lastofp, param_count); continue; @@ -211,7 +211,7 @@ char *ScriptText::_GetEncodedText(char *p, char *lastofp, int ¶m_count) const char *Text::GetDecodedText() { const char *encoded_text = this->GetEncodedText(); - if (encoded_text == NULL) return NULL; + if (encoded_text == nullptr) return nullptr; static char buf[1024]; ::SetDParamStr(0, encoded_text); diff --git a/src/script/api/script_text.hpp b/src/script/api/script_text.hpp index 0b82ffb20..12892a7e7 100644 --- a/src/script/api/script_text.hpp +++ b/src/script/api/script_text.hpp @@ -23,14 +23,14 @@ class Text : public ScriptObject { public: /** * Convert a ScriptText to a normal string. - * @return A string (in a static buffer), or NULL. + * @return A string (in a static buffer), or nullptr. * @api -all */ virtual const char *GetEncodedText() = 0; /** * Convert a #ScriptText into a decoded normal string. - * @return A string (in a static buffer), or NULL. + * @return A string (in a static buffer), or nullptr. * @api -all */ const char *GetDecodedText(); diff --git a/src/script/api/script_tile.cpp b/src/script/api/script_tile.cpp index db9220acd..136461762 100644 --- a/src/script/api/script_tile.cpp +++ b/src/script/api/script_tile.cpp @@ -292,7 +292,7 @@ if (!::IsValidTile(tile)) return INVALID_TOWN; Town *town = ::ClosestTownFromTile(tile, _settings_game.economy.dist_local_authority); - if (town == NULL) return INVALID_TOWN; + if (town == nullptr) return INVALID_TOWN; return town->index; } @@ -302,7 +302,7 @@ if (!::IsValidTile(tile)) return INVALID_TOWN; Town *town = ::ClosestTownFromTile(tile, UINT_MAX); - if (town == NULL) return INVALID_TOWN; + if (town == nullptr) return INVALID_TOWN; return town->index; } @@ -310,14 +310,14 @@ /* static */ Money ScriptTile::GetBuildCost(BuildType build_type) { switch (build_type) { - case BT_FOUNDATION: return ::GetPrice(PR_BUILD_FOUNDATION, 1, NULL); - case BT_TERRAFORM: return ::GetPrice(PR_TERRAFORM, 1, NULL); - case BT_BUILD_TREES: return ::GetPrice(PR_BUILD_TREES, 1, NULL); - case BT_CLEAR_GRASS: return ::GetPrice(PR_CLEAR_GRASS, 1, NULL); - case BT_CLEAR_ROUGH: return ::GetPrice(PR_CLEAR_ROUGH, 1, NULL); - case BT_CLEAR_ROCKY: return ::GetPrice(PR_CLEAR_ROCKS, 1, NULL); - case BT_CLEAR_FIELDS: return ::GetPrice(PR_CLEAR_FIELDS, 1, NULL); - case BT_CLEAR_HOUSE: return ::GetPrice(PR_CLEAR_HOUSE, 1, NULL); + case BT_FOUNDATION: return ::GetPrice(PR_BUILD_FOUNDATION, 1, nullptr); + case BT_TERRAFORM: return ::GetPrice(PR_TERRAFORM, 1, nullptr); + case BT_BUILD_TREES: return ::GetPrice(PR_BUILD_TREES, 1, nullptr); + case BT_CLEAR_GRASS: return ::GetPrice(PR_CLEAR_GRASS, 1, nullptr); + case BT_CLEAR_ROUGH: return ::GetPrice(PR_CLEAR_ROUGH, 1, nullptr); + case BT_CLEAR_ROCKY: return ::GetPrice(PR_CLEAR_ROCKS, 1, nullptr); + case BT_CLEAR_FIELDS: return ::GetPrice(PR_CLEAR_FIELDS, 1, nullptr); + case BT_CLEAR_HOUSE: return ::GetPrice(PR_CLEAR_HOUSE, 1, nullptr); default: return -1; } } diff --git a/src/script/api/script_town.cpp b/src/script/api/script_town.cpp index 64f8e166e..9adfa5075 100644 --- a/src/script/api/script_town.cpp +++ b/src/script/api/script_town.cpp @@ -35,7 +35,7 @@ /* static */ char *ScriptTown::GetName(TownID town_id) { - if (!IsValidTown(town_id)) return NULL; + if (!IsValidTown(town_id)) return nullptr; ::SetDParam(0, town_id); return GetString(STR_TOWN_NAME); @@ -45,8 +45,8 @@ { CCountedPtr counter(name); - const char *text = NULL; - if (name != NULL) { + const char *text = nullptr; + if (name != nullptr) { text = name->GetDecodedText(); EnforcePreconditionEncodedText(false, text); EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_TOWN_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG); @@ -60,7 +60,7 @@ { CCountedPtr counter(text); - EnforcePrecondition(false, text != NULL); + EnforcePrecondition(false, text != nullptr); const char *encoded_text = text->GetEncodedText(); EnforcePreconditionEncodedText(false, encoded_text); EnforcePrecondition(false, IsValidTown(town_id)); @@ -257,7 +257,7 @@ if (ScriptObject::GetCompany() == OWNER_DEITY) return false; if (!IsValidTown(town_id)) return false; - return HasBit(::GetMaskOfTownActions(NULL, ScriptObject::GetCompany(), ::Town::Get(town_id)), town_action); + return HasBit(::GetMaskOfTownActions(nullptr, ScriptObject::GetCompany(), ::Town::Get(town_id)), town_action); } /* static */ bool ScriptTown::PerformTownAction(TownID town_id, TownAction town_action) @@ -293,8 +293,8 @@ layout = (RoadLayout) (byte)_settings_game.economy.town_layout; } - const char *text = NULL; - if (name != NULL) { + const char *text = nullptr; + if (name != nullptr) { text = name->GetDecodedText(); EnforcePreconditionEncodedText(false, text); EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_TOWN_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG); diff --git a/src/script/api/script_town.hpp b/src/script/api/script_town.hpp index 7fdf8a6b3..302c676eb 100644 --- a/src/script/api/script_town.hpp +++ b/src/script/api/script_town.hpp @@ -148,7 +148,7 @@ public: /** * Rename a town. * @param town_id The town to rename - * @param name The new name of the town. If NULL or an empty string is passed, the town name will be reset to the default name. + * @param name The new name of the town. If nullptr or an empty string is passed, the town name will be reset to the default name. * @pre IsValidTown(town_id). * @return True if the action succeeded. * @api -ai @@ -402,7 +402,7 @@ public: * @param size The town size of the new town. * @param city True if the new town should be a city. * @param layout The town layout of the new town. - * @param name The name of the new town. Pass NULL to use a random town name. + * @param name The name of the new town. Pass nullptr to use a random town name. * @game @pre no company mode in scope || ScriptSettings.GetValue("economy.found_town") != 0. * @ai @pre ScriptSettings.GetValue("economy.found_town") != 0. * @game @pre no company mode in scope || size != TOWN_SIZE_LARGE. diff --git a/src/script/api/script_tunnel.cpp b/src/script/api/script_tunnel.cpp index 7b891f28d..a8bfcbfd3 100644 --- a/src/script/api/script_tunnel.cpp +++ b/src/script/api/script_tunnel.cpp @@ -102,7 +102,7 @@ static void _DoCommandReturnBuildTunnel1(class ScriptInstance *instance) } ScriptObject::SetCallbackVariable(0, start); - return ScriptObject::DoCommand(start, type, 0, CMD_BUILD_TUNNEL, NULL, &::_DoCommandReturnBuildTunnel1); + return ScriptObject::DoCommand(start, type, 0, CMD_BUILD_TUNNEL, nullptr, &::_DoCommandReturnBuildTunnel1); } /* static */ bool ScriptTunnel::_BuildTunnelRoad1() @@ -114,7 +114,7 @@ static void _DoCommandReturnBuildTunnel1(class ScriptInstance *instance) DiagDirection dir_1 = ::DiagdirBetweenTiles(end, start); DiagDirection dir_2 = ::ReverseDiagDir(dir_1); - return ScriptObject::DoCommand(start + ::TileOffsByDiagDir(dir_1), ::DiagDirToRoadBits(dir_2) | (ScriptObject::GetRoadType() << 4), 0, CMD_BUILD_ROAD, NULL, &::_DoCommandReturnBuildTunnel2); + return ScriptObject::DoCommand(start + ::TileOffsByDiagDir(dir_1), ::DiagDirToRoadBits(dir_2) | (ScriptObject::GetRoadType() << 4), 0, CMD_BUILD_ROAD, nullptr, &::_DoCommandReturnBuildTunnel2); } /* static */ bool ScriptTunnel::_BuildTunnelRoad2() diff --git a/src/script/api/script_vehicle.cpp b/src/script/api/script_vehicle.cpp index f5023d12c..15bc68a97 100644 --- a/src/script/api/script_vehicle.cpp +++ b/src/script/api/script_vehicle.cpp @@ -29,7 +29,7 @@ /* static */ bool ScriptVehicle::IsValidVehicle(VehicleID vehicle_id) { const Vehicle *v = ::Vehicle::GetIfValid(vehicle_id); - return v != NULL && (v->owner == ScriptObject::GetCompany() || ScriptObject::GetCompany() == OWNER_DEITY) && (v->IsPrimaryVehicle() || (v->type == VEH_TRAIN && ::Train::From(v)->IsFreeWagon())); + return v != nullptr && (v->owner == ScriptObject::GetCompany() || ScriptObject::GetCompany() == OWNER_DEITY) && (v->IsPrimaryVehicle() || (v->type == VEH_TRAIN && ::Train::From(v)->IsFreeWagon())); } /* static */ ScriptCompany::CompanyID ScriptVehicle::GetOwner(VehicleID vehicle_id) @@ -46,8 +46,8 @@ int num = 1; const Train *v = ::Train::GetIfValid(vehicle_id); - if (v != NULL) { - while ((v = v->GetNextUnit()) != NULL) num++; + if (v != nullptr) { + while ((v = v->GetNextUnit()) != nullptr) num++; } return num; @@ -71,7 +71,7 @@ EnforcePreconditionCustomError(VEHICLE_INVALID, !ScriptGameSettings::IsDisabledVehicleType((ScriptVehicle::VehicleType)type), ScriptVehicle::ERR_VEHICLE_BUILD_DISABLED); - if (!ScriptObject::DoCommand(depot, engine_id | (cargo << 24), 0, ::GetCmdBuildVeh(type), NULL, &ScriptInstance::DoCommandReturnVehicleID)) return VEHICLE_INVALID; + if (!ScriptObject::DoCommand(depot, engine_id | (cargo << 24), 0, ::GetCmdBuildVeh(type), nullptr, &ScriptInstance::DoCommandReturnVehicleID)) return VEHICLE_INVALID; /* In case of test-mode, we return VehicleID 0 */ return 0; @@ -104,7 +104,7 @@ EnforcePrecondition(false, ScriptObject::GetCompany() != OWNER_DEITY); EnforcePrecondition(false, IsValidVehicle(vehicle_id)); - if (!ScriptObject::DoCommand(depot, vehicle_id, share_orders, CMD_CLONE_VEHICLE, NULL, &ScriptInstance::DoCommandReturnVehicleID)) return VEHICLE_INVALID; + if (!ScriptObject::DoCommand(depot, vehicle_id, share_orders, CMD_CLONE_VEHICLE, nullptr, &ScriptInstance::DoCommandReturnVehicleID)) return VEHICLE_INVALID; /* In case of test-mode, we return VehicleID 0 */ return 0; @@ -120,13 +120,13 @@ const Train *v = ::Train::Get(source_vehicle_id); while (source_wagon-- > 0) v = v->GetNextUnit(); - const Train *w = NULL; + const Train *w = nullptr; if (dest_vehicle_id != -1) { w = ::Train::Get(dest_vehicle_id); while (dest_wagon-- > 0) w = w->GetNextUnit(); } - return ScriptObject::DoCommand(0, v->index | (move_attached_wagons ? 1 : 0) << 20, w == NULL ? ::INVALID_VEHICLE : w->index, CMD_MOVE_RAIL_VEHICLE); + return ScriptObject::DoCommand(0, v->index | (move_attached_wagons ? 1 : 0) << 20, w == nullptr ? ::INVALID_VEHICLE : w->index, CMD_MOVE_RAIL_VEHICLE); } /* static */ bool ScriptVehicle::MoveWagon(VehicleID source_vehicle_id, int source_wagon, int dest_vehicle_id, int dest_wagon) @@ -243,7 +243,7 @@ EnforcePrecondition(false, ScriptObject::GetCompany() != OWNER_DEITY); EnforcePrecondition(false, IsValidVehicle(vehicle_id)); - EnforcePrecondition(false, name != NULL); + EnforcePrecondition(false, name != nullptr); const char *text = name->GetDecodedText(); EnforcePreconditionEncodedText(false, text); EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_VEHICLE_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG); @@ -293,7 +293,7 @@ /* static */ char *ScriptVehicle::GetName(VehicleID vehicle_id) { - if (!IsValidVehicle(vehicle_id)) return NULL; + if (!IsValidVehicle(vehicle_id)) return nullptr; ::SetDParam(0, vehicle_id); return GetString(STR_VEHICLE_NAME); @@ -410,7 +410,7 @@ if (!ScriptCargo::IsValidCargo(cargo)) return -1; uint32 amount = 0; - for (const Vehicle *v = ::Vehicle::Get(vehicle_id); v != NULL; v = v->Next()) { + for (const Vehicle *v = ::Vehicle::Get(vehicle_id); v != nullptr; v = v->Next()) { if (v->cargo_type == cargo) amount += v->cargo_cap; } @@ -423,7 +423,7 @@ if (!ScriptCargo::IsValidCargo(cargo)) return -1; uint32 amount = 0; - for (const Vehicle *v = ::Vehicle::Get(vehicle_id); v != NULL; v = v->Next()) { + for (const Vehicle *v = ::Vehicle::Get(vehicle_id); v != nullptr; v = v->Next()) { if (v->cargo_type == cargo) amount += v->cargo.StoredCount(); } @@ -455,7 +455,7 @@ if (!IsValidVehicle(vehicle_id)) return false; Vehicle *v = ::Vehicle::Get(vehicle_id); - return v->orders.list != NULL && v->orders.list->GetNumVehicles() > 1; + return v->orders.list != nullptr && v->orders.list->GetNumVehicles() > 1; } /* static */ int ScriptVehicle::GetReliability(VehicleID vehicle_id) diff --git a/src/script/api/script_vehicle.hpp b/src/script/api/script_vehicle.hpp index d027e1243..58a0319d0 100644 --- a/src/script/api/script_vehicle.hpp +++ b/src/script/api/script_vehicle.hpp @@ -115,7 +115,7 @@ public: * @param vehicle_id The vehicle to set the name for. * @param name The name for the vehicle (can be either a raw string, or a ScriptText object). * @pre IsValidVehicle(vehicle_id). - * @pre name != NULL && len(name) != 0. + * @pre name != nullptr && len(name) != 0. * @game @pre Valid ScriptCompanyMode active in scope. * @exception ScriptError::ERR_NAME_IS_NOT_UNIQUE * @return True if and only if the name was changed. diff --git a/src/script/api/script_vehiclelist.cpp b/src/script/api/script_vehiclelist.cpp index 625f0f8c4..48b290cae 100644 --- a/src/script/api/script_vehiclelist.cpp +++ b/src/script/api/script_vehiclelist.cpp @@ -101,7 +101,7 @@ ScriptVehicleList_SharedOrders::ScriptVehicleList_SharedOrders(VehicleID vehicle { if (!ScriptVehicle::IsValidVehicle(vehicle_id)) return; - for (const Vehicle *v = Vehicle::Get(vehicle_id)->FirstShared(); v != NULL; v = v->NextShared()) { + for (const Vehicle *v = Vehicle::Get(vehicle_id)->FirstShared(); v != nullptr; v = v->NextShared()) { this->AddItem(v->index); } } diff --git a/src/script/api/script_waypoint.cpp b/src/script/api/script_waypoint.cpp index 91733a38e..3d121a2dc 100644 --- a/src/script/api/script_waypoint.cpp +++ b/src/script/api/script_waypoint.cpp @@ -20,7 +20,7 @@ /* static */ bool ScriptWaypoint::IsValidWaypoint(StationID waypoint_id) { const Waypoint *wp = ::Waypoint::GetIfValid(waypoint_id); - return wp != NULL && (wp->owner == ScriptObject::GetCompany() || ScriptObject::GetCompany() == OWNER_DEITY || wp->owner == OWNER_NONE); + return wp != nullptr && (wp->owner == ScriptObject::GetCompany() || ScriptObject::GetCompany() == OWNER_DEITY || wp->owner == OWNER_NONE); } /* static */ StationID ScriptWaypoint::GetWaypointID(TileIndex tile) diff --git a/src/script/api/script_waypointlist.cpp b/src/script/api/script_waypointlist.cpp index dd641a684..7e0b45a5b 100644 --- a/src/script/api/script_waypointlist.cpp +++ b/src/script/api/script_waypointlist.cpp @@ -32,7 +32,7 @@ ScriptWaypointList_Vehicle::ScriptWaypointList_Vehicle(VehicleID vehicle_id) const Vehicle *v = ::Vehicle::Get(vehicle_id); - for (const Order *o = v->GetFirstOrder(); o != NULL; o = o->next) { + for (const Order *o = v->GetFirstOrder(); o != nullptr; o = o->next) { if (o->IsType(OT_GOTO_WAYPOINT)) this->AddItem(o->GetDestination()); } } diff --git a/src/script/api/script_window.cpp b/src/script/api/script_window.cpp index 1252f0fc7..2766a0562 100644 --- a/src/script/api/script_window.cpp +++ b/src/script/api/script_window.cpp @@ -34,10 +34,10 @@ if (ScriptGame::IsMultiplayer()) return false; if (number == NUMBER_ALL) { - return (FindWindowByClass((::WindowClass)window) != NULL); + return (FindWindowByClass((::WindowClass)window) != nullptr); } - return FindWindowById((::WindowClass)window, number) != NULL; + return FindWindowById((::WindowClass)window, number) != nullptr; } /* static */ void ScriptWindow::Highlight(WindowClass window, uint32 number, uint8 widget, TextColour colour) @@ -56,6 +56,6 @@ } const NWidgetBase *wid = w->GetWidget(widget); - if (wid == NULL) return; + if (wid == nullptr) return; w->SetWidgetHighlight(widget, (::TextColour)colour); } -- cgit v1.2.3-54-g00ecf