Changeset - r26967:ae6c19bd8920
[Not reviewed]
master
0 2 0
glx22 - 18 months ago 2023-02-10 16:37:18
glx@openttd.org
Codechange: Use SQInteger for generic numbers in script_companymode
2 files changed with 3 insertions and 3 deletions:
0 comments (0 inline, 0 general)
src/script/api/script_companymode.cpp
Show inline comments
 
/*
 
 * 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 script_companymode.cpp Implementation of ScriptCompanyMode. */
 

	
 
#include "../../stdafx.h"
 
#include "../../company_base.h"
 
#include "script_companymode.hpp"
 

	
 
#include "../../safeguards.h"
 

	
 
ScriptCompanyMode::ScriptCompanyMode(int company)
 
ScriptCompanyMode::ScriptCompanyMode(SQInteger company)
 
{
 
	if (company < OWNER_BEGIN || company >= MAX_COMPANIES) company = INVALID_COMPANY;
 
	if (!::Company::IsValidID(company)) company = INVALID_COMPANY;
 

	
 
	this->last_company = ScriptObject::GetCompany();
 
	ScriptObject::SetCompany((CompanyID)company);
 
	ScriptObject::SetCompany((::CompanyID)company);
 
}
 

	
 
ScriptCompanyMode::~ScriptCompanyMode()
 
{
 
	ScriptObject::SetCompany(this->last_company);
 
}
src/script/api/script_companymode.hpp
Show inline comments
 
@@ -19,34 +19,34 @@
 
 *  instance is destroyed.
 
 * All actions performed within the scope of this mode, will be executed
 
 *  on behalf of the company you switched to. This includes any costs
 
 *  attached to the action performed. If the company does not have the
 
 *  funds the action will be aborted. In other words, this is like the
 
 *  real player is executing the commands.
 
 * If the company is not valid during an action, the error
 
 *  ERR_PRECONDITION_INVALID_COMPANY will be returned. You can switch to
 
 *  invalid companies, or a company can become invalid (bankrupt) while you
 
 *  are switched to it.
 
 * @api game
 
 */
 
class ScriptCompanyMode : public ScriptObject {
 
private:
 
	CompanyID last_company; ///< The previous company we were in.
 

	
 
public:
 
	/**
 
	 * Creating instance of this class switches the company used for queries
 
	 *  and commands.
 
	 * @param company The new company to switch to.
 
	 * @note When the instance is destroyed, it restores the company that was
 
	 *   current when the instance was created!
 
	 */
 
	ScriptCompanyMode(int company);
 
	ScriptCompanyMode(SQInteger company);
 

	
 
	/**
 
	 * Destroying this instance reset the company to that what it was
 
	 *   in when the instance was created.
 
	 */
 
	~ScriptCompanyMode();
 
};
 

	
 
#endif /* SCRIPT_COMPANYMODE_HPP */
0 comments (0 inline, 0 general)