Files @ r28827:f131debacb19
Branch filter:

Location: cpp/openttd-patchpack/source/src/game/game_instance.cpp - annotation

Peter Nelson
Codechange: Use `GetVisibleRangeIterators()` in more places. (#12190)

This replaces more first/last index calculation, along with indexed array/vector access, with iterator access instead.
r18746:ffe36c655ceb
r18746:ffe36c655ceb
r18746:ffe36c655ceb
r18746:ffe36c655ceb
r18746:ffe36c655ceb
r18746:ffe36c655ceb
r18746:ffe36c655ceb
r18746:ffe36c655ceb
r18746:ffe36c655ceb
r18746:ffe36c655ceb
r18861:a0daedca90f7
r18746:ffe36c655ceb
r18746:ffe36c655ceb
r18746:ffe36c655ceb
r18746:ffe36c655ceb
r26123:a265ab51722a
r26856:c988753485d9
r18748:5e4b96072e2a
r18748:5e4b96072e2a
r18746:ffe36c655ceb
r18776:45400817a6df
r18746:ffe36c655ceb
r18746:ffe36c655ceb
r24326:510409fb8c32
r24326:510409fb8c32
r18746:ffe36c655ceb
r21383:942c32fb8b0e
r21383:942c32fb8b0e
r18746:ffe36c655ceb
r18746:ffe36c655ceb
r18746:ffe36c655ceb
r18746:ffe36c655ceb
r18746:ffe36c655ceb
r18748:5e4b96072e2a
r18746:ffe36c655ceb
r19539:8ff9f94e70e3
r19539:8ff9f94e70e3
r18746:ffe36c655ceb
r18746:ffe36c655ceb
r18746:ffe36c655ceb
r18774:2977cce7e239
r18746:ffe36c655ceb
r18746:ffe36c655ceb
r18746:ffe36c655ceb
r18746:ffe36c655ceb
r18746:ffe36c655ceb
r18746:ffe36c655ceb
r24326:510409fb8c32
r24326:510409fb8c32
r18746:ffe36c655ceb
r18776:45400817a6df
r19539:8ff9f94e70e3
r19539:8ff9f94e70e3
r18746:ffe36c655ceb
r18746:ffe36c655ceb
r27367:d55d6f0719f9
r18746:ffe36c655ceb
r18748:5e4b96072e2a
r18746:ffe36c655ceb
r18746:ffe36c655ceb
r27354:7a607c98c943
r18746:ffe36c655ceb
r18754:42d72cb83fe7
r18746:ffe36c655ceb
r18746:ffe36c655ceb
r18861:a0daedca90f7
r18861:a0daedca90f7
r18861:a0daedca90f7
r18861:a0daedca90f7
r28791:1f0e3e5e39e0
r28791:1f0e3e5e39e0
r28791:1f0e3e5e39e0
r26856:c988753485d9
r18861:a0daedca90f7
r18861:a0daedca90f7
r23607:36c15679007d
r18861:a0daedca90f7
r18861:a0daedca90f7
r27365:849bb90cdbff
r18861:a0daedca90f7
r18861:a0daedca90f7
r18861:a0daedca90f7
r18861:a0daedca90f7
r18861:a0daedca90f7
r18861:a0daedca90f7
r18746:ffe36c655ceb
r18746:ffe36c655ceb
r26104:2873b00a1dac
r18746:ffe36c655ceb
r26104:2873b00a1dac
r26123:a265ab51722a
r18746:ffe36c655ceb
r26907:b8856ea20ba4
r18746:ffe36c655ceb
r26907:b8856ea20ba4
r23818:7609f20f2104
r23818:7609f20f2104
r18746:ffe36c655ceb
r18746:ffe36c655ceb
r26122:02442b0744ee
r18746:ffe36c655ceb
r18746:ffe36c655ceb
r18746:ffe36c655ceb
/*
 * This file is part of OpenTTD.
 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
 */

/** @file game_instance.cpp Implementation of GameInstance. */

#include "../stdafx.h"
#include "../error.h"

#include "../script/squirrel_class.hpp"

#include "../script/script_storage.hpp"
#include "../script/script_cmd.h"
#include "../script/script_gui.h"
#include "game_config.hpp"
#include "game_info.hpp"
#include "game_instance.hpp"
#include "game_text.hpp"
#include "game.hpp"

/* Convert all Game related classes to Squirrel data. */
#include "../script/api/game/game_includes.hpp"

#include "../safeguards.h"


GameInstance::GameInstance() :
	ScriptInstance("GS")
{}

void GameInstance::Initialize(GameInfo *info)
{
	this->versionAPI = info->GetAPIVersion();

	/* Register the GameController */
	SQGSController_Register(this->engine);

	ScriptInstance::Initialize(info->GetMainScript(), info->GetInstanceName(), OWNER_DEITY);
}

void GameInstance::RegisterAPI()
{
	ScriptInstance::RegisterAPI();

	/* Register all classes */
	SQGS_RegisterAll(this->engine);

	RegisterGameTranslation(this->engine);

	if (!this->LoadCompatibilityScripts(this->versionAPI, GAME_DIR)) this->Died();
}

int GameInstance::GetSetting(const std::string &name)
{
	return GameConfig::GetConfig()->GetSetting(name);
}

ScriptInfo *GameInstance::FindLibrary(const std::string &library, int version)
{
	return (ScriptInfo *)Game::FindLibrary(library, version);
}

void GameInstance::Died()
{
	ScriptInstance::Died();

	/* Don't show errors while loading savegame. They will be shown at end of loading anyway. */
	if (_switch_mode != SM_NONE) return;

	ShowScriptDebugWindow(OWNER_DEITY);

	const GameInfo *info = Game::GetInfo();
	if (info != nullptr) {
		ShowErrorMessage(STR_ERROR_AI_PLEASE_REPORT_CRASH, INVALID_STRING_ID, WL_WARNING);

		if (!info->GetURL().empty()) {
			ScriptLog::Info("Please report the error to the following URL:");
			ScriptLog::Info(info->GetURL());
		}
	}
}

/**
 * DoCommand callback function for all commands executed by Game Scripts.
 * @param cmd cmd as given to DoCommandPInternal.
 * @param result The result of the command.
 * @param data Command data as given to Command<>::Post.
 * @param result_data Additional returned data from the command.
 */
void CcGame(Commands cmd, const CommandCost &result, const CommandDataBuffer &data, CommandDataBuffer result_data)
{
	if (Game::GetGameInstance()->DoCommandCallback(result, data, std::move(result_data), cmd)) {
		Game::GetGameInstance()->Continue();
	}
}

CommandCallbackData *GameInstance::GetDoCommandCallback()
{
	return &CcGame;
}