(svn r23627) -Add: ScriptNews::Create, to create custom news messages (GameScript only)
parent
6961332f05
commit
09ef12ab03
@ -0,0 +1,46 @@
|
|||||||
|
/* $Id$ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* THIS FILE IS AUTO-GENERATED; PLEASE DO NOT ALTER MANUALLY */
|
||||||
|
|
||||||
|
#include "../script_news.hpp"
|
||||||
|
#include "../template/template_news.hpp.sq"
|
||||||
|
|
||||||
|
|
||||||
|
template <> const char *GetClassName<ScriptNews, ST_GS>() { return "GSNews"; }
|
||||||
|
|
||||||
|
void SQGSNews_Register(Squirrel *engine)
|
||||||
|
{
|
||||||
|
DefSQClass<ScriptNews, ST_GS> SQGSNews("GSNews");
|
||||||
|
SQGSNews.PreRegister(engine);
|
||||||
|
SQGSNews.AddConstructor<void (ScriptNews::*)(), 1>(engine, "x");
|
||||||
|
|
||||||
|
SQGSNews.DefSQConst(engine, ScriptNews::NT_ARRIVAL_COMPANY, "NT_ARRIVAL_COMPANY");
|
||||||
|
SQGSNews.DefSQConst(engine, ScriptNews::NT_ARRIVAL_OTHER, "NT_ARRIVAL_OTHER");
|
||||||
|
SQGSNews.DefSQConst(engine, ScriptNews::NT_ACCIDENT, "NT_ACCIDENT");
|
||||||
|
SQGSNews.DefSQConst(engine, ScriptNews::NT_COMPANY_TROUBLE, "NT_COMPANY_TROUBLE");
|
||||||
|
SQGSNews.DefSQConst(engine, ScriptNews::NT_COMPANY_MERGER, "NT_COMPANY_MERGER");
|
||||||
|
SQGSNews.DefSQConst(engine, ScriptNews::NT_COMPANY_BANKRUPT, "NT_COMPANY_BANKRUPT");
|
||||||
|
SQGSNews.DefSQConst(engine, ScriptNews::NT_COMPANY_NEW, "NT_COMPANY_NEW");
|
||||||
|
SQGSNews.DefSQConst(engine, ScriptNews::NT_INDUSTRY_OPEN, "NT_INDUSTRY_OPEN");
|
||||||
|
SQGSNews.DefSQConst(engine, ScriptNews::NT_INDUSTRY_CLOSE, "NT_INDUSTRY_CLOSE");
|
||||||
|
SQGSNews.DefSQConst(engine, ScriptNews::NT_ECONOMY, "NT_ECONOMY");
|
||||||
|
SQGSNews.DefSQConst(engine, ScriptNews::NT_INDUSTRY_COMPANY, "NT_INDUSTRY_COMPANY");
|
||||||
|
SQGSNews.DefSQConst(engine, ScriptNews::NT_INDUSTRY_OTHER, "NT_INDUSTRY_OTHER");
|
||||||
|
SQGSNews.DefSQConst(engine, ScriptNews::NT_INDUSTRY_NOBODY, "NT_INDUSTRY_NOBODY");
|
||||||
|
SQGSNews.DefSQConst(engine, ScriptNews::NT_ADVICE, "NT_ADVICE");
|
||||||
|
SQGSNews.DefSQConst(engine, ScriptNews::NT_NEW_VEHICLES, "NT_NEW_VEHICLES");
|
||||||
|
SQGSNews.DefSQConst(engine, ScriptNews::NT_ACCEPTANCE, "NT_ACCEPTANCE");
|
||||||
|
SQGSNews.DefSQConst(engine, ScriptNews::NT_SUBSIDIES, "NT_SUBSIDIES");
|
||||||
|
SQGSNews.DefSQConst(engine, ScriptNews::NT_GENERAL, "NT_GENERAL");
|
||||||
|
|
||||||
|
SQGSNews.DefSQStaticMethod(engine, &ScriptNews::Create, "Create", 4, ".i.i");
|
||||||
|
|
||||||
|
SQGSNews.PostRegister(engine);
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
/* $Id$ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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_news.cpp Implementation of ScriptNews. */
|
||||||
|
|
||||||
|
#include "../../stdafx.h"
|
||||||
|
#include "script_news.hpp"
|
||||||
|
#include "script_error.hpp"
|
||||||
|
#include "../../news_func.h"
|
||||||
|
#include "../../strings_func.h"
|
||||||
|
#include "../../command_type.h"
|
||||||
|
#include "../../string_func.h"
|
||||||
|
#include "table/strings.h"
|
||||||
|
|
||||||
|
/* static */ bool ScriptNews::Create(NewsType type, const char *text, ScriptCompany::CompanyID company)
|
||||||
|
{
|
||||||
|
EnforcePrecondition(false, !StrEmpty(text));
|
||||||
|
EnforcePrecondition(false, type >= NT_ARRIVAL_COMPANY && type <= NT_GENERAL);
|
||||||
|
EnforcePrecondition(false, company == ScriptCompany::COMPANY_INVALID || ScriptCompany::ResolveCompanyID(company) != ScriptCompany::COMPANY_INVALID);
|
||||||
|
|
||||||
|
uint8 c = company;
|
||||||
|
if (company == ScriptCompany::COMPANY_INVALID) c = INVALID_COMPANY;
|
||||||
|
|
||||||
|
return ScriptObject::DoCommand(0, type | (NR_NONE << 8) | (c << 16), 0, CMD_CUSTOM_NEWS_ITEM, text);
|
||||||
|
}
|
@ -0,0 +1,61 @@
|
|||||||
|
/* $Id$ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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_news.hpp Everything to handle news messages. */
|
||||||
|
|
||||||
|
#ifndef SCRIPT_NEWS_HPP
|
||||||
|
#define SCRIPT_NEWS_HPP
|
||||||
|
|
||||||
|
#include "script_company.hpp"
|
||||||
|
#include "../../news_type.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class that handles news messages.
|
||||||
|
* @api game
|
||||||
|
*/
|
||||||
|
class ScriptNews : public ScriptObject {
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* Enumeration for corners of tiles.
|
||||||
|
*/
|
||||||
|
enum NewsType {
|
||||||
|
/* Note: these values represent part of the in-game NewsSubtype enum */
|
||||||
|
NT_ARRIVAL_COMPANY = ::NS_ARRIVAL_COMPANY, ///< Category arrival for own company.
|
||||||
|
NT_ARRIVAL_OTHER = ::NS_ARRIVAL_OTHER, ///< Category arrival for other companies.
|
||||||
|
NT_ACCIDENT = ::NS_ACCIDENT, ///< Category accident.
|
||||||
|
NT_COMPANY_TROUBLE = ::NS_COMPANY_TROUBLE, ///< Category company in trouble.
|
||||||
|
NT_COMPANY_MERGER = ::NS_COMPANY_MERGER, ///< Category company merger.
|
||||||
|
NT_COMPANY_BANKRUPT = ::NS_COMPANY_BANKRUPT, ///< Category company bankrupt.
|
||||||
|
NT_COMPANY_NEW = ::NS_COMPANY_NEW, ///< Category company new.
|
||||||
|
NT_INDUSTRY_OPEN = ::NS_INDUSTRY_OPEN, ///< Category industry open.
|
||||||
|
NT_INDUSTRY_CLOSE = ::NS_INDUSTRY_CLOSE, ///< Category industry close.
|
||||||
|
NT_ECONOMY = ::NS_ECONOMY, ///< Category economy.
|
||||||
|
NT_INDUSTRY_COMPANY = ::NS_INDUSTRY_COMPANY, ///< Category industry changes for own company.
|
||||||
|
NT_INDUSTRY_OTHER = ::NS_INDUSTRY_OTHER, ///< Category industry changes for other companies.
|
||||||
|
NT_INDUSTRY_NOBODY = ::NS_INDUSTRY_NOBODY, ///< Category industry changes for nobody.
|
||||||
|
NT_ADVICE = ::NS_ADVICE, ///< Category advice.
|
||||||
|
NT_NEW_VEHICLES = ::NS_NEW_VEHICLES, ///< Category new vehicle.
|
||||||
|
NT_ACCEPTANCE = ::NS_ACCEPTANCE, ///< Category acceptance changes.
|
||||||
|
NT_SUBSIDIES = ::NS_SUBSIDIES, ///< Category subsidies.
|
||||||
|
NT_GENERAL = ::NS_GENERAL, ///< Category general.
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a news messages for a company.
|
||||||
|
* @param type The type of the news.
|
||||||
|
* @param text The text message to show.
|
||||||
|
* @param company The company, or COMPANY_INVALID for all companies.
|
||||||
|
* @return True if the action succeeded.
|
||||||
|
* @pre text != NULL.
|
||||||
|
* @pre company == COMPANY_INVALID || ResolveCompanyID(company) != COMPANY_INVALID.
|
||||||
|
*/
|
||||||
|
static bool Create(NewsType type, const char *text, ScriptCompany::CompanyID company);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* SCRIPT_NEWS_HPP */
|
@ -0,0 +1,25 @@
|
|||||||
|
/* $Id$ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* THIS FILE IS AUTO-GENERATED; PLEASE DO NOT ALTER MANUALLY */
|
||||||
|
|
||||||
|
#include "../script_news.hpp"
|
||||||
|
|
||||||
|
namespace SQConvert {
|
||||||
|
/* Allow enums to be used as Squirrel parameters */
|
||||||
|
template <> inline ScriptNews::NewsType GetParam(ForceType<ScriptNews::NewsType>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return (ScriptNews::NewsType)tmp; }
|
||||||
|
template <> inline int Return<ScriptNews::NewsType>(HSQUIRRELVM vm, ScriptNews::NewsType res) { sq_pushinteger(vm, (int32)res); return 1; }
|
||||||
|
|
||||||
|
/* Allow ScriptNews to be used as Squirrel parameter */
|
||||||
|
template <> inline ScriptNews *GetParam(ForceType<ScriptNews *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (ScriptNews *)instance; }
|
||||||
|
template <> inline ScriptNews &GetParam(ForceType<ScriptNews &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(ScriptNews *)instance; }
|
||||||
|
template <> inline const ScriptNews *GetParam(ForceType<const ScriptNews *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (ScriptNews *)instance; }
|
||||||
|
template <> inline const ScriptNews &GetParam(ForceType<const ScriptNews &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(ScriptNews *)instance; }
|
||||||
|
template <> inline int Return<ScriptNews *>(HSQUIRRELVM vm, ScriptNews *res) { if (res == NULL) { sq_pushnull(vm); return 1; } res->AddRef(); Squirrel::CreateClassInstanceVM(vm, "News", res, NULL, DefSQDestructorCallback<ScriptNews>, true); return 1; }
|
||||||
|
} // namespace SQConvert
|
Loading…
Reference in New Issue