diff options
Diffstat (limited to 'src/script')
63 files changed, 338 insertions, 338 deletions
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<Text> 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<Text> 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<Text> 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<Text> 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<Text> 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<Text> 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<Text> 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<Text> 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<bool Tfrom, bool Tvia> ::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<ScriptStationList_Cargo::CargoSelector Tselector> 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<ScriptStationList_Cargo::CargoSelector Tselector> 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<StationCargoList::ConstIterator, StationCargoList::ConstIterator> 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<ScriptText *>(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<Text> 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<Text> 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<NWidgetBase>(widget); - if (wid == NULL) return; + if (wid == nullptr) return; w->SetWidgetHighlight(widget, (::TextColour)colour); } diff --git a/src/script/script_config.cpp b/src/script/script_config.cpp index 3171e67d4..e9b0f69bc 100644 --- a/src/script/script_config.cpp +++ b/src/script/script_config.cpp @@ -21,17 +21,17 @@ void ScriptConfig::Change(const char *name, int version, bool force_exact_match, bool is_random) { free(this->name); - this->name = (name == NULL) ? NULL : stredup(name); - this->info = (name == NULL) ? NULL : this->FindInfo(this->name, version, force_exact_match); - this->version = (info == NULL) ? -1 : info->GetVersion(); + this->name = (name == nullptr) ? nullptr : stredup(name); + this->info = (name == nullptr) ? nullptr : this->FindInfo(this->name, version, force_exact_match); + this->version = (info == nullptr) ? -1 : info->GetVersion(); this->is_random = is_random; - if (this->config_list != NULL) delete this->config_list; - this->config_list = (info == NULL) ? NULL : new ScriptConfigItemList(); - if (this->config_list != NULL) this->PushExtraConfigList(); + if (this->config_list != nullptr) delete this->config_list; + this->config_list = (info == nullptr) ? nullptr : new ScriptConfigItemList(); + if (this->config_list != nullptr) this->PushExtraConfigList(); this->ClearConfigList(); - if (_game_mode == GM_NORMAL && this->info != NULL) { + if (_game_mode == GM_NORMAL && this->info != nullptr) { /* If we're in an existing game and the Script is changed, set all settings * for the Script that have the random flag to a random value. */ for (ScriptConfigItemList::const_iterator it = this->info->GetConfigList()->begin(); it != this->info->GetConfigList()->end(); it++) { @@ -45,10 +45,10 @@ void ScriptConfig::Change(const char *name, int version, bool force_exact_match, ScriptConfig::ScriptConfig(const ScriptConfig *config) { - this->name = (config->name == NULL) ? NULL : stredup(config->name); + this->name = (config->name == nullptr) ? nullptr : stredup(config->name); this->info = config->info; this->version = config->version; - this->config_list = NULL; + this->config_list = nullptr; this->is_random = config->is_random; for (SettingValueList::const_iterator it = config->settings.begin(); it != config->settings.end(); it++) { @@ -61,7 +61,7 @@ ScriptConfig::~ScriptConfig() { free(this->name); this->ResetSettings(); - if (this->config_list != NULL) delete this->config_list; + if (this->config_list != nullptr) delete this->config_list; } ScriptInfo *ScriptConfig::GetInfo() const @@ -71,8 +71,8 @@ ScriptInfo *ScriptConfig::GetInfo() const const ScriptConfigItemList *ScriptConfig::GetConfigList() { - if (this->info != NULL) return this->info->GetConfigList(); - if (this->config_list == NULL) { + if (this->info != nullptr) return this->info->GetConfigList(); + if (this->config_list == nullptr) { this->config_list = new ScriptConfigItemList(); this->PushExtraConfigList(); } @@ -106,10 +106,10 @@ int ScriptConfig::GetSetting(const char *name) const void ScriptConfig::SetSetting(const char *name, int value) { /* You can only set Script specific settings if an Script is selected. */ - if (this->info == NULL) return; + if (this->info == nullptr) return; const ScriptConfigItem *config_item = this->info->GetConfigItem(name); - if (config_item == NULL) return; + if (config_item == nullptr) return; value = Clamp(value, config_item->min_value, config_item->max_value); @@ -140,7 +140,7 @@ void ScriptConfig::AddRandomDeviation() bool ScriptConfig::HasScript() const { - return this->info != NULL; + return this->info != nullptr; } bool ScriptConfig::IsRandom() const @@ -163,18 +163,18 @@ void ScriptConfig::StringToSettings(const char *value) char *value_copy = stredup(value); char *s = value_copy; - while (s != NULL) { + while (s != nullptr) { /* Analyze the string ('name=value,name=value\0') */ char *item_name = s; s = strchr(s, '='); - if (s == NULL) break; + if (s == nullptr) break; if (*s == '\0') break; *s = '\0'; s++; char *item_value = s; s = strchr(s, ','); - if (s != NULL) { + if (s != nullptr) { *s = '\0'; s++; } @@ -209,7 +209,7 @@ void ScriptConfig::SettingsToString(char *string, const char *last) const const char *ScriptConfig::GetTextfile(TextfileType type, CompanyID slot) const { - if (slot == INVALID_COMPANY || this->GetInfo() == NULL) return NULL; + if (slot == INVALID_COMPANY || this->GetInfo() == nullptr) return nullptr; return ::GetTextfile(type, (slot == OWNER_DEITY) ? GAME_DIR : AI_DIR, this->GetInfo()->GetMainScript()); } diff --git a/src/script/script_config.hpp b/src/script/script_config.hpp index 3dfd6bb0b..db04397a7 100644 --- a/src/script/script_config.hpp +++ b/src/script/script_config.hpp @@ -61,10 +61,10 @@ protected: public: ScriptConfig() : - name(NULL), + name(nullptr), version(-1), - info(NULL), - config_list(NULL), + info(nullptr), + config_list(nullptr), is_random(false) {} @@ -178,7 +178,7 @@ public: * Search a textfile file next to this script. * @param type The type of the textfile to search for. * @param slot #CompanyID to check status of. - * @return The filename for the textfile, \c NULL otherwise. + * @return The filename for the textfile, \c nullptr otherwise. */ const char *GetTextfile(TextfileType type, CompanyID slot) const; diff --git a/src/script/script_info.cpp b/src/script/script_info.cpp index 47ff2ee5f..5cab36d0b 100644 --- a/src/script/script_info.cpp +++ b/src/script/script_info.cpp @@ -25,7 +25,7 @@ ScriptInfo::~ScriptInfo() for (ScriptConfigItemList::iterator it = this->config_list.begin(); it != this->config_list.end(); it++) { free((*it).name); free((*it).description); - if (it->labels != NULL) { + if (it->labels != nullptr) { for (auto &lbl_map : *(*it).labels) { free(lbl_map.second); } @@ -85,7 +85,7 @@ bool ScriptInfo::CheckMethod(const char *name) const /* Get location information of the scanner */ info->main_script = stredup(info->scanner->GetMainScript()); const char *tar_name = info->scanner->GetTarFile(); - if (tar_name != NULL) info->tar_file = stredup(tar_name); + if (tar_name != nullptr) info->tar_file = stredup(tar_name); /* Cache the data the info file gives us. */ if (!info->engine->CallStringMethodStrdup(*info->SQ_instance, "GetAuthor", &info->author, MAX_GET_OPS)) return SQ_ERROR; @@ -111,7 +111,7 @@ bool ScriptInfo::CheckMethod(const char *name) const bool ScriptInfo::GetSettings() { - return this->engine->CallMethod(*this->SQ_instance, "GetSettings", NULL, MAX_GET_SETTING_OPS); + return this->engine->CallMethod(*this->SQ_instance, "GetSettings", nullptr, MAX_GET_SETTING_OPS); } SQInteger ScriptInfo::AddSetting(HSQUIRRELVM vm) @@ -138,8 +138,8 @@ SQInteger ScriptInfo::AddSetting(HSQUIRRELVM vm) /* Don't allow '=' and ',' in configure setting names, as we need those * 2 chars to nicely store the settings as a string. */ - while ((s = strchr(name, '=')) != NULL) *s = '_'; - while ((s = strchr(name, ',')) != NULL) *s = '_'; + while ((s = strchr(name, '=')) != nullptr) *s = '_'; + while ((s = strchr(name, ',')) != nullptr) *s = '_'; config.name = name; items |= 0x001; } else if (strcmp(key, "description") == 0) { @@ -233,18 +233,18 @@ SQInteger ScriptInfo::AddLabels(HSQUIRRELVM vm) if (SQ_FAILED(sq_getstring(vm, -2, &setting_name))) return SQ_ERROR; ValidateString(setting_name); - ScriptConfigItem *config = NULL; + ScriptConfigItem *config = nullptr; for (ScriptConfigItemList::iterator it = this->config_list.begin(); it != this->config_list.end(); it++) { if (strcmp((*it).name, setting_name) == 0) config = &(*it); } - if (config == NULL) { + if (config == nullptr) { char error[1024]; seprintf(error, lastof(error), "Trying to add labels for non-defined setting '%s'", setting_name); this->engine->ThrowError(error); return SQ_ERROR; } - if (config->labels != NULL) return SQ_ERROR; + if (config->labels != nullptr) return SQ_ERROR; config->labels = new LabelMapping; @@ -289,7 +289,7 @@ const ScriptConfigItem *ScriptInfo::GetConfigItem(const char *name) const for (ScriptConfigItemList::const_iterator it = this->config_list.begin(); it != this->config_list.end(); it++) { if (strcmp((*it).name, name) == 0) return &(*it); } - return NULL; + return nullptr; } int ScriptInfo::GetSettingDefaultValue(const char *name) const diff --git a/src/script/script_info.hpp b/src/script/script_info.hpp index ae341a7d8..6bcec878a 100644 --- a/src/script/script_info.hpp +++ b/src/script/script_info.hpp @@ -32,19 +32,19 @@ static const int MAX_GET_SETTING_OPS = 100000; class ScriptInfo : public SimpleCountedObject { public: ScriptInfo() : - engine(NULL), - SQ_instance(NULL), - main_script(NULL), - tar_file(NULL), - author(NULL), - name(NULL), - short_name(NULL), - description(NULL), - date(NULL), - instance_name(NULL), + engine(nullptr), + SQ_instance(nullptr), + main_script(nullptr), + tar_file(nullptr), + author(nullptr), + name(nullptr), + short_name(nullptr), + description(nullptr), + date(nullptr), + instance_name(nullptr), version(0), - url(NULL), - scanner(NULL) + url(nullptr), + scanner(nullptr) {} ~ScriptInfo(); diff --git a/src/script/script_info_dummy.cpp b/src/script/script_info_dummy.cpp index 53860386c..34e5541e2 100644 --- a/src/script/script_info_dummy.cpp +++ b/src/script/script_info_dummy.cpp @@ -86,11 +86,11 @@ void Script_CreateDummy(HSQUIRRELVM vm, StringID string, const char *type) char *p = safe_error_message; do { newline = strchr(p, '\n'); - if (newline != NULL) *newline = '\0'; + if (newline != nullptr) *newline = '\0'; dp += seprintf(dp, lastof(dummy_script), " %sLog.Error(\"%s\");\n", type, p); p = newline + 1; - } while (newline != NULL); + } while (newline != nullptr); strecpy(dp, " }\n}\n", lastof(dummy_script)); diff --git a/src/script/script_instance.cpp b/src/script/script_instance.cpp index 5df06ad89..336d3366a 100644 --- a/src/script/script_instance.cpp +++ b/src/script/script_instance.cpp @@ -34,8 +34,8 @@ ScriptStorage::~ScriptStorage() { /* Free our pointers */ - if (event_data != NULL) ScriptEventController::FreeEventPointer(); - if (log_data != NULL) ScriptLog::FreeLogPointer(); + if (event_data != nullptr) ScriptEventController::FreeEventPointer(); + if (log_data != nullptr) ScriptLog::FreeLogPointer(); } /** @@ -50,17 +50,17 @@ static void PrintFunc(bool error_msg, const SQChar *message) } ScriptInstance::ScriptInstance(const char *APIName) : - engine(NULL), - versionAPI(NULL), - controller(NULL), - storage(NULL), - instance(NULL), + engine(nullptr), + versionAPI(nullptr), + controller(nullptr), + storage(nullptr), + instance(nullptr), is_started(false), is_dead(false), is_save_data_on_stack(false), suspend(0), is_paused(false), - callback(NULL) + callback(nullptr) { this->storage = new ScriptStorage(); this->engine = new Squirrel(APIName); @@ -135,8 +135,8 @@ ScriptInstance::~ScriptInstance() { ScriptObject::ActiveInstance active(this); - if (instance != NULL) this->engine->ReleaseObject(this->instance); - if (engine != NULL) delete this->engine; + if (instance != nullptr) this->engine->ReleaseObject(this->instance); + if (engine != nullptr) delete this->engine; delete this->storage; delete this->controller; free(this->instance); @@ -153,10 +153,10 @@ void ScriptInstance::Died() DEBUG(script, 0, "The script died unexpectedly."); this->is_dead = true; - if (this->instance != NULL) this->engine->ReleaseObject(this->instance); + if (this->instance != nullptr) this->engine->ReleaseObject(this->instance); delete this->engine; - this->instance = NULL; - this->engine = NULL; + this->instance = nullptr; + this->engine = nullptr; } void ScriptInstance::GameLoop() @@ -179,7 +179,7 @@ void ScriptInstance::GameLoop() _current_company = ScriptObject::GetCompany(); /* If there is a callback to call, call that first */ - if (this->callback != NULL) { + if (this->callback != nullptr) { if (this->is_save_data_on_stack) { sq_poptop(this->engine->GetVM()); this->is_save_data_on_stack = false; @@ -195,7 +195,7 @@ void ScriptInstance::GameLoop() } this->suspend = 0; - this->callback = NULL; + this->callback = nullptr; if (!this->is_started) { try { @@ -351,7 +351,7 @@ static const SaveLoad _script_byte[] = { case OT_INTEGER: { if (!test) { _script_sl_byte = SQSL_INT; - SlObject(NULL, _script_byte); + SlObject(nullptr, _script_byte); } SQInteger res; sq_getinteger(vm, index, &res); @@ -365,7 +365,7 @@ static const SaveLoad _script_byte[] = { case OT_STRING: { if (!test) { _script_sl_byte = SQSL_STRING; - SlObject(NULL, _script_byte); + SlObject(nullptr, _script_byte); } const SQChar *buf; sq_getstring(vm, index, &buf); @@ -376,7 +376,7 @@ static const SaveLoad _script_byte[] = { } if (!test) { _script_sl_byte = (byte)len; - SlObject(NULL, _script_byte); + SlObject(nullptr, _script_byte); SlArray(const_cast<char *>(buf), len, SLE_CHAR); } return true; @@ -385,7 +385,7 @@ static const SaveLoad _script_byte[] = { case OT_ARRAY: { if (!test) { _script_sl_byte = SQSL_ARRAY; - SlObject(NULL, _script_byte); + SlObject(nullptr, _script_byte); } sq_pushnull(vm); while (SQ_SUCCEEDED(sq_next(vm, index - 1))) { @@ -400,7 +400,7 @@ static const SaveLoad _script_byte[] = { sq_pop(vm, 1); if (!test) { _script_sl_byte = SQSL_ARRAY_TABLE_END; - SlObject(NULL, _script_byte); + SlObject(nullptr, _script_byte); } return true; } @@ -408,7 +408,7 @@ static const SaveLoad _script_byte[] = { case OT_TABLE: { if (!test) { _script_sl_byte = SQSL_TABLE; - SlObject(NULL, _script_byte); + SlObject(nullptr, _script_byte); } sq_pushnull(vm); while (SQ_SUCCEEDED(sq_next(vm, index - 1))) { @@ -423,7 +423,7 @@ static const SaveLoad _script_byte[] = { sq_pop(vm, 1); if (!test) { _script_sl_byte = SQSL_ARRAY_TABLE_END; - SlObject(NULL, _script_byte); + SlObject(nullptr, _script_byte); } return true; } @@ -431,13 +431,13 @@ static const SaveLoad _script_byte[] = { case OT_BOOL: { if (!test) { _script_sl_byte = SQSL_BOOL; - SlObject(NULL, _script_byte); + SlObject(nullptr, _script_byte); } SQBool res; sq_getbool(vm, index, &res); if (!test) { _script_sl_byte = res ? 1 : 0; - SlObject(NULL, _script_byte); + SlObject(nullptr, _script_byte); } return true; } @@ -445,7 +445,7 @@ static const SaveLoad _script_byte[] = { case OT_NULL: { if (!test) { _script_sl_byte = SQSL_NULL; - SlObject(NULL, _script_byte); + SlObject(nullptr, _script_byte); } return true; } @@ -459,7 +459,7 @@ static const SaveLoad _script_byte[] = { /* static */ void ScriptInstance::SaveEmpty() { _script_sl_byte = 0; - SlObject(NULL, _script_byte); + SlObject(nullptr, _script_byte); } void ScriptInstance::Save() @@ -467,7 +467,7 @@ void ScriptInstance::Save() ScriptObject::ActiveInstance active(this); /* Don't save data if the script didn't start yet or if it crashed. */ - if (this->engine == NULL || this->engine->HasScriptCrashed()) { + if (this->engine == nullptr || this->engine->HasScriptCrashed()) { SaveEmpty(); return; } @@ -475,7 +475,7 @@ void ScriptInstance::Save() HSQUIRRELVM vm = this->engine->GetVM(); if (this->is_save_data_on_stack) { _script_sl_byte = 1; - SlObject(NULL, _script_byte); + SlObject(nullptr, _script_byte); /* Save the data that was just loaded. */ SaveObject(vm, -1, SQUIRREL_MAX_DEPTH, false); } else if (!this->is_started) { @@ -518,7 +518,7 @@ void ScriptInstance::Save() sq_pushobject(vm, savedata); if (SaveObject(vm, -1, SQUIRREL_MAX_DEPTH, true)) { _script_sl_byte = 1; - SlObject(NULL, _script_byte); + SlObject(nullptr, _script_byte); SaveObject(vm, -1, SQUIRREL_MAX_DEPTH, false); this->is_save_data_on_stack = true; } else { @@ -528,7 +528,7 @@ void ScriptInstance::Save() } else { ScriptLog::Warning("Save function is not implemented"); _script_sl_byte = 0; - SlObject(NULL, _script_byte); + SlObject(nullptr, _script_byte); } } @@ -553,50 +553,50 @@ bool ScriptInstance::IsPaused() /* static */ bool ScriptInstance::LoadObjects(HSQUIRRELVM vm) { - SlObject(NULL, _script_byte); + SlObject(nullptr, _script_byte); switch (_script_sl_byte) { case SQSL_INT: { int value; SlArray(&value, 1, SLE_INT32); - if (vm != NULL) sq_pushinteger(vm, (SQInteger)value); + if (vm != nullptr) sq_pushinteger(vm, (SQInteger)value); return true; } case SQSL_STRING: { - SlObject(NULL, _script_byte); + SlObject(nullptr, _script_byte); static char buf[256]; SlArray(buf, _script_sl_byte, SLE_CHAR); - if (vm != NULL) sq_pushstring(vm, buf, -1); + if (vm != nullptr) sq_pushstring(vm, buf, -1); return true; } case SQSL_ARRAY: { - if (vm != NULL) sq_newarray(vm, 0); + if (vm != nullptr) sq_newarray(vm, 0); while (LoadObjects(vm)) { - if (vm != NULL) sq_arrayappend(vm, -2); + if (vm != nullptr) sq_arrayappend(vm, -2); /* The value is popped from the stack by squirrel. */ } return true; } case SQSL_TABLE: { - if (vm != NULL) sq_newtable(vm); + if (vm != nullptr) sq_newtable(vm); while (LoadObjects(vm)) { LoadObjects(vm); - if (vm != NULL) sq_rawset(vm, -3); + if (vm != nullptr) sq_rawset(vm, -3); /* The key (-2) and value (-1) are popped from the stack by squirrel. */ } return true; } case SQSL_BOOL: { - SlObject(NULL, _script_byte); - if (vm != NULL) sq_pushbool(vm, (SQBool)(_script_sl_byte != 0)); + SlObject(nullptr, _script_byte); + if (vm != nullptr) sq_pushbool(vm, (SQBool)(_script_sl_byte != 0)); return true; } case SQSL_NULL: { - if (vm != NULL) sq_pushnull(vm); + if (vm != nullptr) sq_pushnull(vm); return true; } @@ -610,24 +610,24 @@ bool ScriptInstance::IsPaused() /* static */ void ScriptInstance::LoadEmpty() { - SlObject(NULL, _script_byte); + SlObject(nullptr, _script_byte); /* Check if there was anything saved at all. */ if (_script_sl_byte == 0) return; - LoadObjects(NULL); + LoadObjects(nullptr); } void ScriptInstance::Load(int version) { ScriptObject::ActiveInstance active(this); - if (this->engine == NULL || version == -1) { + if (this->engine == nullptr || version == -1) { LoadEmpty(); return; } HSQUIRRELVM vm = this->engine->GetVM(); - SlObject(NULL, _script_byte); + SlObject(nullptr, _script_byte); /* Check if there was anything saved at all. */ if (_script_sl_byte == 0) return; diff --git a/src/script/script_instance.hpp b/src/script/script_instance.hpp index e6f3c64b2..56e830367 100644 --- a/src/script/script_instance.hpp +++ b/src/script/script_instance.hpp @@ -52,7 +52,7 @@ public: * Find a library. * @param library The library name to find. * @param version The version the library should have. - * @return The library if found, NULL otherwise. + * @return The library if found, nullptr otherwise. */ virtual class ScriptInfo *FindLibrary(const char *library, int version) = 0; diff --git a/src/script/script_scanner.cpp b/src/script/script_scanner.cpp index 168a852a5..2812ef65e 100644 --- a/src/script/script_scanner.cpp +++ b/src/script/script_scanner.cpp @@ -28,19 +28,19 @@ bool ScriptScanner::AddFile(const char *filename, size_t basepath_length, const { free(this->main_script); this->main_script = stredup(filename); - if (this->main_script == NULL) return false; + if (this->main_script == nullptr) return false; free(this->tar_file); - if (tar_filename != NULL) { + if (tar_filename != nullptr) { this->tar_file = stredup(tar_filename); - if (this->tar_file == NULL) return false; + if (this->tar_file == nullptr) return false; } else { - this->tar_file = NULL; + this->tar_file = nullptr; } const char *end = this->main_script + strlen(this->main_script) + 1; char *p = strrchr(this->main_script, PATHSEPCHAR); - if (p == NULL) { + if (p == nullptr) { p = this->main_script; } else { /* Skip over the path separator character. We don't need that. */ @@ -58,9 +58,9 @@ bool ScriptScanner::AddFile(const char *filename, size_t basepath_length, const } ScriptScanner::ScriptScanner() : - engine(NULL), - main_script(NULL), - tar_file(NULL) + engine(nullptr), + main_script(nullptr), + tar_file(nullptr) { } @@ -203,7 +203,7 @@ struct ScriptFileChecksumCreator : FileScanner { /* Open the file ... */ FILE *f = FioFOpenFile(filename, "rb", this->dir, &size); - if (f == NULL) return false; + if (f == nullptr) return false; /* ... calculate md5sum... */ while ((len = fread(buffer, 1, (size > sizeof(buffer)) ? sizeof(buffer) : size, f)) != 0 && size != 0) { @@ -241,7 +241,7 @@ static bool IsSameScript(const ContentInfo *ci, bool md5sum, ScriptInfo *info, S ScriptFileChecksumCreator checksum(dir); const char *tar_filename = info->GetTarFile(); TarList::iterator iter; - if (tar_filename != NULL && (iter = _tar_list[dir].find(tar_filename)) != _tar_list[dir].end()) { + if (tar_filename != nullptr && (iter = _tar_list[dir].find(tar_filename)) != _tar_list[dir].end()) { /* The main script is in a tar file, so find all files that * are in the same tar and add them to the MD5 checksumming. */ TarFileList::iterator tar; @@ -251,7 +251,7 @@ static bool IsSameScript(const ContentInfo *ci, bool md5sum, ScriptInfo *info, S /* Check the extension. */ const char *ext = strrchr(tar->first.c_str(), '.'); - if (ext == NULL || strcasecmp(ext, ".nut") != 0) continue; + if (ext == nullptr || strcasecmp(ext, ".nut") != 0) continue; checksum.AddFile(tar->first.c_str(), 0, tar_filename); } @@ -281,5 +281,5 @@ const char *ScriptScanner::FindMainScript(const ContentInfo *ci, bool md5sum) for (ScriptInfoList::iterator it = this->info_list.begin(); it != this->info_list.end(); it++) { if (IsSameScript(ci, md5sum, (*it).second, this->GetDirectory())) return (*it).second->GetMainScript(); } - return NULL; + return nullptr; } diff --git a/src/script/script_scanner.hpp b/src/script/script_scanner.hpp index 7fecf6eb2..3627d251b 100644 --- a/src/script/script_scanner.hpp +++ b/src/script/script_scanner.hpp @@ -73,7 +73,7 @@ public: * Find a script of a #ContentInfo * @param ci The information to compare to. * @param md5sum Whether to check the MD5 checksum. - * @return A filename of a file of the content, else \c NULL. + * @return A filename of a file of the content, else \c nullptr. */ const char *FindMainScript(const ContentInfo *ci, bool md5sum); diff --git a/src/script/script_storage.hpp b/src/script/script_storage.hpp index 8fe1e1732..ef7d81ed7 100644 --- a/src/script/script_storage.hpp +++ b/src/script/script_storage.hpp @@ -63,8 +63,8 @@ private: public: ScriptStorage() : - mode (NULL), - mode_instance (NULL), + mode (nullptr), + mode_instance (nullptr), root_company (INVALID_OWNER), company (INVALID_OWNER), delay (1), @@ -82,8 +82,8 @@ public: /* calback_value (can't be set) */ road_type (INVALID_ROADTYPE), rail_type (INVALID_RAILTYPE), - event_data (NULL), - log_data (NULL) + event_data (nullptr), + log_data (nullptr) { } ~ScriptStorage(); diff --git a/src/script/squirrel.cpp b/src/script/squirrel.cpp index 23163f6b3..fd0478bb5 100644 --- a/src/script/squirrel.cpp +++ b/src/script/squirrel.cpp @@ -31,7 +31,7 @@ void Squirrel::CompileError(HSQUIRRELVM vm, const SQChar *desc, const SQChar *so Squirrel *engine = (Squirrel *)sq_getforeignptr(vm); engine->crashed = true; SQPrintFunc *func = engine->print_func; - if (func == NULL) { + if (func == nullptr) { DEBUG(misc, 0, "[Squirrel] Compile error: %s", buf); } else { (*func)(true, buf); @@ -49,7 +49,7 @@ void Squirrel::ErrorPrintFunc(HSQUIRRELVM vm, const SQChar *s, ...) /* Check if we have a custom print function */ SQPrintFunc *func = ((Squirrel *)sq_getforeignptr(vm))->print_func; - if (func == NULL) { + if (func == nullptr) { fprintf(stderr, "%s", buf); } else { (*func)(true, buf); @@ -67,7 +67,7 @@ void Squirrel::RunError(HSQUIRRELVM vm, const SQChar *error) seprintf(buf, lastof(buf), "Your script made an error: %s\n", error); Squirrel *engine = (Squirrel *)sq_getforeignptr(vm); SQPrintFunc *func = engine->print_func; - if (func == NULL) { + if (func == nullptr) { fprintf(stderr, "%s", buf); } else { (*func)(true, buf); @@ -106,7 +106,7 @@ void Squirrel::PrintFunc(HSQUIRRELVM vm, const SQChar *s, ...) /* Check if we have a custom print function */ SQPrintFunc *func = ((Squirrel *)sq_getforeignptr(vm))->print_func; - if (func == NULL) { + if (func == nullptr) { printf("%s", buf); } else { (*func)(false, buf); @@ -234,8 +234,8 @@ bool Squirrel::CallMethod(HSQOBJECT instance, const char *method_name, HSQOBJECT } /* Call the method */ sq_pushobject(this->vm, instance); - if (SQ_FAILED(sq_call(this->vm, 1, ret == NULL ? SQFalse : SQTrue, SQTrue, suspend))) return false; - if (ret != NULL) sq_getstackobj(vm, -1, ret); + if (SQ_FAILED(sq_call(this->vm, 1, ret == nullptr ? SQFalse : SQTrue, SQTrue, suspend))) return false; + if (ret != nullptr) sq_getstackobj(vm, -1, ret); /* Reset the top, but don't do so for the script main function, as we need * a correct stack when resuming. */ if (suspend == -1 || !this->IsSuspended()) sq_settop(this->vm, top); @@ -305,7 +305,7 @@ bool Squirrel::CallBoolMethod(HSQOBJECT instance, const char *method_name, bool return false; } - if (instance != NULL) { + if (instance != nullptr) { /* Find our instance */ sq_getstackobj(vm, -1, instance); /* Add a reference to it, so it survives for ever */ @@ -316,16 +316,16 @@ bool Squirrel::CallBoolMethod(HSQOBJECT instance, const char *method_name, bool /* Store it in the class */ sq_setinstanceup(vm, -1, real_instance); - if (release_hook != NULL) sq_setreleasehook(vm, -1, release_hook); + if (release_hook != nullptr) sq_setreleasehook(vm, -1, release_hook); - if (instance != NULL) sq_settop(vm, oldtop); + if (instance != nullptr) sq_settop(vm, oldtop); return true; } bool Squirrel::CreateClassInstance(const char *class_name, void *real_instance, HSQOBJECT *instance) { - return Squirrel::CreateClassInstanceVM(this->vm, class_name, real_instance, instance, NULL); + return Squirrel::CreateClassInstanceVM(this->vm, class_name, real_instance, instance, nullptr); } Squirrel::Squirrel(const char *APIName) : @@ -336,8 +336,8 @@ Squirrel::Squirrel(const char *APIName) : void Squirrel::Initialize() { - this->global_pointer = NULL; - this->print_func = NULL; + this->global_pointer = nullptr; + this->print_func = nullptr; this->crashed = false; this->overdrawn_ops = 0; this->vm = sq_open(1024); @@ -436,15 +436,15 @@ SQRESULT Squirrel::LoadFile(HSQUIRRELVM vm, const char *filename, SQBool printer size_t size; if (strncmp(this->GetAPIName(), "AI", 2) == 0) { file = FioFOpenFile(filename, "rb", AI_DIR, &size); - if (file == NULL) file = FioFOpenFile(filename, "rb", AI_LIBRARY_DIR, &size); + if (file == nullptr) file = FioFOpenFile(filename, "rb", AI_LIBRARY_DIR, &size); } else if (strncmp(this->GetAPIName(), "GS", 2) == 0) { file = FioFOpenFile(filename, "rb", GAME_DIR, &size); - if (file == NULL) file = FioFOpenFile(filename, "rb", GAME_LIBRARY_DIR, &size); + if (file == nullptr) file = FioFOpenFile(filename, "rb", GAME_LIBRARY_DIR, &size); } else { NOT_REACHED(); } - if (file == NULL) { + if (file == nullptr) { return sq_throwerror(vm, "cannot open the file"); } unsigned short bom = 0; diff --git a/src/script/squirrel.hpp b/src/script/squirrel.hpp index 9e1d113a8..bec41f575 100644 --- a/src/script/squirrel.hpp +++ b/src/script/squirrel.hpp @@ -26,7 +26,7 @@ private: HSQUIRRELVM vm; ///< The VirtualMachine instance for squirrel void *global_pointer; ///< Can be set by who ever initializes Squirrel - SQPrintFunc *print_func; ///< Points to either NULL, or a custom print handler + SQPrintFunc *print_func; ///< Points to either nullptr, or a custom print handler bool crashed; ///< True if the squirrel script made an error. int overdrawn_ops; ///< The amount of operations we have overdrawn. const char *APIName; ///< Name of the API used for this squirrel. @@ -93,7 +93,7 @@ public: * Adds a function to the stack. Depending on the current state this means * either a method or a global function. */ - void AddMethod(const char *method_name, SQFUNCTION proc, uint nparam = 0, const char *params = NULL, void *userdata = NULL, int size = 0); + void AddMethod(const char *method_name, SQFUNCTION proc, uint nparam = 0, const char *params = nullptr, void *userdata = nullptr, int size = 0); /** * Adds a const to the stack. Depending on the current state this means @@ -155,7 +155,7 @@ public: * @return False if the script crashed or returned a wrong type. */ bool CallMethod(HSQOBJECT instance, const char *method_name, HSQOBJECT *ret, int suspend); - bool CallMethod(HSQOBJECT instance, const char *method_name, int suspend) { return this->CallMethod(instance, method_name, NULL, suspend); } + bool CallMethod(HSQOBJECT instance, const char *method_name, int suspend) { return this->CallMethod(instance, method_name, nullptr, suspend); } bool CallStringMethodStrdup(HSQOBJECT instance, const char *method_name, const char **res, int suspend); bool CallIntegerMethod(HSQOBJECT instance, const char *method_name, int *res, int suspend); bool CallBoolMethod(HSQOBJECT instance, const char *method_name, bool *res, int suspend); diff --git a/src/script/squirrel_class.hpp b/src/script/squirrel_class.hpp index ce63e3b03..8ec3f9dc7 100644 --- a/src/script/squirrel_class.hpp +++ b/src/script/squirrel_class.hpp @@ -35,7 +35,7 @@ public: void DefSQMethod(Squirrel *engine, Func function_proc, const char *function_name) { using namespace SQConvert; - engine->AddMethod(function_name, DefSQNonStaticCallback<CL, Func, ST>, 0, NULL, &function_proc, sizeof(function_proc)); + engine->AddMethod(function_name, DefSQNonStaticCallback<CL, Func, ST>, 0, nullptr, &function_proc, sizeof(function_proc)); } /** @@ -45,7 +45,7 @@ public: void DefSQAdvancedMethod(Squirrel *engine, Func function_proc, const char *function_name) { using namespace SQConvert; - engine->AddMethod(function_name, DefSQAdvancedNonStaticCallback<CL, Func, ST>, 0, NULL, &function_proc, sizeof(function_proc)); + engine->AddMethod(function_name, DefSQAdvancedNonStaticCallback<CL, Func, ST>, 0, nullptr, &function_proc, sizeof(function_proc)); } /** @@ -68,7 +68,7 @@ public: void DefSQStaticMethod(Squirrel *engine, Func function_proc, const char *function_name) { using namespace SQConvert; - engine->AddMethod(function_name, DefSQStaticCallback<CL, Func>, 0, NULL, &function_proc, sizeof(function_proc)); + engine->AddMethod(function_name, DefSQStaticCallback<CL, Func>, 0, nullptr, &function_proc, sizeof(function_proc)); } /** @@ -78,7 +78,7 @@ public: void DefSQAdvancedStaticMethod(Squirrel *engine, Func function_proc, const char *function_name) { using namespace SQConvert; - engine->AddMethod(function_name, DefSQAdvancedStaticCallback<CL, Func>, 0, NULL, &function_proc, sizeof(function_proc)); + engine->AddMethod(function_name, DefSQAdvancedStaticCallback<CL, Func>, 0, nullptr, &function_proc, sizeof(function_proc)); } /** @@ -120,7 +120,7 @@ public: void AddSQAdvancedConstructor(Squirrel *engine) { using namespace SQConvert; - engine->AddMethod("constructor", DefSQAdvancedConstructorCallback<CL>, 0, NULL); + engine->AddMethod("constructor", DefSQAdvancedConstructorCallback<CL>, 0, nullptr); } void PostRegister(Squirrel *engine) diff --git a/src/script/squirrel_helper.hpp b/src/script/squirrel_helper.hpp index 10f04f945..e266148c5 100644 --- a/src/script/squirrel_helper.hpp +++ b/src/script/squirrel_helper.hpp @@ -88,8 +88,8 @@ namespace SQConvert { template <> inline int Return<int64> (HSQUIRRELVM vm, int64 res) { sq_pushinteger(vm, res); return 1; } template <> inline int Return<Money> (HSQUIRRELVM vm, Money res) { sq_pushinteger(vm, res); return 1; } template <> inline int Return<bool> (HSQUIRRELVM vm, bool res) { sq_pushbool (vm, res); return 1; } - template <> inline int Return<char *> (HSQUIRRELVM vm, char *res) { if (res == NULL) sq_pushnull(vm); else { sq_pushstring(vm, res, -1); free(res); } return 1; } - template <> inline int Return<const char *>(HSQUIRRELVM vm, const char *res) { if (res == NULL) sq_pushnull(vm); else { sq_pushstring(vm, res, -1); } return 1; } + template <> inline int Return<char *> (HSQUIRRELVM vm, char *res) { if (res == nullptr) sq_pushnull(vm); else { sq_pushstring(vm, res, -1); free(res); } return 1; } + template <> inline int Return<const char *>(HSQUIRRELVM vm, const char *res) { if (res == nullptr) sq_pushnull(vm); else { sq_pushstring(vm, res, -1); } return 1; } template <> inline int Return<void *> (HSQUIRRELVM vm, void *res) { sq_pushuserpointer(vm, res); return 1; } template <> inline int Return<HSQOBJECT> (HSQUIRRELVM vm, HSQOBJECT res) { sq_pushobject(vm, res); return 1; } @@ -739,8 +739,8 @@ namespace SQConvert { { /* Find the amount of params we got */ int nparam = sq_gettop(vm); - SQUserPointer ptr = NULL; - SQUserPointer real_instance = NULL; + SQUserPointer ptr = nullptr; + SQUserPointer real_instance = nullptr; HSQOBJECT instance; /* Get the 'SQ' instance of this class */ @@ -759,7 +759,7 @@ namespace SQConvert { sq_getinstanceup(vm, 1, &real_instance, 0); /* Get the real function pointer */ sq_getuserdata(vm, nparam, &ptr, 0); - if (real_instance == NULL) return sq_throwerror(vm, "couldn't detect real instance of class for non-static call"); + if (real_instance == nullptr) return sq_throwerror(vm, "couldn't detect real instance of class for non-static call"); /* Remove the userdata from the stack */ sq_pop(vm, 1); @@ -781,8 +781,8 @@ namespace SQConvert { { /* Find the amount of params we got */ int nparam = sq_gettop(vm); - SQUserPointer ptr = NULL; - SQUserPointer real_instance = NULL; + SQUserPointer ptr = nullptr; + SQUserPointer real_instance = nullptr; HSQOBJECT instance; /* Get the 'SQ' instance of this class */ @@ -801,7 +801,7 @@ namespace SQConvert { sq_getinstanceup(vm, 1, &real_instance, 0); /* Get the real function pointer */ sq_getuserdata(vm, nparam, &ptr, 0); - if (real_instance == NULL) return sq_throwerror(vm, "couldn't detect real instance of class for non-static call"); + if (real_instance == nullptr) return sq_throwerror(vm, "couldn't detect real instance of class for non-static call"); /* Remove the userdata from the stack */ sq_pop(vm, 1); @@ -819,14 +819,14 @@ namespace SQConvert { { /* Find the amount of params we got */ int nparam = sq_gettop(vm); - SQUserPointer ptr = NULL; + SQUserPointer ptr = nullptr; /* Get the real function pointer */ sq_getuserdata(vm, nparam, &ptr, 0); try { /* Delegate it to a template that can handle this specific function */ - return HelperT<Tmethod>::SQCall((Tcls *)NULL, *(Tmethod *)ptr, vm); + return HelperT<Tmethod>::SQCall((Tcls *)nullptr, *(Tmethod *)ptr, vm); } catch (SQInteger e) { return e; } @@ -843,7 +843,7 @@ namespace SQConvert { { /* Find the amount of params we got */ int nparam = sq_gettop(vm); - SQUserPointer ptr = NULL; + SQUserPointer ptr = nullptr; /* Get the real function pointer */ sq_getuserdata(vm, nparam, &ptr, 0); @@ -862,7 +862,7 @@ namespace SQConvert { static SQInteger DefSQDestructorCallback(SQUserPointer p, SQInteger size) { /* Remove the real instance too */ - if (p != NULL) ((Tcls *)p)->Release(); + if (p != nullptr) ((Tcls *)p)->Release(); return 0; } @@ -876,7 +876,7 @@ namespace SQConvert { { try { /* Create the real instance */ - Tcls *instance = HelperT<Tmethod>::SQConstruct((Tcls *)NULL, (Tmethod)NULL, vm); + Tcls *instance = HelperT<Tmethod>::SQConstruct((Tcls *)nullptr, (Tmethod)nullptr, vm); sq_setinstanceup(vm, -Tnparam, instance); sq_setreleasehook(vm, -Tnparam, DefSQDestructorCallback<Tcls>); instance->AddRef(); diff --git a/src/script/squirrel_std.cpp b/src/script/squirrel_std.cpp index 96f087a2a..715b98934 100644 --- a/src/script/squirrel_std.cpp +++ b/src/script/squirrel_std.cpp @@ -51,7 +51,7 @@ SQInteger SquirrelStd::require(HSQUIRRELVM vm) /* Get the script-name of the current file, so we can work relative from it */ SQStackInfos si; sq_stackinfos(vm, 1, &si); - if (si.source == NULL) { + if (si.source == nullptr) { DEBUG(misc, 0, "[squirrel] Couldn't detect the script-name of the 'require'-caller; this should never happen!"); return SQ_ERROR; } @@ -60,7 +60,7 @@ SQInteger SquirrelStd::require(HSQUIRRELVM vm) strecpy(path, si.source, lastof(path)); /* Keep the dir, remove the rest */ SQChar *s = strrchr(path, PATHSEPCHAR); - if (s != NULL) { + if (s != nullptr) { /* Keep the PATHSEPCHAR there, remove the rest */ s++; *s = '\0'; |