Changeset - r23607:36c15679007d
[Not reviewed]
master
! ! !
Henry Wilson - 6 years ago 2019-04-10 21:07:06
m3henry@googlemail.com
Codechange: Use null pointer literal instead of the NULL macro
80 files changed:
Changeset was too big and was cut off... Show full diff anyway
0 comments (0 inline, 0 general)
src/ai/ai_config.cpp
Show inline comments
 
@@ -31,7 +31,7 @@ ScriptConfigItem _start_date_config = {
 
	AI::START_NEXT_DEVIATION,
 
	30,
 
	SCRIPTCONFIG_NONE,
 
	NULL,
 
	nullptr,
 
	false
 
};
 

	
 
@@ -52,7 +52,7 @@ AIConfig::AIConfig(const AIConfig *confi
 
	} else {
 
		config = &_settings_game.ai_config[company];
 
	}
 
	if (*config == NULL) *config = new AIConfig();
 
	if (*config == nullptr) *config = new AIConfig();
 
	return *config;
 
}
 

	
 
@@ -69,7 +69,7 @@ ScriptInfo *AIConfig::FindInfo(const cha
 
bool AIConfig::ResetInfo(bool force_exact_match)
 
{
 
	this->info = (ScriptInfo *)AI::FindInfo(this->name, force_exact_match ? this->version : -1, force_exact_match);
 
	return this->info != NULL;
 
	return this->info != nullptr;
 
}
 

	
 
void AIConfig::PushExtraConfigList()
 
@@ -90,7 +90,7 @@ void AIConfig::ClearConfigList()
 

	
 
int AIConfig::GetSetting(const char *name) const
 
{
 
	if (this->info == NULL) {
 
	if (this->info == nullptr) {
 
		SettingValueList::const_iterator it = this->settings.find(name);
 
		if (it == this->settings.end()) {
 
			assert(strcmp("start_date", name) == 0);
 
@@ -111,7 +111,7 @@ int AIConfig::GetSetting(const char *nam
 

	
 
void AIConfig::SetSetting(const char *name, int value)
 
{
 
	if (this->info == NULL) {
 
	if (this->info == nullptr) {
 
		if (strcmp("start_date", name) != 0) return;
 
		value = Clamp(value, AI::START_NEXT_MIN, AI::START_NEXT_MAX);
 

	
src/ai/ai_core.cpp
Show inline comments
 
@@ -26,8 +26,8 @@
 
#include "../safeguards.h"
 

	
 
/* static */ uint AI::frame_counter = 0;
 
/* static */ AIScannerInfo *AI::scanner_info = NULL;
 
/* static */ AIScannerLibrary *AI::scanner_library = NULL;
 
/* static */ AIScannerInfo *AI::scanner_info = nullptr;
 
/* static */ AIScannerLibrary *AI::scanner_library = nullptr;
 

	
 
/* static */ bool AI::CanStartNew()
 
{
 
@@ -44,9 +44,9 @@
 

	
 
	AIConfig *config = AIConfig::GetConfig(company, AIConfig::SSS_FORCE_GAME);
 
	AIInfo *info = config->GetInfo();
 
	if (info == NULL || (rerandomise_ai && config->IsRandom())) {
 
	if (info == nullptr || (rerandomise_ai && config->IsRandom())) {
 
		info = AI::scanner_info->SelectRandomAI();
 
		assert(info != NULL);
 
		assert(info != nullptr);
 
		/* Load default data and store the name in the settings */
 
		config->Change(info->GetName(), -1, false, true);
 
	}
 
@@ -56,7 +56,7 @@
 
	Company *c = Company::Get(company);
 

	
 
	c->ai_info = info;
 
	assert(c->ai_instance == NULL);
 
	assert(c->ai_instance == nullptr);
 
	c->ai_instance = new AIInstance();
 
	c->ai_instance->Initialize(info);
 

	
 
@@ -111,8 +111,8 @@
 
	Company *c = Company::Get(company);
 

	
 
	delete c->ai_instance;
 
	c->ai_instance = NULL;
 
	c->ai_info = NULL;
 
	c->ai_instance = nullptr;
 
	c->ai_info = nullptr;
 

	
 
	cur_company.Restore();
 

	
 
@@ -164,10 +164,10 @@
 

	
 
/* static */ void AI::Initialize()
 
{
 
	if (AI::scanner_info != NULL) AI::Uninitialize(true);
 
	if (AI::scanner_info != nullptr) AI::Uninitialize(true);
 

	
 
	AI::frame_counter = 0;
 
	if (AI::scanner_info == NULL) {
 
	if (AI::scanner_info == nullptr) {
 
		TarScanner::DoScan(TarScanner::AI);
 
		AI::scanner_info = new AIScannerInfo();
 
		AI::scanner_info->Initialize();
 
@@ -187,17 +187,17 @@
 
	} else {
 
		delete AI::scanner_info;
 
		delete AI::scanner_library;
 
		AI::scanner_info = NULL;
 
		AI::scanner_library = NULL;
 
		AI::scanner_info = nullptr;
 
		AI::scanner_library = nullptr;
 

	
 
		for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) {
 
			if (_settings_game.ai_config[c] != NULL) {
 
			if (_settings_game.ai_config[c] != nullptr) {
 
				delete _settings_game.ai_config[c];
 
				_settings_game.ai_config[c] = NULL;
 
				_settings_game.ai_config[c] = nullptr;
 
			}
 
			if (_settings_newgame.ai_config[c] != NULL) {
 
			if (_settings_newgame.ai_config[c] != nullptr) {
 
				delete _settings_newgame.ai_config[c];
 
				_settings_newgame.ai_config[c] = NULL;
 
				_settings_newgame.ai_config[c] = nullptr;
 
			}
 
		}
 
	}
 
@@ -209,10 +209,10 @@
 
	 *  the AIConfig. If not, remove the AI from the list (which will assign
 
	 *  a random new AI on reload). */
 
	for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) {
 
		if (_settings_game.ai_config[c] != NULL && _settings_game.ai_config[c]->HasScript()) {
 
		if (_settings_game.ai_config[c] != nullptr && _settings_game.ai_config[c]->HasScript()) {
 
			if (!_settings_game.ai_config[c]->ResetInfo(true)) {
 
				DEBUG(script, 0, "After a reload, the AI by the name '%s' was no longer found, and removed from the list.", _settings_game.ai_config[c]->GetName());
 
				_settings_game.ai_config[c]->Change(NULL);
 
				_settings_game.ai_config[c]->Change(nullptr);
 
				if (Company::IsValidAiID(c)) {
 
					/* The code belonging to an already running AI was deleted. We can only do
 
					 * one thing here to keep everything sane and that is kill the AI. After
 
@@ -226,10 +226,10 @@
 
				Company::Get(c)->ai_info = _settings_game.ai_config[c]->GetInfo();
 
			}
 
		}
 
		if (_settings_newgame.ai_config[c] != NULL && _settings_newgame.ai_config[c]->HasScript()) {
 
		if (_settings_newgame.ai_config[c] != nullptr && _settings_newgame.ai_config[c]->HasScript()) {
 
			if (!_settings_newgame.ai_config[c]->ResetInfo(false)) {
 
				DEBUG(script, 0, "After a reload, the AI by the name '%s' was no longer found, and removed from the list.", _settings_newgame.ai_config[c]->GetName());
 
				_settings_newgame.ai_config[c]->Change(NULL);
 
				_settings_newgame.ai_config[c]->Change(nullptr);
 
			}
 
		}
 
	}
 
@@ -283,7 +283,7 @@
 
{
 
	if (!_networking || _network_server) {
 
		Company *c = Company::GetIfValid(company);
 
		assert(c != NULL && c->ai_instance != NULL);
 
		assert(c != nullptr && c->ai_instance != nullptr);
 

	
 
		Backup<CompanyByte> cur_company(_current_company, company, FILE_LINE);
 
		c->ai_instance->Save();
 
@@ -297,7 +297,7 @@
 
{
 
	if (!_networking || _network_server) {
 
		Company *c = Company::GetIfValid(company);
 
		assert(c != NULL && c->ai_instance != NULL);
 
		assert(c != nullptr && c->ai_instance != nullptr);
 

	
 
		Backup<CompanyByte> cur_company(_current_company, company, FILE_LINE);
 
		c->ai_instance->Load(version);
src/ai/ai_gui.cpp
Show inline comments
 
@@ -139,13 +139,13 @@ struct AIListWindow : public Window {
 
				break;
 
			}
 
			case WID_AIL_INFO_BG: {
 
				AIInfo *selected_info = NULL;
 
				AIInfo *selected_info = nullptr;
 
				ScriptInfoList::const_iterator it = this->info_list->begin();
 
				for (int i = 1; selected_info == NULL && it != this->info_list->end(); i++, it++) {
 
				for (int i = 1; selected_info == nullptr && it != this->info_list->end(); i++, it++) {
 
					if (this->selected == i - 1) selected_info = static_cast<AIInfo *>((*it).second);
 
				}
 
				/* Some info about the currently selected AI. */
 
				if (selected_info != NULL) {
 
				if (selected_info != nullptr) {
 
					int y = r.top + WD_FRAMERECT_TOP;
 
					SetDParamStr(0, selected_info->GetAuthor());
 
					DrawString(r.left + WD_FRAMETEXT_LEFT, r.right - WD_FRAMETEXT_RIGHT, y, STR_AI_LIST_AUTHOR);
 
@@ -153,7 +153,7 @@ struct AIListWindow : public Window {
 
					SetDParam(0, selected_info->GetVersion());
 
					DrawString(r.left + WD_FRAMETEXT_LEFT, r.right - WD_FRAMETEXT_RIGHT, y, STR_AI_LIST_VERSION);
 
					y += FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL;
 
					if (selected_info->GetURL() != NULL) {
 
					if (selected_info->GetURL() != nullptr) {
 
						SetDParamStr(0, selected_info->GetURL());
 
						DrawString(r.left + WD_FRAMETEXT_LEFT, r.right - WD_FRAMETEXT_RIGHT, y, STR_AI_LIST_URL);
 
						y += FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL;
 
@@ -172,7 +172,7 @@ struct AIListWindow : public Window {
 
	void ChangeAI()
 
	{
 
		if (this->selected == -1) {
 
			GetConfig(slot)->Change(NULL);
 
			GetConfig(slot)->Change(nullptr);
 
		} else {
 
			ScriptInfoList::const_iterator it = this->info_list->begin();
 
			for (int i = 0; i < this->selected; i++) it++;
 
@@ -407,7 +407,7 @@ struct AISettingsWindow : public Window 
 
				} else {
 
					DrawArrowButtons(buttons_left, y + button_y_offset, COLOUR_YELLOW, (this->clicked_button == i) ? 1 + (this->clicked_increase != rtl) : 0, editable && current_value > config_item.min_value, editable && current_value < config_item.max_value);
 
				}
 
				if (config_item.labels != NULL && config_item.labels->Contains(current_value)) {
 
				if (config_item.labels != nullptr && config_item.labels->Contains(current_value)) {
 
					SetDParam(idx++, STR_JUST_RAW_STRING);
 
					SetDParamStr(idx++, config_item.labels->Find(current_value)->second);
 
				} else {
 
@@ -805,7 +805,7 @@ struct AIConfigWindow : public Window {
 
	 */
 
	static bool IsEditable(CompanyID slot)
 
	{
 
		if (slot == OWNER_DEITY) return _game_mode != GM_NORMAL || Game::GetInstance() != NULL;
 
		if (slot == OWNER_DEITY) return _game_mode != GM_NORMAL || Game::GetInstance() != nullptr;
 

	
 
		if (_game_mode != GM_NORMAL) {
 
			return slot > 0 && slot <= GetGameSettings().difficulty.max_no_competitors;
 
@@ -825,7 +825,7 @@ struct AIConfigWindow : public Window {
 
			case WID_AIC_GAMELIST: {
 
				StringID text = STR_AI_CONFIG_NONE;
 

	
 
				if (GameConfig::GetConfig()->GetInfo() != NULL) {
 
				if (GameConfig::GetConfig()->GetInfo() != nullptr) {
 
					SetDParamStr(0, GameConfig::GetConfig()->GetInfo()->GetName());
 
					text = STR_JUST_RAW_STRING;
 
				}
 
@@ -843,7 +843,7 @@ struct AIConfigWindow : public Window {
 

	
 
					if ((_game_mode != GM_NORMAL && i == 0) || (_game_mode == GM_NORMAL && Company::IsValidHumanID(i))) {
 
						text = STR_AI_CONFIG_HUMAN_PLAYER;
 
					} else if (AIConfig::GetConfig((CompanyID)i)->GetInfo() != NULL) {
 
					} else if (AIConfig::GetConfig((CompanyID)i)->GetInfo() != nullptr) {
 
						SetDParamStr(0, AIConfig::GetConfig((CompanyID)i)->GetInfo()->GetName());
 
						text = STR_JUST_RAW_STRING;
 
					} else {
 
@@ -861,7 +861,7 @@ struct AIConfigWindow : public Window {
 
	void OnClick(Point pt, int widget, int click_count) override
 
	{
 
		if (widget >= WID_AIC_TEXTFILE && widget < WID_AIC_TEXTFILE + TFT_END) {
 
			if (this->selected_slot == INVALID_COMPANY || GetConfig(this->selected_slot) == NULL) return;
 
			if (this->selected_slot == INVALID_COMPANY || GetConfig(this->selected_slot) == nullptr) return;
 

	
 
			ShowScriptTextfileWindow((TextfileType)(widget - WID_AIC_TEXTFILE), this->selected_slot);
 
			return;
 
@@ -928,7 +928,7 @@ struct AIConfigWindow : public Window {
 
				if (!_network_available) {
 
					ShowErrorMessage(STR_NETWORK_ERROR_NOTAVAILABLE, INVALID_STRING_ID, WL_ERROR);
 
				} else {
 
					ShowNetworkContentListWindow(NULL, CONTENT_TYPE_AI, CONTENT_TYPE_GAME);
 
					ShowNetworkContentListWindow(nullptr, CONTENT_TYPE_AI, CONTENT_TYPE_GAME);
 
				}
 
				break;
 
		}
 
@@ -955,7 +955,7 @@ struct AIConfigWindow : public Window {
 
		this->SetWidgetDisabledState(WID_AIC_MOVE_DOWN, this->selected_slot == OWNER_DEITY || this->selected_slot == INVALID_COMPANY || !IsEditable((CompanyID)(this->selected_slot + 1)));
 

	
 
		for (TextfileType tft = TFT_BEGIN; tft < TFT_END; tft++) {
 
			this->SetWidgetDisabledState(WID_AIC_TEXTFILE + tft, this->selected_slot == INVALID_COMPANY || (GetConfig(this->selected_slot)->GetTextfile(tft, this->selected_slot) == NULL));
 
			this->SetWidgetDisabledState(WID_AIC_TEXTFILE + tft, this->selected_slot == INVALID_COMPANY || (GetConfig(this->selected_slot)->GetTextfile(tft, this->selected_slot) == nullptr));
 
		}
 
	}
 
};
 
@@ -1024,7 +1024,7 @@ struct AIDebugWindow : public Window {
 
	{
 
		if (ai_debug_company == OWNER_DEITY) {
 
			GameInstance *game = Game::GetInstance();
 
			return game == NULL || game->IsDead();
 
			return game == nullptr || game->IsDead();
 
		}
 
		return !Company::IsValidAiID(ai_debug_company) || Company::Get(ai_debug_company)->ai_instance->IsDead();
 
	}
 
@@ -1038,7 +1038,7 @@ struct AIDebugWindow : public Window {
 
	{
 
		switch (company) {
 
			case INVALID_COMPANY: return false;
 
			case OWNER_DEITY:     return Game::GetInstance() != NULL;
 
			case OWNER_DEITY:     return Game::GetInstance() != nullptr;
 
			default:              return Company::IsValidAiID(company);
 
		}
 
	}
 
@@ -1063,7 +1063,7 @@ struct AIDebugWindow : public Window {
 
		}
 

	
 
		/* If no AI is available, see if there is a game script. */
 
		if (Game::GetInstance() != NULL) ChangeToAI(OWNER_DEITY);
 
		if (Game::GetInstance() != nullptr) ChangeToAI(OWNER_DEITY);
 
	}
 

	
 
	/**
 
@@ -1140,7 +1140,7 @@ struct AIDebugWindow : public Window {
 

	
 
		/* Set button colour for Game Script. */
 
		GameInstance *game = Game::GetInstance();
 
		bool valid = game != NULL;
 
		bool valid = game != nullptr;
 
		bool dead = valid && game->IsDead();
 
		bool paused = valid && game->IsPaused();
 

	
 
@@ -1154,7 +1154,7 @@ struct AIDebugWindow : public Window {
 

	
 
		ScriptLog::LogData *log = this->GetLogPointer();
 

	
 
		int scroll_count = (log == NULL) ? 0 : log->used;
 
		int scroll_count = (log == nullptr) ? 0 : log->used;
 
		if (this->vscroll->GetCount() != scroll_count) {
 
			this->vscroll->SetCount(scroll_count);
 

	
 
@@ -1162,7 +1162,7 @@ struct AIDebugWindow : public Window {
 
			this->SetWidgetDirty(WID_AID_SCROLLBAR);
 
		}
 

	
 
		if (log == NULL) return;
 
		if (log == nullptr) return;
 

	
 
		/* Detect when the user scrolls the window. Enable autoscroll when the
 
		 * bottom-most line becomes visible. */
 
@@ -1188,7 +1188,7 @@ struct AIDebugWindow : public Window {
 
			case WID_AID_NAME_TEXT:
 
				if (ai_debug_company == OWNER_DEITY) {
 
					const GameInfo *info = Game::GetInfo();
 
					assert(info != NULL);
 
					assert(info != nullptr);
 
					SetDParam(0, STR_AI_DEBUG_NAME_AND_VERSION);
 
					SetDParamStr(1, info->GetName());
 
					SetDParam(2, info->GetVersion());
 
@@ -1196,7 +1196,7 @@ struct AIDebugWindow : public Window {
 
					SetDParam(0, STR_EMPTY);
 
				} else {
 
					const AIInfo *info = Company::Get(ai_debug_company)->ai_info;
 
					assert(info != NULL);
 
					assert(info != nullptr);
 
					SetDParam(0, STR_AI_DEBUG_NAME_AND_VERSION);
 
					SetDParamStr(1, info->GetName());
 
					SetDParam(2, info->GetVersion());
 
@@ -1212,12 +1212,12 @@ struct AIDebugWindow : public Window {
 
		switch (widget) {
 
			case WID_AID_LOG_PANEL: {
 
				ScriptLog::LogData *log = this->GetLogPointer();
 
				if (log == NULL) return;
 
				if (log == nullptr) return;
 

	
 
				int y = this->top_offset;
 
				for (int i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < log->used; i++) {
 
					int pos = (i + log->pos + 1 - log->used + log->count) % log->count;
 
					if (log->lines[pos] == NULL) break;
 
					if (log->lines[pos] == nullptr) break;
 

	
 
					TextColour colour;
 
					switch (log->type[pos]) {
 
@@ -1357,7 +1357,7 @@ struct AIDebugWindow : public Window {
 
			/* Get the log instance of the active company */
 
			ScriptLog::LogData *log = this->GetLogPointer();
 

	
 
			if (log != NULL) {
 
			if (log != nullptr) {
 
				this->break_string_filter.ResetState();
 
				this->break_string_filter.AddLine(log->lines[log->pos]);
 
				if (this->break_string_filter.GetState()) {
 
@@ -1385,8 +1385,8 @@ struct AIDebugWindow : public Window {
 

	
 
		this->SelectValidDebugCompany();
 

	
 
		ScriptLog::LogData *log = ai_debug_company != INVALID_COMPANY ? this->GetLogPointer() : NULL;
 
		this->vscroll->SetCount((log == NULL) ? 0 : log->used);
 
		ScriptLog::LogData *log = ai_debug_company != INVALID_COMPANY ? this->GetLogPointer() : nullptr;
 
		this->vscroll->SetCount((log == nullptr) ? 0 : log->used);
 

	
 
		/* Update company buttons */
 
		for (CompanyID i = COMPANY_FIRST; i < MAX_COMPANIES; i++) {
 
@@ -1394,7 +1394,7 @@ struct AIDebugWindow : public Window {
 
			this->SetWidgetLoweredState(i + WID_AID_COMPANY_BUTTON_START, ai_debug_company == i);
 
		}
 

	
 
		this->SetWidgetDisabledState(WID_AID_SCRIPT_GAME, Game::GetGameInstance() == NULL);
 
		this->SetWidgetDisabledState(WID_AID_SCRIPT_GAME, Game::GetGameInstance() == nullptr);
 
		this->SetWidgetLoweredState(WID_AID_SCRIPT_GAME, ai_debug_company == OWNER_DEITY);
 

	
 
		this->SetWidgetLoweredState(WID_AID_BREAK_STR_ON_OFF_BTN, this->break_check_enabled);
 
@@ -1437,7 +1437,7 @@ static EventState AIDebugGlobalHotkeys(i
 
{
 
	if (_game_mode != GM_NORMAL) return ES_NOT_HANDLED;
 
	Window *w = ShowAIDebugWindow(INVALID_COMPANY);
 
	if (w == NULL) return ES_NOT_HANDLED;
 
	if (w == nullptr) return ES_NOT_HANDLED;
 
	return w->OnHotkey(hotkey);
 
}
 

	
 
@@ -1530,14 +1530,14 @@ Window *ShowAIDebugWindow(CompanyID show
 
{
 
	if (!_networking || _network_server) {
 
		AIDebugWindow *w = (AIDebugWindow *)BringWindowToFrontById(WC_AI_DEBUG, 0);
 
		if (w == NULL) w = new AIDebugWindow(&_ai_debug_desc, 0);
 
		if (w == nullptr) w = new AIDebugWindow(&_ai_debug_desc, 0);
 
		if (show_company != INVALID_COMPANY) w->ChangeToAI(show_company);
 
		return w;
 
	} else {
 
		ShowErrorMessage(STR_ERROR_AI_DEBUG_SERVER_ONLY, INVALID_STRING_ID, WL_INFO);
 
	}
 

	
 
	return NULL;
 
	return nullptr;
 
}
 

	
 
/**
 
@@ -1563,7 +1563,7 @@ void ShowAIDebugWindowIfAIError()
 
	}
 

	
 
	GameInstance *g = Game::GetGameInstance();
 
	if (g != NULL && g->IsDead()) {
 
	if (g != nullptr && g->IsDead()) {
 
		ShowAIDebugWindow(OWNER_DEITY);
 
	}
 
}
src/ai/ai_info.cpp
Show inline comments
 
@@ -65,8 +65,8 @@ template <> const char *GetClassName<AII
 
/* static */ SQInteger AIInfo::Constructor(HSQUIRRELVM vm)
 
{
 
	/* Get the AIInfo */
 
	SQUserPointer instance = NULL;
 
	if (SQ_FAILED(sq_getinstanceup(vm, 2, &instance, 0)) || instance == NULL) return sq_throwerror(vm, "Pass an instance of a child class of AIInfo to RegisterAI");
 
	SQUserPointer instance = nullptr;
 
	if (SQ_FAILED(sq_getinstanceup(vm, 2, &instance, 0)) || instance == nullptr) return sq_throwerror(vm, "Pass an instance of a child class of AIInfo to RegisterAI");
 
	AIInfo *info = (AIInfo *)instance;
 

	
 
	SQInteger res = ScriptInfo::Constructor(vm, info);
 
@@ -100,7 +100,7 @@ template <> const char *GetClassName<AII
 
	}
 

	
 
	/* Remove the link to the real instance, else it might get deleted by RegisterAI() */
 
	sq_setinstanceup(vm, 2, NULL);
 
	sq_setinstanceup(vm, 2, nullptr);
 
	/* Register the AI to the base system */
 
	info->GetScanner()->RegisterScript(info);
 
	return 0;
 
@@ -112,7 +112,7 @@ template <> const char *GetClassName<AII
 
	SQUserPointer instance;
 
	sq_getinstanceup(vm, 2, &instance, 0);
 
	AIInfo *info = (AIInfo *)instance;
 
	info->api_version = NULL;
 
	info->api_version = nullptr;
 

	
 
	SQInteger res = ScriptInfo::Constructor(vm, info);
 
	if (res != 0) return res;
 
@@ -122,7 +122,7 @@ template <> const char *GetClassName<AII
 
	info->api_version = stredup(buf);
 

	
 
	/* Remove the link to the real instance, else it might get deleted by RegisterAI() */
 
	sq_setinstanceup(vm, 2, NULL);
 
	sq_setinstanceup(vm, 2, nullptr);
 
	/* Register the AI to the base system */
 
	static_cast<AIScannerInfo *>(info->GetScanner())->SetDummyAI(info);
 
	return 0;
 
@@ -131,7 +131,7 @@ template <> const char *GetClassName<AII
 
AIInfo::AIInfo() :
 
	min_loadable_version(0),
 
	use_as_random(false),
 
	api_version(NULL)
 
	api_version(nullptr)
 
{
 
}
 

	
src/ai/ai_info.hpp
Show inline comments
 
@@ -59,7 +59,7 @@ private:
 
/** All static information from an AI library like name, version, etc. */
 
class AILibrary : public ScriptInfo {
 
public:
 
	AILibrary() : ScriptInfo(), category(NULL) {};
 
	AILibrary() : ScriptInfo(), category(nullptr) {};
 
	~AILibrary();
 

	
 
	/**
src/ai/ai_instance.cpp
Show inline comments
 
@@ -216,10 +216,10 @@ void AIInstance::Died()
 
	ShowAIDebugWindow(_current_company);
 

	
 
	const AIInfo *info = AIConfig::GetConfig(_current_company, AIConfig::SSS_FORCE_GAME)->GetInfo();
 
	if (info != NULL) {
 
	if (info != nullptr) {
 
		ShowErrorMessage(STR_ERROR_AI_PLEASE_REPORT_CRASH, INVALID_STRING_ID, WL_WARNING);
 

	
 
		if (info->GetURL() != NULL) {
 
		if (info->GetURL() != nullptr) {
 
			ScriptLog::Info("Please report the error to the following URL:");
 
			ScriptLog::Info(info->GetURL());
 
		}
 
@@ -258,7 +258,7 @@ void CcAI(const CommandCost &result, Til
 
	 * when the company does not exist anymore.
 
	 */
 
	const Company *c = Company::GetIfValid(_current_company);
 
	if (c == NULL || c->ai_instance == NULL) return;
 
	if (c == nullptr || c->ai_instance == nullptr) return;
 

	
 
	c->ai_instance->DoCommandCallback(result, tile, p1, p2);
 
	c->ai_instance->Continue();
src/ai/ai_scanner.cpp
Show inline comments
 
@@ -23,7 +23,7 @@
 

	
 
AIScannerInfo::AIScannerInfo() :
 
	ScriptScanner(),
 
	info_dummy(NULL)
 
	info_dummy(nullptr)
 
{
 
}
 

	
 
@@ -94,14 +94,14 @@ AIInfo *AIScannerInfo::SelectRandomAI() 
 

	
 
AIInfo *AIScannerInfo::FindInfo(const char *nameParam, int versionParam, bool force_exact_match)
 
{
 
	if (this->info_list.size() == 0) return NULL;
 
	if (nameParam == NULL) return NULL;
 
	if (this->info_list.size() == 0) return nullptr;
 
	if (nameParam == nullptr) return nullptr;
 

	
 
	char ai_name[1024];
 
	strecpy(ai_name, nameParam, lastof(ai_name));
 
	strtolower(ai_name);
 

	
 
	AIInfo *info = NULL;
 
	AIInfo *info = nullptr;
 
	int version = -1;
 

	
 
	if (versionParam == -1) {
 
@@ -110,7 +110,7 @@ AIInfo *AIScannerInfo::FindInfo(const ch
 

	
 
		/* If we didn't find a match AI, maybe the user included a version */
 
		char *e = strrchr(ai_name, '.');
 
		if (e == NULL) return NULL;
 
		if (e == nullptr) return nullptr;
 
		*e = '\0';
 
		e++;
 
		versionParam = atoi(e);
 
@@ -165,7 +165,7 @@ AILibrary *AIScannerLibrary::FindLibrary
 

	
 
	/* Check if the library + version exists */
 
	ScriptInfoList::iterator iter = this->info_list.find(library_name);
 
	if (iter == this->info_list.end()) return NULL;
 
	if (iter == this->info_list.end()) return nullptr;
 

	
 
	return static_cast<AILibrary *>((*iter).second);
 
}
src/ai/ai_scanner.hpp
Show inline comments
 
@@ -32,7 +32,7 @@ public:
 
	 * @param nameParam The name of the AI.
 
	 * @param versionParam The version of the AI, or -1 if you want the latest.
 
	 * @param force_exact_match Only match name+version, never latest.
 
	 * @return NULL if no match found, otherwise the AI that matched.
 
	 * @return nullptr if no match found, otherwise the AI that matched.
 
	 */
 
	class AIInfo *FindInfo(const char *nameParam, int versionParam, bool force_exact_match);
 

	
 
@@ -60,7 +60,7 @@ public:
 
	 * Find a library in the pool.
 
	 * @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.
 
	 */
 
	class AILibrary *FindLibrary(const char *library, int version);
 

	
src/aircraft_cmd.cpp
Show inline comments
 
@@ -143,7 +143,7 @@ static StationID FindNearestHangar(const
 
		if (v->acache.cached_max_range_sqr != 0) {
 
			/* Check if our current destination can be reached from the depot airport. */
 
			const Station *cur_dest = GetTargetAirportIfValid(v);
 
			if (cur_dest != NULL && DistanceSquare(st->airport.tile, cur_dest->airport.tile) > v->acache.cached_max_range_sqr) continue;
 
			if (cur_dest != nullptr && DistanceSquare(st->airport.tile, cur_dest->airport.tile) > v->acache.cached_max_range_sqr) continue;
 
		}
 
		if (distance < best || index == INVALID_STATION) {
 
			best = distance;
 
@@ -295,7 +295,7 @@ CommandCost CmdBuildAircraft(TileIndex t
 
		v->cargo_type = e->GetDefaultCargoType();
 
		u->cargo_type = CT_MAIL;
 

	
 
		v->name = NULL;
 
		v->name = nullptr;
 
		v->last_station_visited = INVALID_STATION;
 
		v->last_loading_station = INVALID_STATION;
 

	
 
@@ -379,7 +379,7 @@ bool Aircraft::FindClosestDepot(TileInde
 
{
 
	const Station *st = GetTargetAirportIfValid(this);
 
	/* If the station is not a valid airport or if it has no hangars */
 
	if (st == NULL || !CanVehicleUseStation(this, st) || !st->airport.HasHangar()) {
 
	if (st == nullptr || !CanVehicleUseStation(this, st) || !st->airport.HasHangar()) {
 
		/* the aircraft has to search for a hangar on its own */
 
		StationID station = FindNearestHangar(this);
 

	
 
@@ -388,8 +388,8 @@ bool Aircraft::FindClosestDepot(TileInde
 
		st = Station::Get(station);
 
	}
 

	
 
	if (location    != NULL) *location    = st->xy;
 
	if (destination != NULL) *destination = st->index;
 
	if (location    != nullptr) *location    = st->xy;
 
	if (destination != nullptr) *destination = st->index;
 

	
 
	return true;
 
}
 
@@ -408,7 +408,7 @@ static void CheckIfAircraftNeedsService(
 

	
 
	const Station *st = Station::Get(v->current_order.GetDestination());
 

	
 
	assert(st != NULL);
 
	assert(st != nullptr);
 

	
 
	/* only goto depot if the target airport has a depot */
 
	if (st->airport.HasHangar() && CanVehicleUseStation(v, st)) {
 
@@ -531,7 +531,7 @@ void SetAircraftPosition(Aircraft *v, in
 
	u->UpdatePositionAndViewport();
 

	
 
	u = u->Next();
 
	if (u != NULL) {
 
	if (u != nullptr) {
 
		u->x_pos = x;
 
		u->y_pos = y;
 
		u->z_pos = z + ROTOR_Z_OFFSET;
 
@@ -552,7 +552,7 @@ void HandleAircraftEnterHangar(Aircraft 
 
	Aircraft *u = v->Next();
 
	u->vehstatus |= VS_HIDDEN;
 
	u = u->Next();
 
	if (u != NULL) {
 
	if (u != nullptr) {
 
		u->vehstatus |= VS_HIDDEN;
 
		u->cur_speed = 0;
 
	}
 
@@ -725,8 +725,8 @@ void GetAircraftFlightLevelBounds(const 
 
	/* Make faster planes fly higher so that they can overtake slower ones */
 
	base_altitude += min(20 * (v->vcache.cached_max_speed / 200) - 90, 0);
 

	
 
	if (min_level != NULL) *min_level = base_altitude + AIRCRAFT_MIN_FLYING_ALTITUDE;
 
	if (max_level != NULL) *max_level = base_altitude + AIRCRAFT_MAX_FLYING_ALTITUDE;
 
	if (min_level != nullptr) *min_level = base_altitude + AIRCRAFT_MIN_FLYING_ALTITUDE;
 
	if (max_level != nullptr) *max_level = base_altitude + AIRCRAFT_MAX_FLYING_ALTITUDE;
 
}
 

	
 
/**
 
@@ -801,8 +801,8 @@ template int GetAircraftFlightLevel(Airc
 
 */
 
static byte AircraftGetEntryPoint(const Aircraft *v, const AirportFTAClass *apc, Direction rotation)
 
{
 
	assert(v != NULL);
 
	assert(apc != NULL);
 
	assert(v != nullptr);
 
	assert(apc != nullptr);
 

	
 
	/* In the case the station doesn't exit anymore, set target tile 0.
 
	 * It doesn't hurt much, aircraft will go to next order, nearest hangar
 
@@ -810,7 +810,7 @@ static byte AircraftGetEntryPoint(const 
 
	TileIndex tile = 0;
 

	
 
	const Station *st = Station::GetIfValid(v->targetairport);
 
	if (st != NULL) {
 
	if (st != nullptr) {
 
		/* Make sure we don't go to INVALID_TILE if the airport has been removed. */
 
		tile = (st->airport.tile != INVALID_TILE) ? st->airport.tile : st->xy;
 
	}
 
@@ -844,13 +844,13 @@ static bool AircraftController(Aircraft 
 
{
 
	int count;
 

	
 
	/* NULL if station is invalid */
 
	/* nullptr if station is invalid */
 
	const Station *st = Station::GetIfValid(v->targetairport);
 
	/* INVALID_TILE if there is no station */
 
	TileIndex tile = INVALID_TILE;
 
	Direction rotation = DIR_N;
 
	uint size_x = 1, size_y = 1;
 
	if (st != NULL) {
 
	if (st != nullptr) {
 
		if (st->airport.tile != INVALID_TILE) {
 
			tile = st->airport.tile;
 
			rotation = st->airport.rotation;
 
@@ -864,7 +864,7 @@ static bool AircraftController(Aircraft 
 
	const AirportFTAClass *afc = tile == INVALID_TILE ? GetAirport(AT_DUMMY) : st->airport.GetFTA();
 

	
 
	/* prevent going to INVALID_TILE if airport is deleted. */
 
	if (st == NULL || st->airport.tile == INVALID_TILE) {
 
	if (st == nullptr || st->airport.tile == INVALID_TILE) {
 
		/* Jump into our "holding pattern" state machine if possible */
 
		if (v->pos >= afc->nofelements) {
 
			v->pos = v->previous_pos = AircraftGetEntryPoint(v, afc, DIR_N);
 
@@ -904,7 +904,7 @@ static bool AircraftController(Aircraft 
 
				v->tile = 0;
 

	
 
				int z_dest;
 
				GetAircraftFlightLevelBounds(v, &z_dest, NULL);
 
				GetAircraftFlightLevelBounds(v, &z_dest, nullptr);
 

	
 
				/* Reached altitude? */
 
				if (v->z_pos >= z_dest) {
 
@@ -921,7 +921,7 @@ static bool AircraftController(Aircraft 
 
	if (amd.flag & AMED_HELI_LOWER) {
 
		SetBit(v->flags, VAF_HELI_DIRECT_DESCENT);
 

	
 
		if (st == NULL) {
 
		if (st == nullptr) {
 
			/* FIXME - AircraftController -> if station no longer exists, do not land
 
			 * helicopter will circle until sign disappears, then go to next order
 
			 * what to do when it is the only order left, right now it just stays in 1 place */
 
@@ -1127,7 +1127,7 @@ static bool HandleCrashedAircraft(Aircra
 
	Station *st = GetTargetAirportIfValid(v);
 

	
 
	/* make aircraft crash down to the ground */
 
	if (v->crashed_counter < 500 && st == NULL && ((v->crashed_counter % 3) == 0) ) {
 
	if (v->crashed_counter < 500 && st == nullptr && ((v->crashed_counter % 3) == 0) ) {
 
		int z = GetSlopePixelZ(Clamp(v->x_pos, 0, MapMaxX() * TILE_SIZE), Clamp(v->y_pos, 0, MapMaxY() * TILE_SIZE));
 
		v->z_pos -= 1;
 
		if (v->z_pos == z) {
 
@@ -1158,7 +1158,7 @@ static bool HandleCrashedAircraft(Aircra
 
		/* clear runway-in on all airports, set by crashing plane
 
		 * small airports use AIRPORT_BUSY, city airports use RUNWAY_IN_OUT_block, etc.
 
		 * but they all share the same number */
 
		if (st != NULL) {
 
		if (st != nullptr) {
 
			CLRBITS(st->airport.flags, RUNWAY_IN_block);
 
			CLRBITS(st->airport.flags, RUNWAY_IN_OUT_block); // commuter airport
 
			CLRBITS(st->airport.flags, RUNWAY_IN2_block);    // intercontinental
 
@@ -1232,7 +1232,7 @@ void HandleMissingAircraftOrders(Aircraf
 
	 *    actually stops.
 
	 */
 
	const Station *st = GetTargetAirportIfValid(v);
 
	if (st == NULL) {
 
	if (st == nullptr) {
 
		Backup<CompanyByte> cur_company(_current_company, v->owner, FILE_LINE);
 
		CommandCost ret = DoCommand(v->tile, v->index, 0, DC_EXEC, CMD_SEND_VEHICLE_TO_DEPOT);
 
		cur_company.Restore();
 
@@ -1288,17 +1288,17 @@ static void CrashAirplane(Aircraft *v)
 
	v->Next()->cargo.Truncate();
 
	const Station *st = GetTargetAirportIfValid(v);
 
	StringID newsitem;
 
	if (st == NULL) {
 
	if (st == nullptr) {
 
		newsitem = STR_NEWS_PLANE_CRASH_OUT_OF_FUEL;
 
	} else {
 
		SetDParam(1, st->index);
 
		newsitem = STR_NEWS_AIRCRAFT_CRASH;
 
	}
 

	
 
	AI::NewEvent(v->owner, new ScriptEventVehicleCrashed(v->index, v->tile, st == NULL ? ScriptEventVehicleCrashed::CRASH_AIRCRAFT_NO_AIRPORT : ScriptEventVehicleCrashed::CRASH_PLANE_LANDING));
 
	Game::NewEvent(new ScriptEventVehicleCrashed(v->index, v->tile, st == NULL ? ScriptEventVehicleCrashed::CRASH_AIRCRAFT_NO_AIRPORT : ScriptEventVehicleCrashed::CRASH_PLANE_LANDING));
 
	AI::NewEvent(v->owner, new ScriptEventVehicleCrashed(v->index, v->tile, st == nullptr ? ScriptEventVehicleCrashed::CRASH_AIRCRAFT_NO_AIRPORT : ScriptEventVehicleCrashed::CRASH_PLANE_LANDING));
 
	Game::NewEvent(new ScriptEventVehicleCrashed(v->index, v->tile, st == nullptr ? ScriptEventVehicleCrashed::CRASH_AIRCRAFT_NO_AIRPORT : ScriptEventVehicleCrashed::CRASH_PLANE_LANDING));
 

	
 
	AddVehicleNewsItem(newsitem, NT_ACCIDENT, v->index, st != NULL ? st->index : INVALID_STATION);
 
	AddVehicleNewsItem(newsitem, NT_ACCIDENT, v->index, st != nullptr ? st->index : INVALID_STATION);
 

	
 
	ModifyStationRatingAround(v->tile, v->owner, -160, 30);
 
	if (_settings_client.sound.disaster) SndPlayVehicleFx(SND_12_EXPLOSION, v);
 
@@ -1392,8 +1392,8 @@ void AircraftNextAirportPos_and_Order(Ai
 
	}
 

	
 
	const Station *st = GetTargetAirportIfValid(v);
 
	const AirportFTAClass *apc = st == NULL ? GetAirport(AT_DUMMY) : st->airport.GetFTA();
 
	Direction rotation = st == NULL ? DIR_N : st->airport.rotation;
 
	const AirportFTAClass *apc = st == nullptr ? GetAirport(AT_DUMMY) : st->airport.GetFTA();
 
	Direction rotation = st == nullptr ? DIR_N : st->airport.rotation;
 
	v->pos = v->previous_pos = AircraftGetEntryPoint(v, apc, rotation);
 
}
 

	
 
@@ -1418,7 +1418,7 @@ void AircraftLeaveHangar(Aircraft *v, Di
 

	
 
		/* Rotor blades */
 
		u = u->Next();
 
		if (u != NULL) {
 
		if (u != nullptr) {
 
			u->vehstatus &= ~VS_HIDDEN;
 
			u->cur_speed = 80;
 
		}
 
@@ -1605,7 +1605,7 @@ static void AircraftEventHandler_Flying(
 
		 * it is possible to choose from multiple landing runways, so loop until a free one is found */
 
		byte landingtype = (v->subtype == AIR_HELICOPTER) ? HELILANDING : LANDING;
 
		const AirportFTA *current = apc->layout[v->pos].next;
 
		while (current != NULL) {
 
		while (current != nullptr) {
 
			if (current->heading == landingtype) {
 
				/* save speed before, since if AirportHasBlock is false, it resets them to 0
 
				 * we don't want that for plane in air
 
@@ -1761,7 +1761,7 @@ static bool AirportMove(Aircraft *v, con
 
	v->previous_pos = v->pos; // save previous location
 

	
 
	/* there is only one choice to move to */
 
	if (current->next == NULL) {
 
	if (current->next == nullptr) {
 
		if (AirportSetBlocks(v, current, apc)) {
 
			v->pos = current->next_position;
 
			UpdateAircraftCache(v);
 
@@ -1780,7 +1780,7 @@ static bool AirportMove(Aircraft *v, con
 
			return false;
 
		}
 
		current = current->next;
 
	} while (current != NULL);
 
	} while (current != nullptr);
 

	
 
	DEBUG(misc, 0, "[Ap] cannot move further on Airport! (pos %d state %d) for vehicle %d", v->pos, v->state, v->index);
 
	NOT_REACHED();
 
@@ -1830,7 +1830,7 @@ static bool AirportSetBlocks(Aircraft *v
 
		 * this means more blocks should be checked/set */
 
		const AirportFTA *current = current_pos;
 
		if (current == reference) current = current->next;
 
		while (current != NULL) {
 
		while (current != nullptr) {
 
			if (current->heading == current_pos->heading && current->block != 0) {
 
				airport_flags |= current->block;
 
				break;
 
@@ -1938,7 +1938,7 @@ static bool AirportFindFreeTerminal(Airc
 
		const Station *st = Station::Get(v->targetairport);
 
		const AirportFTA *temp = apc->layout[v->pos].next;
 

	
 
		while (temp != NULL) {
 
		while (temp != nullptr) {
 
			if (temp->heading == 255) {
 
				if (!(st->airport.flags & temp->block)) {
 
					/* read which group do we want to go to?
 
@@ -2037,9 +2037,9 @@ static bool AircraftEventHandler(Aircraf
 
		/* Check the distance to the next destination. This code works because the target
 
		 * airport is only updated after take off and not on the ground. */
 
		Station *cur_st = Station::GetIfValid(v->targetairport);
 
		Station *next_st = v->current_order.IsType(OT_GOTO_STATION) || v->current_order.IsType(OT_GOTO_DEPOT) ? Station::GetIfValid(v->current_order.GetDestination()) : NULL;
 
		Station *next_st = v->current_order.IsType(OT_GOTO_STATION) || v->current_order.IsType(OT_GOTO_DEPOT) ? Station::GetIfValid(v->current_order.GetDestination()) : nullptr;
 

	
 
		if (cur_st != NULL && cur_st->airport.tile != INVALID_TILE && next_st != NULL && next_st->airport.tile != INVALID_TILE) {
 
		if (cur_st != nullptr && cur_st->airport.tile != INVALID_TILE && next_st != nullptr && next_st->airport.tile != INVALID_TILE) {
 
			uint dist = DistanceSquare(cur_st->airport.tile, next_st->airport.tile);
 
			AircraftHandleDestTooFar(v, dist > v->acache.cached_max_range_sqr);
 
		}
 
@@ -2077,16 +2077,16 @@ bool Aircraft::Tick()
 
 * Returns aircraft's target station if v->target_airport
 
 * is a valid station with airport.
 
 * @param v vehicle to get target airport for
 
 * @return pointer to target station, NULL if invalid
 
 * @return pointer to target station, nullptr if invalid
 
 */
 
Station *GetTargetAirportIfValid(const Aircraft *v)
 
{
 
	assert(v->type == VEH_AIRCRAFT);
 

	
 
	Station *st = Station::GetIfValid(v->targetairport);
 
	if (st == NULL) return NULL;
 
	if (st == nullptr) return nullptr;
 

	
 
	return st->airport.tile == INVALID_TILE ? NULL : st;
 
	return st->airport.tile == INVALID_TILE ? nullptr : st;
 
}
 

	
 
/**
src/aircraft_gui.cpp
Show inline comments
 
@@ -36,7 +36,7 @@ void DrawAircraftDetails(const Aircraft 
 
	int y_offset = (v->Next()->cargo_cap != 0) ? -(FONT_HEIGHT_NORMAL + 1): 0;
 
	Money feeder_share = 0;
 

	
 
	for (const Aircraft *u = v; u != NULL; u = u->Next()) {
 
	for (const Aircraft *u = v; u != nullptr; u = u->Next()) {
 
		if (u->IsNormalAircraft()) {
 
			SetDParam(0, u->engine_type);
 
			SetDParam(1, u->build_year);
src/airport.cpp
Show inline comments
 
@@ -46,7 +46,7 @@
 
 * @param delta_z Height of the airport above the land.
 
 */
 
#define HELIPORT(name, num_helipads, delta_z) \
 
	AIRPORT_GENERIC(name, NULL, num_helipads, AirportFTAClass::HELICOPTERS, delta_z)
 
	AIRPORT_GENERIC(name, nullptr, num_helipads, AirportFTAClass::HELICOPTERS, delta_z)
 

	
 
AIRPORT(country, 0, true)
 
AIRPORT(city, 0, false)
 
@@ -58,7 +58,7 @@ HELIPORT(helidepot, 1, 0)
 
AIRPORT(intercontinental, 2, false)
 
HELIPORT(helistation, 3, 0)
 
HELIPORT(oilrig, 1, 54)
 
AIRPORT_GENERIC(dummy, NULL, 0, AirportFTAClass::ALL, 0)
 
AIRPORT_GENERIC(dummy, nullptr, 0, AirportFTAClass::ALL, 0)
 

	
 
#undef HELIPORT
 
#undef AIRPORT
 
@@ -135,7 +135,7 @@ AirportFTAClass::~AirportFTAClass()
 
{
 
	for (uint i = 0; i < nofelements; i++) {
 
		AirportFTA *current = layout[i].next;
 
		while (current != NULL) {
 
		while (current != nullptr) {
 
			AirportFTA *next = current->next;
 
			free(current);
 
			current = next;
 
@@ -195,7 +195,7 @@ static AirportFTA *AirportBuildAutomata(
 
			current = current->next;
 
			internalcounter++;
 
		}
 
		current->next = NULL;
 
		current->next = nullptr;
 
		internalcounter++;
 
	}
 
	return FAutomata;
src/airport_gui.cpp
Show inline comments
 
@@ -161,7 +161,7 @@ static EventState AirportToolbarGlobalHo
 
{
 
	if (_game_mode != GM_NORMAL || !CanBuildVehicleInfrastructure(VEH_AIRCRAFT)) return ES_NOT_HANDLED;
 
	Window *w = ShowBuildAirToolbar();
 
	if (w == NULL) return ES_NOT_HANDLED;
 
	if (w == nullptr) return ES_NOT_HANDLED;
 
	return w->OnHotkey(hotkey);
 
}
 

	
 
@@ -198,11 +198,11 @@ static WindowDesc _air_toolbar_desc(
 
 *
 
 * If the terraform toolbar is linked to the toolbar, that window is also opened.
 
 *
 
 * @return newly opened airport toolbar, or NULL if the toolbar could not be opened.
 
 * @return newly opened airport toolbar, or nullptr if the toolbar could not be opened.
 
 */
 
Window *ShowBuildAirToolbar()
 
{
 
	if (!Company::IsValidID(_local_company)) return NULL;
 
	if (!Company::IsValidID(_local_company)) return nullptr;
 

	
 
	DeleteWindowByClass(WC_BUILD_TOOLBAR);
 
	return AllocateWindowDescFront<BuildAirToolbarWindow>(&_air_toolbar_desc, TRANSPORT_AIR);
src/articulated_vehicles.cpp
Show inline comments
 
@@ -31,9 +31,9 @@ static const uint MAX_ARTICULATED_PARTS 
 
 * @param mirrored Returns whether the part shall be flipped.
 
 * @return engine to add or INVALID_ENGINE
 
 */
 
static EngineID GetNextArticulatedPart(uint index, EngineID front_type, Vehicle *front = NULL, bool *mirrored = NULL)
 
static EngineID GetNextArticulatedPart(uint index, EngineID front_type, Vehicle *front = nullptr, bool *mirrored = nullptr)
 
{
 
	assert(front == NULL || front->engine_type == front_type);
 
	assert(front == nullptr || front->engine_type == front_type);
 

	
 
	const Engine *front_engine = Engine::Get(front_type);
 

	
 
@@ -44,12 +44,12 @@ static EngineID GetNextArticulatedPart(u
 
		/* 8 bits, bit 7 for mirroring */
 
		callback = GB(callback, 0, 8);
 
		if (callback == 0xFF) return INVALID_ENGINE;
 
		if (mirrored != NULL) *mirrored = HasBit(callback, 7);
 
		if (mirrored != nullptr) *mirrored = HasBit(callback, 7);
 
		callback = GB(callback, 0, 7);
 
	} else {
 
		/* 15 bits, bit 14 for mirroring */
 
		if (callback == 0x7FFF) return INVALID_ENGINE;
 
		if (mirrored != NULL) *mirrored = HasBit(callback, 14);
 
		if (mirrored != nullptr) *mirrored = HasBit(callback, 14);
 
		callback = GB(callback, 0, 14);
 
	}
 

	
 
@@ -80,7 +80,7 @@ uint CountArticulatedParts(EngineID engi
 
	 * either, so it doesn't matter how many articulated parts there are. */
 
	if (!Vehicle::CanAllocateItem()) return 0;
 

	
 
	Vehicle *v = NULL;
 
	Vehicle *v = nullptr;
 
	if (!purchase_window) {
 
		v = new Vehicle();
 
		v->engine_type = engine_type;
 
@@ -108,7 +108,7 @@ static inline uint16 GetVehicleDefaultCa
 
{
 
	const Engine *e = Engine::Get(engine);
 
	CargoID cargo = (e->CanCarryCargo() ? e->GetDefaultCargoType() : (CargoID)CT_INVALID);
 
	if (cargo_type != NULL) *cargo_type = cargo;
 
	if (cargo_type != nullptr) *cargo_type = cargo;
 
	if (cargo == CT_INVALID) return 0;
 
	return e->GetDisplayDefaultCapacity();
 
}
 
@@ -290,15 +290,15 @@ bool IsArticulatedVehicleCarryingDiffere
 
		if (v->cargo_type != CT_INVALID && v->GetEngine()->CanCarryCargo()) {
 
			if (first_cargo == CT_INVALID) first_cargo = v->cargo_type;
 
			if (first_cargo != v->cargo_type) {
 
				if (cargo_type != NULL) *cargo_type = CT_INVALID;
 
				if (cargo_type != nullptr) *cargo_type = CT_INVALID;
 
				return true;
 
			}
 
		}
 

	
 
		v = v->HasArticulatedPart() ? v->GetNextArticulatedPart() : NULL;
 
	} while (v != NULL);
 
		v = v->HasArticulatedPart() ? v->GetNextArticulatedPart() : nullptr;
 
	} while (v != nullptr);
 

	
 
	if (cargo_type != NULL) *cargo_type = first_cargo;
 
	if (cargo_type != nullptr) *cargo_type = first_cargo;
 
	return false;
 
}
 

	
 
@@ -330,8 +330,8 @@ void CheckConsistencyOfArticulatedVehicl
 
		assert(v->cargo_type < NUM_CARGO);
 
		real_default_capacity[v->cargo_type] += v->cargo_cap;
 

	
 
		v = v->HasArticulatedPart() ? v->GetNextArticulatedPart() : NULL;
 
	} while (v != NULL);
 
		v = v->HasArticulatedPart() ? v->GetNextArticulatedPart() : nullptr;
 
	} while (v != nullptr);
 

	
 
	/* Check whether the vehicle carries more cargoes than expected */
 
	bool carries_more = false;
src/autoreplace.cpp
Show inline comments
 
@@ -29,11 +29,11 @@ static EngineRenew *GetEngineReplacement
 
{
 
	EngineRenew *er = (EngineRenew *)erl;
 

	
 
	while (er != NULL) {
 
	while (er != nullptr) {
 
		if (er->from == engine && GroupIsInGroup(group, er->group_id)) return er;
 
		er = er->next;
 
	}
 
	return NULL;
 
	return nullptr;
 
}
 

	
 
/**
 
@@ -46,12 +46,12 @@ void RemoveAllEngineReplacement(EngineRe
 
	EngineRenew *er = (EngineRenew *)(*erl);
 
	EngineRenew *next;
 

	
 
	while (er != NULL) {
 
	while (er != nullptr) {
 
		next = er->next;
 
		delete er;
 
		er = next;
 
	}
 
	*erl = NULL; // Empty list
 
	*erl = nullptr; // Empty list
 
}
 

	
 
/**
 
@@ -66,12 +66,12 @@ void RemoveAllEngineReplacement(EngineRe
 
EngineID EngineReplacement(EngineRenewList erl, EngineID engine, GroupID group, bool *replace_when_old)
 
{
 
	const EngineRenew *er = GetEngineReplacement(erl, engine, group);
 
	if (er == NULL && (group == DEFAULT_GROUP || (Group::IsValidID(group) && !Group::Get(group)->replace_protection))) {
 
	if (er == nullptr && (group == DEFAULT_GROUP || (Group::IsValidID(group) && !Group::Get(group)->replace_protection))) {
 
		/* We didn't find anything useful in the vehicle's own group so we will try ALL_GROUP */
 
		er = GetEngineReplacement(erl, engine, ALL_GROUP);
 
	}
 
	if (replace_when_old != NULL) *replace_when_old = er == NULL ? false : er->replace_when_old;
 
	return er == NULL ? INVALID_ENGINE : er->to;
 
	if (replace_when_old != nullptr) *replace_when_old = er == nullptr ? false : er->replace_when_old;
 
	return er == nullptr ? INVALID_ENGINE : er->to;
 
}
 

	
 
/**
 
@@ -88,7 +88,7 @@ CommandCost AddEngineReplacement(EngineR
 
{
 
	/* Check if the old vehicle is already in the list */
 
	EngineRenew *er = GetEngineReplacement(*erl, old_engine, group);
 
	if (er != NULL) {
 
	if (er != nullptr) {
 
		if (flags & DC_EXEC) {
 
			er->to = new_engine;
 
			er->replace_when_old = replace_when_old;
 
@@ -122,12 +122,12 @@ CommandCost AddEngineReplacement(EngineR
 
CommandCost RemoveEngineReplacement(EngineRenewList *erl, EngineID engine, GroupID group, DoCommandFlag flags)
 
{
 
	EngineRenew *er = (EngineRenew *)(*erl);
 
	EngineRenew *prev = NULL;
 
	EngineRenew *prev = nullptr;
 

	
 
	while (er != NULL) {
 
	while (er != nullptr) {
 
		if (er->from == engine && er->group_id == group) {
 
			if (flags & DC_EXEC) {
 
				if (prev == NULL) { // First element
 
				if (prev == nullptr) { // First element
 
					/* The second becomes the new first element */
 
					*erl = (EngineRenewList)er->next;
 
				} else {
src/autoreplace_cmd.cpp
Show inline comments
 
@@ -98,9 +98,9 @@ bool CheckAutoreplaceValidity(EngineID f
 
 */
 
void CheckCargoCapacity(Vehicle *v)
 
{
 
	assert(v == NULL || v->First() == v);
 
	assert(v == nullptr || v->First() == v);
 

	
 
	for (Vehicle *src = v; src != NULL; src = src->Next()) {
 
	for (Vehicle *src = v; src != nullptr; src = src->Next()) {
 
		assert(src->cargo.TotalCount() == src->cargo.ActionCount(VehicleCargoList::MTA_KEEP));
 

	
 
		/* Do we need to more cargo away? */
 
@@ -108,7 +108,7 @@ void CheckCargoCapacity(Vehicle *v)
 

	
 
		/* We need to move a particular amount. Try that on the other vehicles. */
 
		uint to_spread = src->cargo.TotalCount() - src->cargo_cap;
 
		for (Vehicle *dest = v; dest != NULL && to_spread != 0; dest = dest->Next()) {
 
		for (Vehicle *dest = v; dest != nullptr && to_spread != 0; dest = dest->Next()) {
 
			assert(dest->cargo.TotalCount() == dest->cargo.ActionCount(VehicleCargoList::MTA_KEEP));
 
			if (dest->cargo.TotalCount() >= dest->cargo_cap || dest->cargo_type != src->cargo_type) continue;
 

	
 
@@ -135,7 +135,7 @@ static void TransferCargo(Vehicle *old_v
 
{
 
	assert(!part_of_chain || new_head->IsPrimaryVehicle());
 
	/* Loop through source parts */
 
	for (Vehicle *src = old_veh; src != NULL; src = src->Next()) {
 
	for (Vehicle *src = old_veh; src != nullptr; src = src->Next()) {
 
		assert(src->cargo.TotalCount() == src->cargo.ActionCount(VehicleCargoList::MTA_KEEP));
 
		if (!part_of_chain && src->type == VEH_TRAIN && src != old_veh && src != Train::From(old_veh)->other_multiheaded_part && !src->IsArticulatedPart()) {
 
			/* Skip vehicles, which do not belong to old_veh */
 
@@ -145,7 +145,7 @@ static void TransferCargo(Vehicle *old_v
 
		if (src->cargo_type >= NUM_CARGO || src->cargo.TotalCount() == 0) continue;
 

	
 
		/* Find free space in the new chain */
 
		for (Vehicle *dest = new_head; dest != NULL && src->cargo.TotalCount() > 0; dest = dest->Next()) {
 
		for (Vehicle *dest = new_head; dest != nullptr && src->cargo.TotalCount() > 0; dest = dest->Next()) {
 
			assert(dest->cargo.TotalCount() == dest->cargo.ActionCount(VehicleCargoList::MTA_KEEP));
 
			if (!part_of_chain && dest->type == VEH_TRAIN && dest != new_head && dest != Train::From(new_head)->other_multiheaded_part && !dest->IsArticulatedPart()) {
 
				/* Skip vehicles, which do not belong to new_head */
 
@@ -216,7 +216,7 @@ static CargoID GetNewCargoTypeForReplace
 
		/* the old engine didn't have cargo capacity, but the new one does
 
		 * now we will figure out what cargo the train is carrying and refit to fit this */
 

	
 
		for (v = v->First(); v != NULL; v = v->Next()) {
 
		for (v = v->First(); v != nullptr; v = v->Next()) {
 
			if (!v->GetEngine()->CanCarryCargo()) continue;
 
			/* Now we found a cargo type being carried on the train and we will see if it is possible to carry to this one */
 
			if (HasBit(available_cargo_types, v->cargo_type)) return v->cargo_type;
 
@@ -280,7 +280,7 @@ static CommandCost GetNewEngineType(cons
 
 */
 
static CommandCost BuildReplacementVehicle(Vehicle *old_veh, Vehicle **new_vehicle, bool part_of_chain)
 
{
 
	*new_vehicle = NULL;
 
	*new_vehicle = nullptr;
 

	
 
	/* Shall the vehicle be replaced? */
 
	const Company *c = Company::Get(_current_company);
 
@@ -330,14 +330,14 @@ static inline CommandCost CmdStartStopVe
 
/**
 
 * Issue a train vehicle move command
 
 * @param v The vehicle to move
 
 * @param after The vehicle to insert 'v' after, or NULL to start new chain
 
 * @param after The vehicle to insert 'v' after, or nullptr to start new chain
 
 * @param flags the command flags to use
 
 * @param whole_chain move all vehicles following 'v' (true), or only 'v' (false)
 
 * @return success or error
 
 */
 
static inline CommandCost CmdMoveVehicle(const Vehicle *v, const Vehicle *after, DoCommandFlag flags, bool whole_chain)
 
{
 
	return DoCommand(0, v->index | (whole_chain ? 1 : 0) << 20, after != NULL ? after->index : INVALID_VEHICLE, flags | DC_NO_CARGO_CAP_CHECK, CMD_MOVE_RAIL_VEHICLE);
 
	return DoCommand(0, v->index | (whole_chain ? 1 : 0) << 20, after != nullptr ? after->index : INVALID_VEHICLE, flags | DC_NO_CARGO_CAP_CHECK, CMD_MOVE_RAIL_VEHICLE);
 
}
 

	
 
/**
 
@@ -395,11 +395,11 @@ static CommandCost ReplaceFreeUnit(Vehic
 
	CommandCost cost = CommandCost(EXPENSES_NEW_VEHICLES, 0);
 

	
 
	/* Build and refit replacement vehicle */
 
	Vehicle *new_v = NULL;
 
	Vehicle *new_v = nullptr;
 
	cost.AddCost(BuildReplacementVehicle(old_v, &new_v, false));
 

	
 
	/* Was a new vehicle constructed? */
 
	if (cost.Succeeded() && new_v != NULL) {
 
	if (cost.Succeeded() && new_v != nullptr) {
 
		*nothing_to_do = false;
 

	
 
		if ((flags & DC_EXEC) != 0) {
 
@@ -449,17 +449,17 @@ static CommandCost ReplaceChain(Vehicle 
 
		uint16 old_total_length = CeilDiv(Train::From(old_head)->gcache.cached_total_length, TILE_SIZE) * TILE_SIZE;
 

	
 
		int num_units = 0; ///< Number of units in the chain
 
		for (Train *w = Train::From(old_head); w != NULL; w = w->GetNextUnit()) num_units++;
 
		for (Train *w = Train::From(old_head); w != nullptr; w = w->GetNextUnit()) num_units++;
 

	
 
		Train **old_vehs = CallocT<Train *>(num_units); ///< Will store vehicles of the old chain in their order
 
		Train **new_vehs = CallocT<Train *>(num_units); ///< New vehicles corresponding to old_vehs or NULL if no replacement
 
		Train **new_vehs = CallocT<Train *>(num_units); ///< New vehicles corresponding to old_vehs or nullptr if no replacement
 
		Money *new_costs = MallocT<Money>(num_units);   ///< Costs for buying and refitting the new vehicles
 

	
 
		/* Collect vehicles and build replacements
 
		 * Note: The replacement vehicles can only successfully build as long as the old vehicles are still in their chain */
 
		int i;
 
		Train *w;
 
		for (w = Train::From(old_head), i = 0; w != NULL; w = w->GetNextUnit(), i++) {
 
		for (w = Train::From(old_head), i = 0; w != nullptr; w = w->GetNextUnit(), i++) {
 
			assert(i < num_units);
 
			old_vehs[i] = w;
 

	
 
@@ -468,41 +468,41 @@ static CommandCost ReplaceChain(Vehicle 
 
			if (cost.Failed()) break;
 

	
 
			new_costs[i] = ret.GetCost();
 
			if (new_vehs[i] != NULL) *nothing_to_do = false;
 
			if (new_vehs[i] != nullptr) *nothing_to_do = false;
 
		}
 
		Train *new_head = (new_vehs[0] != NULL ? new_vehs[0] : old_vehs[0]);
 
		Train *new_head = (new_vehs[0] != nullptr ? new_vehs[0] : old_vehs[0]);
 

	
 
		/* Note: When autoreplace has already failed here, old_vehs[] is not completely initialized. But it is also not needed. */
 
		if (cost.Succeeded()) {
 
			/* Separate the head, so we can start constructing the new chain */
 
			Train *second = Train::From(old_head)->GetNextUnit();
 
			if (second != NULL) cost.AddCost(CmdMoveVehicle(second, NULL, DC_EXEC | DC_AUTOREPLACE, true));
 
			if (second != nullptr) cost.AddCost(CmdMoveVehicle(second, nullptr, DC_EXEC | DC_AUTOREPLACE, true));
 

	
 
			assert(Train::From(new_head)->GetNextUnit() == NULL);
 
			assert(Train::From(new_head)->GetNextUnit() == nullptr);
 

	
 
			/* Append engines to the new chain
 
			 * We do this from back to front, so that the head of the temporary vehicle chain does not change all the time.
 
			 * That way we also have less trouble when exceeding the unitnumber limit.
 
			 * OTOH the vehicle attach callback is more expensive this way :s */
 
			Train *last_engine = NULL; ///< Shall store the last engine unit after this step
 
			Train *last_engine = nullptr; ///< Shall store the last engine unit after this step
 
			if (cost.Succeeded()) {
 
				for (int i = num_units - 1; i > 0; i--) {
 
					Train *append = (new_vehs[i] != NULL ? new_vehs[i] : old_vehs[i]);
 
					Train *append = (new_vehs[i] != nullptr ? new_vehs[i] : old_vehs[i]);
 

	
 
					if (RailVehInfo(append->engine_type)->railveh_type == RAILVEH_WAGON) continue;
 

	
 
					if (new_vehs[i] != NULL) {
 
					if (new_vehs[i] != nullptr) {
 
						/* Move the old engine to a separate row with DC_AUTOREPLACE. Else
 
						 * moving the wagon in front may fail later due to unitnumber limit.
 
						 * (We have to attach wagons without DC_AUTOREPLACE.) */
 
						CmdMoveVehicle(old_vehs[i], NULL, DC_EXEC | DC_AUTOREPLACE, false);
 
						CmdMoveVehicle(old_vehs[i], nullptr, DC_EXEC | DC_AUTOREPLACE, false);
 
					}
 

	
 
					if (last_engine == NULL) last_engine = append;
 
					if (last_engine == nullptr) last_engine = append;
 
					cost.AddCost(CmdMoveVehicle(append, new_head, DC_EXEC, false));
 
					if (cost.Failed()) break;
 
				}
 
				if (last_engine == NULL) last_engine = new_head;
 
				if (last_engine == nullptr) last_engine = new_head;
 
			}
 

	
 
			/* When wagon removal is enabled and the new engines without any wagons are already longer than the old, we have to fail */
 
@@ -513,8 +513,8 @@ static CommandCost ReplaceChain(Vehicle 
 
			 */
 
			if (cost.Succeeded()) {
 
				for (int i = num_units - 1; i > 0; i--) {
 
					assert(last_engine != NULL);
 
					Vehicle *append = (new_vehs[i] != NULL ? new_vehs[i] : old_vehs[i]);
 
					assert(last_engine != nullptr);
 
					Vehicle *append = (new_vehs[i] != nullptr ? new_vehs[i] : old_vehs[i]);
 

	
 
					if (RailVehInfo(append->engine_type)->railveh_type == RAILVEH_WAGON) {
 
						/* Insert wagon after 'last_engine' */
 
@@ -524,7 +524,7 @@ static CommandCost ReplaceChain(Vehicle 
 
						 * to the train becoming too long, or the train becoming longer
 
						 * would move the vehicle to the empty vehicle chain. */
 
						if (wagon_removal && (res.Failed() ? res.GetErrorMessage() == STR_ERROR_TRAIN_TOO_LONG : new_head->gcache.cached_total_length > old_total_length)) {
 
							CmdMoveVehicle(append, NULL, DC_EXEC | DC_AUTOREPLACE, false);
 
							CmdMoveVehicle(append, nullptr, DC_EXEC | DC_AUTOREPLACE, false);
 
							break;
 
						}
 

	
 
@@ -543,7 +543,7 @@ static CommandCost ReplaceChain(Vehicle 
 
				assert(new_head->gcache.cached_total_length <= _settings_game.vehicle.max_train_length * TILE_SIZE);
 
				for (int i = 1; i < num_units; i++) {
 
					Vehicle *wagon = new_vehs[i];
 
					if (wagon == NULL) continue;
 
					if (wagon == nullptr) continue;
 
					if (wagon->First() == new_head) break;
 

	
 
					assert(RailVehInfo(wagon->engine_type)->railveh_type == RAILVEH_WAGON);
 
@@ -551,7 +551,7 @@ static CommandCost ReplaceChain(Vehicle 
 
					/* Sell wagon */
 
					CommandCost ret = DoCommand(0, wagon->index, 0, DC_EXEC, GetCmdSellVeh(wagon));
 
					assert(ret.Succeeded());
 
					new_vehs[i] = NULL;
 
					new_vehs[i] = nullptr;
 

	
 
					/* Revert the money subtraction when the vehicle was built.
 
					 * This value is different from the sell value, esp. because of refitting */
 
@@ -572,7 +572,7 @@ static CommandCost ReplaceChain(Vehicle 
 
				for (int i = 0; i < num_units; i++) {
 
					Vehicle *w = old_vehs[i];
 
					/* Is the vehicle again part of the new chain?
 
					 * Note: We cannot test 'new_vehs[i] != NULL' as wagon removal might cause to remove both */
 
					 * Note: We cannot test 'new_vehs[i] != nullptr' as wagon removal might cause to remove both */
 
					if (w->First() == new_head) continue;
 

	
 
					if ((flags & DC_EXEC) != 0) TransferCargo(w, new_head, true);
 
@@ -582,8 +582,8 @@ static CommandCost ReplaceChain(Vehicle 
 
					 *       it from failing due to engine limits. */
 
					cost.AddCost(DoCommand(0, w->index, 0, flags | DC_AUTOREPLACE, GetCmdSellVeh(w)));
 
					if ((flags & DC_EXEC) != 0) {
 
						old_vehs[i] = NULL;
 
						if (i == 0) old_head = NULL;
 
						old_vehs[i] = nullptr;
 
						if (i == 0) old_head = nullptr;
 
					}
 
				}
 

	
 
@@ -596,9 +596,9 @@ static CommandCost ReplaceChain(Vehicle 
 
			if ((flags & DC_EXEC) == 0) {
 
				/* Separate the head, so we can reattach the old vehicles */
 
				Train *second = Train::From(old_head)->GetNextUnit();
 
				if (second != NULL) CmdMoveVehicle(second, NULL, DC_EXEC | DC_AUTOREPLACE, true);
 
				if (second != nullptr) CmdMoveVehicle(second, nullptr, DC_EXEC | DC_AUTOREPLACE, true);
 

	
 
				assert(Train::From(old_head)->GetNextUnit() == NULL);
 
				assert(Train::From(old_head)->GetNextUnit() == nullptr);
 

	
 
				for (int i = num_units - 1; i > 0; i--) {
 
					CommandCost ret = CmdMoveVehicle(old_vehs[i], old_head, DC_EXEC | DC_AUTOREPLACE, false);
 
@@ -610,9 +610,9 @@ static CommandCost ReplaceChain(Vehicle 
 
		/* Finally undo buying of new vehicles */
 
		if ((flags & DC_EXEC) == 0) {
 
			for (int i = num_units - 1; i >= 0; i--) {
 
				if (new_vehs[i] != NULL) {
 
				if (new_vehs[i] != nullptr) {
 
					DoCommand(0, new_vehs[i]->index, 0, DC_EXEC, GetCmdSellVeh(new_vehs[i]));
 
					new_vehs[i] = NULL;
 
					new_vehs[i] = nullptr;
 
				}
 
			}
 
		}
 
@@ -622,11 +622,11 @@ static CommandCost ReplaceChain(Vehicle 
 
		free(new_costs);
 
	} else {
 
		/* Build and refit replacement vehicle */
 
		Vehicle *new_head = NULL;
 
		Vehicle *new_head = nullptr;
 
		cost.AddCost(BuildReplacementVehicle(old_head, &new_head, true));
 

	
 
		/* Was a new vehicle constructed? */
 
		if (cost.Succeeded() && new_head != NULL) {
 
		if (cost.Succeeded() && new_head != nullptr) {
 
			*nothing_to_do = false;
 

	
 
			/* The new vehicle is constructed, now take over orders and everything... */
 
@@ -666,7 +666,7 @@ static CommandCost ReplaceChain(Vehicle 
 
CommandCost CmdAutoreplaceVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	Vehicle *v = Vehicle::GetIfValid(p1);
 
	if (v == NULL) return CMD_ERROR;
 
	if (v == nullptr) return CMD_ERROR;
 

	
 
	CommandCost ret = CheckOwnership(v->owner);
 
	if (ret.Failed()) return ret;
 
@@ -690,12 +690,12 @@ CommandCost CmdAutoreplaceVehicle(TileIn
 
	/* Test whether any replacement is set, before issuing a whole lot of commands that would end in nothing changed */
 
	Vehicle *w = v;
 
	bool any_replacements = false;
 
	while (w != NULL) {
 
	while (w != nullptr) {
 
		EngineID e;
 
		CommandCost cost = GetNewEngineType(w, c, false, e);
 
		if (cost.Failed()) return cost;
 
		any_replacements |= (e != INVALID_ENGINE);
 
		w = (!free_wagon && w->type == VEH_TRAIN ? Train::From(w)->GetNextUnit() : NULL);
 
		w = (!free_wagon && w->type == VEH_TRAIN ? Train::From(w)->GetNextUnit() : nullptr);
 
	}
 

	
 
	CommandCost cost = CommandCost(EXPENSES_NEW_VEHICLES, 0);
 
@@ -756,7 +756,7 @@ CommandCost CmdAutoreplaceVehicle(TileIn
 
CommandCost CmdSetAutoReplace(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	Company *c = Company::GetIfValid(_current_company);
 
	if (c == NULL) return CMD_ERROR;
 
	if (c == nullptr) return CMD_ERROR;
 

	
 
	EngineID old_engine_type = GB(p2, 0, 16);
 
	EngineID new_engine_type = GB(p2, 16, 16);
src/autoreplace_func.h
Show inline comments
 
@@ -16,7 +16,7 @@
 
#include "company_base.h"
 

	
 
void RemoveAllEngineReplacement(EngineRenewList *erl);
 
EngineID EngineReplacement(EngineRenewList erl, EngineID engine, GroupID group, bool *replace_when_old = NULL);
 
EngineID EngineReplacement(EngineRenewList erl, EngineID engine, GroupID group, bool *replace_when_old = nullptr);
 
CommandCost AddEngineReplacement(EngineRenewList *erl, EngineID old_engine, EngineID new_engine, GroupID group, bool replace_when_old, DoCommandFlag flags);
 
CommandCost RemoveEngineReplacement(EngineRenewList *erl, EngineID engine, GroupID group, DoCommandFlag flags);
 

	
 
@@ -38,7 +38,7 @@ static inline void RemoveAllEngineReplac
 
 * @return The engine type to replace with, or INVALID_ENGINE if no
 
 * replacement is in the list.
 
 */
 
static inline EngineID EngineReplacementForCompany(const Company *c, EngineID engine, GroupID group, bool *replace_when_old = NULL)
 
static inline EngineID EngineReplacementForCompany(const Company *c, EngineID engine, GroupID group, bool *replace_when_old = nullptr)
 
{
 
	return EngineReplacement(c->engine_renew_list, engine, group, replace_when_old);
 
}
src/base_consist.cpp
Show inline comments
 
@@ -30,7 +30,7 @@ void BaseConsist::CopyConsistPropertiesF
 
	if (this == src) return;
 

	
 
	free(this->name);
 
	this->name = src->name != NULL ? stredup(src->name) : NULL;
 
	this->name = src->name != nullptr ? stredup(src->name) : nullptr;
 

	
 
	this->current_order_time = src->current_order_time;
 
	this->lateness_counter = src->lateness_counter;
src/base_consist.h
Show inline comments
 
@@ -31,7 +31,7 @@ struct BaseConsist {
 

	
 
	uint16 vehicle_flags;               ///< Used for gradual loading and other miscellaneous things (@see VehicleFlags enum)
 

	
 
	BaseConsist() : name(NULL) {}
 
	BaseConsist() : name(nullptr) {}
 
	virtual ~BaseConsist();
 

	
 
	void CopyConsistPropertiesFrom(const BaseConsist *src);
src/base_media_base.h
Show inline comments
 
@@ -118,9 +118,9 @@ struct BaseSet {
 
	 * @param isocode the isocode to search for
 
	 * @return the description
 
	 */
 
	const char *GetDescription(const char *isocode = NULL) const
 
	const char *GetDescription(const char *isocode = nullptr) const
 
	{
 
		if (isocode != NULL) {
 
		if (isocode != nullptr) {
 
			/* First the full ISO code */
 
			for (const auto &pair : this->description) {
 
				if (strcmp(pair.first, isocode) == 0) return pair.second;
 
@@ -151,17 +151,17 @@ struct BaseSet {
 
	/**
 
	 * Search a textfile file next to this base media.
 
	 * @param type The type of the textfile to search for.
 
	 * @return The filename for the textfile, \c NULL otherwise.
 
	 * @return The filename for the textfile, \c nullptr otherwise.
 
	 */
 
	const char *GetTextfile(TextfileType type) const
 
	{
 
		for (uint i = 0; i < NUM_FILES; i++) {
 
			const char *textfile = ::GetTextfile(type, BASESET_DIR, this->files[i].filename);
 
			if (textfile != NULL) {
 
			if (textfile != nullptr) {
 
				return textfile;
 
			}
 
		}
 
		return NULL;
 
		return nullptr;
 
	}
 
};
 

	
 
@@ -231,7 +231,7 @@ template <class Tbase_set> /* static */ 
 
 * @param ci The content info to compare it to.
 
 * @param md5sum Should the MD5 checksum be tested as well?
 
 * @param s The list with sets.
 
 * @return The filename of the first file of the base set, or \c NULL if there is no match.
 
 * @return The filename of the first file of the base set, or \c nullptr if there is no match.
 
 */
 
template <class Tbase_set>
 
const char *TryGetBaseSetFile(const ContentInfo *ci, bool md5sum, const Tbase_set *s);
src/base_media_func.h
Show inline comments
 
@@ -23,7 +23,7 @@
 
 */
 
#define fetch_metadata(name) \
 
	item = metadata->GetItem(name, false); \
 
	if (item == NULL || StrEmpty(item->value)) { \
 
	if (item == nullptr || StrEmpty(item->value)) { \
 
		DEBUG(grf, 0, "Base " SET_TYPE "set detail loading: %s field missing.", name); \
 
		DEBUG(grf, 0, "  Is %s readable for the user running OpenTTD?", full_filename); \
 
		return false; \
 
@@ -50,7 +50,7 @@ bool BaseSet<T, Tnum_files, Tsearch_in_t
 
	this->description[stredup("")] = stredup(item->value);
 

	
 
	/* Add the translations of the descriptions too. */
 
	for (const IniItem *item = metadata->item; item != NULL; item = item->next) {
 
	for (const IniItem *item = metadata->item; item != nullptr; item = item->next) {
 
		if (strncmp("description.", item->name, 12) != 0) continue;
 

	
 
		this->description[stredup(item->name + 12)] = stredup(item->value);
 
@@ -65,7 +65,7 @@ bool BaseSet<T, Tnum_files, Tsearch_in_t
 
	this->version = atoi(item->value);
 

	
 
	item = metadata->GetItem("fallback", false);
 
	this->fallback = (item != NULL && strcmp(item->value, "0") != 0 && strcmp(item->value, "false") != 0);
 
	this->fallback = (item != nullptr && strcmp(item->value, "0") != 0 && strcmp(item->value, "false") != 0);
 

	
 
	/* For each of the file types we want to find the file, MD5 checksums and warning messages. */
 
	IniGroup *files  = ini->GetGroup("files");
 
@@ -75,14 +75,14 @@ bool BaseSet<T, Tnum_files, Tsearch_in_t
 
		MD5File *file = &this->files[i];
 
		/* Find the filename first. */
 
		item = files->GetItem(BaseSet<T, Tnum_files, Tsearch_in_tars>::file_names[i], false);
 
		if (item == NULL || (item->value == NULL && !allow_empty_filename)) {
 
		if (item == nullptr || (item->value == nullptr && !allow_empty_filename)) {
 
			DEBUG(grf, 0, "No " SET_TYPE " file for: %s (in %s)", BaseSet<T, Tnum_files, Tsearch_in_tars>::file_names[i], full_filename);
 
			return false;
 
		}
 

	
 
		const char *filename = item->value;
 
		if (filename == NULL) {
 
			file->filename = NULL;
 
		if (filename == nullptr) {
 
			file->filename = nullptr;
 
			/* If we list no file, that file must be valid */
 
			this->valid_files++;
 
			this->found_files++;
 
@@ -93,7 +93,7 @@ bool BaseSet<T, Tnum_files, Tsearch_in_t
 

	
 
		/* Then find the MD5 checksum */
 
		item = md5s->GetItem(filename, false);
 
		if (item == NULL || item->value == NULL) {
 
		if (item == nullptr || item->value == nullptr) {
 
			DEBUG(grf, 0, "No MD5 checksum specified for: %s (in %s)", filename, full_filename);
 
			return false;
 
		}
 
@@ -119,8 +119,8 @@ bool BaseSet<T, Tnum_files, Tsearch_in_t
 

	
 
		/* Then find the warning message when the file's missing */
 
		item = origin->GetItem(filename, false);
 
		if (item == NULL) item = origin->GetItem("default", false);
 
		if (item == NULL) {
 
		if (item == nullptr) item = origin->GetItem("default", false);
 
		if (item == nullptr) {
 
			DEBUG(grf, 1, "No origin warning message specified for: %s", filename);
 
			file->missing_warning = stredup("");
 
		} else {
 
@@ -163,21 +163,21 @@ bool BaseMedia<Tbase_set>::AddFile(const
 

	
 
	char *path = stredup(filename + basepath_length);
 
	char *psep = strrchr(path, PATHSEPCHAR);
 
	if (psep != NULL) {
 
	if (psep != nullptr) {
 
		psep[1] = '\0';
 
	} else {
 
		*path = '\0';
 
	}
 

	
 
	if (set->FillSetDetails(ini, path, filename)) {
 
		Tbase_set *duplicate = NULL;
 
		for (Tbase_set *c = BaseMedia<Tbase_set>::available_sets; c != NULL; c = c->next) {
 
		Tbase_set *duplicate = nullptr;
 
		for (Tbase_set *c = BaseMedia<Tbase_set>::available_sets; c != nullptr; c = c->next) {
 
			if (strcmp(c->name, set->name) == 0 || c->shortname == set->shortname) {
 
				duplicate = c;
 
				break;
 
			}
 
		}
 
		if (duplicate != NULL) {
 
		if (duplicate != nullptr) {
 
			/* The more complete set takes precedence over the version number. */
 
			if ((duplicate->valid_files == set->valid_files && duplicate->version >= set->version) ||
 
					duplicate->valid_files > set->valid_files) {
 
@@ -205,7 +205,7 @@ bool BaseMedia<Tbase_set>::AddFile(const
 
			}
 
		} else {
 
			Tbase_set **last = &BaseMedia<Tbase_set>::available_sets;
 
			while (*last != NULL) last = &(*last)->next;
 
			while (*last != nullptr) last = &(*last)->next;
 

	
 
			*last = set;
 
			ret = true;
 
@@ -238,7 +238,7 @@ template <class Tbase_set>
 
		return true;
 
	}
 

	
 
	for (const Tbase_set *s = BaseMedia<Tbase_set>::available_sets; s != NULL; s = s->next) {
 
	for (const Tbase_set *s = BaseMedia<Tbase_set>::available_sets; s != nullptr; s = s->next) {
 
		if (strcmp(name, s->name) == 0) {
 
			BaseMedia<Tbase_set>::used_set = s;
 
			CheckExternalFiles();
 
@@ -258,7 +258,7 @@ template <class Tbase_set>
 
/* static */ char *BaseMedia<Tbase_set>::GetSetsList(char *p, const char *last)
 
{
 
	p += seprintf(p, last, "List of " SET_TYPE " sets:\n");
 
	for (const Tbase_set *s = BaseMedia<Tbase_set>::available_sets; s != NULL; s = s->next) {
 
	for (const Tbase_set *s = BaseMedia<Tbase_set>::available_sets; s != nullptr; s = s->next) {
 
		p += seprintf(p, last, "%18s: %s", s->name, s->GetDescription());
 
		int invalid = s->GetNumInvalid();
 
		if (invalid != 0) {
 
@@ -281,7 +281,7 @@ template <class Tbase_set>
 

	
 
template <class Tbase_set> const char *TryGetBaseSetFile(const ContentInfo *ci, bool md5sum, const Tbase_set *s)
 
{
 
	for (; s != NULL; s = s->next) {
 
	for (; s != nullptr; s = s->next) {
 
		if (s->GetNumMissing() != 0) continue;
 

	
 
		if (s->shortname != ci->unique_id) continue;
 
@@ -296,14 +296,14 @@ template <class Tbase_set> const char *T
 
		}
 
		if (memcmp(md5, ci->md5sum, sizeof(md5)) == 0) return s->files[0].filename;
 
	}
 
	return NULL;
 
	return nullptr;
 
}
 

	
 
template <class Tbase_set>
 
/* static */ bool BaseMedia<Tbase_set>::HasSet(const ContentInfo *ci, bool md5sum)
 
{
 
	return (TryGetBaseSetFile(ci, md5sum, BaseMedia<Tbase_set>::available_sets) != NULL) ||
 
			(TryGetBaseSetFile(ci, md5sum, BaseMedia<Tbase_set>::duplicate_sets) != NULL);
 
	return (TryGetBaseSetFile(ci, md5sum, BaseMedia<Tbase_set>::available_sets) != nullptr) ||
 
			(TryGetBaseSetFile(ci, md5sum, BaseMedia<Tbase_set>::duplicate_sets) != nullptr);
 
}
 

	
 
/**
 
@@ -314,7 +314,7 @@ template <class Tbase_set>
 
/* static */ int BaseMedia<Tbase_set>::GetNumSets()
 
{
 
	int n = 0;
 
	for (const Tbase_set *s = BaseMedia<Tbase_set>::available_sets; s != NULL; s = s->next) {
 
	for (const Tbase_set *s = BaseMedia<Tbase_set>::available_sets; s != nullptr; s = s->next) {
 
		if (s != BaseMedia<Tbase_set>::used_set && s->GetNumMissing() != 0) continue;
 
		n++;
 
	}
 
@@ -329,7 +329,7 @@ template <class Tbase_set>
 
/* static */ int BaseMedia<Tbase_set>::GetIndexOfUsedSet()
 
{
 
	int n = 0;
 
	for (const Tbase_set *s = BaseMedia<Tbase_set>::available_sets; s != NULL; s = s->next) {
 
	for (const Tbase_set *s = BaseMedia<Tbase_set>::available_sets; s != nullptr; s = s->next) {
 
		if (s == BaseMedia<Tbase_set>::used_set) return n;
 
		if (s->GetNumMissing() != 0) continue;
 
		n++;
 
@@ -344,7 +344,7 @@ template <class Tbase_set>
 
template <class Tbase_set>
 
/* static */ const Tbase_set *BaseMedia<Tbase_set>::GetSet(int index)
 
{
 
	for (const Tbase_set *s = BaseMedia<Tbase_set>::available_sets; s != NULL; s = s->next) {
 
	for (const Tbase_set *s = BaseMedia<Tbase_set>::available_sets; s != nullptr; s = s->next) {
 
		if (s != BaseMedia<Tbase_set>::used_set && s->GetNumMissing() != 0) continue;
 
		if (index == 0) return s;
 
		index--;
src/base_station_base.h
Show inline comments
 
@@ -220,7 +220,7 @@ struct SpecializedStation : public BaseS
 
	 */
 
	static inline T *GetIfValid(size_t index)
 
	{
 
		return IsValidID(index) ? Get(index) : NULL;
 
		return IsValidID(index) ? Get(index) : nullptr;
 
	}
 

	
 
	/**
src/blitter/32bpp_anim.cpp
Show inline comments
 
@@ -414,7 +414,7 @@ void Blitter_32bppAnim::CopyToBuffer(con
 
	uint32 *udst = (uint32 *)dst;
 
	const uint32 *src = (const uint32 *)video;
 

	
 
	if (this->anim_buf == NULL) return;
 
	if (this->anim_buf == nullptr) return;
 

	
 
	const uint16 *anim_line = this->ScreenToAnimOffset((const uint32 *)video) + this->anim_buf;
 

	
src/blitter/32bpp_anim.hpp
Show inline comments
 
@@ -26,8 +26,8 @@ protected:
 

	
 
public:
 
	Blitter_32bppAnim() :
 
		anim_buf(NULL),
 
		anim_alloc(NULL),
 
		anim_buf(nullptr),
 
		anim_alloc(nullptr),
 
		anim_buf_width(0),
 
		anim_buf_height(0),
 
		anim_buf_pitch(0)
src/blitter/8bpp_optimized.cpp
Show inline comments
 
@@ -167,7 +167,7 @@ Sprite *Blitter_8bppOptimized::Encode(co
 
			uint trans = 0;
 
			uint pixels = 0;
 
			uint last_colour = 0;
 
			byte *count_dst = NULL;
 
			byte *count_dst = nullptr;
 

	
 
			/* Store the scaled image */
 
			const SpriteLoader::CommonPixel *src = &sprite[i].data[y * sprite[i].width];
 
@@ -176,11 +176,11 @@ Sprite *Blitter_8bppOptimized::Encode(co
 
				uint colour = src++->m;
 

	
 
				if (last_colour == 0 || colour == 0 || pixels == 255) {
 
					if (count_dst != NULL) {
 
					if (count_dst != nullptr) {
 
						/* Write how many non-transparent bytes we get */
 
						*count_dst = pixels;
 
						pixels = 0;
 
						count_dst = NULL;
 
						count_dst = nullptr;
 
					}
 
					/* As long as we find transparency bytes, keep counting */
 
					if (colour == 0 && trans != 255) {
 
@@ -206,7 +206,7 @@ Sprite *Blitter_8bppOptimized::Encode(co
 
				}
 
			}
 

	
 
			if (count_dst != NULL) *count_dst = pixels;
 
			if (count_dst != nullptr) *count_dst = pixels;
 

	
 
			/* Write line-ending */
 
			*dst = 0; dst++;
src/blitter/factory.hpp
Show inline comments
 
@@ -48,7 +48,7 @@ private:
 
	 */
 
	static Blitter **GetActiveBlitter()
 
	{
 
		static Blitter *s_blitter = NULL;
 
		static Blitter *s_blitter = nullptr;
 
		return &s_blitter;
 
	}
 

	
 
@@ -58,8 +58,8 @@ protected:
 
	 * @param name        The name of the blitter.
 
	 * @param description A longer description for the blitter.
 
	 * @param usable      Whether the blitter is usable (on the current computer). For example for disabling SSE blitters when the CPU can't handle them.
 
	 * @pre name != NULL.
 
	 * @pre description != NULL.
 
	 * @pre name != nullptr.
 
	 * @pre description != nullptr.
 
	 * @pre There is no blitter registered with this name.
 
	 */
 
	BlitterFactory(const char *name, const char *description, bool usable = true) :
 
@@ -96,7 +96,7 @@ public:
 
	static Blitter *SelectBlitter(const char *name)
 
	{
 
		BlitterFactory *b = GetBlitterFactory(name);
 
		if (b == NULL) return NULL;
 
		if (b == nullptr) return nullptr;
 

	
 
		Blitter *newb = b->CreateInstance();
 
		delete *GetActiveBlitter();
 
@@ -109,7 +109,7 @@ public:
 
	/**
 
	 * Get the blitter factory with the given name.
 
	 * @param name the blitter factory to select.
 
	 * @return The blitter factory, or NULL when there isn't one with the wanted name.
 
	 * @return The blitter factory, or nullptr when there isn't one with the wanted name.
 
	 */
 
	static BlitterFactory *GetBlitterFactory(const char *name)
 
	{
 
@@ -128,7 +128,7 @@ public:
 
		}
 
#endif /* defined(WITH_COCOA) */
 
#endif /* defined(DEDICATED) */
 
		if (GetBlitters().size() == 0) return NULL;
 
		if (GetBlitters().size() == 0) return nullptr;
 
		const char *bname = (StrEmpty(name)) ? default_blitter : name;
 

	
 
		Blitters::iterator it = GetBlitters().begin();
 
@@ -138,7 +138,7 @@ public:
 
				return b;
 
			}
 
		}
 
		return NULL;
 
		return nullptr;
 
	}
 

	
 
	/**
src/blitter/null.hpp
Show inline comments
 
@@ -21,7 +21,7 @@ public:
 
	void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) override {};
 
	void DrawColourMappingRect(void *dst, int width, int height, PaletteID pal) override {};
 
	Sprite *Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator) override;
 
	void *MoveTo(void *video, int x, int y) override { return NULL; };
 
	void *MoveTo(void *video, int x, int y) override { return nullptr; };
 
	void SetPixel(void *video, int x, int y, uint8 colour) override {};
 
	void DrawRect(void *video, int width, int height, uint8 colour) override {};
 
	void DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8 colour, int width, int dash) override {};
src/bmp.cpp
Show inline comments
 
@@ -319,7 +319,7 @@ static inline bool BmpRead24(BmpBuffer *
 
bool BmpReadHeader(BmpBuffer *buffer, BmpInfo *info, BmpData *data)
 
{
 
	uint32 header_size;
 
	assert(info != NULL);
 
	assert(info != nullptr);
 
	MemSetT(info, 0);
 

	
 
	/* Reading BMP header */
 
@@ -390,7 +390,7 @@ bool BmpReadHeader(BmpBuffer *buffer, Bm
 
 */
 
bool BmpReadBitmap(BmpBuffer *buffer, BmpInfo *info, BmpData *data)
 
{
 
	assert(info != NULL && data != NULL);
 
	assert(info != nullptr && data != nullptr);
 

	
 
	data->bitmap = CallocT<byte>(info->width * info->height * ((info->bpp == 24) ? 3 : 1));
 

	
 
@@ -413,7 +413,7 @@ bool BmpReadBitmap(BmpBuffer *buffer, Bm
 

	
 
void BmpDestroyData(BmpData *data)
 
{
 
	assert(data != NULL);
 
	assert(data != nullptr);
 
	free(data->palette);
 
	free(data->bitmap);
 
}
src/bootstrap_gui.cpp
Show inline comments
 
@@ -40,7 +40,7 @@ static const struct NWidgetPart _backgro
 
 * Window description for the background window to prevent smearing.
 
 */
 
static WindowDesc _background_desc(
 
	WDP_MANUAL, NULL, 0, 0,
 
	WDP_MANUAL, nullptr, 0, 0,
 
	WC_BOOTSTRAP, WC_NONE,
 
	0,
 
	_background_widgets, lengthof(_background_widgets)
 
@@ -73,7 +73,7 @@ static const NWidgetPart _nested_boostra
 

	
 
/** Window description for the download window */
 
static WindowDesc _bootstrap_download_status_window_desc(
 
	WDP_CENTER, NULL, 0, 0,
 
	WDP_CENTER, nullptr, 0, 0,
 
	WC_NETWORK_STATUS_WINDOW, WC_NONE,
 
	WDF_MODAL,
 
	_nested_boostrap_download_status_window_widgets, lengthof(_nested_boostrap_download_status_window_widgets)
 
@@ -118,7 +118,7 @@ static const NWidgetPart _bootstrap_quer
 

	
 
/** The window description for the query. */
 
static WindowDesc _bootstrap_query_desc(
 
	WDP_CENTER, NULL, 0, 0,
 
	WDP_CENTER, nullptr, 0, 0,
 
	WC_CONFIRM_POPUP_QUERY, WC_NONE,
 
	0,
 
	_bootstrap_query_widgets, lengthof(_bootstrap_query_widgets)
 
@@ -214,7 +214,7 @@ public:
 
 */
 
bool HandleBootstrap()
 
{
 
	if (BaseGraphics::GetUsedSet() != NULL) return true;
 
	if (BaseGraphics::GetUsedSet() != nullptr) return true;
 

	
 
	/* No user interface, bail out with an error. */
 
	if (BlitterFactory::GetCurrentBlitter()->GetScreenDepth() == 0) goto failure;
 
@@ -255,7 +255,7 @@ bool HandleBootstrap()
 
	if (_exit_game) return false;
 

	
 
	/* Try to probe the graphics. Should work this time. */
 
	if (!BaseGraphics::SetSet(NULL)) goto failure;
 
	if (!BaseGraphics::SetSet(nullptr)) goto failure;
 

	
 
	/* Finally we can continue heading for the menu. */
 
	_game_mode = GM_MENU;
src/bridge_gui.cpp
Show inline comments
 
@@ -392,7 +392,7 @@ void ShowBuildBridgeWindow(TileIndex sta
 
	StringID errmsg = INVALID_STRING_ID;
 
	CommandCost ret = DoCommand(end, start, type, CommandFlagsToDCFlags(GetCommandFlags(CMD_BUILD_BRIDGE)) | DC_QUERY_COST, CMD_BUILD_BRIDGE);
 

	
 
	GUIBridgeList *bl = NULL;
 
	GUIBridgeList *bl = nullptr;
 
	if (ret.Failed()) {
 
		errmsg = ret.GetErrorMessage();
 
	} else {
 
@@ -427,7 +427,7 @@ void ShowBuildBridgeWindow(TileIndex sta
 
		}
 
	}
 

	
 
	if (bl != NULL && bl->size() != 0) {
 
	if (bl != nullptr && bl->size() != 0) {
 
		new BuildBridgeWindow(&_build_bridge_desc, start, end, type, bl);
 
	} else {
 
		delete bl;
src/build_vehicle_gui.cpp
Show inline comments
 
@@ -833,7 +833,7 @@ static int DrawAircraftPurchaseInfo(int 
 
 */
 
static uint ShowAdditionalText(int left, int right, int y, EngineID engine)
 
{
 
	uint16 callback = GetVehicleCallback(CBID_VEHICLE_ADDITIONAL_TEXT, 0, 0, engine, NULL);
 
	uint16 callback = GetVehicleCallback(CBID_VEHICLE_ADDITIONAL_TEXT, 0, 0, engine, nullptr);
 
	if (callback == CALLBACK_FAILED || callback == 0x400) return y;
 
	const GRFFile *grffile = Engine::Get(engine)->GetGRF();
 
	if (callback > 0x400) {
 
@@ -1180,7 +1180,7 @@ struct BuildVehicleWindow : Window {
 

	
 
		if (!this->listview_mode) {
 
			/* Query for cost and refitted capacity */
 
			CommandCost ret = DoCommand(this->window_number, this->sel_engine | (cargo << 24), 0, DC_QUERY_COST, GetCmdBuildVeh(this->vehicle_type), NULL);
 
			CommandCost ret = DoCommand(this->window_number, this->sel_engine | (cargo << 24), 0, DC_QUERY_COST, GetCmdBuildVeh(this->vehicle_type), nullptr);
 
			if (ret.Succeeded()) {
 
				this->te.cost          = ret.GetCost() - e->GetCost();
 
				this->te.capacity      = _returned_refit_capacity;
 
@@ -1316,7 +1316,7 @@ struct BuildVehicleWindow : Window {
 

	
 
		this->eng_list.clear();
 

	
 
		const Station *st = this->listview_mode ? NULL : Station::GetByTile(this->window_number);
 
		const Station *st = this->listview_mode ? nullptr : Station::GetByTile(this->window_number);
 

	
 
		/* Make list of all available planes.
 
		 * Also check to see if the previously selected plane is still available,
 
@@ -1408,8 +1408,8 @@ struct BuildVehicleWindow : Window {
 
				break;
 

	
 
			case WID_BV_SHOW_HIDE: {
 
				const Engine *e = (this->sel_engine == INVALID_ENGINE) ? NULL : Engine::Get(this->sel_engine);
 
				if (e != NULL) {
 
				const Engine *e = (this->sel_engine == INVALID_ENGINE) ? nullptr : Engine::Get(this->sel_engine);
 
				if (e != nullptr) {
 
					DoCommandP(0, 0, this->sel_engine | (e->IsHidden(_current_company) ? 0 : (1u << 31)), CMD_SET_VEHICLE_VISIBILITY);
 
				}
 
				break;
 
@@ -1477,8 +1477,8 @@ struct BuildVehicleWindow : Window {
 
				break;
 

	
 
			case WID_BV_SHOW_HIDE: {
 
				const Engine *e = (this->sel_engine == INVALID_ENGINE) ? NULL : Engine::Get(this->sel_engine);
 
				if (e != NULL && e->IsHidden(_local_company)) {
 
				const Engine *e = (this->sel_engine == INVALID_ENGINE) ? nullptr : Engine::Get(this->sel_engine);
 
				if (e != nullptr && e->IsHidden(_local_company)) {
 
					SetDParam(0, STR_BUY_VEHICLE_TRAIN_SHOW_TOGGLE_BUTTON + this->vehicle_type);
 
				} else {
 
					SetDParam(0, STR_BUY_VEHICLE_TRAIN_HIDE_TOGGLE_BUTTON + this->vehicle_type);
 
@@ -1567,9 +1567,9 @@ struct BuildVehicleWindow : Window {
 

	
 
	void OnQueryTextFinished(char *str) override
 
	{
 
		if (str == NULL) return;
 
		if (str == nullptr) return;
 

	
 
		DoCommandP(0, this->rename_engine, 0, CMD_RENAME_ENGINE | CMD_MSG(STR_ERROR_CAN_T_RENAME_TRAIN_TYPE + this->vehicle_type), NULL, str);
 
		DoCommandP(0, this->rename_engine, 0, CMD_RENAME_ENGINE | CMD_MSG(STR_ERROR_CAN_T_RENAME_TRAIN_TYPE + this->vehicle_type), nullptr, str);
 
	}
 

	
 
	void OnDropdownSelect(int widget, int index) override
src/cargoaction.cpp
Show inline comments
 
@@ -121,7 +121,7 @@ bool CargoDelivery::operator()(CargoPack
 
bool CargoLoad::operator()(CargoPacket *cp)
 
{
 
	CargoPacket *cp_new = this->Preprocess(cp);
 
	if (cp_new == NULL) return false;
 
	if (cp_new == nullptr) return false;
 
	cp_new->SetLoadPlace(this->load_place);
 
	this->source->RemoveFromCache(cp_new, cp_new->Count());
 
	this->destination->Append(cp_new, VehicleCargoList::MTA_KEEP);
 
@@ -136,7 +136,7 @@ bool CargoLoad::operator()(CargoPacket *
 
bool CargoReservation::operator()(CargoPacket *cp)
 
{
 
	CargoPacket *cp_new = this->Preprocess(cp);
 
	if (cp_new == NULL) return false;
 
	if (cp_new == nullptr) return false;
 
	cp_new->SetLoadPlace(this->load_place);
 
	this->source->reserved_count += cp_new->Count();
 
	this->source->RemoveFromCache(cp_new, cp_new->Count());
 
@@ -152,7 +152,7 @@ bool CargoReservation::operator()(CargoP
 
bool CargoReturn::operator()(CargoPacket *cp)
 
{
 
	CargoPacket *cp_new = this->Preprocess(cp);
 
	if (cp_new == NULL) cp_new = cp;
 
	if (cp_new == nullptr) cp_new = cp;
 
	assert(cp_new->Count() <= this->destination->reserved_count);
 
	this->source->RemoveFromMeta(cp_new, VehicleCargoList::MTA_LOAD, cp_new->Count());
 
	this->destination->reserved_count -= cp_new->Count();
 
@@ -168,7 +168,7 @@ bool CargoReturn::operator()(CargoPacket
 
bool CargoTransfer::operator()(CargoPacket *cp)
 
{
 
	CargoPacket *cp_new = this->Preprocess(cp);
 
	if (cp_new == NULL) return false;
 
	if (cp_new == nullptr) return false;
 
	this->source->RemoveFromMeta(cp_new, VehicleCargoList::MTA_TRANSFER, cp_new->Count());
 
	/* No transfer credits here as they were already granted during Stage(). */
 
	this->destination->Append(cp_new, cp_new->NextStation());
 
@@ -183,7 +183,7 @@ bool CargoTransfer::operator()(CargoPack
 
bool CargoShift::operator()(CargoPacket *cp)
 
{
 
	CargoPacket *cp_new = this->Preprocess(cp);
 
	if (cp_new == NULL) cp_new = cp;
 
	if (cp_new == nullptr) cp_new = cp;
 
	this->source->RemoveFromMeta(cp_new, VehicleCargoList::MTA_KEEP, cp_new->Count());
 
	this->destination->Append(cp_new, VehicleCargoList::MTA_KEEP);
 
	return cp_new == cp;
 
@@ -197,7 +197,7 @@ bool CargoShift::operator()(CargoPacket 
 
bool StationCargoReroute::operator()(CargoPacket *cp)
 
{
 
	CargoPacket *cp_new = this->Preprocess(cp);
 
	if (cp_new == NULL) cp_new = cp;
 
	if (cp_new == nullptr) cp_new = cp;
 
	StationID next = this->ge->GetVia(cp_new->SourceStation(), this->avoid, this->avoid2);
 
	assert(next != this->avoid && next != this->avoid2);
 
	if (this->source != this->destination) {
 
@@ -220,7 +220,7 @@ bool StationCargoReroute::operator()(Car
 
bool VehicleCargoReroute::operator()(CargoPacket *cp)
 
{
 
	CargoPacket *cp_new = this->Preprocess(cp);
 
	if (cp_new == NULL) cp_new = cp;
 
	if (cp_new == nullptr) cp_new = cp;
 
	if (cp_new->NextStation() == this->avoid || cp_new->NextStation() == this->avoid2) {
 
		cp->SetNextStation(this->ge->GetVia(cp_new->SourceStation(), this->avoid, this->avoid2));
 
	}
src/cargopacket.cpp
Show inline comments
 
@@ -86,11 +86,11 @@ CargoPacket::CargoPacket(uint16 count, b
 
/**
 
 * Split this packet in two and return the split off part.
 
 * @param new_size Size of the split part.
 
 * @return Split off part, or NULL if no packet could be allocated!
 
 * @return Split off part, or nullptr if no packet could be allocated!
 
 */
 
CargoPacket *CargoPacket::Split(uint new_size)
 
{
 
	if (!CargoPacket::CanAllocateItem()) return NULL;
 
	if (!CargoPacket::CanAllocateItem()) return nullptr;
 

	
 
	Money fs = this->FeederShare(new_size);
 
	CargoPacket *cp_new = new CargoPacket(new_size, this->days_in_transit, this->source, this->source_xy, this->loaded_at_xy, fs, this->source_type, this->source_id);
 
@@ -248,12 +248,12 @@ template <class Tinst, class Tcont>
 
 * @param cp Cargo packet to add.
 
 * @param action Either MTA_KEEP if you want to add the packet directly or MTA_LOAD
 
 * if you want to reserve it first.
 
 * @pre cp != NULL
 
 * @pre cp != nullptr
 
 * @pre action == MTA_LOAD || (action == MTA_KEEP && this->designation_counts[MTA_LOAD] == 0)
 
 */
 
void VehicleCargoList::Append(CargoPacket *cp, MoveToAction action)
 
{
 
	assert(cp != NULL);
 
	assert(cp != nullptr);
 
	assert(action == MTA_LOAD ||
 
			(action == MTA_KEEP && this->action_counts[MTA_LOAD] == 0));
 
	this->AddToMeta(cp, action);
 
@@ -689,11 +689,11 @@ uint VehicleCargoList::Reroute(uint max_
 
 * @note Do not use the cargo packet anymore after it has been appended to this CargoList!
 
 * @param next the next hop
 
 * @param cp the cargo packet to add
 
 * @pre cp != NULL
 
 * @pre cp != nullptr
 
 */
 
void StationCargoList::Append(CargoPacket *cp, StationID next)
 
{
 
	assert(cp != NULL);
 
	assert(cp != nullptr);
 
	this->AddToCache(cp);
 

	
 
	StationCargoPacketMap::List &list = this->packets[next];
 
@@ -776,7 +776,7 @@ uint StationCargoList::Truncate(uint max
 
	uint prev_count = this->count;
 
	uint moved = 0;
 
	uint loop = 0;
 
	bool do_count = cargo_per_source != NULL;
 
	bool do_count = cargo_per_source != nullptr;
 
	while (max_move > moved) {
 
		for (Iterator it(this->packets.begin()); it != this->packets.end();) {
 
			CargoPacket *cp = *it;
src/cargopacket.h
Show inline comments
 
@@ -549,7 +549,7 @@ public:
 

	
 
	uint Reserve(uint max_move, VehicleCargoList *dest, TileIndex load_place, StationIDStack next);
 
	uint Load(uint max_move, VehicleCargoList *dest, TileIndex load_place, StationIDStack next);
 
	uint Truncate(uint max_move = UINT_MAX, StationCargoAmountMap *cargo_per_source = NULL);
 
	uint Truncate(uint max_move = UINT_MAX, StationCargoAmountMap *cargo_per_source = nullptr);
 
	uint Reroute(uint max_move, StationCargoList *dest, StationID avoid, StationID avoid2, const GoodsEntry *ge);
 

	
 
	/**
src/cargotype.h
Show inline comments
 
@@ -152,7 +152,7 @@ static inline bool IsCargoInClass(CargoI
 
	return (CargoSpec::Get(c)->classes & cc) != 0;
 
}
 

	
 
#define FOR_ALL_CARGOSPECS_FROM(var, start) for (size_t cargospec_index = start; var = NULL, cargospec_index < CargoSpec::GetArraySize(); cargospec_index++) \
 
#define FOR_ALL_CARGOSPECS_FROM(var, start) for (size_t cargospec_index = start; var = nullptr, cargospec_index < CargoSpec::GetArraySize(); cargospec_index++) \
 
		if ((var = CargoSpec::Get(cargospec_index))->IsValid())
 
#define FOR_ALL_CARGOSPECS(var) FOR_ALL_CARGOSPECS_FROM(var, 0)
 

	
src/cheat_gui.cpp
Show inline comments
 
@@ -186,9 +186,9 @@ struct CheatEntry {
 
static const CheatEntry _cheats_ui[] = {
 
	{SLE_INT32, STR_CHEAT_MONEY,           &_money_cheat_amount,                    &_cheats.money.been_used,            &ClickMoneyCheat         },
 
	{SLE_UINT8, STR_CHEAT_CHANGE_COMPANY,  &_local_company,                         &_cheats.switch_company.been_used,   &ClickChangeCompanyCheat },
 
	{SLE_BOOL,  STR_CHEAT_EXTRA_DYNAMITE,  &_cheats.magic_bulldozer.value,          &_cheats.magic_bulldozer.been_used,  NULL                     },
 
	{SLE_BOOL,  STR_CHEAT_CROSSINGTUNNELS, &_cheats.crossing_tunnels.value,         &_cheats.crossing_tunnels.been_used, NULL                     },
 
	{SLE_BOOL,  STR_CHEAT_NO_JETCRASH,     &_cheats.no_jetcrash.value,              &_cheats.no_jetcrash.been_used,      NULL                     },
 
	{SLE_BOOL,  STR_CHEAT_EXTRA_DYNAMITE,  &_cheats.magic_bulldozer.value,          &_cheats.magic_bulldozer.been_used,  nullptr                     },
 
	{SLE_BOOL,  STR_CHEAT_CROSSINGTUNNELS, &_cheats.crossing_tunnels.value,         &_cheats.crossing_tunnels.been_used, nullptr                     },
 
	{SLE_BOOL,  STR_CHEAT_NO_JETCRASH,     &_cheats.no_jetcrash.value,              &_cheats.no_jetcrash.been_used,      nullptr                     },
 
	{SLE_BOOL,  STR_CHEAT_SETUP_PROD,      &_cheats.setup_prod.value,               &_cheats.setup_prod.been_used,       &ClickSetProdCheat       },
 
	{SLE_UINT8, STR_CHEAT_EDIT_MAX_HL,     &_settings_game.construction.max_heightlevel, &_cheats.edit_max_hl.been_used, &ClickChangeMaxHlCheat   },
 
	{SLE_INT32, STR_CHEAT_CHANGE_DATE,     &_cur_year,                              &_cheats.change_date.been_used,      &ClickChangeDateCheat    },
 
@@ -365,7 +365,7 @@ struct CheatWindow : Window {
 
		switch (ce->type) {
 
			case SLE_BOOL:
 
				value ^= 1;
 
				if (ce->proc != NULL) ce->proc(value, 0);
 
				if (ce->proc != nullptr) ce->proc(value, 0);
 
				break;
 

	
 
			default:
 
@@ -393,7 +393,7 @@ struct CheatWindow : Window {
 
	void OnQueryTextFinished(char *str) override
 
	{
 
		/* Was 'cancel' pressed or nothing entered? */
 
		if (str == NULL || StrEmpty(str)) return;
 
		if (str == nullptr || StrEmpty(str)) return;
 

	
 
		const CheatEntry *ce = &_cheats_ui[clicked_widget];
 
		int oldvalue = (int32)ReadValue(ce->variable, ce->type);
src/clear_cmd.cpp
Show inline comments
 
@@ -389,15 +389,15 @@ extern const TileTypeProcs _tile_type_cl
 
	DrawTile_Clear,           ///< draw_tile_proc
 
	GetSlopePixelZ_Clear,     ///< get_slope_z_proc
 
	ClearTile_Clear,          ///< clear_tile_proc
 
	NULL,                     ///< add_accepted_cargo_proc
 
	nullptr,                     ///< add_accepted_cargo_proc
 
	GetTileDesc_Clear,        ///< get_tile_desc_proc
 
	GetTileTrackStatus_Clear, ///< get_tile_track_status_proc
 
	NULL,                     ///< click_tile_proc
 
	NULL,                     ///< animate_tile_proc
 
	nullptr,                     ///< click_tile_proc
 
	nullptr,                     ///< animate_tile_proc
 
	TileLoop_Clear,           ///< tile_loop_proc
 
	ChangeTileOwner_Clear,    ///< change_tile_owner_proc
 
	NULL,                     ///< add_produced_cargo_proc
 
	NULL,                     ///< vehicle_enter_tile_proc
 
	nullptr,                     ///< add_produced_cargo_proc
 
	nullptr,                     ///< vehicle_enter_tile_proc
 
	GetFoundation_Clear,      ///< get_foundation_proc
 
	TerraformTile_Clear,      ///< terraform_tile_proc
 
};
src/command.cpp
Show inline comments
 
@@ -361,7 +361,7 @@ static const Command _command_proc_table
 
};
 

	
 
/*!
 
 * This function range-checks a cmd, and checks if the cmd is not NULL
 
 * This function range-checks a cmd, and checks if the cmd is not nullptr
 
 *
 
 * @param cmd The integer value of a command
 
 * @return true if the command is valid (and got a CommandProc function)
 
@@ -370,7 +370,7 @@ bool IsValidCommand(uint32 cmd)
 
{
 
	cmd &= CMD_ID_MASK;
 

	
 
	return cmd < lengthof(_command_proc_table) && _command_proc_table[cmd].proc != NULL;
 
	return cmd < lengthof(_command_proc_table) && _command_proc_table[cmd].proc != nullptr;
 
}
 

	
 
/*!
 
@@ -594,7 +594,7 @@ bool DoCommandP(TileIndex tile, uint32 p
 
		ShowCostOrIncomeAnimation(x, y, GetSlopePixelZ(x, y), res.GetCost());
 
	}
 

	
 
	if (!estimate_only && !only_sending && callback != NULL) {
 
	if (!estimate_only && !only_sending && callback != nullptr) {
 
		callback(res, tile, p1, p2);
 
	}
 

	
 
@@ -637,7 +637,7 @@ CommandCost DoCommandPInternal(TileIndex
 
	CommandProc *proc = _command_proc_table[cmd_id].proc;
 
	/* Shouldn't happen, but you never know when someone adds
 
	 * NULLs to the _command_proc_table. */
 
	assert(proc != NULL);
 
	assert(proc != nullptr);
 

	
 
	/* Command flags are used internally */
 
	CommandFlags cmd_flags = GetCommandFlags(cmd);
 
@@ -750,7 +750,7 @@ CommandCost DoCommandPInternal(TileIndex
 
	/* update last build coordinate of company. */
 
	if (tile != 0) {
 
		Company *c = Company::GetIfValid(_current_company);
 
		if (c != NULL) c->last_build_coordinate = tile;
 
		if (c != nullptr) c->last_build_coordinate = tile;
 
	}
 

	
 
	SubtractMoneyFromCompany(res2);
src/command_func.h
Show inline comments
 
@@ -34,10 +34,10 @@ static const CommandCost CMD_ERROR = Com
 
 */
 
#define return_cmd_error(errcode) return CommandCost(errcode);
 

	
 
CommandCost DoCommand(TileIndex tile, uint32 p1, uint32 p2, DoCommandFlag flags, uint32 cmd, const char *text = NULL);
 
CommandCost DoCommand(TileIndex tile, uint32 p1, uint32 p2, DoCommandFlag flags, uint32 cmd, const char *text = nullptr);
 
CommandCost DoCommand(const CommandContainer *container, DoCommandFlag flags);
 

	
 
bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback = NULL, const char *text = NULL, bool my_cmd = true);
 
bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback = nullptr, const char *text = nullptr, bool my_cmd = true);
 
bool DoCommandP(const CommandContainer *container, bool my_cmd = true);
 

	
 
CommandCost DoCommandPInternal(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback, const char *text, bool my_cmd, bool estimate_only);
src/command_type.h
Show inline comments
 
@@ -36,25 +36,25 @@ public:
 
	/**
 
	 * Creates a command cost return with no cost and no error
 
	 */
 
	CommandCost() : expense_type(INVALID_EXPENSES), cost(0), message(INVALID_STRING_ID), success(true), textref_stack_grffile(NULL), textref_stack_size(0) {}
 
	CommandCost() : expense_type(INVALID_EXPENSES), cost(0), message(INVALID_STRING_ID), success(true), textref_stack_grffile(nullptr), textref_stack_size(0) {}
 

	
 
	/**
 
	 * Creates a command return value the is failed with the given message
 
	 */
 
	explicit CommandCost(StringID msg) : expense_type(INVALID_EXPENSES), cost(0), message(msg), success(false), textref_stack_grffile(NULL), textref_stack_size(0) {}
 
	explicit CommandCost(StringID msg) : expense_type(INVALID_EXPENSES), cost(0), message(msg), success(false), textref_stack_grffile(nullptr), textref_stack_size(0) {}
 

	
 
	/**
 
	 * Creates a command cost with given expense type and start cost of 0
 
	 * @param ex_t the expense type
 
	 */
 
	explicit CommandCost(ExpensesType ex_t) : expense_type(ex_t), cost(0), message(INVALID_STRING_ID), success(true), textref_stack_grffile(NULL), textref_stack_size(0) {}
 
	explicit CommandCost(ExpensesType ex_t) : expense_type(ex_t), cost(0), message(INVALID_STRING_ID), success(true), textref_stack_grffile(nullptr), textref_stack_size(0) {}
 

	
 
	/**
 
	 * Creates a command return value with the given start cost and expense type
 
	 * @param ex_t the expense type
 
	 * @param cst the initial cost of this command
 
	 */
 
	CommandCost(ExpensesType ex_t, const Money &cst) : expense_type(ex_t), cost(cst), message(INVALID_STRING_ID), success(true), textref_stack_grffile(NULL), textref_stack_size(0) {}
 
	CommandCost(ExpensesType ex_t, const Money &cst) : expense_type(ex_t), cost(cst), message(INVALID_STRING_ID), success(true), textref_stack_grffile(nullptr), textref_stack_size(0) {}
 

	
 

	
 
	/**
src/company_base.h
Show inline comments
 
@@ -98,7 +98,7 @@ struct CompanyProperties {
 

	
 
	// TODO: Change some of these member variables to use relevant INVALID_xxx constants
 
	CompanyProperties()
 
		: name_2(0), name_1(0), name(NULL), president_name_1(0), president_name_2(0), president_name(NULL),
 
		: name_2(0), name_1(0), name(nullptr), president_name_1(0), president_name_2(0), president_name(nullptr),
 
		  face(0), money(0), money_fraction(0), current_loan(0), colour(0), block_preview(0),
 
		  location_of_HQ(0), last_build_coordinate(0), share_owners(), inaugurated_year(0),
 
		  months_of_bankruptcy(0), bankrupt_asked(0), bankrupt_timeout(0), bankrupt_value(0),
 
@@ -137,7 +137,7 @@ struct Company : CompanyPool::PoolItem<&
 
	static inline bool IsValidAiID(size_t index)
 
	{
 
		const Company *c = Company::GetIfValid(index);
 
		return c != NULL && c->is_ai;
 
		return c != nullptr && c->is_ai;
 
	}
 

	
 
	/**
 
@@ -149,7 +149,7 @@ struct Company : CompanyPool::PoolItem<&
 
	static inline bool IsValidHumanID(size_t index)
 
	{
 
		const Company *c = Company::GetIfValid(index);
 
		return c != NULL && !c->is_ai;
 
		return c != nullptr && !c->is_ai;
 
	}
 

	
 
	/**
src/company_cmd.cpp
Show inline comments
 
@@ -193,7 +193,7 @@ bool CheckCompanyHasMoney(CommandCost &c
 
{
 
	if (cost.GetCost() > 0) {
 
		const Company *c = Company::GetIfValid(_current_company);
 
		if (c != NULL && cost.GetCost() > c->money) {
 
		if (c != nullptr && cost.GetCost() > c->money) {
 
			SetDParam(0, cost.GetCost());
 
			cost.MakeError(STR_ERROR_NOT_ENOUGH_CASH_REQUIRES_CURRENCY);
 
			return false;
 
@@ -239,7 +239,7 @@ static void SubtractMoneyFromAnyCompany(
 
void SubtractMoneyFromCompany(CommandCost cost)
 
{
 
	Company *c = Company::GetIfValid(_current_company);
 
	if (c != NULL) SubtractMoneyFromAnyCompany(c, cost);
 
	if (c != nullptr) SubtractMoneyFromAnyCompany(c, cost);
 
}
 

	
 
/**
 
@@ -353,7 +353,7 @@ static void GenerateCompanyName(Company 
 

	
 
	StringID str;
 
	uint32 strp;
 
	if (t->name == NULL && IsInsideMM(t->townnametype, SPECSTR_TOWNNAME_START, SPECSTR_TOWNNAME_LAST + 1)) {
 
	if (t->name == nullptr && IsInsideMM(t->townnametype, SPECSTR_TOWNNAME_START, SPECSTR_TOWNNAME_LAST + 1)) {
 
		str = t->townnametype - SPECSTR_TOWNNAME_START + SPECSTR_COMPANY_NAME_START;
 
		strp = t->townnameparts;
 

	
 
@@ -539,7 +539,7 @@ void ResetCompanyLivery(Company *c)
 
 */
 
Company *DoStartupNewCompany(bool is_ai, CompanyID company = INVALID_COMPANY)
 
{
 
	if (!Company::CanAllocateItem()) return NULL;
 
	if (!Company::CanAllocateItem()) return nullptr;
 

	
 
	/* we have to generate colour before this company is valid */
 
	Colours colour = GenerateCompanyColour();
 
@@ -548,7 +548,7 @@ Company *DoStartupNewCompany(bool is_ai,
 
	if (company == INVALID_COMPANY) {
 
		c = new Company(STR_SV_UNNAMED, is_ai);
 
	} else {
 
		if (Company::IsValidID(company)) return NULL;
 
		if (Company::IsValidID(company)) return nullptr;
 
		c = new (company) Company(STR_SV_UNNAMED, is_ai);
 
	}
 

	
 
@@ -670,7 +670,7 @@ static void HandleBankruptcyTakeover(Com
 
	/* Did we ask everyone for bankruptcy? If so, bail out. */
 
	if (c->bankrupt_asked == MAX_UVALUE(CompanyMask)) return;
 

	
 
	Company *c2, *best = NULL;
 
	Company *c2, *best = nullptr;
 
	int32 best_performance = -1;
 

	
 
	/* Ask the company with the highest performance history first */
 
@@ -706,7 +706,7 @@ void OnTick_Companies()
 
	if (_game_mode == GM_EDITOR) return;
 

	
 
	Company *c = Company::GetIfValid(_cur_company_tick_index);
 
	if (c != NULL) {
 
	if (c != nullptr) {
 
		if (c->name_1 != 0) GenerateCompanyName(c);
 
		if (c->bankrupt_asked != 0) HandleBankruptcyTakeover(c);
 
	}
 
@@ -759,14 +759,14 @@ void CompaniesYearlyLoop()
 
/**
 
 * Fill the CompanyNewsInformation struct with the required data.
 
 * @param c the current company.
 
 * @param other the other company (use \c NULL if not relevant).
 
 * @param other the other company (use \c nullptr if not relevant).
 
 */
 
void CompanyNewsInformation::FillData(const Company *c, const Company *other)
 
{
 
	SetDParam(0, c->index);
 
	GetString(this->company_name, STR_COMPANY_NAME, lastof(this->company_name));
 

	
 
	if (other == NULL) {
 
	if (other == nullptr) {
 
		*this->other_company_name = '\0';
 
	} else {
 
		SetDParam(0, other->index);
 
@@ -832,8 +832,8 @@ CommandCost CmdCompanyCtrl(TileIndex til
 
			/* When replaying the client ID is not a valid client; there
 
			 * are actually no clients at all. However, the company has to
 
			 * be created, otherwise we cannot rerun the game properly.
 
			 * So only allow a NULL client info in that case. */
 
			if (ci == NULL) return CommandCost();
 
			 * So only allow a nullptr client info in that case. */
 
			if (ci == nullptr) return CommandCost();
 
#endif /* NOT DEBUG_DUMP_COMMANDS */
 

	
 
			/* Delete multiplayer progress bar */
 
@@ -842,7 +842,7 @@ CommandCost CmdCompanyCtrl(TileIndex til
 
			Company *c = DoStartupNewCompany(false);
 

	
 
			/* A new company could not be created, revert to being a spectator */
 
			if (c == NULL) {
 
			if (c == nullptr) {
 
				if (_network_server) {
 
					ci->client_playas = COMPANY_SPECTATOR;
 
					NetworkUpdateClientInfo(ci->client_id);
 
@@ -874,7 +874,7 @@ CommandCost CmdCompanyCtrl(TileIndex til
 

	
 
			if (company_id != INVALID_COMPANY && (company_id >= MAX_COMPANIES || Company::IsValidID(company_id))) return CMD_ERROR;
 
			Company *c = DoStartupNewCompany(true, company_id);
 
			if (c != NULL) NetworkServerNewCompany(c, NULL);
 
			if (c != nullptr) NetworkServerNewCompany(c, nullptr);
 
			break;
 
		}
 

	
 
@@ -883,7 +883,7 @@ CommandCost CmdCompanyCtrl(TileIndex til
 
			if (reason >= CRR_END) return CMD_ERROR;
 

	
 
			Company *c = Company::GetIfValid(company_id);
 
			if (c == NULL) return CMD_ERROR;
 
			if (c == nullptr) return CMD_ERROR;
 

	
 
			if (!(flags & DC_EXEC)) return CommandCost();
 

	
 
@@ -1055,7 +1055,7 @@ static bool IsUniqueCompanyName(const ch
 
	const Company *c;
 

	
 
	FOR_ALL_COMPANIES(c) {
 
		if (c->name != NULL && strcmp(c->name, name) == 0) return false;
 
		if (c->name != nullptr && strcmp(c->name, name) == 0) return false;
 
	}
 

	
 
	return true;
 
@@ -1082,7 +1082,7 @@ CommandCost CmdRenameCompany(TileIndex t
 
	if (flags & DC_EXEC) {
 
		Company *c = Company::Get(_current_company);
 
		free(c->name);
 
		c->name = reset ? NULL : stredup(text);
 
		c->name = reset ? nullptr : stredup(text);
 
		MarkWholeScreenDirty();
 
		CompanyAdminUpdate(c);
 
	}
 
@@ -1100,7 +1100,7 @@ static bool IsUniquePresidentName(const 
 
	const Company *c;
 

	
 
	FOR_ALL_COMPANIES(c) {
 
		if (c->president_name != NULL && strcmp(c->president_name, name) == 0) return false;
 
		if (c->president_name != nullptr && strcmp(c->president_name, name) == 0) return false;
 
	}
 

	
 
	return true;
 
@@ -1129,11 +1129,11 @@ CommandCost CmdRenamePresident(TileIndex
 
		free(c->president_name);
 

	
 
		if (reset) {
 
			c->president_name = NULL;
 
			c->president_name = nullptr;
 
		} else {
 
			c->president_name = stredup(text);
 

	
 
			if (c->name_1 == STR_SV_UNNAMED && c->name == NULL) {
 
			if (c->name_1 == STR_SV_UNNAMED && c->name == nullptr) {
 
				char buf[80];
 

	
 
				seprintf(buf, lastof(buf), "%s Transport", text);
 
@@ -1150,13 +1150,13 @@ CommandCost CmdRenamePresident(TileIndex
 

	
 
/**
 
 * Get the service interval for the given company and vehicle type.
 
 * @param c The company, or NULL for client-default settings.
 
 * @param c The company, or nullptr for client-default settings.
 
 * @param type The vehicle type to get the interval for.
 
 * @return The service interval.
 
 */
 
int CompanyServiceInterval(const Company *c, VehicleType type)
 
{
 
	const VehicleDefaultSettings *vds = (c == NULL) ? &_settings_client.company.vehicle : &c->settings.vehicle;
 
	const VehicleDefaultSettings *vds = (c == nullptr) ? &_settings_client.company.vehicle : &c->settings.vehicle;
 
	switch (type) {
 
		default: NOT_REACHED();
 
		case VEH_TRAIN:    return vds->servint_trains;
src/company_gui.cpp
Show inline comments
 
@@ -569,7 +569,7 @@ private:
 
	{
 
		uint32 used_colours = 0;
 
		const Company *c;
 
		const Livery *livery, *default_livery = NULL;
 
		const Livery *livery, *default_livery = nullptr;
 
		bool primary = widget == WID_SCL_PRI_COL_DROPDOWN;
 
		byte default_col;
 

	
 
@@ -603,7 +603,7 @@ private:
 
		}
 

	
 
		DropDownList list;
 
		if (default_livery != NULL) {
 
		if (default_livery != nullptr) {
 
			/* Add COLOUR_END to put the colour out of range, but also allow us to show what the default is */
 
			default_col = (primary ? default_livery->colour1 : default_livery->colour2) + COLOUR_END;
 
			list.emplace_back(new DropDownListColourItem(default_col, false));
 
@@ -612,13 +612,13 @@ private:
 
			list.emplace_back(new DropDownListColourItem(i, HasBit(used_colours, i)));
 
		}
 

	
 
		byte sel = (default_livery == NULL || HasBit(livery->in_use, primary ? 0 : 1)) ? (primary ? livery->colour1 : livery->colour2) : default_col;
 
		byte sel = (default_livery == nullptr || HasBit(livery->in_use, primary ? 0 : 1)) ? (primary ? livery->colour1 : livery->colour2) : default_col;
 
		ShowDropDownList(this, std::move(list), sel, widget);
 
	}
 

	
 
	static int CDECL GroupNameSorter(const Group * const *a, const Group * const *b)
 
	{
 
		static const Group *last_group[2] = { NULL, NULL };
 
		static const Group *last_group[2] = { nullptr, nullptr };
 
		static char         last_name[2][64] = { "", "" };
 

	
 
		if (*a != last_group[0]) {
 
@@ -1100,7 +1100,7 @@ static WindowDesc _select_company_livery
 
void ShowCompanyLiveryWindow(CompanyID company, GroupID group)
 
{
 
	SelectCompanyLiveryWindow *w = (SelectCompanyLiveryWindow *)BringWindowToFrontById(WC_COMPANY_COLOUR, company);
 
	if (w == NULL) {
 
	if (w == nullptr) {
 
		new SelectCompanyLiveryWindow(&_select_company_livery_desc, company, group);
 
	} else if (group != INVALID_GROUP) {
 
		w->SetSelectedGroup(company, group);
 
@@ -1711,10 +1711,10 @@ public:
 

	
 
	void OnQueryTextFinished(char *str) override
 
	{
 
		if (str == NULL) return;
 
		if (str == nullptr) return;
 
		/* Set a new company manager face number */
 
		if (!StrEmpty(str)) {
 
			this->face = strtoul(str, NULL, 10);
 
			this->face = strtoul(str, nullptr, 10);
 
			ScaleAllCompanyManagerFaceBits(this->face);
 
			ShowErrorMessage(STR_FACE_FACECODE_SET, INVALID_STRING_ID, WL_INFO);
 
			this->UpdateData();
 
@@ -2633,17 +2633,17 @@ struct CompanyWindow : Window
 

	
 
	void OnQueryTextFinished(char *str) override
 
	{
 
		if (str == NULL) return;
 
		if (str == nullptr) return;
 

	
 
		switch (this->query_widget) {
 
			default: NOT_REACHED();
 

	
 
			case WID_C_PRESIDENT_NAME:
 
				DoCommandP(0, 0, 0, CMD_RENAME_PRESIDENT | CMD_MSG(STR_ERROR_CAN_T_CHANGE_PRESIDENT), NULL, str);
 
				DoCommandP(0, 0, 0, CMD_RENAME_PRESIDENT | CMD_MSG(STR_ERROR_CAN_T_CHANGE_PRESIDENT), nullptr, str);
 
				break;
 

	
 
			case WID_C_COMPANY_NAME:
 
				DoCommandP(0, 0, 0, CMD_RENAME_COMPANY | CMD_MSG(STR_ERROR_CAN_T_CHANGE_COMPANY_NAME), NULL, str);
 
				DoCommandP(0, 0, 0, CMD_RENAME_COMPANY | CMD_MSG(STR_ERROR_CAN_T_CHANGE_COMPANY_NAME), nullptr, str);
 
				break;
 

	
 
			case WID_C_COMPANY_JOIN:
 
@@ -2796,7 +2796,7 @@ static const NWidgetPart _nested_buy_com
 
};
 

	
 
static WindowDesc _buy_company_desc(
 
	WDP_AUTO, NULL, 0, 0,
 
	WDP_AUTO, nullptr, 0, 0,
 
	WC_BUY_COMPANY, WC_NONE,
 
	WDF_CONSTRUCTION,
 
	_nested_buy_company_widgets, lengthof(_nested_buy_company_widgets)
src/console.cpp
Show inline comments
 
@@ -32,7 +32,7 @@ FILE *_iconsole_output_file;
 

	
 
void IConsoleInit()
 
{
 
	_iconsole_output_file = NULL;
 
	_iconsole_output_file = nullptr;
 
	_redirect_console_to_client = INVALID_CLIENT_ID;
 
	_redirect_console_to_admin  = INVALID_ADMIN_ID;
 

	
 
@@ -43,14 +43,14 @@ void IConsoleInit()
 

	
 
static void IConsoleWriteToLogFile(const char *string)
 
{
 
	if (_iconsole_output_file != NULL) {
 
	if (_iconsole_output_file != nullptr) {
 
		/* if there is an console output file ... also print it there */
 
		const char *header = GetLogPrefix();
 
		if ((strlen(header) != 0 && fwrite(header, strlen(header), 1, _iconsole_output_file) != 1) ||
 
				fwrite(string, strlen(string), 1, _iconsole_output_file) != 1 ||
 
				fwrite("\n", 1, 1, _iconsole_output_file) != 1) {
 
			fclose(_iconsole_output_file);
 
			_iconsole_output_file = NULL;
 
			_iconsole_output_file = nullptr;
 
			IConsolePrintF(CC_DEFAULT, "cannot write to log file");
 
		}
 
	}
 
@@ -58,10 +58,10 @@ static void IConsoleWriteToLogFile(const
 

	
 
bool CloseConsoleLogIfActive()
 
{
 
	if (_iconsole_output_file != NULL) {
 
	if (_iconsole_output_file != nullptr) {
 
		IConsolePrintF(CC_DEFAULT, "file output complete");
 
		fclose(_iconsole_output_file);
 
		_iconsole_output_file = NULL;
 
		_iconsole_output_file = nullptr;
 
		return true;
 
	}
 

	
 
@@ -203,22 +203,22 @@ bool GetArgumentInteger(uint32 *value, c
 
template<class T>
 
void IConsoleAddSorted(T **base, T *item_new)
 
{
 
	if (*base == NULL) {
 
	if (*base == nullptr) {
 
		*base = item_new;
 
		return;
 
	}
 

	
 
	T *item_before = NULL;
 
	T *item_before = nullptr;
 
	T *item = *base;
 
	/* The list is alphabetically sorted, insert the new item at the correct location */
 
	while (item != NULL) {
 
	while (item != nullptr) {
 
		if (strcmp(item->name, item_new->name) > 0) break; // insert here
 

	
 
		item_before = item;
 
		item = item->next;
 
	}
 

	
 
	if (item_before == NULL) {
 
	if (item_before == nullptr) {
 
		*base = item_new;
 
	} else {
 
		item_before->next = item_new;
 
@@ -251,7 +251,7 @@ void IConsoleCmdRegister(const char *nam
 
{
 
	IConsoleCmd *item_new = MallocT<IConsoleCmd>(1);
 
	item_new->name = RemoveUnderscores(stredup(name));
 
	item_new->next = NULL;
 
	item_new->next = nullptr;
 
	item_new->proc = proc;
 
	item_new->hook = hook;
 

	
 
@@ -261,16 +261,16 @@ void IConsoleCmdRegister(const char *nam
 
/**
 
 * Find the command pointed to by its string
 
 * @param name command to be found
 
 * @return return Cmdstruct of the found command, or NULL on failure
 
 * @return return Cmdstruct of the found command, or nullptr on failure
 
 */
 
IConsoleCmd *IConsoleCmdGet(const char *name)
 
{
 
	IConsoleCmd *item;
 

	
 
	for (item = _iconsole_cmds; item != NULL; item = item->next) {
 
	for (item = _iconsole_cmds; item != nullptr; item = item->next) {
 
		if (strcmp(item->name, name) == 0) return item;
 
	}
 
	return NULL;
 
	return nullptr;
 
}
 

	
 
/**
 
@@ -280,7 +280,7 @@ IConsoleCmd *IConsoleCmdGet(const char *
 
 */
 
void IConsoleAliasRegister(const char *name, const char *cmd)
 
{
 
	if (IConsoleAliasGet(name) != NULL) {
 
	if (IConsoleAliasGet(name) != nullptr) {
 
		IConsoleError("an alias with this name already exists; insertion aborted");
 
		return;
 
	}
 
@@ -289,7 +289,7 @@ void IConsoleAliasRegister(const char *n
 
	char *cmd_aliased = stredup(cmd);
 
	IConsoleAlias *item_new = MallocT<IConsoleAlias>(1);
 

	
 
	item_new->next = NULL;
 
	item_new->next = nullptr;
 
	item_new->cmdline = cmd_aliased;
 
	item_new->name = new_alias;
 

	
 
@@ -299,17 +299,17 @@ void IConsoleAliasRegister(const char *n
 
/**
 
 * Find the alias pointed to by its string
 
 * @param name alias to be found
 
 * @return return Aliasstruct of the found alias, or NULL on failure
 
 * @return return Aliasstruct of the found alias, or nullptr on failure
 
 */
 
IConsoleAlias *IConsoleAliasGet(const char *name)
 
{
 
	IConsoleAlias *item;
 

	
 
	for (item = _iconsole_aliases; item != NULL; item = item->next) {
 
	for (item = _iconsole_aliases; item != nullptr; item = item->next) {
 
		if (strcmp(item->name, name) == 0) return item;
 
	}
 

	
 
	return NULL;
 
	return nullptr;
 
}
 
/**
 
 * An alias is just another name for a command, or for more commands
 
@@ -478,7 +478,7 @@ void IConsoleCmdExec(const char *cmdstr)
 
		}
 
	}
 

	
 
	for (uint i = 0; i < lengthof(tokens) && tokens[i] != NULL; i++) {
 
	for (uint i = 0; i < lengthof(tokens) && tokens[i] != nullptr; i++) {
 
		DEBUG(console, 8, "Token %d is: '%s'", i, tokens[i]);
 
	}
 

	
 
@@ -489,12 +489,12 @@ void IConsoleCmdExec(const char *cmdstr)
 
	 */
 
	RemoveUnderscores(tokens[0]);
 
	IConsoleCmd *cmd = IConsoleCmdGet(tokens[0]);
 
	if (cmd != NULL) {
 
		ConsoleHookResult chr = (cmd->hook == NULL ? CHR_ALLOW : cmd->hook(true));
 
	if (cmd != nullptr) {
 
		ConsoleHookResult chr = (cmd->hook == nullptr ? CHR_ALLOW : cmd->hook(true));
 
		switch (chr) {
 
			case CHR_ALLOW:
 
				if (!cmd->proc(t_index, tokens)) { // index started with 0
 
					cmd->proc(0, NULL); // if command failed, give help
 
					cmd->proc(0, nullptr); // if command failed, give help
 
				}
 
				return;
 

	
 
@@ -505,7 +505,7 @@ void IConsoleCmdExec(const char *cmdstr)
 

	
 
	t_index--;
 
	IConsoleAlias *alias = IConsoleAliasGet(tokens[0]);
 
	if (alias != NULL) {
 
	if (alias != nullptr) {
 
		IConsoleAliasExec(alias, t_index, &tokens[1]);
 
		return;
 
	}
src/console_cmds.cpp
Show inline comments
 
@@ -349,7 +349,7 @@ DEF_CONSOLE_CMD(ConLoad)
 
	const char *file = argv[1];
 
	_console_file_list.ValidateFileList();
 
	const FiosItem *item = _console_file_list.FindItem(file);
 
	if (item != NULL) {
 
	if (item != nullptr) {
 
		if (GetAbstractFileType(item->type) == FT_SAVEGAME) {
 
			_switch_mode = SM_LOAD_GAME;
 
			_file_to_saveload.SetMode(item->type);
 
@@ -378,7 +378,7 @@ DEF_CONSOLE_CMD(ConRemove)
 
	const char *file = argv[1];
 
	_console_file_list.ValidateFileList();
 
	const FiosItem *item = _console_file_list.FindItem(file);
 
	if (item != NULL) {
 
	if (item != nullptr) {
 
		if (!FiosDelete(item->name)) {
 
			IConsolePrintF(CC_ERROR, "%s: Failed to delete file", file);
 
		}
 
@@ -420,7 +420,7 @@ DEF_CONSOLE_CMD(ConChangeDirectory)
 
	const char *file = argv[1];
 
	_console_file_list.ValidateFileList(true);
 
	const FiosItem *item = _console_file_list.FindItem(file);
 
	if (item != NULL) {
 
	if (item != nullptr) {
 
		switch (item->type) {
 
			case FIOS_TYPE_DIR: case FIOS_TYPE_DRIVE: case FIOS_TYPE_PARENT:
 
				FiosBrowseTo(item);
 
@@ -448,7 +448,7 @@ DEF_CONSOLE_CMD(ConPrintWorkingDirectory
 
	_console_file_list.ValidateFileList(true);
 
	_console_file_list.InvalidateFileList();
 

	
 
	FiosGetDescText(&path, NULL);
 
	FiosGetDescText(&path, nullptr);
 
	IConsolePrint(CC_DEFAULT, path);
 
	return true;
 
}
 
@@ -474,7 +474,7 @@ static bool ConKickOrBan(const char *arg
 
{
 
	uint n;
 

	
 
	if (strchr(argv, '.') == NULL && strchr(argv, ':') == NULL) { // banning with ID
 
	if (strchr(argv, '.') == nullptr && strchr(argv, ':') == nullptr) { // banning with ID
 
		ClientID client_id = (ClientID)atoi(argv);
 

	
 
		/* Don't kill the server, or the client doing the rcon. The latter can't be kicked because
 
@@ -487,7 +487,7 @@ static bool ConKickOrBan(const char *arg
 
		}
 

	
 
		NetworkClientInfo *ci = NetworkClientInfo::GetByClientID(client_id);
 
		if (ci == NULL) {
 
		if (ci == nullptr) {
 
			IConsoleError("Invalid client");
 
			return true;
 
		}
 
@@ -688,7 +688,7 @@ DEF_CONSOLE_CMD(ConClientNickChange)
 
		return true;
 
	}
 

	
 
	if (NetworkClientInfo::GetByClientID(client_id) == NULL) {
 
	if (NetworkClientInfo::GetByClientID(client_id) == nullptr) {
 
		IConsoleError("Invalid client");
 
		return true;
 
	}
 
@@ -759,7 +759,7 @@ DEF_CONSOLE_CMD(ConMoveClient)
 
	CompanyID company_id = (CompanyID)(atoi(argv[2]) <= MAX_COMPANIES ? atoi(argv[2]) - 1 : atoi(argv[2]));
 

	
 
	/* check the client exists */
 
	if (ci == NULL) {
 
	if (ci == nullptr) {
 
		IConsoleError("Invalid client-id, check the command 'clients' for valid client-id's.");
 
		return true;
 
	}
 
@@ -887,8 +887,8 @@ DEF_CONSOLE_CMD(ConNetworkConnect)
 
	if (argc < 2) return false;
 
	if (_networking) NetworkDisconnect(); // we are in network-mode, first close it!
 

	
 
	const char *port = NULL;
 
	const char *company = NULL;
 
	const char *port = nullptr;
 
	const char *company = nullptr;
 
	char *ip = argv[1];
 
	/* Default settings: default port and new company */
 
	uint16 rport = NETWORK_DEFAULT_PORT;
 
@@ -897,7 +897,7 @@ DEF_CONSOLE_CMD(ConNetworkConnect)
 
	ParseConnectionString(&company, &port, ip);
 

	
 
	IConsolePrintF(CC_DEFAULT, "Connecting to %s...", ip);
 
	if (company != NULL) {
 
	if (company != nullptr) {
 
		join_as = (CompanyID)atoi(company);
 
		IConsolePrintF(CC_DEFAULT, "    company-no: %d", join_as);
 

	
 
@@ -908,7 +908,7 @@ DEF_CONSOLE_CMD(ConNetworkConnect)
 
			join_as--;
 
		}
 
	}
 
	if (port != NULL) {
 
	if (port != nullptr) {
 
		rport = atoi(port);
 
		IConsolePrintF(CC_DEFAULT, "    port: %s", port);
 
	}
 
@@ -933,7 +933,7 @@ DEF_CONSOLE_CMD(ConExec)
 

	
 
	FILE *script_file = FioFOpenFile(argv[1], "r", BASE_DIR);
 

	
 
	if (script_file == NULL) {
 
	if (script_file == nullptr) {
 
		if (argc == 2 || atoi(argv[2]) != 0) IConsoleError("script file not found");
 
		return true;
 
	}
 
@@ -941,7 +941,7 @@ DEF_CONSOLE_CMD(ConExec)
 
	_script_running = true;
 

	
 
	char cmdline[ICON_CMDLN_SIZE];
 
	while (_script_running && fgets(cmdline, sizeof(cmdline), script_file) != NULL) {
 
	while (_script_running && fgets(cmdline, sizeof(cmdline), script_file) != nullptr) {
 
		/* Remove newline characters from the executing script */
 
		for (char *cmdptr = cmdline; *cmdptr != '\0'; cmdptr++) {
 
			if (*cmdptr == '\n' || *cmdptr == '\r') {
 
@@ -992,7 +992,7 @@ DEF_CONSOLE_CMD(ConScript)
 

	
 
		IConsolePrintF(CC_DEFAULT, "file output started to: %s", argv[1]);
 
		_iconsole_output_file = fopen(argv[1], "ab");
 
		if (_iconsole_output_file == NULL) IConsoleError("could not open file");
 
		if (_iconsole_output_file == nullptr) IConsoleError("could not open file");
 
	}
 

	
 
	return true;
 
@@ -1031,7 +1031,7 @@ DEF_CONSOLE_CMD(ConNewGame)
 
		return true;
 
	}
 

	
 
	StartNewGameWithoutGUI((argc == 2) ? strtoul(argv[1], NULL, 10) : GENERATE_NEW_SEED);
 
	StartNewGameWithoutGUI((argc == 2) ? strtoul(argv[1], nullptr, 10) : GENERATE_NEW_SEED);
 
	return true;
 
}
 

	
 
@@ -1283,7 +1283,7 @@ DEF_CONSOLE_CMD(ConRescanNewGRF)
 
		return true;
 
	}
 

	
 
	ScanNewGRFFiles(NULL);
 
	ScanNewGRFFiles(nullptr);
 

	
 
	return true;
 
}
 
@@ -1326,7 +1326,7 @@ DEF_CONSOLE_CMD(ConAlias)
 
	if (argc < 3) return false;
 

	
 
	alias = IConsoleAliasGet(argv[1]);
 
	if (alias == NULL) {
 
	if (alias == nullptr) {
 
		IConsoleAliasRegister(argv[1], argv[2]);
 
	} else {
 
		free(alias->cmdline);
 
@@ -1348,7 +1348,7 @@ DEF_CONSOLE_CMD(ConScreenShot)
 
	if (argc > 3) return false;
 

	
 
	ScreenshotType type = SC_VIEWPORT;
 
	const char *name = NULL;
 
	const char *name = nullptr;
 

	
 
	if (argc > 1) {
 
		if (strcmp(argv[1], "big") == 0) {
 
@@ -1386,7 +1386,7 @@ DEF_CONSOLE_CMD(ConInfoCmd)
 
	if (argc < 2) return false;
 

	
 
	const IConsoleCmd *cmd = IConsoleCmdGet(argv[1]);
 
	if (cmd == NULL) {
 
	if (cmd == nullptr) {
 
		IConsoleError("the given command was not found");
 
		return true;
 
	}
 
@@ -1394,7 +1394,7 @@ DEF_CONSOLE_CMD(ConInfoCmd)
 
	IConsolePrintF(CC_DEFAULT, "command name: %s", cmd->name);
 
	IConsolePrintF(CC_DEFAULT, "command proc: %p", cmd->proc);
 

	
 
	if (cmd->hook != NULL) IConsoleWarning("command is hooked");
 
	if (cmd->hook != nullptr) IConsoleWarning("command is hooked");
 

	
 
	return true;
 
}
 
@@ -1452,16 +1452,16 @@ DEF_CONSOLE_CMD(ConHelp)
 

	
 
		RemoveUnderscores(argv[1]);
 
		cmd = IConsoleCmdGet(argv[1]);
 
		if (cmd != NULL) {
 
			cmd->proc(0, NULL);
 
		if (cmd != nullptr) {
 
			cmd->proc(0, nullptr);
 
			return true;
 
		}
 

	
 
		alias = IConsoleAliasGet(argv[1]);
 
		if (alias != NULL) {
 
		if (alias != nullptr) {
 
			cmd = IConsoleCmdGet(alias->cmdline);
 
			if (cmd != NULL) {
 
				cmd->proc(0, NULL);
 
			if (cmd != nullptr) {
 
				cmd->proc(0, nullptr);
 
				return true;
 
			}
 
			IConsolePrintF(CC_ERROR, "ERROR: alias is of special type, please see its execution-line: '%s'", alias->cmdline);
 
@@ -1491,9 +1491,9 @@ DEF_CONSOLE_CMD(ConListCommands)
 
		return true;
 
	}
 

	
 
	for (const IConsoleCmd *cmd = _iconsole_cmds; cmd != NULL; cmd = cmd->next) {
 
		if (argv[1] == NULL || strstr(cmd->name, argv[1]) != NULL) {
 
			if (cmd->hook == NULL || cmd->hook(false) != CHR_HIDE) IConsolePrintF(CC_DEFAULT, "%s", cmd->name);
 
	for (const IConsoleCmd *cmd = _iconsole_cmds; cmd != nullptr; cmd = cmd->next) {
 
		if (argv[1] == nullptr || strstr(cmd->name, argv[1]) != nullptr) {
 
			if (cmd->hook == nullptr || cmd->hook(false) != CHR_HIDE) IConsolePrintF(CC_DEFAULT, "%s", cmd->name);
 
		}
 
	}
 

	
 
@@ -1507,8 +1507,8 @@ DEF_CONSOLE_CMD(ConListAliases)
 
		return true;
 
	}
 

	
 
	for (const IConsoleAlias *alias = _iconsole_aliases; alias != NULL; alias = alias->next) {
 
		if (argv[1] == NULL || strstr(alias->name, argv[1]) != NULL) {
 
	for (const IConsoleAlias *alias = _iconsole_aliases; alias != nullptr; alias = alias->next) {
 
		if (argv[1] == nullptr || strstr(alias->name, argv[1]) != nullptr) {
 
			IConsolePrintF(CC_DEFAULT, "%s => %s", alias->name, alias->cmdline);
 
		}
 
	}
 
@@ -1717,8 +1717,8 @@ static void OutputContentState(const Con
 

	
 
DEF_CONSOLE_CMD(ConContent)
 
{
 
	static ContentCallback *cb = NULL;
 
	if (cb == NULL) {
 
	static ContentCallback *cb = nullptr;
 
	if (cb == nullptr) {
 
		cb = new ConsoleContentCallback();
 
		_network_content_client.AddCallback(cb);
 
	}
 
@@ -1776,7 +1776,7 @@ DEF_CONSOLE_CMD(ConContent)
 
	if (strcasecmp(argv[1], "state") == 0) {
 
		IConsolePrintF(CC_WHITE, "id, type, state, name");
 
		for (ConstContentIterator iter = _network_content_client.Begin(); iter != _network_content_client.End(); iter++) {
 
			if (argc > 2 && strcasestr((*iter)->name, argv[2]) == NULL) continue;
 
			if (argc > 2 && strcasestr((*iter)->name, argv[2]) == nullptr) continue;
 
			OutputContentState(*iter);
 
		}
 
		return true;
 
@@ -1841,7 +1841,7 @@ DEF_CONSOLE_CMD(ConListSettings)
 

	
 
	if (argc > 2) return false;
 

	
 
	IConsoleListSettings((argc == 2) ? argv[1] : NULL);
 
	IConsoleListSettings((argc == 2) ? argv[1] : nullptr);
 
	return true;
 
}
 

	
src/console_gui.cpp
Show inline comments
 
@@ -78,7 +78,7 @@ struct IConsoleLine {
 
	static const IConsoleLine *Get(uint index)
 
	{
 
		const IConsoleLine *item = IConsoleLine::front;
 
		while (index != 0 && item != NULL) {
 
		while (index != 0 && item != nullptr) {
 
			index--;
 
			item = item->previous;
 
		}
 
@@ -96,14 +96,14 @@ struct IConsoleLine {
 
	static bool Truncate()
 
	{
 
		IConsoleLine *cur = IConsoleLine::front;
 
		if (cur == NULL) return false;
 
		if (cur == nullptr) return false;
 

	
 
		int count = 1;
 
		for (IConsoleLine *item = cur->previous; item != NULL; count++, cur = item, item = item->previous) {
 
		for (IConsoleLine *item = cur->previous; item != nullptr; count++, cur = item, item = item->previous) {
 
			if (item->time > _settings_client.gui.console_backlog_timeout &&
 
					count > _settings_client.gui.console_backlog_length) {
 
				delete item;
 
				cur->previous = NULL;
 
				cur->previous = nullptr;
 
				return true;
 
			}
 

	
 
@@ -119,12 +119,12 @@ struct IConsoleLine {
 
	static void Reset()
 
	{
 
		delete IConsoleLine::front;
 
		IConsoleLine::front = NULL;
 
		IConsoleLine::front = nullptr;
 
		IConsoleLine::size = 0;
 
	}
 
};
 

	
 
/* static */ IConsoleLine *IConsoleLine::front = NULL;
 
/* static */ IConsoleLine *IConsoleLine::front = nullptr;
 
/* static */ int IConsoleLine::size  = 0;
 

	
 

	
 
@@ -162,7 +162,7 @@ static const struct NWidgetPart _nested_
 
};
 

	
 
static WindowDesc _console_window_desc(
 
	WDP_MANUAL, NULL, 0, 0,
 
	WDP_MANUAL, nullptr, 0, 0,
 
	WC_CONSOLE, WC_NONE,
 
	0,
 
	_nested_console_window_widgets, lengthof(_nested_console_window_widgets)
 
@@ -207,7 +207,7 @@ struct IConsoleWindow : Window
 

	
 
		GfxFillRect(0, 0, this->width - 1, this->height - 1, PC_BLACK);
 
		int ypos = this->height - this->line_height;
 
		for (const IConsoleLine *print = IConsoleLine::Get(IConsoleWindow::scroll); print != NULL; print = print->previous) {
 
		for (const IConsoleLine *print = IConsoleLine::Get(IConsoleWindow::scroll); print != nullptr; print = print->previous) {
 
			SetDParamStr(0, print->buffer);
 
			ypos = DrawStringMultiLine(5, right, -this->line_height, ypos, STR_JUST_RAW_STRING, print->colour, SA_LEFT | SA_BOTTOM | SA_FORCE) - ICON_LINE_SPACING;
 
			if (ypos < 0) break;
 
@@ -287,7 +287,7 @@ struct IConsoleWindow : Window
 
				const char *cmd = IConsoleHistoryAdd(_iconsole_cmdline.buf);
 
				IConsoleClearCommand();
 

	
 
				if (cmd != NULL) IConsoleCmdExec(cmd);
 
				if (cmd != nullptr) IConsoleCmdExec(cmd);
 
				break;
 
			}
 

	
 
@@ -335,7 +335,7 @@ struct IConsoleWindow : Window
 

	
 
	const char *GetMarkedText(size_t *length) const override
 
	{
 
		if (_iconsole_cmdline.markend == 0) return NULL;
 
		if (_iconsole_cmdline.markend == 0) return nullptr;
 

	
 
		*length = _iconsole_cmdline.markend - _iconsole_cmdline.markpos;
 
		return _iconsole_cmdline.buf + _iconsole_cmdline.markpos;
 
@@ -364,7 +364,7 @@ struct IConsoleWindow : Window
 
	{
 
		int delta = min(this->width - this->line_offset - _iconsole_cmdline.pixels - ICON_RIGHT_BORDERWIDTH, 0);
 

	
 
		if (!IsInsideMM(pt.y, this->height - this->line_height, this->height)) return NULL;
 
		if (!IsInsideMM(pt.y, this->height - this->line_height, this->height)) return nullptr;
 

	
 
		return GetCharAtPosition(_iconsole_cmdline.buf, pt.x - delta);
 
	}
 
@@ -459,10 +459,10 @@ static const char *IConsoleHistoryAdd(co
 
	while (IsWhitespace(*cmd)) cmd++;
 

	
 
	/* Do not put empty command in history */
 
	if (StrEmpty(cmd)) return NULL;
 
	if (StrEmpty(cmd)) return nullptr;
 

	
 
	/* Do not put in history if command is same as previous */
 
	if (_iconsole_history[0] == NULL || strcmp(_iconsole_history[0], cmd) != 0) {
 
	if (_iconsole_history[0] == nullptr || strcmp(_iconsole_history[0], cmd) != 0) {
 
		free(_iconsole_history[ICON_HISTORY_SIZE - 1]);
 
		memmove(&_iconsole_history[1], &_iconsole_history[0], sizeof(_iconsole_history[0]) * (ICON_HISTORY_SIZE - 1));
 
		_iconsole_history[0] = stredup(cmd);
 
@@ -479,10 +479,10 @@ static const char *IConsoleHistoryAdd(co
 
 */
 
static void IConsoleHistoryNavigate(int direction)
 
{
 
	if (_iconsole_history[0] == NULL) return; // Empty history
 
	if (_iconsole_history[0] == nullptr) return; // Empty history
 
	_iconsole_historypos = Clamp(_iconsole_historypos + direction, -1, ICON_HISTORY_SIZE - 1);
 

	
 
	if (direction > 0 && _iconsole_history[_iconsole_historypos] == NULL) _iconsole_historypos--;
 
	if (direction > 0 && _iconsole_history[_iconsole_historypos] == nullptr) _iconsole_historypos--;
 

	
 
	if (_iconsole_historypos == -1) {
 
		_iconsole_cmdline.DeleteAll();
src/console_internal.h
Show inline comments
 
@@ -69,7 +69,7 @@ extern IConsoleAlias *_iconsole_aliases;
 
void IConsoleClearBuffer();
 

	
 
/* Commands */
 
void IConsoleCmdRegister(const char *name, IConsoleCmdProc *proc, IConsoleHook *hook = NULL);
 
void IConsoleCmdRegister(const char *name, IConsoleCmdProc *proc, IConsoleHook *hook = nullptr);
 
void IConsoleAliasRegister(const char *name, const char *cmd);
 
IConsoleCmd *IConsoleCmdGet(const char *name);
 
IConsoleAlias *IConsoleAliasGet(const char *name);
src/core/alloc_func.hpp
Show inline comments
 
@@ -53,23 +53,23 @@ static inline void CheckAllocationConstr
 
 * @note the memory contains garbage data (i.e. possibly non-zero values).
 
 * @tparam T the type of the variable(s) to allocation.
 
 * @param num_elements the number of elements to allocate of the given type.
 
 * @return NULL when num_elements == 0, non-NULL otherwise.
 
 * @return nullptr when num_elements == 0, non-nullptr otherwise.
 
 */
 
template <typename T>
 
static inline T *MallocT(size_t num_elements)
 
{
 
	/*
 
	 * MorphOS cannot handle 0 elements allocations, or rather that always
 
	 * returns NULL. So we do that for *all* allocations, thus causing it
 
	 * returns nullptr. So we do that for *all* allocations, thus causing it
 
	 * to behave the same on all OSes.
 
	 */
 
	if (num_elements == 0) return NULL;
 
	if (num_elements == 0) return nullptr;
 

	
 
	/* Ensure the size does not overflow. */
 
	CheckAllocationConstraints<T>(num_elements);
 

	
 
	T *t_ptr = (T*)malloc(num_elements * sizeof(T));
 
	if (t_ptr == NULL) MallocError(num_elements * sizeof(T));
 
	if (t_ptr == nullptr) MallocError(num_elements * sizeof(T));
 
	return t_ptr;
 
}
 

	
 
@@ -81,20 +81,20 @@ static inline T *MallocT(size_t num_elem
 
 * @note the memory contains all zero values.
 
 * @tparam T the type of the variable(s) to allocation.
 
 * @param num_elements the number of elements to allocate of the given type.
 
 * @return NULL when num_elements == 0, non-NULL otherwise.
 
 * @return nullptr when num_elements == 0, non-nullptr otherwise.
 
 */
 
template <typename T>
 
static inline T *CallocT(size_t num_elements)
 
{
 
	/*
 
	 * MorphOS cannot handle 0 elements allocations, or rather that always
 
	 * returns NULL. So we do that for *all* allocations, thus causing it
 
	 * returns nullptr. So we do that for *all* allocations, thus causing it
 
	 * to behave the same on all OSes.
 
	 */
 
	if (num_elements == 0) return NULL;
 
	if (num_elements == 0) return nullptr;
 

	
 
	T *t_ptr = (T*)calloc(num_elements, sizeof(T));
 
	if (t_ptr == NULL) MallocError(num_elements * sizeof(T));
 
	if (t_ptr == nullptr) MallocError(num_elements * sizeof(T));
 
	return t_ptr;
 
}
 

	
 
@@ -107,26 +107,26 @@ static inline T *CallocT(size_t num_elem
 
 * @tparam T the type of the variable(s) to allocation.
 
 * @param t_ptr the previous allocation to extend/shrink.
 
 * @param num_elements the number of elements to allocate of the given type.
 
 * @return NULL when num_elements == 0, non-NULL otherwise.
 
 * @return nullptr when num_elements == 0, non-nullptr otherwise.
 
 */
 
template <typename T>
 
static inline T *ReallocT(T *t_ptr, size_t num_elements)
 
{
 
	/*
 
	 * MorphOS cannot handle 0 elements allocations, or rather that always
 
	 * returns NULL. So we do that for *all* allocations, thus causing it
 
	 * returns nullptr. So we do that for *all* allocations, thus causing it
 
	 * to behave the same on all OSes.
 
	 */
 
	if (num_elements == 0) {
 
		free(t_ptr);
 
		return NULL;
 
		return nullptr;
 
	}
 

	
 
	/* Ensure the size does not overflow. */
 
	CheckAllocationConstraints<T>(num_elements);
 

	
 
	t_ptr = (T*)realloc(static_cast<void *>(t_ptr), num_elements * sizeof(T));
 
	if (t_ptr == NULL) ReallocError(num_elements * sizeof(T));
 
	if (t_ptr == nullptr) ReallocError(num_elements * sizeof(T));
 
	return t_ptr;
 
}
 

	
src/core/alloc_type.hpp
Show inline comments
 
@@ -73,7 +73,7 @@ private:
 

	
 
public:
 
	/** Create a new buffer */
 
	ReusableBuffer() : buffer(NULL), count(0) {}
 
	ReusableBuffer() : buffer(nullptr), count(0) {}
 
	/** Clear the buffer */
 
	~ReusableBuffer() { free(this->buffer); }
 

	
src/core/kdtree.hpp
Show inline comments
 
@@ -108,11 +108,11 @@ class Kdtree {
 
		std::vector<T> elements = this->FreeSubtree(this->root);
 
		elements.push_back(root_element);
 

	
 
		if (include_element != NULL) {
 
		if (include_element != nullptr) {
 
			elements.push_back(*include_element);
 
			initial_count++;
 
		}
 
		if (exclude_element != NULL) {
 
		if (exclude_element != nullptr) {
 
			typename std::vector<T>::iterator removed = std::remove(elements.begin(), elements.end(), *exclude_element);
 
			elements.erase(removed, elements.end());
 
			initial_count--;
 
@@ -377,7 +377,7 @@ public:
 
	 */
 
	void Rebuild()
 
	{
 
		this->Rebuild(NULL, NULL);
 
		this->Rebuild(nullptr, nullptr);
 
	}
 

	
 
	/**
 
@@ -390,7 +390,7 @@ public:
 
		if (this->Count() == 0) {
 
			this->root = this->AddNode(element);
 
		} else {
 
			if (!this->IsUnbalanced() || !this->Rebuild(&element, NULL)) {
 
			if (!this->IsUnbalanced() || !this->Rebuild(&element, nullptr)) {
 
				this->InsertRecursive(element, this->root, 0);
 
				this->IncrementUnbalanced();
 
			}
 
@@ -408,7 +408,7 @@ public:
 
	{
 
		size_t count = this->Count();
 
		if (count == 0) return;
 
		if (!this->IsUnbalanced() || !this->Rebuild(NULL, &element)) {
 
		if (!this->IsUnbalanced() || !this->Rebuild(nullptr, &element)) {
 
			/* If the removed element is the root node, this modifies this->root */
 
			this->root = this->RemoveRecursive(element, this->root, 0);
 
			this->IncrementUnbalanced();
src/core/mem_func.hpp
Show inline comments
 
@@ -78,7 +78,7 @@ static inline int MemCmpT(const T *ptr1,
 
template <typename T>
 
static inline void MemReverseT(T *ptr1, T *ptr2)
 
{
 
	assert(ptr1 != NULL && ptr2 != NULL);
 
	assert(ptr1 != nullptr && ptr2 != nullptr);
 
	assert(ptr1 < ptr2);
 

	
 
	do {
 
@@ -95,7 +95,7 @@ static inline void MemReverseT(T *ptr1, 
 
template <typename T>
 
static inline void MemReverseT(T *ptr, size_t num)
 
{
 
	assert(ptr != NULL);
 
	assert(ptr != nullptr);
 

	
 
	MemReverseT(ptr, ptr + (num - 1));
 
}
src/core/pool_func.hpp
Show inline comments
 
@@ -39,8 +39,8 @@ DEFINE_POOL_METHOD(inline)::Pool(const c
 
		checked(0),
 
#endif /* OTTD_ASSERT */
 
		cleaning(false),
 
		data(NULL),
 
		alloc_cache(NULL)
 
		data(nullptr),
 
		alloc_cache(nullptr)
 
{ }
 

	
 
/**
 
@@ -71,7 +71,7 @@ DEFINE_POOL_METHOD(inline size_t)::FindF
 
	size_t index = this->first_free;
 

	
 
	for (; index < this->first_unused; index++) {
 
		if (this->data[index] == NULL) return index;
 
		if (this->data[index] == nullptr) return index;
 
	}
 

	
 
	if (index < this->size) {
 
@@ -96,17 +96,17 @@ DEFINE_POOL_METHOD(inline size_t)::FindF
 
 * @param size size of item
 
 * @param index index of item
 
 * @pre index < this->size
 
 * @pre this->Get(index) == NULL
 
 * @pre this->Get(index) == nullptr
 
 */
 
DEFINE_POOL_METHOD(inline void *)::AllocateItem(size_t size, size_t index)
 
{
 
	assert(this->data[index] == NULL);
 
	assert(this->data[index] == nullptr);
 

	
 
	this->first_unused = max(this->first_unused, index + 1);
 
	this->items++;
 

	
 
	Titem *item;
 
	if (Tcache && this->alloc_cache != NULL) {
 
	if (Tcache && this->alloc_cache != nullptr) {
 
		assert(sizeof(Titem) == size);
 
		item = (Titem *)this->alloc_cache;
 
		this->alloc_cache = this->alloc_cache->next;
 
@@ -164,7 +164,7 @@ DEFINE_POOL_METHOD(void *)::GetNew(size_
 

	
 
	if (index >= this->size) this->ResizeFor(index);
 

	
 
	if (this->data[index] != NULL) {
 
	if (this->data[index] != nullptr) {
 
		SlErrorCorruptFmt("%s index " PRINTF_SIZE " already in use", this->name, index);
 
	}
 

	
 
@@ -174,13 +174,13 @@ DEFINE_POOL_METHOD(void *)::GetNew(size_
 
/**
 
 * Deallocates memory used by this index and marks item as free
 
 * @param index item to deallocate
 
 * @pre unit is allocated (non-NULL)
 
 * @note 'delete NULL' doesn't cause call of this function, so it is safe
 
 * @pre unit is allocated (non-nullptr)
 
 * @note 'delete nullptr' doesn't cause call of this function, so it is safe
 
 */
 
DEFINE_POOL_METHOD(void)::FreeItem(size_t index)
 
{
 
	assert(index < this->size);
 
	assert(this->data[index] != NULL);
 
	assert(this->data[index] != nullptr);
 
	if (Tcache) {
 
		AllocCache *ac = (AllocCache *)this->data[index];
 
		ac->next = this->alloc_cache;
 
@@ -188,7 +188,7 @@ DEFINE_POOL_METHOD(void)::FreeItem(size_
 
	} else {
 
		free(this->data[index]);
 
	}
 
	this->data[index] = NULL;
 
	this->data[index] = nullptr;
 
	this->first_free = min(this->first_free, index);
 
	this->items--;
 
	if (!this->cleaning) Titem::PostDestructor(index);
 
@@ -199,16 +199,16 @@ DEFINE_POOL_METHOD(void)::CleanPool()
 
{
 
	this->cleaning = true;
 
	for (size_t i = 0; i < this->first_unused; i++) {
 
		delete this->Get(i); // 'delete NULL;' is very valid
 
		delete this->Get(i); // 'delete nullptr;' is very valid
 
	}
 
	assert(this->items == 0);
 
	free(this->data);
 
	this->first_unused = this->first_free = this->size = 0;
 
	this->data = NULL;
 
	this->data = nullptr;
 
	this->cleaning = false;
 

	
 
	if (Tcache) {
 
		while (this->alloc_cache != NULL) {
 
		while (this->alloc_cache != nullptr) {
 
			AllocCache *ac = this->alloc_cache;
 
			this->alloc_cache = ac->next;
 
			free(ac);
src/core/pool_type.hpp
Show inline comments
 
@@ -91,7 +91,7 @@ struct Pool : PoolBase {
 
	size_t size;         ///< Current allocated size
 
	size_t first_free;   ///< No item with index lower than this is free (doesn't say anything about this one!)
 
	size_t first_unused; ///< This and all higher indexes are free (doesn't say anything about first_unused-1 !)
 
	size_t items;        ///< Number of used indexes (non-NULL)
 
	size_t items;        ///< Number of used indexes (non-nullptr)
 
#ifdef OTTD_ASSERT
 
	size_t checked;      ///< Number of items we checked for
 
#endif /* OTTD_ASSERT */
 
@@ -115,13 +115,13 @@ struct Pool : PoolBase {
 
	}
 

	
 
	/**
 
	 * Tests whether given index can be used to get valid (non-NULL) Titem
 
	 * Tests whether given index can be used to get valid (non-nullptr) Titem
 
	 * @param index index to examine
 
	 * @return true if PoolItem::Get(index) will return non-NULL pointer
 
	 * @return true if PoolItem::Get(index) will return non-nullptr pointer
 
	 */
 
	inline bool IsValidID(size_t index)
 
	{
 
		return index < this->first_unused && this->Get(index) != NULL;
 
		return index < this->first_unused && this->Get(index) != nullptr;
 
	}
 

	
 
	/**
 
@@ -150,7 +150,7 @@ struct Pool : PoolBase {
 
		 * Allocates space for new Titem
 
		 * @param size size of Titem
 
		 * @return pointer to allocated memory
 
		 * @note can never fail (return NULL), use CanAllocate() to check first!
 
		 * @note can never fail (return nullptr), use CanAllocate() to check first!
 
		 */
 
		inline void *operator new(size_t size)
 
		{
 
@@ -164,7 +164,7 @@ struct Pool : PoolBase {
 
		 */
 
		inline void operator delete(void *p)
 
		{
 
			if (p == NULL) return;
 
			if (p == nullptr) return;
 
			Titem *pn = (Titem *)p;
 
			assert(pn == Tpool->Get(pn->index));
 
			Tpool->FreeItem(pn->index);
 
@@ -175,7 +175,7 @@ struct Pool : PoolBase {
 
		 * @param size size of Titem
 
		 * @param index index of item
 
		 * @return pointer to allocated memory
 
		 * @note can never fail (return NULL), use CanAllocate() to check first!
 
		 * @note can never fail (return nullptr), use CanAllocate() to check first!
 
		 * @pre index has to be unused! Else it will crash
 
		 */
 
		inline void *operator new(size_t size, size_t index)
 
@@ -228,9 +228,9 @@ struct Pool : PoolBase {
 
		}
 

	
 
		/**
 
		 * Tests whether given index can be used to get valid (non-NULL) Titem
 
		 * Tests whether given index can be used to get valid (non-nullptr) Titem
 
		 * @param index index to examine
 
		 * @return true if PoolItem::Get(index) will return non-NULL pointer
 
		 * @return true if PoolItem::Get(index) will return non-nullptr pointer
 
		 */
 
		static inline bool IsValidID(size_t index)
 
		{
 
@@ -252,11 +252,11 @@ struct Pool : PoolBase {
 
		 * Returns Titem with given index
 
		 * @param index of item to get
 
		 * @return pointer to Titem
 
		 * @note returns NULL for invalid index
 
		 * @note returns nullptr for invalid index
 
		 */
 
		static inline Titem *GetIfValid(size_t index)
 
		{
 
			return index < Tpool->first_unused ? Tpool->Get(index) : NULL;
 
			return index < Tpool->first_unused ? Tpool->Get(index) : nullptr;
 
		}
 

	
 
		/**
 
@@ -282,7 +282,7 @@ struct Pool : PoolBase {
 
		 * Dummy function called after destructor of each member.
 
		 * If you want to use it, override it in PoolItem's subclass.
 
		 * @param index index of deleted item
 
		 * @note when this function is called, PoolItem::Get(index) == NULL.
 
		 * @note when this function is called, PoolItem::Get(index) == nullptr.
 
		 * @note it's called only when !CleaningPool()
 
		 */
 
		static inline void PostDestructor(size_t index) { }
 
@@ -314,8 +314,8 @@ private:
 
};
 

	
 
#define FOR_ALL_ITEMS_FROM(type, iter, var, start) \
 
	for (size_t iter = start; var = NULL, iter < type::GetPoolSize(); iter++) \
 
		if ((var = type::Get(iter)) != NULL)
 
	for (size_t iter = start; var = nullptr, iter < type::GetPoolSize(); iter++) \
 
		if ((var = type::Get(iter)) != nullptr)
 

	
 
#define FOR_ALL_ITEMS(type, iter, var) FOR_ALL_ITEMS_FROM(type, iter, var, 0)
 

	
src/core/smallmatrix_type.hpp
Show inline comments
 
@@ -46,13 +46,13 @@ protected:
 

	
 
public:
 

	
 
	SmallMatrix() : data(NULL), width(0), height(0), capacity(0) {}
 
	SmallMatrix() : data(nullptr), width(0), height(0), capacity(0) {}
 

	
 
	/**
 
	 * Copy constructor.
 
	 * @param other The other matrix to copy.
 
	 */
 
	SmallMatrix(const SmallMatrix &other) : data(NULL), width(0), height(0), capacity(0)
 
	SmallMatrix(const SmallMatrix &other) : data(nullptr), width(0), height(0), capacity(0)
 
	{
 
		this->Assign(other);
 
	}
 
@@ -112,7 +112,7 @@ public:
 
		this->width = 0;
 
		this->capacity = 0;
 
		free(this->data);
 
		this->data = NULL;
 
		this->data = nullptr;
 
	}
 

	
 
	/**
 
@@ -216,8 +216,8 @@ public:
 
	inline void Resize(uint new_width, uint new_height)
 
	{
 
		uint new_capacity = new_width * new_height;
 
		T *new_data = NULL;
 
		void (*copy)(T *dest, const T *src, size_t count) = NULL;
 
		T *new_data = nullptr;
 
		void (*copy)(T *dest, const T *src, size_t count) = nullptr;
 
		if (new_capacity > this->capacity) {
 
			/* If the data doesn't fit into current capacity, resize and copy ... */
 
			new_data = MallocT<T>(new_capacity);
src/core/sort_func.hpp
Show inline comments
 
@@ -53,8 +53,8 @@ static inline void GSortT(T *base, size_
 
{
 
	if (num < 2) return;
 

	
 
	assert(base != NULL);
 
	assert(comparator != NULL);
 
	assert(base != nullptr);
 
	assert(comparator != nullptr);
 

	
 
	T *a = base;
 
	T *b = base + 1;
src/crashlog.cpp
Show inline comments
 
@@ -70,9 +70,9 @@
 

	
 
#include "safeguards.h"
 

	
 
/* static */ const char *CrashLog::message = NULL;
 
/* static */ char *CrashLog::gamelog_buffer = NULL;
 
/* static */ const char *CrashLog::gamelog_last = NULL;
 
/* static */ const char *CrashLog::message = nullptr;
 
/* static */ char *CrashLog::gamelog_buffer = nullptr;
 
/* static */ const char *CrashLog::gamelog_last = nullptr;
 

	
 
char *CrashLog::LogCompiler(char *buffer, const char *last) const
 
{
 
@@ -168,18 +168,18 @@ char *CrashLog::LogConfiguration(char *b
 
			" Sound driver: %s\n"
 
			" Sound set:    %s (%u)\n"
 
			" Video driver: %s\n\n",
 
			BlitterFactory::GetCurrentBlitter() == NULL ? "none" : BlitterFactory::GetCurrentBlitter()->GetName(),
 
			BaseGraphics::GetUsedSet() == NULL ? "none" : BaseGraphics::GetUsedSet()->name,
 
			BaseGraphics::GetUsedSet() == NULL ? UINT32_MAX : BaseGraphics::GetUsedSet()->version,
 
			_current_language == NULL ? "none" : _current_language->file,
 
			MusicDriver::GetInstance() == NULL ? "none" : MusicDriver::GetInstance()->GetName(),
 
			BaseMusic::GetUsedSet() == NULL ? "none" : BaseMusic::GetUsedSet()->name,
 
			BaseMusic::GetUsedSet() == NULL ? UINT32_MAX : BaseMusic::GetUsedSet()->version,
 
			BlitterFactory::GetCurrentBlitter() == nullptr ? "none" : BlitterFactory::GetCurrentBlitter()->GetName(),
 
			BaseGraphics::GetUsedSet() == nullptr ? "none" : BaseGraphics::GetUsedSet()->name,
 
			BaseGraphics::GetUsedSet() == nullptr ? UINT32_MAX : BaseGraphics::GetUsedSet()->version,
 
			_current_language == nullptr ? "none" : _current_language->file,
 
			MusicDriver::GetInstance() == nullptr ? "none" : MusicDriver::GetInstance()->GetName(),
 
			BaseMusic::GetUsedSet() == nullptr ? "none" : BaseMusic::GetUsedSet()->name,
 
			BaseMusic::GetUsedSet() == nullptr ? UINT32_MAX : BaseMusic::GetUsedSet()->version,
 
			_networking ? (_network_server ? "server" : "client") : "no",
 
			SoundDriver::GetInstance() == NULL ? "none" : SoundDriver::GetInstance()->GetName(),
 
			BaseSounds::GetUsedSet() == NULL ? "none" : BaseSounds::GetUsedSet()->name,
 
			BaseSounds::GetUsedSet() == NULL ? UINT32_MAX : BaseSounds::GetUsedSet()->version,
 
			VideoDriver::GetInstance() == NULL ? "none" : VideoDriver::GetInstance()->GetName()
 
			SoundDriver::GetInstance() == nullptr ? "none" : SoundDriver::GetInstance()->GetName(),
 
			BaseSounds::GetUsedSet() == nullptr ? "none" : BaseSounds::GetUsedSet()->name,
 
			BaseSounds::GetUsedSet() == nullptr ? UINT32_MAX : BaseSounds::GetUsedSet()->version,
 
			VideoDriver::GetInstance() == nullptr ? "none" : VideoDriver::GetInstance()->GetName()
 
	);
 

	
 
	buffer += seprintf(buffer, last,
 
@@ -197,14 +197,14 @@ char *CrashLog::LogConfiguration(char *b
 
	buffer += seprintf(buffer, last, "AI Configuration (local: %i) (current: %i):\n", (int)_local_company, (int)_current_company);
 
	const Company *c;
 
	FOR_ALL_COMPANIES(c) {
 
		if (c->ai_info == NULL) {
 
		if (c->ai_info == nullptr) {
 
			buffer += seprintf(buffer, last, " %2i: Human\n", (int)c->index);
 
		} else {
 
			buffer += seprintf(buffer, last, " %2i: %s (v%d)\n", (int)c->index, c->ai_info->GetName(), c->ai_info->GetVersion());
 
		}
 
	}
 

	
 
	if (Game::GetInfo() != NULL) {
 
	if (Game::GetInfo() != nullptr) {
 
		buffer += seprintf(buffer, last, " GS: %s (v%d)\n", Game::GetInfo()->GetName(), Game::GetInfo()->GetVersion());
 
	}
 
	buffer += seprintf(buffer, last, "\n");
 
@@ -263,7 +263,7 @@ char *CrashLog::LogLibraries(char *buffe
 
#endif
 

	
 
#ifdef WITH_PNG
 
	buffer += seprintf(buffer, last, " PNG:        %s\n", png_get_libpng_ver(NULL));
 
	buffer += seprintf(buffer, last, " PNG:        %s\n", png_get_libpng_ver(nullptr));
 
#endif /* WITH_PNG */
 

	
 
#ifdef WITH_SDL
 
@@ -312,7 +312,7 @@ char *CrashLog::LogRecentNews(char *buff
 
{
 
	buffer += seprintf(buffer, last, "Recent news messages:\n");
 

	
 
	for (NewsItem *news = _oldest_news; news != NULL; news = news->next) {
 
	for (NewsItem *news = _oldest_news; news != nullptr; news = news->next) {
 
		YearMonthDay ymd;
 
		ConvertDateToYMD(news->date, &ymd);
 
		buffer += seprintf(buffer, last, "(%i-%02i-%02i) StringID: %u, Type: %u, Ref1: %u, %u, Ref2: %u, %u\n",
 
@@ -331,7 +331,7 @@ char *CrashLog::LogRecentNews(char *buff
 
 */
 
char *CrashLog::FillCrashLog(char *buffer, const char *last) const
 
{
 
	time_t cur_time = time(NULL);
 
	time_t cur_time = time(nullptr);
 
	buffer += seprintf(buffer, last, "*** OpenTTD Crash Report ***\n\n");
 
	buffer += seprintf(buffer, last, "Crash at: %s", asctime(gmtime(&cur_time)));
 

	
 
@@ -369,7 +369,7 @@ bool CrashLog::WriteCrashLog(const char 
 
	seprintf(filename, filename_last, "%scrash.log", _personal_dir);
 

	
 
	FILE *file = FioFOpenFile(filename, "w", NO_DIRECTORY);
 
	if (file == NULL) return false;
 
	if (file == nullptr) return false;
 

	
 
	size_t len = strlen(buffer);
 
	size_t written = fwrite(buffer, 1, len, file);
 
@@ -396,7 +396,7 @@ bool CrashLog::WriteSavegame(char *filen
 
{
 
	/* If the map array doesn't exist, saving will fail too. If the map got
 
	 * initialised, there is a big chance the rest is initialised too. */
 
	if (_m == NULL) return false;
 
	if (_m == nullptr) return false;
 

	
 
	try {
 
		GamelogEmergency();
 
@@ -421,7 +421,7 @@ bool CrashLog::WriteSavegame(char *filen
 
bool CrashLog::WriteScreenshot(char *filename, const char *filename_last) const
 
{
 
	/* Don't draw when we have invalid screen size */
 
	if (_screen.width < 1 || _screen.height < 1 || _screen.dst_ptr == NULL) return false;
 
	if (_screen.width < 1 || _screen.height < 1 || _screen.dst_ptr == nullptr) return false;
 

	
 
	bool res = MakeScreenshot(SC_CRASHLOG, "crash");
 
	if (res) strecpy(filename, _full_screenshot_name, filename_last);
 
@@ -504,7 +504,7 @@ bool CrashLog::MakeCrashLog() const
 
 */
 
/* static */ void CrashLog::AfterCrashLogCleanup()
 
{
 
	if (MusicDriver::GetInstance() != NULL) MusicDriver::GetInstance()->Stop();
 
	if (SoundDriver::GetInstance() != NULL) SoundDriver::GetInstance()->Stop();
 
	if (VideoDriver::GetInstance() != NULL) VideoDriver::GetInstance()->Stop();
 
	if (MusicDriver::GetInstance() != nullptr) MusicDriver::GetInstance()->Stop();
 
	if (SoundDriver::GetInstance() != nullptr) SoundDriver::GetInstance()->Stop();
 
	if (VideoDriver::GetInstance() != nullptr) VideoDriver::GetInstance()->Stop();
 
}
src/crashlog.h
Show inline comments
 
@@ -48,7 +48,7 @@ protected:
 
	 * Writes actually encountered error to the buffer.
 
	 * @param buffer  The begin where to write at.
 
	 * @param last    The last position in the buffer to write to.
 
	 * @param message Message passed to use for possible errors. Can be NULL.
 
	 * @param message Message passed to use for possible errors. Can be nullptr.
 
	 * @return the position of the \c '\0' character after the buffer.
 
	 */
 
	virtual char *LogError(char *buffer, const char *last, const char *message) const = 0;
src/date_gui.cpp
Show inline comments
 
@@ -148,7 +148,7 @@ struct SetDateWindow : Window {
 
				break;
 

	
 
			case WID_SD_SET_DATE:
 
				if (this->callback != NULL) this->callback(this, ConvertYMDToDate(this->date.year, this->date.month, this->date.day));
 
				if (this->callback != nullptr) this->callback(this, ConvertYMDToDate(this->date.year, this->date.month, this->date.day));
 
				delete this;
 
				break;
 
		}
 
@@ -197,7 +197,7 @@ static const NWidgetPart _nested_set_dat
 

	
 
/** Description of the date setting window. */
 
static WindowDesc _set_date_desc(
 
	WDP_CENTER, NULL, 0, 0,
 
	WDP_CENTER, nullptr, 0, 0,
 
	WC_SET_DATE, WC_NONE,
 
	0,
 
	_nested_set_date_widgets, lengthof(_nested_set_date_widgets)
src/debug.cpp
Show inline comments
 
@@ -120,14 +120,14 @@ static void debug_print(const char *dbg,
 
	}
 
	if (strcmp(dbg, "desync") == 0) {
 
		static FILE *f = FioFOpenFile("commands-out.log", "wb", AUTOSAVE_DIR);
 
		if (f == NULL) return;
 
		if (f == nullptr) return;
 

	
 
		fprintf(f, "%s%s\n", GetLogPrefix(), buf);
 
		fflush(f);
 
#ifdef RANDOM_DEBUG
 
	} else if (strcmp(dbg, "random") == 0) {
 
		static FILE *f = FioFOpenFile("random-out.log", "wb", AUTOSAVE_DIR);
 
		if (f == NULL) return;
 
		if (f == nullptr) return;
 

	
 
		fprintf(f, "%s\n", buf);
 
		fflush(f);
 
@@ -200,7 +200,7 @@ void SetDebugString(const char *s)
 
		while (*s >= 'a' && *s <= 'z') s++;
 

	
 
		/* check debugging levels */
 
		p = NULL;
 
		p = nullptr;
 
		for (i = debug_level; i != endof(debug_level); ++i) {
 
			if (s == t + strlen(i->name) && strncmp(t, i->name, s - t) == 0) {
 
				p = i->level;
 
@@ -211,7 +211,7 @@ void SetDebugString(const char *s)
 
		if (*s == '=') s++;
 
		v = strtoul(s, &end, 0);
 
		s = end;
 
		if (p != NULL) {
 
		if (p != nullptr) {
 
			*p = v;
 
		} else {
 
			ShowInfoF("Unknown debug level '%.*s'", (int)(s - t), t);
 
@@ -246,13 +246,13 @@ const char *GetDebugString()
 
/**
 
 * Get the prefix for logs; if show_date_in_logs is enabled it returns
 
 * the date, otherwise it returns nothing.
 
 * @return the prefix for logs (do not free), never NULL
 
 * @return the prefix for logs (do not free), never nullptr
 
 */
 
const char *GetLogPrefix()
 
{
 
	static char _log_prefix[24];
 
	if (_settings_client.gui.show_date_in_logs) {
 
		time_t cur_time = time(NULL);
 
		time_t cur_time = time(nullptr);
 
		strftime(_log_prefix, sizeof(_log_prefix), "[%Y-%m-%d %H:%M:%S] ", localtime(&cur_time));
 
	} else {
 
		*_log_prefix = '\0';
src/dedicated.cpp
Show inline comments
 
@@ -11,8 +11,8 @@
 

	
 
#include "stdafx.h"
 

	
 
char *_log_file = NULL; ///< File to reroute output of a forked OpenTTD to
 
FILE *_log_fd   = NULL; ///< File to reroute output of a forked OpenTTD to
 
char *_log_file = nullptr; ///< File to reroute output of a forked OpenTTD to
 
FILE *_log_fd   = nullptr; ///< File to reroute output of a forked OpenTTD to
 

	
 
#if defined(UNIX)
 

	
 
@@ -41,7 +41,7 @@ void DedicatedFork()
 
		case 0: { // We're the child
 
			/* Open the log-file to log all stuff too */
 
			_log_fd = fopen(_log_file, "a");
 
			if (_log_fd == NULL) {
 
			if (_log_fd == nullptr) {
 
				perror("Unable to open logfile");
 
				exit(1);
 
			}
src/depend/depend.cpp
Show inline comments
 
@@ -54,7 +54,7 @@
 
 *
 
 * Copies the source string to the destination buffer with respect of the
 
 * terminating null-character and the last pointer to the last element in
 
 * the destination buffer. If the last pointer is set to NULL no boundary
 
 * the destination buffer. If the last pointer is set to nullptr no boundary
 
 * check is performed.
 
 *
 
 * @note usage: strecpy(dst, src, lastof(dst));
 
@@ -85,7 +85,7 @@ char *strecpy(char *dst, const char *src
 
 *
 
 * Appends the source string to the destination string with respect of the
 
 * terminating null-character and and the last pointer to the last element
 
 * in the destination buffer. If the last pointer is set to NULL no
 
 * in the destination buffer. If the last pointer is set to nullptr no
 
 * boundary check is performed.
 
 *
 
 * @note usage: strecat(dst, src, lastof(dst));
 
@@ -163,13 +163,13 @@ public:
 
	File(const char *filename)
 
	{
 
		this->fp = fopen(filename, "r");
 
		if (this->fp == NULL) {
 
		if (this->fp == nullptr) {
 
			fprintf(stdout, "Could not open %s for reading\n", filename);
 
			exit(1);
 
		}
 
		this->dirname = strdup(filename);
 
		char *last = strrchr(this->dirname, '/');
 
		if (last != NULL) {
 
		if (last != nullptr) {
 
			*last = '\0';
 
		} else {
 
			*this->dirname = '\0';
 
@@ -247,7 +247,7 @@ public:
 
	 * Create the lexer and fill the keywords table.
 
	 * @param file the file to read from.
 
	 */
 
	Lexer(const File *file) : file(file), current_char('\0'), string(NULL), token(TOKEN_UNKNOWN)
 
	Lexer(const File *file) : file(file), current_char('\0'), string(nullptr), token(TOKEN_UNKNOWN)
 
	{
 
		this->keywords["define"]  = TOKEN_DEFINE;
 
		this->keywords["defined"] = TOKEN_DEFINED;
 
@@ -293,7 +293,7 @@ public:
 

	
 
	/**
 
	 * Read the currenty processed string.
 
	 * @return the string, can be NULL.
 
	 * @return the string, can be nullptr.
 
	 */
 
	const char *GetString() const
 
	{
 
@@ -308,7 +308,7 @@ public:
 
	{
 
		for (;;) {
 
			free(this->string);
 
			this->string = NULL;
 
			this->string = nullptr;
 
			this->token  = TOKEN_UNKNOWN;
 

	
 
			switch (this->current_char) {
 
@@ -503,7 +503,7 @@ private:
 
 * @param dirname the directory to look in.
 
 * @param filename the file to look for.
 
 * @param local whether to look locally (in dirname) for the file.
 
 * @return the absolute path, or NULL if the file doesn't exist.
 
 * @return the absolute path, or nullptr if the file doesn't exist.
 
 */
 
const char *GeneratePath(const char *dirname, const char *filename, bool local)
 
{
 
@@ -517,7 +517,7 @@ const char *GeneratePath(const char *dir
 
		while (*p == '.') {
 
			if (*(++p) == '.') {
 
				char *s = strrchr(path, '/');
 
				if (s != NULL) *s = '\0';
 
				if (s != nullptr) *s = '\0';
 
				p += 2;
 
			}
 
		}
 
@@ -535,7 +535,7 @@ const char *GeneratePath(const char *dir
 
		while (*p == '.') {
 
			if (*(++p) == '.') {
 
				char *s = strrchr(path, '/');
 
				if (s != NULL) *s = '\0';
 
				if (s != nullptr) *s = '\0';
 
				p += 2;
 
			}
 
		}
 
@@ -545,7 +545,7 @@ const char *GeneratePath(const char *dir
 
		if (access(path, R_OK) == 0) return strdup(path);
 
	}
 

	
 
	return NULL;
 
	return nullptr;
 
}
 

	
 
/**
 
@@ -730,7 +730,7 @@ void ScanFile(const char *filename, cons
 
									break;
 
								}
 
								const char *h = GeneratePath(file.GetDirname(), lexer.GetString(), lexer.GetToken() == TOKEN_LOCAL);
 
								if (h != NULL) {
 
								if (h != nullptr) {
 
									StringMap::iterator it = _headers.find(h);
 
									if (it == _headers.end()) {
 
										it = (_headers.insert(StringMapItem(strdup(h), new StringSet()))).first;
 
@@ -745,7 +745,7 @@ void ScanFile(const char *filename, cons
 
										char path[PATH_MAX];
 
										strecpy(path, filename, lastof(path));
 
										*(strrchr(path, '.')) = '\0';
 
										strecat(path, ext != NULL ? ext : ".o", lastof(path));
 
										strecat(path, ext != nullptr ? ext : ".o", lastof(path));
 
										curfile = _files.find(path);
 
										if (curfile == _files.end()) {
 
											curfile = (_files.insert(StringMapItem(strdup(path), new StringSet()))).first;
 
@@ -909,9 +909,9 @@ void ScanFile(const char *filename, cons
 
int main(int argc, char *argv[])
 
{
 
	bool ignorenext = true;
 
	char *filename = NULL;
 
	char *ext = NULL;
 
	char *delimiter = NULL;
 
	char *filename = nullptr;
 
	char *ext = nullptr;
 
	char *delimiter = nullptr;
 
	bool append = false;
 
	bool verbose = false;
 

	
 
@@ -936,25 +936,25 @@ int main(int argc, char *argv[])
 
			/* Define */
 
			if (strncmp(argv[i], "-D", 2) == 0) {
 
				char *p = strchr(argv[i], '=');
 
				if (p != NULL) *p = '\0';
 
				if (p != nullptr) *p = '\0';
 
				_defines.insert(strdup(&argv[i][2]));
 
				continue;
 
			}
 
			/* Output file */
 
			if (strncmp(argv[i], "-f", 2) == 0) {
 
				if (filename != NULL) continue;
 
				if (filename != nullptr) continue;
 
				filename = strdup(&argv[i][2]);
 
				continue;
 
			}
 
			/* Object file extension */
 
			if (strncmp(argv[i], "-o", 2) == 0) {
 
				if (ext != NULL) continue;
 
				if (ext != nullptr) continue;
 
				ext = strdup(&argv[i][2]);
 
				continue;
 
			}
 
			/* Starting string delimiter */
 
			if (strncmp(argv[i], "-s", 2) == 0) {
 
				if (delimiter != NULL) continue;
 
				if (delimiter != nullptr) continue;
 
				delimiter = strdup(&argv[i][2]);
 
				continue;
 
			}
 
@@ -966,22 +966,22 @@ int main(int argc, char *argv[])
 
	}
 

	
 
	/* Default output file is Makefile */
 
	if (filename == NULL) filename = strdup("Makefile");
 
	if (filename == nullptr) filename = strdup("Makefile");
 

	
 
	/* Default delimiter string */
 
	if (delimiter == NULL) delimiter = strdup("# DO NOT DELETE");
 
	if (delimiter == nullptr) delimiter = strdup("# DO NOT DELETE");
 

	
 
	char backup[PATH_MAX];
 
	strecpy(backup, filename, lastof(backup));
 
	strecat(backup, ".bak", lastof(backup));
 

	
 
	char *content = NULL;
 
	char *content = nullptr;
 
	long size = 0;
 

	
 
	/* Read in the current file; so we can overwrite everything from the
 
	 * end of non-depend data marker down till the end. */
 
	FILE *src = fopen(filename, "rb");
 
	if (src != NULL) {
 
	if (src != nullptr) {
 
		fseek(src, 0, SEEK_END);
 
		if ((size = ftell(src)) < 0) {
 
			fprintf(stderr, "Could not read %s\n", filename);
 
@@ -1009,7 +1009,7 @@ int main(int argc, char *argv[])
 

	
 
		/* Then append it to the real file. */
 
		src = fopen(backup, "r");
 
		while (fgets(content, size, src) != NULL) {
 
		while (fgets(content, size, src) != nullptr) {
 
			fputs(content, dst);
 
			if (!strncmp(content, delimiter, strlen(delimiter))) found_delimiter = true;
 
			if (!append && found_delimiter) break;
src/depot_cmd.cpp
Show inline comments
 
@@ -33,7 +33,7 @@ static bool IsUniqueDepotName(const char
 
	const Depot *d;
 

	
 
	FOR_ALL_DEPOTS(d) {
 
		if (d->name != NULL && strcmp(d->name, name) == 0) return false;
 
		if (d->name != nullptr && strcmp(d->name, name) == 0) return false;
 
	}
 

	
 
	return true;
 
@@ -51,7 +51,7 @@ static bool IsUniqueDepotName(const char
 
CommandCost CmdRenameDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	Depot *d = Depot::GetIfValid(p1);
 
	if (d == NULL) return CMD_ERROR;
 
	if (d == nullptr) return CMD_ERROR;
 

	
 
	CommandCost ret = CheckTileOwnership(d->xy);
 
	if (ret.Failed()) return ret;
 
@@ -67,7 +67,7 @@ CommandCost CmdRenameDepot(TileIndex til
 
		free(d->name);
 

	
 
		if (reset) {
 
			d->name = NULL;
 
			d->name = nullptr;
 
			MakeDefaultName(d);
 
		} else {
 
			d->name = stredup(text);
src/depot_gui.cpp
Show inline comments
 
@@ -133,16 +133,16 @@ static void TrainDepotMoveVehicle(const 
 

	
 
	if (v == wagon) return;
 

	
 
	if (wagon == NULL) {
 
		if (head != NULL) wagon = head->Last();
 
	if (wagon == nullptr) {
 
		if (head != nullptr) wagon = head->Last();
 
	} else {
 
		wagon = wagon->Previous();
 
		if (wagon == NULL) return;
 
		if (wagon == nullptr) return;
 
	}
 

	
 
	if (wagon == v) return;
 

	
 
	DoCommandP(v->tile, v->index | (_ctrl_pressed ? 1 : 0) << 20, wagon == NULL ? INVALID_VEHICLE : wagon->index, CMD_MOVE_RAIL_VEHICLE | CMD_MSG(STR_ERROR_CAN_T_MOVE_VEHICLE));
 
	DoCommandP(v->tile, v->index | (_ctrl_pressed ? 1 : 0) << 20, wagon == nullptr ? INVALID_VEHICLE : wagon->index, CMD_MOVE_RAIL_VEHICLE | CMD_MSG(STR_ERROR_CAN_T_MOVE_VEHICLE));
 
}
 

	
 
static VehicleCellSize _base_block_sizes_depot[VEH_COMPANY_END];    ///< Cell size for vehicle images in the depot view.
 
@@ -228,7 +228,7 @@ void InitDepotWindowBlockSizes()
 
		if (!e->IsEnabled()) continue;
 

	
 
		uint w = TRAININFO_DEFAULT_VEHICLE_WIDTH;
 
		if (e->GetGRF() != NULL && is_custom_sprite(e->u.rail.image_index)) {
 
		if (e->GetGRF() != nullptr && is_custom_sprite(e->u.rail.image_index)) {
 
			w = e->GetGRF()->traininfo_vehicle_width;
 
			if (w != VEHICLEINFO_FULL_VEHICLE_WIDTH) {
 
				/* Hopeless.
 
@@ -279,7 +279,7 @@ struct DepotWindow : Window {
 
		this->unitnumber_digits = 2;
 

	
 
		this->CreateNestedTree();
 
		this->hscroll = (this->type == VEH_TRAIN ? this->GetScrollbar(WID_D_H_SCROLL) : NULL);
 
		this->hscroll = (this->type == VEH_TRAIN ? this->GetScrollbar(WID_D_H_SCROLL) : nullptr);
 
		this->vscroll = this->GetScrollbar(WID_D_V_SCROLL);
 
		/* Don't show 'rename button' of aircraft hangar */
 
		this->GetWidget<NWidgetStacked>(WID_D_SHOW_RENAME)->SetDisplayedPlane(type == VEH_AIRCRAFT ? SZSP_NONE : 0);
 
@@ -469,8 +469,8 @@ struct DepotWindow : Window {
 
			/* Clicking on 'line' / 'block' without a vehicle */
 
			if (this->type == VEH_TRAIN) {
 
				/* End the dragging */
 
				d->head  = NULL;
 
				d->wagon = NULL;
 
				d->head  = nullptr;
 
				d->wagon = nullptr;
 
				return MODE_DRAG_VEHICLE;
 
			} else {
 
				return MODE_ERROR; // empty block, so no vehicle is selected
 
@@ -490,7 +490,7 @@ struct DepotWindow : Window {
 
			wagon = true;
 
		}
 

	
 
		const Train *v = NULL;
 
		const Train *v = nullptr;
 
		if (this->type == VEH_TRAIN) {
 
			v = Train::From(*veh);
 
			d->head = d->wagon = v;
 
@@ -525,12 +525,12 @@ struct DepotWindow : Window {
 
		x -= this->header_width;
 

	
 
		/* find the vehicle in this row that was clicked */
 
		for (; v != NULL; v = v->Next()) {
 
		for (; v != nullptr; v = v->Next()) {
 
			x -= v->GetDisplayImageWidth();
 
			if (x < 0) break;
 
		}
 

	
 
		d->wagon = (v != NULL ? v->GetFirstEnginePart() : NULL);
 
		d->wagon = (v != nullptr ? v->GetFirstEnginePart() : nullptr);
 

	
 
		return MODE_DRAG_VEHICLE;
 
	}
 
@@ -542,8 +542,8 @@ struct DepotWindow : Window {
 
	 */
 
	void DepotClick(int x, int y)
 
	{
 
		GetDepotVehiclePtData gdvp = { NULL, NULL };
 
		const Vehicle *v = NULL;
 
		GetDepotVehiclePtData gdvp = { nullptr, nullptr };
 
		const Vehicle *v = nullptr;
 
		DepotGUIAction mode = this->GetVehicleFromDepotWndPt(x, y, &v, &gdvp);
 

	
 
		if (this->type == VEH_TRAIN) v = gdvp.wagon;
 
@@ -553,14 +553,14 @@ struct DepotWindow : Window {
 
				return;
 

	
 
			case MODE_DRAG_VEHICLE: { // start dragging of vehicle
 
				if (v != NULL && VehicleClicked(v)) return;
 
				if (v != nullptr && VehicleClicked(v)) return;
 

	
 
				VehicleID sel = this->sel;
 

	
 
				if (this->type == VEH_TRAIN && sel != INVALID_VEHICLE) {
 
					this->sel = INVALID_VEHICLE;
 
					TrainDepotMoveVehicle(v, sel, gdvp.head);
 
				} else if (v != NULL) {
 
				} else if (v != nullptr) {
 
					SetObjectToPlaceWnd(SPR_CURSOR_MOUSE, PAL_NONE, HT_DRAG, this);
 
					SetMouseCursorVehicle(v, EIT_IN_DEPOT);
 
					_cursor.vehchain = _ctrl_pressed;
 
@@ -728,7 +728,7 @@ struct DepotWindow : Window {
 
			uint max_width = ScaleGUITrad(VEHICLEINFO_FULL_VEHICLE_WIDTH);
 
			for (uint num = 0; num < this->vehicle_list.size(); num++) {
 
				uint width = 0;
 
				for (const Train *v = Train::From(this->vehicle_list[num]); v != NULL; v = v->Next()) {
 
				for (const Train *v = Train::From(this->vehicle_list[num]); v != nullptr; v = v->Next()) {
 
					width += v->GetDisplayImageWidth();
 
				}
 
				max_width = max(max_width, width);
 
@@ -839,24 +839,24 @@ struct DepotWindow : Window {
 

	
 
	void OnQueryTextFinished(char *str) override
 
	{
 
		if (str == NULL) return;
 
		if (str == nullptr) return;
 

	
 
		/* Do depot renaming */
 
		DoCommandP(0, GetDepotIndex(this->window_number), 0, CMD_RENAME_DEPOT | CMD_MSG(STR_ERROR_CAN_T_RENAME_DEPOT), NULL, str);
 
		DoCommandP(0, GetDepotIndex(this->window_number), 0, CMD_RENAME_DEPOT | CMD_MSG(STR_ERROR_CAN_T_RENAME_DEPOT), nullptr, str);
 
	}
 

	
 
	bool OnRightClick(Point pt, int widget) override
 
	{
 
		if (widget != WID_D_MATRIX) return false;
 

	
 
		GetDepotVehiclePtData gdvp = { NULL, NULL };
 
		const Vehicle *v = NULL;
 
		GetDepotVehiclePtData gdvp = { nullptr, nullptr };
 
		const Vehicle *v = nullptr;
 
		NWidgetBase *nwi = this->GetWidget<NWidgetBase>(WID_D_MATRIX);
 
		DepotGUIAction mode = this->GetVehicleFromDepotWndPt(pt.x - nwi->pos_x, pt.y - nwi->pos_y, &v, &gdvp);
 

	
 
		if (this->type == VEH_TRAIN) v = gdvp.wagon;
 

	
 
		if (v == NULL || mode != MODE_DRAG_VEHICLE) return false;
 
		if (v == nullptr || mode != MODE_DRAG_VEHICLE) return false;
 

	
 
		CargoArray capacity, loaded;
 

	
 
@@ -865,7 +865,7 @@ struct DepotWindow : Window {
 

	
 
		/* loop through vehicle chain and collect cargoes */
 
		uint num = 0;
 
		for (const Vehicle *w = v; w != NULL; w = w->Next()) {
 
		for (const Vehicle *w = v; w != nullptr; w = w->Next()) {
 
			if (w->cargo_cap > 0 && w->cargo_type < NUM_CARGO) {
 
				capacity[w->cargo_type] += w->cargo_cap;
 
				loaded  [w->cargo_type] += w->cargo.StoredCount();
 
@@ -910,7 +910,7 @@ struct DepotWindow : Window {
 
	{
 
		if (_ctrl_pressed) {
 
			/* Share-clone, do not open new viewport, and keep tool active */
 
			DoCommandP(this->window_number, v->index, 1, CMD_CLONE_VEHICLE | CMD_MSG(STR_ERROR_CAN_T_BUY_TRAIN + v->type), NULL);
 
			DoCommandP(this->window_number, v->index, 1, CMD_CLONE_VEHICLE | CMD_MSG(STR_ERROR_CAN_T_BUY_TRAIN + v->type), nullptr);
 
		} else {
 
			/* Copy-clone, open viewport for new vehicle, and deselect the tool (assume player wants to changs things on new vehicle) */
 
			if (DoCommandP(this->window_number, v->index, 0, CMD_CLONE_VEHICLE | CMD_MSG(STR_ERROR_CAN_T_BUY_TRAIN + v->type), CcCloneVehicle)) {
 
@@ -965,20 +965,20 @@ struct DepotWindow : Window {
 
		}
 

	
 
		NWidgetBase *matrix = this->GetWidget<NWidgetBase>(widget);
 
		const Vehicle *v = NULL;
 
		GetDepotVehiclePtData gdvp = {NULL, NULL};
 
		const Vehicle *v = nullptr;
 
		GetDepotVehiclePtData gdvp = {nullptr, nullptr};
 

	
 
		if (this->GetVehicleFromDepotWndPt(pt.x - matrix->pos_x, pt.y - matrix->pos_y, &v, &gdvp) != MODE_DRAG_VEHICLE) return;
 

	
 
		VehicleID new_vehicle_over = INVALID_VEHICLE;
 
		if (gdvp.head != NULL) {
 
			if (gdvp.wagon == NULL && gdvp.head->Last()->index != this->sel) { // ..at the end of the train.
 
		if (gdvp.head != nullptr) {
 
			if (gdvp.wagon == nullptr && gdvp.head->Last()->index != this->sel) { // ..at the end of the train.
 
				/* NOTE: As a wagon can't be moved at the begin of a train, head index isn't used to mark a drag-and-drop
 
				 * destination inside a train. This head index is then used to indicate that a wagon is inserted at
 
				 * the end of the train.
 
				 */
 
				new_vehicle_over = gdvp.head->index;
 
			} else if (gdvp.wagon != NULL && gdvp.head != gdvp.wagon &&
 
			} else if (gdvp.wagon != nullptr && gdvp.head != gdvp.wagon &&
 
					gdvp.wagon->index != this->sel &&
 
					gdvp.wagon->Previous()->index != this->sel) { // ..over an existing wagon.
 
				new_vehicle_over = gdvp.wagon->index;
 
@@ -995,7 +995,7 @@ struct DepotWindow : Window {
 
	{
 
		switch (widget) {
 
			case WID_D_MATRIX: {
 
				const Vehicle *v = NULL;
 
				const Vehicle *v = nullptr;
 
				VehicleID sel = this->sel;
 

	
 
				this->sel = INVALID_VEHICLE;
 
@@ -1003,20 +1003,20 @@ struct DepotWindow : Window {
 

	
 
				NWidgetBase *nwi = this->GetWidget<NWidgetBase>(WID_D_MATRIX);
 
				if (this->type == VEH_TRAIN) {
 
					GetDepotVehiclePtData gdvp = { NULL, NULL };
 
					GetDepotVehiclePtData gdvp = { nullptr, nullptr };
 

	
 
					if (this->GetVehicleFromDepotWndPt(pt.x - nwi->pos_x, pt.y - nwi->pos_y, &v, &gdvp) == MODE_DRAG_VEHICLE && sel != INVALID_VEHICLE) {
 
						if (gdvp.wagon != NULL && gdvp.wagon->index == sel && _ctrl_pressed) {
 
						if (gdvp.wagon != nullptr && gdvp.wagon->index == sel && _ctrl_pressed) {
 
							DoCommandP(Vehicle::Get(sel)->tile, Vehicle::Get(sel)->index, true,
 
									CMD_REVERSE_TRAIN_DIRECTION | CMD_MSG(STR_ERROR_CAN_T_REVERSE_DIRECTION_RAIL_VEHICLE));
 
						} else if (gdvp.wagon == NULL || gdvp.wagon->index != sel) {
 
						} else if (gdvp.wagon == nullptr || gdvp.wagon->index != sel) {
 
							this->vehicle_over = INVALID_VEHICLE;
 
							TrainDepotMoveVehicle(gdvp.wagon, sel, gdvp.head);
 
						} else if (gdvp.head != NULL && gdvp.head->IsFrontEngine()) {
 
						} else if (gdvp.head != nullptr && gdvp.head->IsFrontEngine()) {
 
							ShowVehicleViewWindow(gdvp.head);
 
						}
 
					}
 
				} else if (this->GetVehicleFromDepotWndPt(pt.x - nwi->pos_x, pt.y - nwi->pos_y, &v, NULL) == MODE_DRAG_VEHICLE && v != NULL && sel == v->index) {
 
				} else if (this->GetVehicleFromDepotWndPt(pt.x - nwi->pos_x, pt.y - nwi->pos_y, &v, nullptr) == MODE_DRAG_VEHICLE && v != nullptr && sel == v->index) {
 
					ShowVehicleViewWindow(v);
 
				}
 
				break;
 
@@ -1052,7 +1052,7 @@ struct DepotWindow : Window {
 
			this->RaiseWidget(WID_D_SELL);
 
			this->SetWidgetDirty(WID_D_SELL);
 
		}
 
		if (this->nested_array[WID_D_SELL] != NULL && !this->IsWidgetDisabled(WID_D_SELL_CHAIN)) {
 
		if (this->nested_array[WID_D_SELL] != nullptr && !this->IsWidgetDisabled(WID_D_SELL_CHAIN)) {
 
			this->RaiseWidget(WID_D_SELL_CHAIN);
 
			this->SetWidgetDirty(WID_D_SELL_CHAIN);
 
		}
 
@@ -1098,7 +1098,7 @@ static void DepotSellAllConfirmationCall
 
 */
 
void ShowDepotWindow(TileIndex tile, VehicleType type)
 
{
 
	if (BringWindowToFrontById(WC_VEHICLE_DEPOT, tile) != NULL) return;
 
	if (BringWindowToFrontById(WC_VEHICLE_DEPOT, tile) != nullptr) return;
 

	
 
	WindowDesc *desc;
 
	switch (type) {
 
@@ -1126,7 +1126,7 @@ void DeleteDepotHighlightOfVehicle(const
 
	if (_special_mouse_mode != WSM_DRAGDROP) return;
 

	
 
	w = dynamic_cast<DepotWindow*>(FindWindowById(WC_VEHICLE_DEPOT, v->tile));
 
	if (w != NULL) {
 
	if (w != nullptr) {
 
		if (w->sel == v->index) ResetObjectToPlace();
 
	}
 
}
src/disaster_vehicle.cpp
Show inline comments
 
@@ -137,11 +137,11 @@ DisasterVehicle::DisasterVehicle(int x, 
 
		case ST_HELICOPTER:
 
		case ST_BIG_UFO:
 
		case ST_BIG_UFO_DESTROYER:
 
			GetAircraftFlightLevelBounds(this, &this->z_pos, NULL);
 
			GetAircraftFlightLevelBounds(this, &this->z_pos, nullptr);
 
			break;
 

	
 
		case ST_HELICOPTER_ROTORS:
 
			GetAircraftFlightLevelBounds(this, &this->z_pos, NULL);
 
			GetAircraftFlightLevelBounds(this, &this->z_pos, nullptr);
 
			this->z_pos += ROTOR_Z_OFFSET;
 
			break;
 

	
 
@@ -190,7 +190,7 @@ void DisasterVehicle::UpdatePosition(int
 
	this->UpdatePositionAndViewport();
 

	
 
	DisasterVehicle *u = this->Next();
 
	if (u != NULL) {
 
	if (u != nullptr) {
 
		int safe_x = Clamp(x, 0, MapMaxX() * TILE_SIZE);
 
		int safe_y = Clamp(y - 1, 0, MapMaxY() * TILE_SIZE);
 

	
 
@@ -203,7 +203,7 @@ void DisasterVehicle::UpdatePosition(int
 
		u->UpdateImage();
 
		u->UpdatePositionAndViewport();
 

	
 
		if ((u = u->Next()) != NULL) {
 
		if ((u = u->Next()) != nullptr) {
 
			u->x_pos = x;
 
			u->y_pos = y;
 
			u->z_pos = z + ROTOR_Z_OFFSET;
 
@@ -357,7 +357,7 @@ static bool DisasterTick_Ufo(DisasterVeh
 
	} else {
 
		/* Target a vehicle */
 
		RoadVehicle *u = RoadVehicle::Get(v->dest_tile);
 
		assert(u != NULL && u->type == VEH_ROAD && u->IsFrontEngine());
 
		assert(u != nullptr && u->type == VEH_ROAD && u->IsFrontEngine());
 

	
 
		uint dist = Delta(v->x_pos, u->x_pos) + Delta(v->y_pos, u->y_pos);
 

	
 
@@ -748,16 +748,16 @@ static void Disaster_Airplane_Init()
 
{
 
	if (!Vehicle::CanAllocateItem(2)) return;
 

	
 
	Industry *i, *found = NULL;
 
	Industry *i, *found = nullptr;
 

	
 
	FOR_ALL_INDUSTRIES(i) {
 
		if ((GetIndustrySpec(i->type)->behaviour & INDUSTRYBEH_AIRPLANE_ATTACKS) &&
 
				(found == NULL || Chance16(1, 2))) {
 
				(found == nullptr || Chance16(1, 2))) {
 
			found = i;
 
		}
 
	}
 

	
 
	if (found == NULL) return;
 
	if (found == nullptr) return;
 

	
 
	/* Start from the bottom (south side) of the map */
 
	int x = (MapSizeX() + 9) * TILE_SIZE - 1;
 
@@ -774,16 +774,16 @@ static void Disaster_Helicopter_Init()
 
{
 
	if (!Vehicle::CanAllocateItem(3)) return;
 

	
 
	Industry *i, *found = NULL;
 
	Industry *i, *found = nullptr;
 

	
 
	FOR_ALL_INDUSTRIES(i) {
 
		if ((GetIndustrySpec(i->type)->behaviour & INDUSTRYBEH_CHOPPER_ATTACKS) &&
 
				(found == NULL || Chance16(1, 2))) {
 
				(found == nullptr || Chance16(1, 2))) {
 
			found = i;
 
		}
 
	}
 

	
 
	if (found == NULL) return;
 
	if (found == nullptr) return;
 

	
 
	int x = -16 * (int)TILE_SIZE;
 
	int y = TileY(found->location.tile) * TILE_SIZE + 37;
 
@@ -966,7 +966,7 @@ void ReleaseDisastersTargetingVehicle(Ve
 
				/* Revert to target-searching */
 
				v->current_order.SetDestination(0);
 
				v->dest_tile = RandomTile();
 
				GetAircraftFlightLevelBounds(v, &v->z_pos, NULL);
 
				GetAircraftFlightLevelBounds(v, &v->z_pos, nullptr);
 
				v->age = 0;
 
			}
 
		}
src/dock_gui.cpp
Show inline comments
 
@@ -60,7 +60,7 @@ void CcPlaySound_SPLAT_WATER(const Comma
 
 * @param[out] tile_to   The tile till where to show a selection for the aqueduct.
 
 * @return The other end of the aqueduct, or otherwise a tile in line with the aqueduct to cause the right error message.
 
 */
 
static TileIndex GetOtherAqueductEnd(TileIndex tile_from, TileIndex *tile_to = NULL)
 
static TileIndex GetOtherAqueductEnd(TileIndex tile_from, TileIndex *tile_to = nullptr)
 
{
 
	int z;
 
	DiagDirection dir = GetInclinedSlopeDirection(GetTileSlope(tile_from, &z));
 
@@ -83,7 +83,7 @@ static TileIndex GetOtherAqueductEnd(Til
 
		if (length > max_length) break;
 

	
 
		if (GetTileMaxZ(endtile) > z) {
 
			if (tile_to != NULL) *tile_to = endtile;
 
			if (tile_to != nullptr) *tile_to = endtile;
 
			break;
 
		}
 
	}
 
@@ -287,7 +287,7 @@ static EventState DockToolbarGlobalHotke
 
{
 
	if (_game_mode != GM_NORMAL) return ES_NOT_HANDLED;
 
	Window *w = ShowBuildDocksToolbar();
 
	if (w == NULL) return ES_NOT_HANDLED;
 
	if (w == nullptr) return ES_NOT_HANDLED;
 
	return w->OnHotkey(hotkey);
 
}
 

	
 
@@ -341,11 +341,11 @@ static WindowDesc _build_docks_toolbar_d
 
 *
 
 * If the terraform toolbar is linked to the toolbar, that window is also opened.
 
 *
 
 * @return newly opened water toolbar, or NULL if the toolbar could not be opened.
 
 * @return newly opened water toolbar, or nullptr if the toolbar could not be opened.
 
 */
 
Window *ShowBuildDocksToolbar()
 
{
 
	if (!Company::IsValidID(_local_company)) return NULL;
 
	if (!Company::IsValidID(_local_company)) return nullptr;
 

	
 
	DeleteWindowByClass(WC_BUILD_TOOLBAR);
 
	return AllocateWindowDescFront<BuildDocksToolbarWindow>(&_build_docks_toolbar_desc, TRANSPORT_WATER);
 
@@ -382,7 +382,7 @@ static WindowDesc _build_docks_scen_tool
 
/**
 
 * Open the build water toolbar window for the scenario editor.
 
 *
 
 * @return newly opened water toolbar, or NULL if the toolbar could not be opened.
 
 * @return newly opened water toolbar, or nullptr if the toolbar could not be opened.
 
 */
 
Window *ShowBuildDocksScenToolbar()
 
{
 
@@ -475,7 +475,7 @@ static const NWidgetPart _nested_build_d
 
};
 

	
 
static WindowDesc _build_dock_station_desc(
 
	WDP_AUTO, NULL, 0, 0,
 
	WDP_AUTO, nullptr, 0, 0,
 
	WC_BUILD_STATION, WC_BUILD_TOOLBAR,
 
	WDF_CONSTRUCTION,
 
	_nested_build_dock_station_widgets, lengthof(_nested_build_dock_station_widgets)
 
@@ -568,7 +568,7 @@ static const NWidgetPart _nested_build_d
 
};
 

	
 
static WindowDesc _build_docks_depot_desc(
 
	WDP_AUTO, NULL, 0, 0,
 
	WDP_AUTO, nullptr, 0, 0,
 
	WC_BUILD_DEPOT, WC_BUILD_TOOLBAR,
 
	WDF_CONSTRUCTION,
 
	_nested_build_docks_depot_widgets, lengthof(_nested_build_docks_depot_widgets)
src/driver.cpp
Show inline comments
 
@@ -41,10 +41,10 @@ const char *GetDriverParam(const char * 
 
{
 
	size_t len;
 

	
 
	if (parm == NULL) return NULL;
 
	if (parm == nullptr) return nullptr;
 

	
 
	len = strlen(name);
 
	for (; *parm != NULL; parm++) {
 
	for (; *parm != nullptr; parm++) {
 
		const char *p = *parm;
 

	
 
		if (strncmp(p, name, len) == 0) {
 
@@ -52,7 +52,7 @@ const char *GetDriverParam(const char * 
 
			if (p[len] == '\0') return p + len;
 
		}
 
	}
 
	return NULL;
 
	return nullptr;
 
}
 

	
 
/**
 
@@ -63,7 +63,7 @@ const char *GetDriverParam(const char * 
 
 */
 
bool GetDriverParamBool(const char * const *parm, const char *name)
 
{
 
	return GetDriverParam(parm, name) != NULL;
 
	return GetDriverParam(parm, name) != nullptr;
 
}
 

	
 
/**
 
@@ -76,7 +76,7 @@ bool GetDriverParamBool(const char * con
 
int GetDriverParamInt(const char * const *parm, const char *name, int def)
 
{
 
	const char *p = GetDriverParam(parm, name);
 
	return p != NULL ? atoi(p) : def;
 
	return p != nullptr ? atoi(p) : def;
 
}
 

	
 
/**
 
@@ -120,8 +120,8 @@ bool DriverFactoryBase::SelectDriverImpl
 
				Driver *newd = d->CreateInstance();
 
				*GetActiveDriver(type) = newd;
 

	
 
				const char *err = newd->Start(NULL);
 
				if (err == NULL) {
 
				const char *err = newd->Start(nullptr);
 
				if (err == nullptr) {
 
					DEBUG(driver, 1, "Successfully probed %s driver '%s'", GetDriverTypeName(type), d->name);
 
					delete oldd;
 
					return true;
 
@@ -141,8 +141,8 @@ bool DriverFactoryBase::SelectDriverImpl
 
		/* Extract the driver name and put parameter list in parm */
 
		strecpy(buffer, name, lastof(buffer));
 
		parm = strchr(buffer, ':');
 
		parms[0] = NULL;
 
		if (parm != NULL) {
 
		parms[0] = nullptr;
 
		if (parm != nullptr) {
 
			uint np = 0;
 
			/* Tokenize the parm. */
 
			do {
 
@@ -150,7 +150,7 @@ bool DriverFactoryBase::SelectDriverImpl
 
				if (np < lengthof(parms) - 1) parms[np++] = parm;
 
				while (*parm != '\0' && *parm != ',') parm++;
 
			} while (*parm == ',');
 
			parms[np] = NULL;
 
			parms[np] = nullptr;
 
		}
 

	
 
		/* Find this driver */
 
@@ -168,7 +168,7 @@ bool DriverFactoryBase::SelectDriverImpl
 
			Driver *newd = d->CreateInstance();
 

	
 
			const char *err = newd->Start(parms);
 
			if (err != NULL) {
 
			if (err != nullptr) {
 
				delete newd;
 
				usererror("Unable to load driver '%s'. The error was: %s", d->name, err);
 
			}
src/driver.h
Show inline comments
 
@@ -26,7 +26,7 @@ public:
 
	/**
 
	 * Start this driver.
 
	 * @param parm Parameters passed to the driver.
 
	 * @return NULL if everything went okay, otherwise an error message.
 
	 * @return nullptr if everything went okay, otherwise an error message.
 
	 */
 
	virtual const char *Start(const char * const *parm) = 0;
 

	
 
@@ -86,7 +86,7 @@ private:
 
	 */
 
	static Driver **GetActiveDriver(Driver::Type type)
 
	{
 
		static Driver *s_driver[3] = { NULL, NULL, NULL };
 
		static Driver *s_driver[3] = { nullptr, nullptr, nullptr };
 
		return &s_driver[type];
 
	}
 

	
 
@@ -116,7 +116,7 @@ public:
 
	{
 
		for (Driver::Type dt = Driver::DT_BEGIN; dt < Driver::DT_END; dt++) {
 
			Driver *driver = *GetActiveDriver(dt);
 
			if (driver != NULL) driver->Stop();
 
			if (driver != nullptr) driver->Stop();
 
		}
 
	}
 

	
src/economy.cpp
Show inline comments
 
@@ -401,7 +401,7 @@ void ChangeOwnershipOfCompanyItems(Owner
 
		FOR_ALL_VEHICLES(v) {
 
			if (v->owner == old_owner && IsCompanyBuildableVehicleType(v->type)) {
 
				if (new_owner == INVALID_OWNER) {
 
					if (v->Previous() == NULL) delete v;
 
					if (v->Previous() == nullptr) delete v;
 
				} else {
 
					if (v->IsEngineCountable()) GroupStatistics::CountEngine(v, -1);
 
					if (v->IsPrimaryVehicle()) GroupStatistics::CountVehicle(v, -1);
 
@@ -476,7 +476,7 @@ void ChangeOwnershipOfCompanyItems(Owner
 
				}
 

	
 
				/* Invalidate the vehicle's cargo payment "owner cache". */
 
				if (v->cargo_payment != NULL) v->cargo_payment->owner = NULL;
 
				if (v->cargo_payment != nullptr) v->cargo_payment->owner = nullptr;
 
			}
 
		}
 

	
 
@@ -959,7 +959,7 @@ Money GetPrice(Price index, uint cost_fa
 
	if (index >= PR_END) return 0;
 

	
 
	Money cost = _price[index] * cost_factor;
 
	if (grf_file != NULL) shift += grf_file->price_base_multipliers[index];
 
	if (grf_file != nullptr) shift += grf_file->price_base_multipliers[index];
 

	
 
	if (shift >= 0) {
 
		cost <<= shift;
 
@@ -1180,7 +1180,7 @@ CargoPayment::~CargoPayment()
 
{
 
	if (this->CleaningPool()) return;
 

	
 
	this->front->cargo_payment = NULL;
 
	this->front->cargo_payment = nullptr;
 

	
 
	if (this->visual_profit == 0 && this->visual_transfer == 0) return;
 

	
 
@@ -1211,7 +1211,7 @@ CargoPayment::~CargoPayment()
 
 */
 
void CargoPayment::PayFinalDelivery(const CargoPacket *cp, uint count)
 
{
 
	if (this->owner == NULL) {
 
	if (this->owner == nullptr) {
 
		this->owner = Company::Get(this->front->owner);
 
	}
 

	
 
@@ -1259,7 +1259,7 @@ void PrepareUnload(Vehicle *front_v)
 
	/* Start unloading at the first possible moment */
 
	front_v->load_unload_ticks = 1;
 

	
 
	assert(front_v->cargo_payment == NULL);
 
	assert(front_v->cargo_payment == nullptr);
 
	/* One CargoPayment per vehicle and the vehicle limit equals the
 
	 * limit in number of CargoPayments. Can't go wrong. */
 
	assert_compile(CargoPaymentPool::MAX_SIZE == VehiclePool::MAX_SIZE);
 
@@ -1267,9 +1267,9 @@ void PrepareUnload(Vehicle *front_v)
 
	front_v->cargo_payment = new CargoPayment(front_v);
 

	
 
	StationIDStack next_station = front_v->GetNextStoppingStation();
 
	if (front_v->orders.list == NULL || (front_v->current_order.GetUnloadType() & OUFB_NO_UNLOAD) == 0) {
 
	if (front_v->orders.list == nullptr || (front_v->current_order.GetUnloadType() & OUFB_NO_UNLOAD) == 0) {
 
		Station *st = Station::Get(front_v->last_station_visited);
 
		for (Vehicle *v = front_v; v != NULL; v = v->Next()) {
 
		for (Vehicle *v = front_v; v != nullptr; v = v->Next()) {
 
			const GoodsEntry *ge = &st->goods[v->cargo_type];
 
			if (v->cargo_cap > 0 && v->cargo.TotalCount() > 0) {
 
				v->cargo.Stage(
 
@@ -1300,7 +1300,7 @@ static uint GetLoadAmount(Vehicle *v)
 

	
 
	if (_settings_game.order.gradual_loading) {
 
		uint16 cb_load_amount = CALLBACK_FAILED;
 
		if (e->GetGRF() != NULL && e->GetGRF()->grf_version >= 8) {
 
		if (e->GetGRF() != nullptr && e->GetGRF()->grf_version >= 8) {
 
			/* Use callback 36 */
 
			cb_load_amount = GetVehicleProperty(v, PROP_VEHICLE_LOAD_AMOUNT, CALLBACK_FAILED);
 
		} else if (HasBit(e->info.callback_mask, CBM_VEHICLE_LOAD_AMOUNT)) {
 
@@ -1336,8 +1336,8 @@ static uint GetLoadAmount(Vehicle *v)
 
template<class Taction>
 
bool IterateVehicleParts(Vehicle *v, Taction action)
 
{
 
	for (Vehicle *w = v; w != NULL;
 
			w = w->HasArticulatedPart() ? w->GetNextArticulatedPart() : NULL) {
 
	for (Vehicle *w = v; w != nullptr;
 
			w = w->HasArticulatedPart() ? w->GetNextArticulatedPart() : nullptr) {
 
		if (!action(w)) return false;
 
		if (w->type == VEH_TRAIN) {
 
			Train *train = Train::From(w);
 
@@ -1564,8 +1564,8 @@ static void ReserveConsist(Station *st, 
 
	/* If there is a cargo payment not all vehicles of the consist have tried to do the refit.
 
	 * In that case, only reserve if it's a fixed refit and the equivalent of "articulated chain"
 
	 * a vehicle belongs to already has the right cargo. */
 
	bool must_reserve = !u->current_order.IsRefit() || u->cargo_payment == NULL;
 
	for (Vehicle *v = u; v != NULL; v = v->Next()) {
 
	bool must_reserve = !u->current_order.IsRefit() || u->cargo_payment == nullptr;
 
	for (Vehicle *v = u; v != nullptr; v = v->Next()) {
 
		assert(v->cargo_cap >= v->cargo.RemainingCount());
 

	
 
		/* Exclude various ways in which the vehicle might not be the head of an equivalent of
 
@@ -1577,7 +1577,7 @@ static void ReserveConsist(Station *st, 
 
				(must_reserve || u->current_order.GetRefitCargo() == v->cargo_type)) {
 
			IterateVehicleParts(v, ReserveCargoAction(st, next_station));
 
		}
 
		if (consist_capleft == NULL || v->cargo_cap == 0) continue;
 
		if (consist_capleft == nullptr || v->cargo_cap == 0) continue;
 
		(*consist_capleft)[v->cargo_type] += v->cargo_cap - v->cargo.RemainingCount();
 
	}
 
}
 
@@ -1618,9 +1618,9 @@ static void LoadUnloadVehicle(Vehicle *f
 
	bool use_autorefit = front->current_order.IsRefit() && front->current_order.GetRefitCargo() == CT_AUTO_REFIT;
 
	CargoArray consist_capleft;
 
	if (_settings_game.order.improved_load && use_autorefit ?
 
			front->cargo_payment == NULL : (front->current_order.GetLoadType() & OLFB_FULL_LOAD) != 0) {
 
			front->cargo_payment == nullptr : (front->current_order.GetLoadType() & OLFB_FULL_LOAD) != 0) {
 
		ReserveConsist(st, front,
 
				(use_autorefit && front->load_unload_ticks != 0) ? &consist_capleft : NULL,
 
				(use_autorefit && front->load_unload_ticks != 0) ? &consist_capleft : nullptr,
 
				&next_station);
 
	}
 

	
 
@@ -1652,7 +1652,7 @@ static void LoadUnloadVehicle(Vehicle *f
 
	CargoPayment *payment = front->cargo_payment;
 

	
 
	uint artic_part = 0; // Articulated part we are currently trying to load. (not counting parts without capacity)
 
	for (Vehicle *v = front; v != NULL; v = v->Next()) {
 
	for (Vehicle *v = front; v != nullptr; v = v->Next()) {
 
		if (v == front || !v->Previous()->HasArticulatedPart()) artic_part = 0;
 
		if (v->cargo_cap == 0) continue;
 
		artic_part++;
 
@@ -1664,7 +1664,7 @@ static void LoadUnloadVehicle(Vehicle *f
 
			uint amount_unloaded = _settings_game.order.gradual_loading ? min(cargo_count, GetLoadAmount(v)) : cargo_count;
 
			bool remaining = false; // Are there cargo entities in this vehicle that can still be unloaded here?
 

	
 
			assert(payment != NULL);
 
			assert(payment != nullptr);
 
			payment->SetCargo(v->cargo_type);
 

	
 
			if (!HasBit(ge->status, GoodsEntry::GES_ACCEPTANCE) && v->cargo.ActionCount(VehicleCargoList::MTA_DELIVER) > 0) {
 
@@ -1916,7 +1916,7 @@ void LoadUnloadStation(Station *st)
 
	/* No vehicle is here... */
 
	if (st->loading_vehicles.empty()) return;
 

	
 
	Vehicle *last_loading = NULL;
 
	Vehicle *last_loading = nullptr;
 
	std::list<Vehicle *>::iterator iter;
 

	
 
	/* Check if anything will be loaded at all. Otherwise we don't need to reserve either. */
 
@@ -1936,7 +1936,7 @@ void LoadUnloadStation(Station *st)
 
	 * consist in a station which is not allowed to load yet because its
 
	 * load_unload_ticks is still not 0.
 
	 */
 
	if (last_loading == NULL) return;
 
	if (last_loading == nullptr) return;
 

	
 
	for (iter = st->loading_vehicles.begin(); iter != st->loading_vehicles.end(); ++iter) {
 
		Vehicle *v = *iter;
 
@@ -2018,7 +2018,7 @@ CommandCost CmdBuyShareInCompany(TileInd
 

	
 
	/* Check if buying shares is allowed (protection against modified clients)
 
	 * Cannot buy own shares */
 
	if (c == NULL || !_settings_game.economy.allow_shares || _current_company == target_company) return CMD_ERROR;
 
	if (c == nullptr || !_settings_game.economy.allow_shares || _current_company == target_company) return CMD_ERROR;
 

	
 
	/* Protect new companies from hostile takeovers */
 
	if (_cur_year - c->inaugurated_year < 6) return_cmd_error(STR_ERROR_PROTECTED);
 
@@ -2068,7 +2068,7 @@ CommandCost CmdSellShareInCompany(TileIn
 
	Company *c = Company::GetIfValid(target_company);
 

	
 
	/* Cannot sell own shares */
 
	if (c == NULL || _current_company == target_company) return CMD_ERROR;
 
	if (c == nullptr || _current_company == target_company) return CMD_ERROR;
 

	
 
	/* Check if selling shares is allowed (protection against modified clients).
 
	 * However, we must sell shares of companies being closed down. */
 
@@ -2107,7 +2107,7 @@ CommandCost CmdBuyCompany(TileIndex tile
 
{
 
	CompanyID target_company = (CompanyID)p1;
 
	Company *c = Company::GetIfValid(target_company);
 
	if (c == NULL) return CMD_ERROR;
 
	if (c == nullptr) return CMD_ERROR;
 

	
 
	/* Disable takeovers when not asked */
 
	if (!HasBit(c->bankrupt_asked, _current_company)) return CMD_ERROR;
src/effectvehicle.cpp
Show inline comments
 
@@ -595,7 +595,7 @@ assert_compile(lengthof(_effect_transpar
 
 */
 
EffectVehicle *CreateEffectVehicle(int x, int y, int z, EffectVehicleType type)
 
{
 
	if (!Vehicle::CanAllocateItem()) return NULL;
 
	if (!Vehicle::CanAllocateItem()) return nullptr;
 

	
 
	EffectVehicle *v = new EffectVehicle();
 
	v->subtype = type;
src/elrail.cpp
Show inline comments
 
@@ -82,7 +82,7 @@ static inline TLG GetTLG(TileIndex t)
 
/**
 
 * Finds which Electrified Rail Bits are present on a given tile.
 
 * @param t tile to check
 
 * @param override pointer to PCP override, can be NULL
 
 * @param override pointer to PCP override, can be nullptr
 
 * @return trackbits of tile if it is electrified
 
 */
 
static TrackBits GetRailTrackBitsUniversal(TileIndex t, byte *override)
 
@@ -101,7 +101,7 @@ static TrackBits GetRailTrackBitsUnivers
 
		case MP_TUNNELBRIDGE:
 
			if (GetTunnelBridgeTransportType(t) != TRANSPORT_RAIL) return TRACK_BIT_NONE;
 
			if (!HasRailCatenary(GetRailType(t))) return TRACK_BIT_NONE;
 
			if (override != NULL && (IsTunnel(t) || GetTunnelBridgeLength(t, GetOtherBridgeEnd(t)) > 0)) {
 
			if (override != nullptr && (IsTunnel(t) || GetTunnelBridgeLength(t, GetOtherBridgeEnd(t)) > 0)) {
 
				*override = 1 << GetTunnelBridgeDirection(t);
 
			}
 
			return DiagDirToDiagTrackBits(GetTunnelBridgeDirection(t));
 
@@ -326,7 +326,7 @@ static void DrawRailCatenaryRailway(cons
 
		/* Here's one of the main headaches. GetTileSlope does not correct for possibly
 
		 * existing foundataions, so we do have to do that manually later on.*/
 
		tileh[TS_NEIGHBOUR] = GetTileSlope(neighbour);
 
		trackconfig[TS_NEIGHBOUR] = GetRailTrackBitsUniversal(neighbour, NULL);
 
		trackconfig[TS_NEIGHBOUR] = GetRailTrackBitsUniversal(neighbour, nullptr);
 
		wireconfig[TS_NEIGHBOUR] = MaskWireBits(neighbour, trackconfig[TS_NEIGHBOUR]);
 
		if (IsTunnelTile(neighbour) && i != GetTunnelBridgeDirection(neighbour)) wireconfig[TS_NEIGHBOUR] = trackconfig[TS_NEIGHBOUR] = TRACK_BIT_NONE;
 

	
src/engine.cpp
Show inline comments
 
@@ -69,9 +69,9 @@ assert_compile(lengthof(_orig_rail_vehic
 
const uint EngineOverrideManager::NUM_DEFAULT_ENGINES = _engine_counts[VEH_TRAIN] + _engine_counts[VEH_ROAD] + _engine_counts[VEH_SHIP] + _engine_counts[VEH_AIRCRAFT];
 

	
 
Engine::Engine() :
 
	name(NULL),
 
	name(nullptr),
 
	overrides_count(0),
 
	overrides(NULL)
 
	overrides(nullptr)
 
{
 
}
 

	
 
@@ -162,7 +162,7 @@ bool Engine::IsEnabled() const
 
uint32 Engine::GetGRFID() const
 
{
 
	const GRFFile *file = this->GetGRF();
 
	return file == NULL ? 0 : file->grfid;
 
	return file == nullptr ? 0 : file->grfid;
 
}
 

	
 
/**
 
@@ -199,28 +199,28 @@ bool Engine::CanCarryCargo() const
 
/**
 
 * Determines capacity of a given vehicle from scratch.
 
 * For aircraft the main capacity is determined. Mail might be present as well.
 
 * @param v Vehicle of interest; NULL in purchase list
 
 * @param v Vehicle of interest; nullptr in purchase list
 
 * @param mail_capacity returns secondary cargo (mail) capacity of aircraft
 
 * @return Capacity
 
 */
 
uint Engine::DetermineCapacity(const Vehicle *v, uint16 *mail_capacity) const
 
{
 
	assert(v == NULL || this->index == v->engine_type);
 
	if (mail_capacity != NULL) *mail_capacity = 0;
 
	assert(v == nullptr || this->index == v->engine_type);
 
	if (mail_capacity != nullptr) *mail_capacity = 0;
 

	
 
	if (!this->CanCarryCargo()) return 0;
 

	
 
	bool new_multipliers = HasBit(this->info.misc_flags, EF_NO_DEFAULT_CARGO_MULTIPLIER);
 
	CargoID default_cargo = this->GetDefaultCargoType();
 
	CargoID cargo_type = (v != NULL) ? v->cargo_type : default_cargo;
 
	CargoID cargo_type = (v != nullptr) ? v->cargo_type : default_cargo;
 

	
 
	if (mail_capacity != NULL && this->type == VEH_AIRCRAFT && IsCargoInClass(cargo_type, CC_PASSENGERS)) {
 
	if (mail_capacity != nullptr && this->type == VEH_AIRCRAFT && IsCargoInClass(cargo_type, CC_PASSENGERS)) {
 
		*mail_capacity = GetEngineProperty(this->index, PROP_AIRCRAFT_MAIL_CAPACITY, this->u.air.mail_capacity, v);
 
	}
 

	
 
	/* Check the refit capacity callback if we are not in the default configuration, or if we are using the new multiplier algorithm. */
 
	if (HasBit(this->info.callback_mask, CBM_VEHICLE_REFIT_CAPACITY) &&
 
			(new_multipliers || default_cargo != cargo_type || (v != NULL && v->cargo_subtype != 0))) {
 
			(new_multipliers || default_cargo != cargo_type || (v != nullptr && v->cargo_subtype != 0))) {
 
		uint16 callback = GetVehicleCallback(CBID_VEHICLE_REFIT_CAPACITY, 0, 0, this->index, v);
 
		if (callback != CALLBACK_FAILED) return callback;
 
	}
 
@@ -233,7 +233,7 @@ uint Engine::DetermineCapacity(const Veh
 
			capacity = GetEngineProperty(this->index, PROP_TRAIN_CARGO_CAPACITY,        this->u.rail.capacity, v);
 

	
 
			/* In purchase list add the capacity of the second head. Always use the plain property for this. */
 
			if (v == NULL && this->u.rail.railveh_type == RAILVEH_MULTIHEAD) capacity += this->u.rail.capacity;
 
			if (v == nullptr && this->u.rail.railveh_type == RAILVEH_MULTIHEAD) capacity += this->u.rail.capacity;
 
			break;
 

	
 
		case VEH_ROAD:
 
@@ -869,7 +869,7 @@ void ClearEnginesHiddenFlagOfCompany(Com
 
CommandCost CmdSetVehicleVisibility(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	Engine *e = Engine::GetIfValid(GB(p2, 0, 31));
 
	if (e == NULL || _current_company >= MAX_COMPANIES) return CMD_ERROR;
 
	if (e == nullptr || _current_company >= MAX_COMPANIES) return CMD_ERROR;
 
	if (!IsEngineBuildable(e->index, e->type, _current_company)) return CMD_ERROR;
 

	
 
	if ((flags & DC_EXEC) != 0) {
 
@@ -893,7 +893,7 @@ CommandCost CmdSetVehicleVisibility(Tile
 
CommandCost CmdWantEnginePreview(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	Engine *e = Engine::GetIfValid(p1);
 
	if (e == NULL || !(e->flags & ENGINE_EXCLUSIVE_PREVIEW) || e->preview_company != _current_company) return CMD_ERROR;
 
	if (e == nullptr || !(e->flags & ENGINE_EXCLUSIVE_PREVIEW) || e->preview_company != _current_company) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) AcceptEnginePreview(p1, _current_company);
 

	
 
@@ -1021,7 +1021,7 @@ static bool IsUniqueEngineName(const cha
 
	const Engine *e;
 

	
 
	FOR_ALL_ENGINES(e) {
 
		if (e->name != NULL && strcmp(e->name, name) == 0) return false;
 
		if (e->name != nullptr && strcmp(e->name, name) == 0) return false;
 
	}
 

	
 
	return true;
 
@@ -1039,7 +1039,7 @@ static bool IsUniqueEngineName(const cha
 
CommandCost CmdRenameEngine(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	Engine *e = Engine::GetIfValid(p1);
 
	if (e == NULL) return CMD_ERROR;
 
	if (e == nullptr) return CMD_ERROR;
 

	
 
	bool reset = StrEmpty(text);
 

	
 
@@ -1052,7 +1052,7 @@ CommandCost CmdRenameEngine(TileIndex ti
 
		free(e->name);
 

	
 
		if (reset) {
 
			e->name = NULL;
 
			e->name = nullptr;
 
		} else {
 
			e->name = stredup(text);
 
		}
 
@@ -1077,7 +1077,7 @@ bool IsEngineBuildable(EngineID engine, 
 
	const Engine *e = Engine::GetIfValid(engine);
 

	
 
	/* check if it's an engine that is in the engine array */
 
	if (e == NULL) return false;
 
	if (e == nullptr) return false;
 

	
 
	/* check if it's an engine of specified type */
 
	if (e->type != type) return false;
 
@@ -1113,7 +1113,7 @@ bool IsEngineRefittable(EngineID engine)
 
	const Engine *e = Engine::GetIfValid(engine);
 

	
 
	/* check if it's an engine that is in the engine array */
 
	if (e == NULL) return false;
 
	if (e == nullptr) return false;
 

	
 
	if (!e->CanCarryCargo()) return false;
 

	
src/engine_base.h
Show inline comments
 
@@ -83,7 +83,7 @@ struct Engine : EnginePool::PoolItem<&_e
 
		return this->info.cargo_type;
 
	}
 

	
 
	uint DetermineCapacity(const Vehicle *v, uint16 *mail_capacity = NULL) const;
 
	uint DetermineCapacity(const Vehicle *v, uint16 *mail_capacity = nullptr) const;
 

	
 
	bool CanCarryCargo() const;
 

	
 
@@ -98,9 +98,9 @@ struct Engine : EnginePool::PoolItem<&_e
 
	 * @return The default capacity
 
	 * @see GetDefaultCargoType
 
	 */
 
	uint GetDisplayDefaultCapacity(uint16 *mail_capacity = NULL) const
 
	uint GetDisplayDefaultCapacity(uint16 *mail_capacity = nullptr) const
 
	{
 
		return this->DetermineCapacity(NULL, mail_capacity);
 
		return this->DetermineCapacity(nullptr, mail_capacity);
 
	}
 

	
 
	Money GetRunningCost() const;
src/error.h
Show inline comments
 
@@ -43,7 +43,7 @@ protected:
 
public:
 
	ErrorMessageData(const ErrorMessageData &data);
 
	~ErrorMessageData();
 
	ErrorMessageData(StringID summary_msg, StringID detailed_msg, uint duration = 0, int x = 0, int y = 0, const GRFFile *textref_stack_grffile = NULL, uint textref_stack_size = 0, const uint32 *textref_stack = NULL);
 
	ErrorMessageData(StringID summary_msg, StringID detailed_msg, uint duration = 0, int x = 0, int y = 0, const GRFFile *textref_stack_grffile = nullptr, uint textref_stack_size = 0, const uint32 *textref_stack = nullptr);
 

	
 
	/** Check whether error window shall display a company manager face */
 
	bool HasFace() const { return face != INVALID_COMPANY; }
 
@@ -56,7 +56,7 @@ public:
 

	
 
void ScheduleErrorMessage(const ErrorMessageData &data);
 

	
 
void ShowErrorMessage(StringID summary_msg, StringID detailed_msg, WarningLevel wl, int x = 0, int y = 0, const GRFFile *textref_stack_grffile = NULL, uint textref_stack_size = 0, const uint32 *textref_stack = NULL);
 
void ShowErrorMessage(StringID summary_msg, StringID detailed_msg, WarningLevel wl, int x = 0, int y = 0, const GRFFile *textref_stack_grffile = nullptr, uint textref_stack_size = 0, const uint32 *textref_stack = nullptr);
 
void ClearErrorMessages();
 
void ShowFirstError();
 
void UnshowCriticalError();
src/error_gui.cpp
Show inline comments
 
@@ -76,7 +76,7 @@ ErrorMessageData::ErrorMessageData(const
 
{
 
	*this = data;
 
	for (size_t i = 0; i < lengthof(this->strings); i++) {
 
		if (this->strings[i] != NULL) {
 
		if (this->strings[i] != nullptr) {
 
			this->strings[i] = stredup(this->strings[i]);
 
			this->decode_params[i] = (size_t)this->strings[i];
 
		}
 
@@ -357,7 +357,7 @@ void ShowFirstError()
 
void UnshowCriticalError()
 
{
 
	ErrmsgWindow *w = (ErrmsgWindow*)FindWindowById(WC_ERRMSG, 0);
 
	if (_window_system_initialized && w != NULL) {
 
	if (_window_system_initialized && w != nullptr) {
 
		if (w->IsCritical()) _error_list.push_front(*w);
 
		_window_system_initialized = false;
 
		delete w;
 
@@ -377,7 +377,7 @@ void UnshowCriticalError()
 
 */
 
void ShowErrorMessage(StringID summary_msg, StringID detailed_msg, WarningLevel wl, int x, int y, const GRFFile *textref_stack_grffile, uint textref_stack_size, const uint32 *textref_stack)
 
{
 
	assert(textref_stack_size == 0 || (textref_stack_grffile != NULL && textref_stack != NULL));
 
	assert(textref_stack_size == 0 || (textref_stack_grffile != nullptr && textref_stack != nullptr));
 
	if (summary_msg == STR_NULL) summary_msg = STR_EMPTY;
 

	
 
	if (wl != WL_INFO) {
 
@@ -408,7 +408,7 @@ void ShowErrorMessage(StringID summary_m
 
	data.CopyOutDParams();
 

	
 
	ErrmsgWindow *w = (ErrmsgWindow*)FindWindowById(WC_ERRMSG, 0);
 
	if (w != NULL && w->IsCritical()) {
 
	if (w != nullptr && w->IsCritical()) {
 
		/* A critical error is currently shown. */
 
		if (wl == WL_CRITICAL) {
 
			/* Push another critical error in the queue of errors,
src/fileio.cpp
Show inline comments
 
@@ -99,7 +99,7 @@ void FioSeekTo(size_t pos, int mode)
 
static void FioRestoreFile(int slot)
 
{
 
	/* Do we still have the file open, or should we reopen it? */
 
	if (_fio.handles[slot] == NULL) {
 
	if (_fio.handles[slot] == nullptr) {
 
		DEBUG(misc, 6, "Restoring file '%s' in slot '%d' from disk", _fio.filenames[slot], slot);
 
		FioOpenFile(slot, _fio.filenames[slot]);
 
	}
 
@@ -120,7 +120,7 @@ void FioSeekToFile(uint8 slot, size_t po
 
	FioRestoreFile(slot);
 
#endif /* LIMITED_FDS */
 
	f = _fio.handles[slot];
 
	assert(f != NULL);
 
	assert(f != nullptr);
 
	_fio.cur_fh = f;
 
	_fio.filename = _fio.filenames[slot];
 
	FioSeekTo(pos, SEEK_SET);
 
@@ -196,13 +196,13 @@ void FioReadBlock(void *ptr, size_t size
 
 */
 
static inline void FioCloseFile(int slot)
 
{
 
	if (_fio.handles[slot] != NULL) {
 
	if (_fio.handles[slot] != nullptr) {
 
		fclose(_fio.handles[slot]);
 

	
 
		free(_fio.shortnames[slot]);
 
		_fio.shortnames[slot] = NULL;
 
		_fio.shortnames[slot] = nullptr;
 

	
 
		_fio.handles[slot] = NULL;
 
		_fio.handles[slot] = nullptr;
 
#if defined(LIMITED_FDS)
 
		_fio.open_handles--;
 
#endif /* LIMITED_FDS */
 
@@ -229,7 +229,7 @@ static void FioFreeHandle()
 
		slot = -1;
 
		/* Find the file that is used the least */
 
		for (i = 0; i < lengthof(_fio.handles); i++) {
 
			if (_fio.handles[i] != NULL && _fio.usage_count[i] < count) {
 
			if (_fio.handles[i] != nullptr && _fio.usage_count[i] < count) {
 
				count = _fio.usage_count[i];
 
				slot  = i;
 
			}
 
@@ -255,7 +255,7 @@ void FioOpenFile(int slot, const char *f
 
	FioFreeHandle();
 
#endif /* LIMITED_FDS */
 
	f = FioFOpenFile(filename, "rb", subdir);
 
	if (f == NULL) usererror("Cannot open file '%s'", filename);
 
	if (f == nullptr) usererror("Cannot open file '%s'", filename);
 
	long pos = ftell(f);
 
	if (pos < 0) usererror("Cannot read file '%s'", filename);
 

	
 
@@ -265,9 +265,9 @@ void FioOpenFile(int slot, const char *f
 

	
 
	/* Store the filename without path and extension */
 
	const char *t = strrchr(filename, PATHSEPCHAR);
 
	_fio.shortnames[slot] = stredup(t == NULL ? filename : t);
 
	_fio.shortnames[slot] = stredup(t == nullptr ? filename : t);
 
	char *t2 = strrchr(_fio.shortnames[slot], '.');
 
	if (t2 != NULL) *t2 = '\0';
 
	if (t2 != nullptr) *t2 = '\0';
 
	strtolower(_fio.shortnames[slot]);
 

	
 
#if defined(LIMITED_FDS)
 
@@ -312,7 +312,7 @@ static TarLinkList _tar_linklist[NUM_SUB
 
bool FioCheckFileExists(const char *filename, Subdirectory subdir)
 
{
 
	FILE *f = FioFOpenFile(filename, "rb", subdir);
 
	if (f == NULL) return false;
 
	if (f == nullptr) return false;
 

	
 
	FioFCloseFile(f);
 
	return true;
 
@@ -351,7 +351,7 @@ char *FioGetFullPath(char *buf, const ch
 
 * @param last End of the destination buffer.
 
 * @param subdir Subdirectory to try.
 
 * @param filename Filename to look for.
 
 * @return \a buf containing the path if the path was found, else \c NULL.
 
 * @return \a buf containing the path if the path was found, else \c nullptr.
 
 */
 
char *FioFindFullPath(char *buf, const char *last, Subdirectory subdir, const char *filename)
 
{
 
@@ -369,7 +369,7 @@ char *FioFindFullPath(char *buf, const c
 
#endif
 
	}
 

	
 
	return NULL;
 
	return nullptr;
 
}
 

	
 
char *FioAppendDirectory(char *buf, const char *last, Searchpath sp, Subdirectory subdir)
 
@@ -407,7 +407,7 @@ static FILE *FioFOpenFileSp(const char *
 
	wchar_t Lmode[5];
 
	MultiByteToWideChar(CP_ACP, 0, mode, -1, Lmode, lengthof(Lmode));
 
#endif
 
	FILE *f = NULL;
 
	FILE *f = nullptr;
 
	char buf[MAX_PATH];
 

	
 
	if (subdir == NO_DIRECTORY) {
 
@@ -417,16 +417,16 @@ static FILE *FioFOpenFileSp(const char *
 
	}
 

	
 
#if defined(_WIN32)
 
	if (mode[0] == 'r' && GetFileAttributes(OTTD2FS(buf)) == INVALID_FILE_ATTRIBUTES) return NULL;
 
	if (mode[0] == 'r' && GetFileAttributes(OTTD2FS(buf)) == INVALID_FILE_ATTRIBUTES) return nullptr;
 
#endif
 

	
 
	f = fopen(buf, mode);
 
#if !defined(_WIN32)
 
	if (f == NULL && strtolower(buf + ((subdir == NO_DIRECTORY) ? 0 : strlen(_searchpaths[sp]) - 1))) {
 
	if (f == nullptr && strtolower(buf + ((subdir == NO_DIRECTORY) ? 0 : strlen(_searchpaths[sp]) - 1))) {
 
		f = fopen(buf, mode);
 
	}
 
#endif
 
	if (f != NULL && filesize != NULL) {
 
	if (f != nullptr && filesize != nullptr) {
 
		/* Find the size of the file */
 
		fseek(f, 0, SEEK_END);
 
		*filesize = ftell(f);
 
@@ -438,21 +438,21 @@ static FILE *FioFOpenFileSp(const char *
 
/**
 
 * Opens a file from inside a tar archive.
 
 * @param entry The entry to open.
 
 * @param[out] filesize If not \c NULL, size of the opened file.
 
 * @return File handle of the opened file, or \c NULL if the file is not available.
 
 * @param[out] filesize If not \c nullptr, size of the opened file.
 
 * @return File handle of the opened file, or \c nullptr if the file is not available.
 
 * @note The file is read from within the tar file, and may not return \c EOF after reading the whole file.
 
 */
 
FILE *FioFOpenFileTar(TarFileListEntry *entry, size_t *filesize)
 
{
 
	FILE *f = fopen(entry->tar_filename, "rb");
 
	if (f == NULL) return f;
 
	if (f == nullptr) return f;
 

	
 
	if (fseek(f, entry->position, SEEK_SET) < 0) {
 
		fclose(f);
 
		return NULL;
 
		return nullptr;
 
	}
 

	
 
	if (filesize != NULL) *filesize = entry->size;
 
	if (filesize != nullptr) *filesize = entry->size;
 
	return f;
 
}
 

	
 
@@ -460,22 +460,22 @@ FILE *FioFOpenFileTar(TarFileListEntry *
 
 * Opens a OpenTTD file somewhere in a personal or global directory.
 
 * @param filename Name of the file to open.
 
 * @param subdir Subdirectory to open.
 
 * @return File handle of the opened file, or \c NULL if the file is not available.
 
 * @return File handle of the opened file, or \c nullptr if the file is not available.
 
 */
 
FILE *FioFOpenFile(const char *filename, const char *mode, Subdirectory subdir, size_t *filesize)
 
{
 
	FILE *f = NULL;
 
	FILE *f = nullptr;
 
	Searchpath sp;
 

	
 
	assert(subdir < NUM_SUBDIRS || subdir == NO_DIRECTORY);
 

	
 
	FOR_ALL_SEARCHPATHS(sp) {
 
		f = FioFOpenFileSp(filename, mode, sp, subdir, filesize);
 
		if (f != NULL || subdir == NO_DIRECTORY) break;
 
		if (f != nullptr || subdir == NO_DIRECTORY) break;
 
	}
 

	
 
	/* We can only use .tar in case of data-dir, and read-mode */
 
	if (f == NULL && mode[0] == 'r' && subdir != NO_DIRECTORY) {
 
	if (f == nullptr && mode[0] == 'r' && subdir != NO_DIRECTORY) {
 
		static const uint MAX_RESOLVED_LENGTH = 2 * (100 + 100 + 155) + 1; // Enough space to hold two filenames plus link. See 'TarHeader'.
 
		char resolved_name[MAX_RESOLVED_LENGTH];
 

	
 
@@ -508,11 +508,11 @@ FILE *FioFOpenFile(const char *filename,
 

	
 
	/* Sometimes a full path is given. To support
 
	 * the 'subdirectory' must be 'removed'. */
 
	if (f == NULL && subdir != NO_DIRECTORY) {
 
	if (f == nullptr && subdir != NO_DIRECTORY) {
 
		switch (subdir) {
 
			case BASESET_DIR:
 
				f = FioFOpenFile(filename, mode, OLD_GM_DIR, filesize);
 
				if (f != NULL) break;
 
				if (f != nullptr) break;
 
				FALLTHROUGH;
 
			case NEWGRF_DIR:
 
				f = FioFOpenFile(filename, mode, OLD_DATA_DIR, filesize);
 
@@ -536,7 +536,7 @@ void FioCreateDirectory(const char *name
 
	/* Ignore directory creation errors; they'll surface later on, and most
 
	 * of the time they are 'directory already exists' errors anyhow. */
 
#if defined(_WIN32)
 
	CreateDirectory(OTTD2FS(name), NULL);
 
	CreateDirectory(OTTD2FS(name), nullptr);
 
#elif defined(OS2) && !defined(__INNOTEK_LIBC__)
 
	mkdir(OTTD2FS(name));
 
#else
 
@@ -573,7 +573,7 @@ bool AppendPathSeparator(char *buf, cons
 
const char *FioTarFirstDir(const char *tarname, Subdirectory subdir)
 
{
 
	TarList::iterator it = _tar_list[subdir].find(tarname);
 
	if (it == _tar_list[subdir].end()) return NULL;
 
	if (it == _tar_list[subdir].end()) return nullptr;
 
	return (*it).second.dirname;
 
}
 

	
 
@@ -675,7 +675,7 @@ bool TarScanner::AddFile(Subdirectory sd
 
bool TarScanner::AddFile(const char *filename, size_t basepath_length, const char *tar_filename)
 
{
 
	/* No tar within tar. */
 
	assert(tar_filename == NULL);
 
	assert(tar_filename == nullptr);
 

	
 
	/* The TAR-header, repeated for every file */
 
	struct TarHeader {
 
@@ -708,11 +708,11 @@ bool TarScanner::AddFile(const char *fil
 
	 * a number of reasons we cannot open the file.
 
	 * Most common case is when we simply have not
 
	 * been given read access. */
 
	if (f == NULL) return false;
 
	if (f == nullptr) return false;
 

	
 
	const char *dupped_filename = stredup(filename);
 
	_tar_list[this->subdir][filename].filename = dupped_filename;
 
	_tar_list[this->subdir][filename].dirname = NULL;
 
	_tar_list[this->subdir][filename].dirname = nullptr;
 

	
 
	TarLinkList links; ///< Temporary list to collect links
 

	
 
@@ -801,13 +801,13 @@ bool TarScanner::AddFile(const char *fil
 
				 * Note: The destination of links must not contain any directory-links. */
 
				strecpy(dest, name, lastof(dest));
 
				char *destpos = strrchr(dest, PATHSEPCHAR);
 
				if (destpos == NULL) destpos = dest;
 
				if (destpos == nullptr) destpos = dest;
 
				*destpos = '\0';
 

	
 
				char *pos = link;
 
				while (*pos != '\0') {
 
					char *next = strchr(pos, PATHSEPCHAR);
 
					if (next == NULL) {
 
					if (next == nullptr) {
 
						next = pos + strlen(pos);
 
					} else {
 
						/* Terminate the substring up to the path separator character. */
 
@@ -826,7 +826,7 @@ bool TarScanner::AddFile(const char *fil
 
						/* Truncate 'dest' after last PATHSEPCHAR.
 
						 * This assumes that the truncated part is a real directory and not a link. */
 
						destpos = strrchr(dest, PATHSEPCHAR);
 
						if (destpos == NULL) destpos = dest;
 
						if (destpos == nullptr) destpos = dest;
 
						*destpos = '\0';
 
					} else {
 
						/* Append at end of 'dest' */
 
@@ -856,7 +856,7 @@ bool TarScanner::AddFile(const char *fil
 

	
 
				/* Store the first directory name we detect */
 
				DEBUG(misc, 6, "Found dir in tar: %s", name);
 
				if (_tar_list[this->subdir][filename].dirname == NULL) _tar_list[this->subdir][filename].dirname = stredup(name);
 
				if (_tar_list[this->subdir][filename].dirname == nullptr) _tar_list[this->subdir][filename].dirname = stredup(name);
 
				break;
 

	
 
			default:
 
@@ -911,13 +911,13 @@ bool ExtractTar(const char *tar_filename
 
	const char *dirname = (*it).second.dirname;
 

	
 
	/* The file doesn't have a sub directory! */
 
	if (dirname == NULL) return false;
 
	if (dirname == nullptr) return false;
 

	
 
	char filename[MAX_PATH];
 
	strecpy(filename, tar_filename, lastof(filename));
 
	char *p = strrchr(filename, PATHSEPCHAR);
 
	/* The file's path does not have a separator? */
 
	if (p == NULL) return false;
 
	if (p == nullptr) return false;
 

	
 
	p++;
 
	strecpy(p, dirname, lastof(filename));
 
@@ -934,14 +934,14 @@ bool ExtractTar(const char *tar_filename
 
		/* First open the file in the .tar. */
 
		size_t to_copy = 0;
 
		FILE *in = FioFOpenFileTar(&(*it2).second, &to_copy);
 
		if (in == NULL) {
 
		if (in == nullptr) {
 
			DEBUG(misc, 6, "Extracting %s failed; could not open %s", filename, tar_filename);
 
			return false;
 
		}
 

	
 
		/* Now open the 'output' file. */
 
		FILE *out = fopen(filename, "wb");
 
		if (out == NULL) {
 
		if (out == nullptr) {
 
			DEBUG(misc, 6, "Extracting %s failed; could not open %s", filename, filename);
 
			fclose(in);
 
			return false;
 
@@ -993,12 +993,12 @@ static bool ChangeWorkingDirectoryToExec
 
	bool success = false;
 
#ifdef WITH_COCOA
 
	char *app_bundle = strchr(tmp, '.');
 
	while (app_bundle != NULL && strncasecmp(app_bundle, ".app", 4) != 0) app_bundle = strchr(&app_bundle[1], '.');
 
	while (app_bundle != nullptr && strncasecmp(app_bundle, ".app", 4) != 0) app_bundle = strchr(&app_bundle[1], '.');
 

	
 
	if (app_bundle != NULL) *app_bundle = '\0';
 
	if (app_bundle != nullptr) *app_bundle = '\0';
 
#endif /* WITH_COCOA */
 
	char *s = strrchr(tmp, PATHSEPCHAR);
 
	if (s != NULL) {
 
	if (s != nullptr) {
 
		*s = '\0';
 
		if (chdir(tmp) != 0) {
 
			DEBUG(misc, 0, "Directory with the binary does not exist?");
 
@@ -1022,13 +1022,13 @@ static bool ChangeWorkingDirectoryToExec
 
bool DoScanWorkingDirectory()
 
{
 
	/* No working directory, so nothing to do. */
 
	if (_searchpaths[SP_WORKING_DIR] == NULL) return false;
 
	if (_searchpaths[SP_WORKING_DIR] == nullptr) return false;
 

	
 
	/* Working directory is root, so do nothing. */
 
	if (strcmp(_searchpaths[SP_WORKING_DIR], PATHSEP) == 0) return false;
 

	
 
	/* No personal/home directory, so the working directory won't be that. */
 
	if (_searchpaths[SP_PERSONAL_DIR] == NULL) return true;
 
	if (_searchpaths[SP_PERSONAL_DIR] == nullptr) return true;
 

	
 
	char tmp[MAX_PATH];
 
	seprintf(tmp, lastof(tmp), "%s%s", _searchpaths[SP_WORKING_DIR], PERSONAL_DIR);
 
@@ -1044,7 +1044,7 @@ void DetermineBasePaths(const char *exe)
 
{
 
	char tmp[MAX_PATH];
 
#if defined(WITH_XDG_BASEDIR) && defined(WITH_PERSONAL_DIR)
 
	const char *xdg_data_home = xdgDataHome(NULL);
 
	const char *xdg_data_home = xdgDataHome(nullptr);
 
	seprintf(tmp, lastof(tmp), "%s" PATHSEP "%s", xdg_data_home,
 
			PERSONAL_DIR[0] == '.' ? &PERSONAL_DIR[1] : PERSONAL_DIR);
 
	free(xdg_data_home);
 
@@ -1053,7 +1053,7 @@ void DetermineBasePaths(const char *exe)
 
	_searchpaths[SP_PERSONAL_DIR_XDG] = stredup(tmp);
 
#endif
 
#if defined(OS2) || !defined(WITH_PERSONAL_DIR)
 
	_searchpaths[SP_PERSONAL_DIR] = NULL;
 
	_searchpaths[SP_PERSONAL_DIR] = nullptr;
 
#else
 
#ifdef __HAIKU__
 
	BPath path;
 
@@ -1065,17 +1065,17 @@ void DetermineBasePaths(const char *exe)
 
	 * variables in any way. It can also contain all kinds of
 
	 * unvalidated data we rather not want internally. */
 
	const char *homedir = getenv("HOME");
 
	if (homedir != NULL) {
 
	if (homedir != nullptr) {
 
		homedir = stredup(homedir);
 
	}
 

	
 
	if (homedir == NULL) {
 
	if (homedir == nullptr) {
 
		const struct passwd *pw = getpwuid(getuid());
 
		homedir = (pw == NULL) ? NULL : stredup(pw->pw_dir);
 
		homedir = (pw == nullptr) ? nullptr : stredup(pw->pw_dir);
 
	}
 
#endif
 

	
 
	if (homedir != NULL) {
 
	if (homedir != nullptr) {
 
		ValidateString(homedir);
 
		seprintf(tmp, lastof(tmp), "%s" PATHSEP "%s", homedir, PERSONAL_DIR);
 
		AppendPathSeparator(tmp, lastof(tmp));
 
@@ -1083,7 +1083,7 @@ void DetermineBasePaths(const char *exe)
 
		_searchpaths[SP_PERSONAL_DIR] = stredup(tmp);
 
		free(homedir);
 
	} else {
 
		_searchpaths[SP_PERSONAL_DIR] = NULL;
 
		_searchpaths[SP_PERSONAL_DIR] = nullptr;
 
	}
 
#endif
 

	
 
@@ -1092,10 +1092,10 @@ void DetermineBasePaths(const char *exe)
 
	AppendPathSeparator(tmp, lastof(tmp));
 
	_searchpaths[SP_SHARED_DIR] = stredup(tmp);
 
#else
 
	_searchpaths[SP_SHARED_DIR] = NULL;
 
	_searchpaths[SP_SHARED_DIR] = nullptr;
 
#endif
 

	
 
	if (getcwd(tmp, MAX_PATH) == NULL) *tmp = '\0';
 
	if (getcwd(tmp, MAX_PATH) == nullptr) *tmp = '\0';
 
	AppendPathSeparator(tmp, lastof(tmp));
 
	_searchpaths[SP_WORKING_DIR] = stredup(tmp);
 

	
 
@@ -1103,14 +1103,14 @@ void DetermineBasePaths(const char *exe)
 

	
 
	/* Change the working directory to that one of the executable */
 
	if (ChangeWorkingDirectoryToExecutable(exe)) {
 
		if (getcwd(tmp, MAX_PATH) == NULL) *tmp = '\0';
 
		if (getcwd(tmp, MAX_PATH) == nullptr) *tmp = '\0';
 
		AppendPathSeparator(tmp, lastof(tmp));
 
		_searchpaths[SP_BINARY_DIR] = stredup(tmp);
 
	} else {
 
		_searchpaths[SP_BINARY_DIR] = NULL;
 
		_searchpaths[SP_BINARY_DIR] = nullptr;
 
	}
 

	
 
	if (_searchpaths[SP_WORKING_DIR] != NULL) {
 
	if (_searchpaths[SP_WORKING_DIR] != nullptr) {
 
		/* Go back to the current working directory. */
 
		if (chdir(_searchpaths[SP_WORKING_DIR]) != 0) {
 
			DEBUG(misc, 0, "Failed to return to working directory!");
 
@@ -1118,7 +1118,7 @@ void DetermineBasePaths(const char *exe)
 
	}
 

	
 
#if !defined(GLOBAL_DATA_DIR)
 
	_searchpaths[SP_INSTALLATION_DIR] = NULL;
 
	_searchpaths[SP_INSTALLATION_DIR] = nullptr;
 
#else
 
	seprintf(tmp, lastof(tmp), "%s", GLOBAL_DATA_DIR);
 
	AppendPathSeparator(tmp, lastof(tmp));
 
@@ -1128,7 +1128,7 @@ void DetermineBasePaths(const char *exe)
 
extern void cocoaSetApplicationBundleDir();
 
	cocoaSetApplicationBundleDir();
 
#else
 
	_searchpaths[SP_APPLICATION_BUNDLE_DIR] = NULL;
 
	_searchpaths[SP_APPLICATION_BUNDLE_DIR] = nullptr;
 
#endif
 
}
 
#endif /* defined(_WIN32) */
 
@@ -1148,7 +1148,7 @@ void DeterminePaths(const char *exe)
 
#if defined(WITH_XDG_BASEDIR) && defined(WITH_PERSONAL_DIR)
 
	char config_home[MAX_PATH];
 

	
 
	const char *xdg_config_home = xdgConfigHome(NULL);
 
	const char *xdg_config_home = xdgConfigHome(nullptr);
 
	seprintf(config_home, lastof(config_home), "%s" PATHSEP "%s", xdg_config_home,
 
			PERSONAL_DIR[0] == '.' ? &PERSONAL_DIR[1] : PERSONAL_DIR);
 
	free(xdg_config_home);
 
@@ -1163,19 +1163,19 @@ void DeterminePaths(const char *exe)
 
	}
 

	
 
	char *config_dir;
 
	if (_config_file != NULL) {
 
	if (_config_file != nullptr) {
 
		config_dir = stredup(_config_file);
 
		char *end = strrchr(config_dir, PATHSEPCHAR);
 
		if (end == NULL) {
 
		if (end == nullptr) {
 
			config_dir[0] = '\0';
 
		} else {
 
			end[1] = '\0';
 
		}
 
	} else {
 
		char personal_dir[MAX_PATH];
 
		if (FioFindFullPath(personal_dir, lastof(personal_dir), BASE_DIR, "openttd.cfg") != NULL) {
 
		if (FioFindFullPath(personal_dir, lastof(personal_dir), BASE_DIR, "openttd.cfg") != nullptr) {
 
			char *end = strrchr(personal_dir, PATHSEPCHAR);
 
			if (end != NULL) end[1] = '\0';
 
			if (end != nullptr) end[1] = '\0';
 
			config_dir = stredup(personal_dir);
 
			_config_file = str_fmt("%sopenttd.cfg", config_dir);
 
		} else {
 
@@ -1187,14 +1187,14 @@ void DeterminePaths(const char *exe)
 
					SP_PERSONAL_DIR, SP_BINARY_DIR, SP_WORKING_DIR, SP_SHARED_DIR, SP_INSTALLATION_DIR
 
				};
 

	
 
			config_dir = NULL;
 
			config_dir = nullptr;
 
			for (uint i = 0; i < lengthof(new_openttd_cfg_order); i++) {
 
				if (IsValidSearchPath(new_openttd_cfg_order[i])) {
 
					config_dir = stredup(_searchpaths[new_openttd_cfg_order[i]]);
 
					break;
 
				}
 
			}
 
			assert(config_dir != NULL);
 
			assert(config_dir != nullptr);
 
#endif
 
			_config_file = str_fmt("%sopenttd.cfg", config_dir);
 
		}
 
@@ -1277,27 +1277,27 @@ void SanitizeFilename(char *filename)
 
 * @param filename Name of the file to load.
 
 * @param[out] lenp Length of loaded data.
 
 * @param maxsize Maximum size to load.
 
 * @return Pointer to new memory containing the loaded data, or \c NULL if loading failed.
 
 * @return Pointer to new memory containing the loaded data, or \c nullptr if loading failed.
 
 * @note If \a maxsize less than the length of the file, loading fails.
 
 */
 
void *ReadFileToMem(const char *filename, size_t *lenp, size_t maxsize)
 
{
 
	FILE *in = fopen(filename, "rb");
 
	if (in == NULL) return NULL;
 
	if (in == nullptr) return nullptr;
 

	
 
	fseek(in, 0, SEEK_END);
 
	size_t len = ftell(in);
 
	fseek(in, 0, SEEK_SET);
 
	if (len > maxsize) {
 
		fclose(in);
 
		return NULL;
 
		return nullptr;
 
	}
 
	byte *mem = MallocT<byte>(len + 1);
 
	mem[len] = 0;
 
	if (fread(mem, len, 1, in) != 1) {
 
		fclose(in);
 
		free(mem);
 
		return NULL;
 
		return nullptr;
 
	}
 
	fclose(in);
 

	
 
@@ -1309,14 +1309,14 @@ void *ReadFileToMem(const char *filename
 
 * Helper to see whether a given filename matches the extension.
 
 * @param extension The extension to look for.
 
 * @param filename  The filename to look in for the extension.
 
 * @return True iff the extension is NULL, or the filename ends with it.
 
 * @return True iff the extension is nullptr, or the filename ends with it.
 
 */
 
static bool MatchesExtension(const char *extension, const char *filename)
 
{
 
	if (extension == NULL) return true;
 
	if (extension == nullptr) return true;
 

	
 
	const char *ext = strrchr(filename, extension[0]);
 
	return ext != NULL && strcasecmp(ext, extension) == 0;
 
	return ext != nullptr && strcasecmp(ext, extension) == 0;
 
}
 

	
 
/**
 
@@ -1337,9 +1337,9 @@ static uint ScanPath(FileScanner *fs, co
 
	struct dirent *dirent;
 
	DIR *dir;
 

	
 
	if (path == NULL || (dir = ttd_opendir(path)) == NULL) return 0;
 
	if (path == nullptr || (dir = ttd_opendir(path)) == nullptr) return 0;
 

	
 
	while ((dirent = readdir(dir)) != NULL) {
 
	while ((dirent = readdir(dir)) != nullptr) {
 
		const char *d_name = FS2OTTD(dirent->d_name);
 
		char filename[MAX_PATH];
 

	
 
@@ -1355,7 +1355,7 @@ static uint ScanPath(FileScanner *fs, co
 
			num += ScanPath(fs, extension, filename, basepath_length, recursive);
 
		} else if (S_ISREG(sb.st_mode)) {
 
			/* File */
 
			if (MatchesExtension(extension, filename) && fs->AddFile(filename, basepath_length, NULL)) num++;
 
			if (MatchesExtension(extension, filename) && fs->AddFile(filename, basepath_length, nullptr)) num++;
 
		}
 
	}
 

	
src/fileio_func.h
Show inline comments
 
@@ -30,7 +30,7 @@ void FioSkipBytes(int n);
 
/**
 
 * The search paths OpenTTD could search through.
 
 * At least one of the slots has to be filled with a path.
 
 * NULL paths tell that there is no such path for the
 
 * nullptr paths tell that there is no such path for the
 
 * current operating system.
 
 */
 
extern const char *_searchpaths[NUM_SEARCHPATHS];
 
@@ -42,14 +42,14 @@ extern const char *_searchpaths[NUM_SEAR
 
 */
 
static inline bool IsValidSearchPath(Searchpath sp)
 
{
 
	return sp < NUM_SEARCHPATHS && _searchpaths[sp] != NULL;
 
	return sp < NUM_SEARCHPATHS && _searchpaths[sp] != nullptr;
 
}
 

	
 
/** Iterator for all the search paths */
 
#define FOR_ALL_SEARCHPATHS(sp) for (sp = SP_FIRST_DIR; sp < NUM_SEARCHPATHS; sp++) if (IsValidSearchPath(sp))
 

	
 
void FioFCloseFile(FILE *f);
 
FILE *FioFOpenFile(const char *filename, const char *mode, Subdirectory subdir, size_t *filesize = NULL);
 
FILE *FioFOpenFile(const char *filename, const char *mode, Subdirectory subdir, size_t *filesize = nullptr);
 
bool FioCheckFileExists(const char *filename, Subdirectory subdir);
 
char *FioGetFullPath(char *buf, const char *last, Searchpath sp, Subdirectory subdir, const char *filename);
 
char *FioFindFullPath(char *buf, const char *last, Subdirectory subdir, const char *filename);
 
@@ -107,7 +107,7 @@ public:
 
		ALL      = BASESET | NEWGRF | AI | SCENARIO | GAME, ///< Scan for everything.
 
	};
 

	
 
	bool AddFile(const char *filename, size_t basepath_length, const char *tar_filename = NULL) override;
 
	bool AddFile(const char *filename, size_t basepath_length, const char *tar_filename = nullptr) override;
 

	
 
	bool AddFile(Subdirectory sd, const char *filename);
 

	
src/fios.cpp
Show inline comments
 
@@ -105,7 +105,7 @@ void FileList::BuildFileList(AbstractFil
 
 * Find file information of a file by its name from the file list.
 
 * @param file The filename to return information about. Can be the actual name
 
 *             or a numbered entry into the filename list.
 
 * @return The information on the file, or \c NULL if the file is not available.
 
 * @return The information on the file, or \c nullptr if the file is not available.
 
 */
 
const FiosItem *FileList::FindItem(const char *file)
 
{
 
@@ -130,14 +130,14 @@ const FiosItem *FileList::FindItem(const
 
		if (strcmp(long_file, item->title) == 0) return item;
 
	}
 

	
 
	return NULL;
 
	return nullptr;
 
}
 

	
 
/**
 
 * Get descriptive texts. Returns the path and free space
 
 * left on the device
 
 * @param path string describing the path
 
 * @param total_free total free space in megabytes, optional (can be NULL)
 
 * @param total_free total free space in megabytes, optional (can be nullptr)
 
 * @return StringID describing the path (free space or failure)
 
 */
 
StringID FiosGetDescText(const char **path, uint64 *total_free)
 
@@ -149,7 +149,7 @@ StringID FiosGetDescText(const char **pa
 
/**
 
 * Browse to a new path based on the passed \a item, starting at #_fios_path.
 
 * @param *item Item telling us what to do.
 
 * @return A filename w/path if we reached a file, otherwise \c NULL.
 
 * @return A filename w/path if we reached a file, otherwise \c nullptr.
 
 */
 
const char *FiosBrowseTo(const FiosItem *item)
 
{
 
@@ -164,13 +164,13 @@ const char *FiosBrowseTo(const FiosItem 
 
			break;
 

	
 
		case FIOS_TYPE_PARENT: {
 
			/* Check for possible NULL ptr */
 
			/* Check for possible nullptr ptr */
 
			char *s = strrchr(_fios_path, PATHSEPCHAR);
 
			if (s != NULL && s != _fios_path) {
 
			if (s != nullptr && s != _fios_path) {
 
				s[0] = '\0'; // Remove last path separator character, so we can go up one level.
 
			}
 
			s = strrchr(_fios_path, PATHSEPCHAR);
 
			if (s != NULL) {
 
			if (s != nullptr) {
 
				s[1] = '\0'; // go up a directory
 
			}
 
			break;
 
@@ -194,13 +194,13 @@ const char *FiosBrowseTo(const FiosItem 
 
			return item->name;
 
	}
 

	
 
	return NULL;
 
	return nullptr;
 
}
 

	
 
/**
 
 * Construct a filename from its components in destination buffer \a buf.
 
 * @param buf Destination buffer.
 
 * @param path Directory path, may be \c NULL.
 
 * @param path Directory path, may be \c nullptr.
 
 * @param name Filename.
 
 * @param ext Filename extension (use \c "" for no extension).
 
 * @param last Last element of buffer \a buf.
 
@@ -211,7 +211,7 @@ static void FiosMakeFilename(char *buf, 
 

	
 
	/* Don't append the extension if it is already there */
 
	period = strrchr(name, '.');
 
	if (period != NULL && strcasecmp(period, ext) == 0) ext = "";
 
	if (period != nullptr && strcasecmp(period, ext) == 0) ext = "";
 
	seprintf(buf, last, "%s" PATHSEP "%s%s", path, name, ext);
 
}
 

	
 
@@ -288,7 +288,7 @@ public:
 
bool FiosFileScanner::AddFile(const char *filename, size_t basepath_length, const char *tar_filename)
 
{
 
	const char *ext = strrchr(filename, '.');
 
	if (ext == NULL) return false;
 
	if (ext == nullptr) return false;
 

	
 
	char fios_title[64];
 
	fios_title[0] = '\0'; // reset the title;
 
@@ -320,7 +320,7 @@ bool FiosFileScanner::AddFile(const char
 
	const char *t = fios_title;
 
	if (StrEmpty(fios_title)) {
 
		t = strrchr(filename, PATHSEPCHAR);
 
		t = (t == NULL) ? filename : (t + 1);
 
		t = (t == nullptr) ? filename : (t + 1);
 
	}
 
	strecpy(fios->title, t, lastof(fios->title));
 
	str_validate(fios->title, lastof(fios->title));
 
@@ -357,8 +357,8 @@ static void FiosGetFileList(SaveLoadOper
 
	}
 

	
 
	/* Show subdirectories */
 
	if ((dir = ttd_opendir(_fios_path)) != NULL) {
 
		while ((dirent = readdir(dir)) != NULL) {
 
	if ((dir = ttd_opendir(_fios_path)) != nullptr) {
 
		while ((dirent = readdir(dir)) != nullptr) {
 
			strecpy(d_name, FS2OTTD(dirent->d_name), lastof(d_name));
 

	
 
			/* found file must be directory, but not '.' or '..' */
 
@@ -390,9 +390,9 @@ static void FiosGetFileList(SaveLoadOper
 
	/* Show files */
 
	FiosFileScanner scanner(fop, callback_proc, file_list);
 
	if (subdir == NO_DIRECTORY) {
 
		scanner.Scan(NULL, _fios_path, false);
 
		scanner.Scan(nullptr, _fios_path, false);
 
	} else {
 
		scanner.Scan(NULL, subdir, true, true);
 
		scanner.Scan(nullptr, subdir, true, true);
 
	}
 

	
 
	QSortT(file_list.Get(sort_start), file_list.Length() - sort_start, CompareFiosItems);
 
@@ -418,7 +418,7 @@ static void GetFileTitle(const char *fil
 
	strecat(buf, ".title", lastof(buf));
 

	
 
	FILE *f = FioFOpenFile(buf, "r", subdir);
 
	if (f == NULL) return;
 
	if (f == nullptr) return;
 

	
 
	size_t read = fread(title, 1, last - title, f);
 
	assert(title + read <= last);
 
@@ -432,8 +432,8 @@ static void GetFileTitle(const char *fil
 
 * @param fop Purpose of collecting the list.
 
 * @param file Name of the file to check.
 
 * @param ext A pointer to the extension identifier inside file
 
 * @param title Buffer if a callback wants to lookup the title of the file; NULL to skip the lookup
 
 * @param last Last available byte in buffer (to prevent buffer overflows); not used when title == NULL
 
 * @param title Buffer if a callback wants to lookup the title of the file; nullptr to skip the lookup
 
 * @param last Last available byte in buffer (to prevent buffer overflows); not used when title == nullptr
 
 * @return a FIOS_TYPE_* type of the found file, FIOS_TYPE_INVALID if not a savegame
 
 * @see FiosGetFileList
 
 * @see FiosGetSavegameList
 
@@ -447,7 +447,7 @@ FiosType FiosGetSavegameListCallback(Sav
 
	 * .SV2 Transport Tycoon Deluxe (Patch) saved 2-player game */
 

	
 
	/* Don't crash if we supply no extension */
 
	if (ext == NULL) return FIOS_TYPE_INVALID;
 
	if (ext == nullptr) return FIOS_TYPE_INVALID;
 

	
 
	if (strcasecmp(ext, ".sav") == 0) {
 
		GetFileTitle(file, title, last, SAVE_DIR);
 
@@ -457,7 +457,7 @@ FiosType FiosGetSavegameListCallback(Sav
 
	if (fop == SLO_LOAD) {
 
		if (strcasecmp(ext, ".ss1") == 0 || strcasecmp(ext, ".sv1") == 0 ||
 
				strcasecmp(ext, ".sv2") == 0) {
 
			if (title != NULL) GetOldSaveGameName(file, title, last);
 
			if (title != nullptr) GetOldSaveGameName(file, title, last);
 
			return FIOS_TYPE_OLDFILE;
 
		}
 
	}
 
@@ -473,10 +473,10 @@ FiosType FiosGetSavegameListCallback(Sav
 
 */
 
void FiosGetSavegameList(SaveLoadOperation fop, FileList &file_list)
 
{
 
	static char *fios_save_path = NULL;
 
	static char *fios_save_path_last = NULL;
 
	static char *fios_save_path = nullptr;
 
	static char *fios_save_path_last = nullptr;
 

	
 
	if (fios_save_path == NULL) {
 
	if (fios_save_path == nullptr) {
 
		fios_save_path = MallocT<char>(MAX_PATH);
 
		fios_save_path_last = fios_save_path + MAX_PATH - 1;
 
		FioGetDirectory(fios_save_path, fios_save_path_last, SAVE_DIR);
 
@@ -528,11 +528,11 @@ static FiosType FiosGetScenarioListCallb
 
 */
 
void FiosGetScenarioList(SaveLoadOperation fop, FileList &file_list)
 
{
 
	static char *fios_scn_path = NULL;
 
	static char *fios_scn_path_last = NULL;
 
	static char *fios_scn_path = nullptr;
 
	static char *fios_scn_path_last = nullptr;
 

	
 
	/* Copy the default path on first run or on 'New Game' */
 
	if (fios_scn_path == NULL) {
 
	if (fios_scn_path == nullptr) {
 
		fios_scn_path = MallocT<char>(MAX_PATH);
 
		fios_scn_path_last = fios_scn_path + MAX_PATH - 1;
 
		FioGetDirectory(fios_scn_path, fios_scn_path_last, SCENARIO_DIR);
 
@@ -599,10 +599,10 @@ static FiosType FiosGetHeightmapListCall
 
 */
 
void FiosGetHeightmapList(SaveLoadOperation fop, FileList &file_list)
 
{
 
	static char *fios_hmap_path = NULL;
 
	static char *fios_hmap_path_last = NULL;
 
	static char *fios_hmap_path = nullptr;
 
	static char *fios_hmap_path_last = nullptr;
 

	
 
	if (fios_hmap_path == NULL) {
 
	if (fios_hmap_path == nullptr) {
 
		fios_hmap_path = MallocT<char>(MAX_PATH);
 
		fios_hmap_path_last = fios_hmap_path + MAX_PATH - 1;
 
		FioGetDirectory(fios_hmap_path, fios_hmap_path_last, HEIGHTMAP_DIR);
 
@@ -624,9 +624,9 @@ void FiosGetHeightmapList(SaveLoadOperat
 
 */
 
const char *FiosGetScreenshotDir()
 
{
 
	static char *fios_screenshot_path = NULL;
 
	static char *fios_screenshot_path = nullptr;
 

	
 
	if (fios_screenshot_path == NULL) {
 
	if (fios_screenshot_path == nullptr) {
 
		fios_screenshot_path = MallocT<char>(MAX_PATH);
 
		FioGetDirectory(fios_screenshot_path, fios_screenshot_path + MAX_PATH - 1, SCREENSHOT_DIR);
 
	}
 
@@ -676,7 +676,7 @@ public:
 
	bool AddFile(const char *filename, size_t basepath_length, const char *tar_filename) override
 
	{
 
		FILE *f = FioFOpenFile(filename, "r", SCENARIO_DIR);
 
		if (f == NULL) return false;
 
		if (f == nullptr) return false;
 

	
 
		ScenarioIdentifier id;
 
		int fret = fscanf(f, "%i", &id.scenid);
 
@@ -695,7 +695,7 @@ public:
 
		strecpy(basename, filename, lastof(basename));
 
		*strrchr(basename, '.') = '\0';
 
		f = FioFOpenFile(basename, "rb", SCENARIO_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) {
 
@@ -718,7 +718,7 @@ static ScenarioScanner _scanner;
 
 * Find a given scenario based on its unique ID.
 
 * @param ci The content info to compare it to.
 
 * @param md5sum Whether to look at the md5sum or the id.
 
 * @return The filename of the file, else \c NULL.
 
 * @return The filename of the file, else \c nullptr.
 
 */
 
const char *FindScenario(const ContentInfo *ci, bool md5sum)
 
{
 
@@ -731,7 +731,7 @@ const char *FindScenario(const ContentIn
 
		}
 
	}
 

	
 
	return NULL;
 
	return nullptr;
 
}
 

	
 
/**
 
@@ -742,7 +742,7 @@ const char *FindScenario(const ContentIn
 
 */
 
bool HasScenario(const ContentInfo *ci, bool md5sum)
 
{
 
	return (FindScenario(ci, md5sum) != NULL);
 
	return (FindScenario(ci, md5sum) != nullptr);
 
}
 

	
 
/**
src/fios.h
Show inline comments
 
@@ -48,8 +48,8 @@ struct LoadCheckData {
 
	struct LoggedAction *gamelog_action;          ///< Gamelog actions
 
	uint gamelog_actions;                         ///< Number of gamelog actions
 

	
 
	LoadCheckData() : error_data(NULL), grfconfig(NULL),
 
			grf_compatibility(GLC_NOT_FOUND), gamelog_action(NULL), gamelog_actions(0)
 
	LoadCheckData() : error_data(nullptr), grfconfig(nullptr),
 
			grf_compatibility(GLC_NOT_FOUND), gamelog_action(nullptr), gamelog_actions(0)
 
	{
 
		this->Clear();
 
	}
 
@@ -77,7 +77,7 @@ struct LoadCheckData {
 
	 */
 
	bool HasNewGrfs()
 
	{
 
		return this->checkable && this->error == INVALID_STRING_ID && this->grfconfig != NULL;
 
		return this->checkable && this->error == INVALID_STRING_ID && this->grfconfig != nullptr;
 
	}
 

	
 
	void Clear();
src/fios_gui.cpp
Show inline comments
 
@@ -51,7 +51,7 @@ void LoadCheckData::Clear()
 
	this->checkable = false;
 
	this->error = INVALID_STRING_ID;
 
	free(this->error_data);
 
	this->error_data = NULL;
 
	this->error_data = nullptr;
 

	
 
	this->map_size_x = this->map_size_y = 256; // Default for old savegames which do not store mapsize.
 
	this->current_date = 0;
 
@@ -63,7 +63,7 @@ void LoadCheckData::Clear()
 
	companies.clear();
 

	
 
	GamelogFree(this->gamelog_action, this->gamelog_actions);
 
	this->gamelog_action = NULL;
 
	this->gamelog_action = nullptr;
 
	this->gamelog_actions = 0;
 

	
 
	ClearGRFConfigList(&this->grfconfig);
 
@@ -273,7 +273,7 @@ private:
 
	SaveLoadOperation fop;        ///< File operation to perform.
 
	FileList fios_items;          ///< Save game list.
 
	FiosItem o_dir;
 
	const FiosItem *selected;     ///< Selected game in #fios_items, or \c NULL.
 
	const FiosItem *selected;     ///< Selected game in #fios_items, or \c nullptr.
 
	Scrollbar *vscroll;
 

	
 
	StringFilter string_filter; ///< Filter for available games.
 
@@ -417,7 +417,7 @@ public:
 
				break;
 

	
 
			case WID_SL_BACKGROUND: {
 
				static const char *path = NULL;
 
				static const char *path = nullptr;
 
				static StringID str = STR_ERROR_UNABLE_TO_READ_DRIVE;
 
				static uint64 tot = 0;
 

	
 
@@ -461,7 +461,7 @@ public:
 
						r.right - WD_FRAMERECT_RIGHT, r.top + FONT_HEIGHT_NORMAL * 2 + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM, PC_GREY);
 
				DrawString(r.left, r.right, r.top + FONT_HEIGHT_NORMAL / 2 + WD_FRAMERECT_TOP, STR_SAVELOAD_DETAIL_CAPTION, TC_FROMSTRING, SA_HOR_CENTER);
 

	
 
				if (this->selected == NULL) break;
 
				if (this->selected == nullptr) break;
 

	
 
				uint y = r.top + FONT_HEIGHT_NORMAL * 2 + WD_PAR_VSEP_NORMAL + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
 
				uint y_max = r.bottom - FONT_HEIGHT_NORMAL - WD_FRAMERECT_BOTTOM;
 
@@ -517,7 +517,7 @@ public:
 
						if (y > y_max) break;
 

	
 
						/* NewGrf compatibility */
 
						SetDParam(0, _load_check_data.grfconfig == NULL ? STR_NEWGRF_LIST_NONE :
 
						SetDParam(0, _load_check_data.grfconfig == nullptr ? STR_NEWGRF_LIST_NONE :
 
								STR_NEWGRF_LIST_ALL_FOUND + _load_check_data.grf_compatibility);
 
						DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_SAVELOAD_DETAIL_GRFSTATUS);
 
						y += FONT_HEIGHT_NORMAL;
 
@@ -533,7 +533,7 @@ public:
 
						for (auto &pair : _load_check_data.companies) {
 
							SetDParam(0, pair.first + 1);
 
							const CompanyProperties &c = *pair.second;
 
							if (c.name != NULL) {
 
							if (c.name != nullptr) {
 
								SetDParam(1, STR_JUST_RAW_STRING);
 
								SetDParamStr(2, c.name);
 
							} else {
 
@@ -607,7 +607,7 @@ public:
 
				break;
 

	
 
			case WID_SL_LOAD_BUTTON:
 
				if (this->selected != NULL && !_load_check_data.HasErrors()) {
 
				if (this->selected != nullptr && !_load_check_data.HasErrors()) {
 
					const char *name = FiosBrowseTo(this->selected);
 
					_file_to_saveload.SetMode(this->selected->type);
 
					_file_to_saveload.SetName(name);
 
@@ -652,7 +652,7 @@ public:
 
				const FiosItem *file = this->fios_items.Get(y);
 

	
 
				const char *name = FiosBrowseTo(file);
 
				if (name != NULL) {
 
				if (name != nullptr) {
 
					if (click_count == 1) {
 
						if (this->selected != file) {
 
							this->selected = file;
 
@@ -700,8 +700,8 @@ public:
 
					assert(this->fop == SLO_LOAD);
 
					switch (this->abstract_filetype) {
 
						default: NOT_REACHED();
 
						case FT_SCENARIO:  ShowNetworkContentListWindow(NULL, CONTENT_TYPE_SCENARIO);  break;
 
						case FT_HEIGHTMAP: ShowNetworkContentListWindow(NULL, CONTENT_TYPE_HEIGHTMAP); break;
 
						case FT_SCENARIO:  ShowNetworkContentListWindow(nullptr, CONTENT_TYPE_SCENARIO);  break;
 
						case FT_HEIGHTMAP: ShowNetworkContentListWindow(nullptr, CONTENT_TYPE_HEIGHTMAP); break;
 
					}
 
				}
 
				break;
 
@@ -776,14 +776,14 @@ public:
 
		switch (data) {
 
			case SLIWD_RESCAN_FILES:
 
				/* Rescan files */
 
				this->selected = NULL;
 
				this->selected = nullptr;
 
				_load_check_data.Clear();
 
				if (!gui_scope) break;
 

	
 
				_fios_path_changed = true;
 
				this->fios_items.BuildFileList(this->abstract_filetype, this->fop);
 
				this->vscroll->SetCount((uint)this->fios_items.Length());
 
				this->selected = NULL;
 
				this->selected = nullptr;
 
				_load_check_data.Clear();
 

	
 
				/* We reset the files filtered */
 
@@ -799,12 +799,12 @@ public:
 

	
 
				switch (this->abstract_filetype) {
 
					case FT_HEIGHTMAP:
 
						this->SetWidgetDisabledState(WID_SL_LOAD_BUTTON, this->selected == NULL || _load_check_data.HasErrors());
 
						this->SetWidgetDisabledState(WID_SL_LOAD_BUTTON, this->selected == nullptr || _load_check_data.HasErrors());
 
						break;
 

	
 
					case FT_SAVEGAME:
 
					case FT_SCENARIO: {
 
						bool disabled = this->selected == NULL || _load_check_data.HasErrors();
 
						bool disabled = this->selected == nullptr || _load_check_data.HasErrors();
 
						if (!_settings_client.gui.UserIsAllowedToChangeNewGRFs()) {
 
							disabled |= _load_check_data.HasNewGrfs() && _load_check_data.grf_compatibility == GLC_NOT_FOUND;
 
						}
 
@@ -839,7 +839,7 @@ public:
 

	
 
						if (&(this->fios_items[i]) == this->selected && this->fios_items_shown[i] == false) {
 
							/* The selected element has been filtered out */
 
							this->selected = NULL;
 
							this->selected = nullptr;
 
							this->OnInvalidateData(SLIWD_SELECTION_CHANGES);
 
						}
 
					}
src/fontcache.cpp
Show inline comments
 
@@ -41,7 +41,7 @@ FontCache::FontCache(FontSize fs) : pare
 
		ascender(_default_font_ascender[fs]), descender(_default_font_ascender[fs] - _default_font_height[fs]),
 
		units_per_em(1)
 
{
 
	assert(this->parent == NULL || this->fs == this->parent->fs);
 
	assert(this->parent == nullptr || this->fs == this->parent->fs);
 
	FontCache::caches[this->fs] = this;
 
	Layouter::ResetFontCache(this->fs);
 
}
 
@@ -84,7 +84,7 @@ public:
 
	virtual int GetHeight() const;
 
	virtual bool GetDrawGlyphShadow();
 
	virtual GlyphID MapCharToGlyph(WChar key) { assert(IsPrintable(key)); return SPRITE_GLYPH | key; }
 
	virtual const void *GetFontTable(uint32 tag, size_t &length) { length = 0; return NULL; }
 
	virtual const void *GetFontTable(uint32 tag, size_t &length) { length = 0; return nullptr; }
 
	virtual const char *GetFontName() { return "sprite"; }
 
	virtual bool IsBuiltInFont() { return true; }
 
};
 
@@ -93,7 +93,7 @@ public:
 
 * Create a new sprite font cache.
 
 * @param fs The font size to create the cache for.
 
 */
 
SpriteFontCache::SpriteFontCache(FontSize fs) : FontCache(fs), glyph_to_spriteid_map(NULL)
 
SpriteFontCache::SpriteFontCache(FontSize fs) : FontCache(fs), glyph_to_spriteid_map(nullptr)
 
{
 
	this->InitializeUnicodeGlyphMap();
 
}
 
@@ -108,14 +108,14 @@ SpriteFontCache::~SpriteFontCache()
 

	
 
SpriteID SpriteFontCache::GetUnicodeGlyph(GlyphID key)
 
{
 
	if (this->glyph_to_spriteid_map[GB(key, 8, 8)] == NULL) return 0;
 
	if (this->glyph_to_spriteid_map[GB(key, 8, 8)] == nullptr) return 0;
 
	return this->glyph_to_spriteid_map[GB(key, 8, 8)][GB(key, 0, 8)];
 
}
 

	
 
void SpriteFontCache::SetUnicodeGlyph(GlyphID key, SpriteID sprite)
 
{
 
	if (this->glyph_to_spriteid_map == NULL) this->glyph_to_spriteid_map = CallocT<SpriteID*>(256);
 
	if (this->glyph_to_spriteid_map[GB(key, 8, 8)] == NULL) this->glyph_to_spriteid_map[GB(key, 8, 8)] = CallocT<SpriteID>(256);
 
	if (this->glyph_to_spriteid_map == nullptr) this->glyph_to_spriteid_map = CallocT<SpriteID*>(256);
 
	if (this->glyph_to_spriteid_map[GB(key, 8, 8)] == nullptr) this->glyph_to_spriteid_map[GB(key, 8, 8)] = CallocT<SpriteID>(256);
 
	this->glyph_to_spriteid_map[GB(key, 8, 8)][GB(key, 0, 8)] = sprite;
 
}
 

	
 
@@ -159,13 +159,13 @@ void SpriteFontCache::InitializeUnicodeG
 
 */
 
void SpriteFontCache::ClearGlyphToSpriteMap()
 
{
 
	if (this->glyph_to_spriteid_map == NULL) return;
 
	if (this->glyph_to_spriteid_map == nullptr) return;
 

	
 
	for (uint i = 0; i < 256; i++) {
 
		free(this->glyph_to_spriteid_map[i]);
 
	}
 
	free(this->glyph_to_spriteid_map);
 
	this->glyph_to_spriteid_map = NULL;
 
	this->glyph_to_spriteid_map = nullptr;
 
}
 

	
 
void SpriteFontCache::ClearFontCache()
 
@@ -258,7 +258,7 @@ public:
 
	virtual bool IsBuiltInFont() { return false; }
 
};
 

	
 
FT_Library _library = NULL;
 
FT_Library _library = nullptr;
 

	
 
FreeTypeSettings _freetype;
 

	
 
@@ -271,9 +271,9 @@ static const byte SHADOW_COLOUR = 2;
 
 * @param face   The font that has to be loaded.
 
 * @param pixels The number of pixels this font should be high.
 
 */
 
FreeTypeFontCache::FreeTypeFontCache(FontSize fs, FT_Face face, int pixels) : FontCache(fs), face(face), req_size(pixels), glyph_to_sprite(NULL)
 
FreeTypeFontCache::FreeTypeFontCache(FontSize fs, FT_Face face, int pixels) : FontCache(fs), face(face), req_size(pixels), glyph_to_sprite(nullptr)
 
{
 
	assert(face != NULL);
 
	assert(face != nullptr);
 

	
 
	this->SetFontSize(fs, face, pixels);
 
}
 
@@ -286,7 +286,7 @@ void FreeTypeFontCache::SetFontSize(Font
 
		pixels = scaled_height;
 

	
 
		TT_Header *head = (TT_Header *)FT_Get_Sfnt_Table(this->face, ft_sfnt_head);
 
		if (head != NULL) {
 
		if (head != nullptr) {
 
			/* Font height is minimum height plus the difference between the default
 
			 * height for this font size and the small size. */
 
			int diff = scaled_height - ScaleFontTrad(_default_font_height[FS_SMALL]);
 
@@ -338,7 +338,7 @@ void FreeTypeFontCache::SetFontSize(Font
 
 */
 
static void LoadFreeTypeFont(FontSize fs)
 
{
 
	FreeTypeSubSetting *settings = NULL;
 
	FreeTypeSubSetting *settings = nullptr;
 
	switch (fs) {
 
		default: NOT_REACHED();
 
		case FS_SMALL:  settings = &_freetype.small;  break;
 
@@ -349,7 +349,7 @@ static void LoadFreeTypeFont(FontSize fs
 

	
 
	if (StrEmpty(settings->font)) return;
 

	
 
	if (_library == NULL) {
 
	if (_library == nullptr) {
 
		if (FT_Init_FreeType(&_library) != FT_Err_Ok) {
 
			ShowInfoF("Unable to initialize FreeType, using sprite fonts instead");
 
			return;
 
@@ -358,7 +358,7 @@ static void LoadFreeTypeFont(FontSize fs
 
		DEBUG(freetype, 2, "Initialized");
 
	}
 

	
 
	FT_Face face = NULL;
 
	FT_Face face = nullptr;
 
	FT_Error error = FT_New_Face(_library, settings->font, 0, &face);
 

	
 
	if (error != FT_Err_Ok) error = GetFontByFaceName(settings->font, &face);
 
@@ -384,7 +384,7 @@ static void LoadFreeTypeFont(FontSize fs
 
				}
 
			}
 

	
 
			if (found != NULL) {
 
			if (found != nullptr) {
 
				error = FT_Set_Charmap(face, found);
 
				if (error == FT_Err_Ok) goto found_face;
 
			}
 
@@ -408,7 +408,7 @@ found_face:
 
FreeTypeFontCache::~FreeTypeFontCache()
 
{
 
	FT_Done_Face(this->face);
 
	this->face = NULL;
 
	this->face = nullptr;
 
	this->ClearFontCache();
 

	
 
	for (auto &iter : this->font_tables) {
 
@@ -422,12 +422,12 @@ FreeTypeFontCache::~FreeTypeFontCache()
 
void FreeTypeFontCache::ClearFontCache()
 
{
 
	/* Font scaling might have changed, determine font size anew if it was automatically selected. */
 
	if (this->face != NULL) this->SetFontSize(this->fs, this->face, this->req_size);
 
	if (this->face != nullptr) this->SetFontSize(this->fs, this->face, this->req_size);
 

	
 
	if (this->glyph_to_sprite == NULL) return;
 
	if (this->glyph_to_sprite == nullptr) return;
 

	
 
	for (int i = 0; i < 256; i++) {
 
		if (this->glyph_to_sprite[i] == NULL) continue;
 
		if (this->glyph_to_sprite[i] == nullptr) continue;
 

	
 
		for (int j = 0; j < 256; j++) {
 
			if (this->glyph_to_sprite[i][j].duplicate) continue;
 
@@ -438,27 +438,27 @@ void FreeTypeFontCache::ClearFontCache()
 
	}
 

	
 
	free(this->glyph_to_sprite);
 
	this->glyph_to_sprite = NULL;
 
	this->glyph_to_sprite = nullptr;
 

	
 
	Layouter::ResetFontCache(this->fs);
 
}
 

	
 
FreeTypeFontCache::GlyphEntry *FreeTypeFontCache::GetGlyphPtr(GlyphID key)
 
{
 
	if (this->glyph_to_sprite == NULL) return NULL;
 
	if (this->glyph_to_sprite[GB(key, 8, 8)] == NULL) return NULL;
 
	if (this->glyph_to_sprite == nullptr) return nullptr;
 
	if (this->glyph_to_sprite[GB(key, 8, 8)] == nullptr) return nullptr;
 
	return &this->glyph_to_sprite[GB(key, 8, 8)][GB(key, 0, 8)];
 
}
 

	
 

	
 
void FreeTypeFontCache::SetGlyphPtr(GlyphID key, const GlyphEntry *glyph, bool duplicate)
 
{
 
	if (this->glyph_to_sprite == NULL) {
 
	if (this->glyph_to_sprite == nullptr) {
 
		DEBUG(freetype, 3, "Allocating root glyph cache for size %u", this->fs);
 
		this->glyph_to_sprite = CallocT<GlyphEntry*>(256);
 
	}
 

	
 
	if (this->glyph_to_sprite[GB(key, 8, 8)] == NULL) {
 
	if (this->glyph_to_sprite[GB(key, 8, 8)] == nullptr) {
 
		DEBUG(freetype, 3, "Allocating glyph cache for range 0x%02X00, size %u", GB(key, 8, 8), this->fs);
 
		this->glyph_to_sprite[GB(key, 8, 8)] = CallocT<GlyphEntry>(256);
 
	}
 
@@ -497,7 +497,7 @@ const Sprite *FreeTypeFontCache::GetGlyp
 

	
 
	/* Check for the glyph in our cache */
 
	GlyphEntry *glyph = this->GetGlyphPtr(key);
 
	if (glyph != NULL && glyph->sprite != NULL) return glyph->sprite;
 
	if (glyph != nullptr && glyph->sprite != nullptr) return glyph->sprite;
 

	
 
	FT_GlyphSlot slot = this->face->glyph;
 

	
 
@@ -535,7 +535,7 @@ const Sprite *FreeTypeFontCache::GetGlyp
 
			};
 

	
 
			Sprite *spr = BlitterFactory::GetCurrentBlitter()->Encode(&builtin_questionmark, AllocateFont);
 
			assert(spr != NULL);
 
			assert(spr != nullptr);
 
			new_glyph.sprite = spr;
 
			new_glyph.width  = spr->width + (this->fs != FS_NORMAL);
 
			this->SetGlyphPtr(key, &new_glyph, false);
 
@@ -611,7 +611,7 @@ uint FreeTypeFontCache::GetGlyphWidth(Gl
 
	if ((key & SPRITE_GLYPH) != 0) return this->parent->GetGlyphWidth(key);
 

	
 
	GlyphEntry *glyph = this->GetGlyphPtr(key);
 
	if (glyph == NULL || glyph->sprite == NULL) {
 
	if (glyph == nullptr || glyph->sprite == nullptr) {
 
		this->GetGlyph(key);
 
		glyph = this->GetGlyphPtr(key);
 
	}
 
@@ -639,9 +639,9 @@ const void *FreeTypeFontCache::GetFontTa
 
	}
 

	
 
	FT_ULong len = 0;
 
	FT_Byte *result = NULL;
 
	FT_Byte *result = nullptr;
 

	
 
	FT_Load_Sfnt_Table(this->face, tag, 0, NULL, &len);
 
	FT_Load_Sfnt_Table(this->face, tag, 0, nullptr, &len);
 

	
 
	if (len > 0) {
 
		result = MallocT<FT_Byte>(len);
 
@@ -685,6 +685,6 @@ void UninitFreeType()
 

	
 
#ifdef WITH_FREETYPE
 
	FT_Done_FreeType(_library);
 
	_library = NULL;
 
	_library = nullptr;
 
#endif /* WITH_FREETYPE */
 
}
src/fontcache.h
Show inline comments
 
@@ -147,7 +147,7 @@ public:
 
	 */
 
	inline bool HasParent()
 
	{
 
		return this->parent != NULL;
 
		return this->parent != nullptr;
 
	}
 

	
 
	/**

Changeset was too big and was cut off... Show full diff anyway

0 comments (0 inline, 0 general)