From 0143f486f29d1e72082bcb3ac6c1d16c695b09af Mon Sep 17 00:00:00 2001 From: alberth Date: Sun, 22 Feb 2015 17:25:29 +0000 Subject: (svn r27164) -Add: [NoGo] Game scripts can point to a location, station, industry, or town when publishing news. --- src/script/api/game/game_news.hpp.sq | 7 ++++++- src/script/api/game_changelog.hpp | 5 +++++ src/script/api/script_news.cpp | 14 ++++++++++++-- src/script/api/script_news.hpp | 25 +++++++++++++++++++++++-- src/script/api/template/template_news.hpp.sq | 2 ++ 5 files changed, 48 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/script/api/game/game_news.hpp.sq b/src/script/api/game/game_news.hpp.sq index 70416f6b7..3d7022e10 100644 --- a/src/script/api/game/game_news.hpp.sq +++ b/src/script/api/game/game_news.hpp.sq @@ -28,8 +28,13 @@ void SQGSNews_Register(Squirrel *engine) 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.DefSQConst(engine, ScriptNews::NR_NONE, "NR_NONE"); + SQGSNews.DefSQConst(engine, ScriptNews::NR_TILE, "NR_TILE"); + SQGSNews.DefSQConst(engine, ScriptNews::NR_STATION, "NR_STATION"); + SQGSNews.DefSQConst(engine, ScriptNews::NR_INDUSTRY, "NR_INDUSTRY"); + SQGSNews.DefSQConst(engine, ScriptNews::NR_TOWN, "NR_TOWN"); - SQGSNews.DefSQStaticMethod(engine, &ScriptNews::Create, "Create", 4, ".i.i"); + SQGSNews.DefSQStaticMethod(engine, &ScriptNews::Create, "Create", 6, ".i.iii"); SQGSNews.PostRegister(engine); } diff --git a/src/script/api/game_changelog.hpp b/src/script/api/game_changelog.hpp index 535284caa..8ff41f775 100644 --- a/src/script/api/game_changelog.hpp +++ b/src/script/api/game_changelog.hpp @@ -35,6 +35,11 @@ * \li GSStationList_CargoWaitingFromByVia * \li GSStationList_CargoWaitingViaByFrom * + * Other changes: + * \li GSNews::Create takes two extra parameters to refer to a location, station, + * industry, or town. The user can click at the news message to jump to the + * referred location. + * * \b 1.4.4 * * No changes diff --git a/src/script/api/script_news.cpp b/src/script/api/script_news.cpp index 8d808ff3c..5f84f96d6 100644 --- a/src/script/api/script_news.cpp +++ b/src/script/api/script_news.cpp @@ -11,13 +11,17 @@ #include "../../stdafx.h" #include "script_news.hpp" +#include "script_industry.hpp" +#include "script_station.hpp" +#include "script_map.hpp" +#include "script_town.hpp" #include "script_error.hpp" #include "../../command_type.h" #include "../../string_func.h" #include "../../safeguards.h" -/* static */ bool ScriptNews::Create(NewsType type, Text *text, ScriptCompany::CompanyID company) +/* static */ bool ScriptNews::Create(NewsType type, Text *text, ScriptCompany::CompanyID company, NewsReferenceType ref_type, uint32 reference) { CCountedPtr counter(text); @@ -26,9 +30,15 @@ EnforcePreconditionEncodedText(false, encoded); EnforcePrecondition(false, type == NT_ECONOMY || type == NT_SUBSIDIES || type == NT_GENERAL); EnforcePrecondition(false, company == ScriptCompany::COMPANY_INVALID || ScriptCompany::ResolveCompanyID(company) != ScriptCompany::COMPANY_INVALID); + EnforcePrecondition(false, (ref_type == NR_NONE) || + (ref_type == NR_TILE && ScriptMap::IsValidTile(reference)) || + (ref_type == NR_STATION && ScriptStation::IsValidStation(reference)) || + (ref_type == NR_INDUSTRY && ScriptIndustry::IsValidIndustry(reference)) || + (ref_type == NR_TOWN && ScriptTown::IsValidTown(reference))); 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, encoded); + if (ref_type == NR_NONE) reference = 0; + return ScriptObject::DoCommand(0, type | (ref_type << 8) | (c << 16), reference, CMD_CUSTOM_NEWS_ITEM, encoded); } diff --git a/src/script/api/script_news.hpp b/src/script/api/script_news.hpp index 8defa3a85..ca0656608 100644 --- a/src/script/api/script_news.hpp +++ b/src/script/api/script_news.hpp @@ -36,15 +36,36 @@ public: }; /** - * Create a news messages for a company. + * Reference to a game element. + */ + enum NewsReferenceType { + /* Selection of useful game elements to refer to. */ + NR_NONE = ::NR_NONE, ///< No reference supplied. + NR_TILE = ::NR_TILE, ///< Reference location, scroll to the location when clicking on the news. + NR_STATION = ::NR_STATION, ///< Reference station, scroll to the station when clicking on the news. Delete news when the station is deleted. + NR_INDUSTRY = ::NR_INDUSTRY, ///< Reference industry, scrolls to the industry when clicking on the news. Delete news when the industry is deleted. + NR_TOWN = ::NR_TOWN, ///< Reference town, scroll to the town when clicking on the news. + }; + + /** + * Create a news message for everybody, or for one company. * @param type The type of the news. * @param text The text message to show (can be either a raw string, or a ScriptText object). * @param company The company, or COMPANY_INVALID for all companies. + * @param ref_type Type of referred game element. + * @param reference The referenced game element of \a ref_type. + * - For #NR_NONE this parameter is ignored. + * - For #NR_TILE this parameter should be a valid location (ScriptMap::IsValidTile). + * - For #NR_STATION this parameter should be a valid stationID (ScriptStation::IsValidStation). + * - For #NR_INDUSTRY this parameter should be a valid industryID (ScriptIndustry::IsValidIndustry). + * - For #NR_TOWN this parameter should be a valid townID (ScriptTown::IsValidTown). * @return True if the action succeeded. + * @pre type must be #NT_ECONOMY, #NT_SUBSIDIES, or #NT_GENERAL. * @pre text != NULL. * @pre company == COMPANY_INVALID || ResolveCompanyID(company) != COMPANY_INVALID. + * @pre The \a reference condition must be fulfilled. */ - static bool Create(NewsType type, Text *text, ScriptCompany::CompanyID company); + static bool Create(NewsType type, Text *text, ScriptCompany::CompanyID company, NewsReferenceType ref_type, uint32 reference); }; #endif /* SCRIPT_NEWS_HPP */ diff --git a/src/script/api/template/template_news.hpp.sq b/src/script/api/template/template_news.hpp.sq index f0a09bb49..445a055e1 100644 --- a/src/script/api/template/template_news.hpp.sq +++ b/src/script/api/template/template_news.hpp.sq @@ -15,6 +15,8 @@ namespace SQConvert { /* Allow enums to be used as Squirrel parameters */ template <> inline ScriptNews::NewsType GetParam(ForceType, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return (ScriptNews::NewsType)tmp; } template <> inline int Return(HSQUIRRELVM vm, ScriptNews::NewsType res) { sq_pushinteger(vm, (int32)res); return 1; } + template <> inline ScriptNews::NewsReferenceType GetParam(ForceType, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return (ScriptNews::NewsReferenceType)tmp; } + template <> inline int Return(HSQUIRRELVM vm, ScriptNews::NewsReferenceType res) { sq_pushinteger(vm, (int32)res); return 1; } /* Allow ScriptNews to be used as Squirrel parameter */ template <> inline ScriptNews *GetParam(ForceType, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (ScriptNews *)instance; } -- cgit v1.2.3-54-g00ecf