(svn r27164) -Add: [NoGo] Game scripts can point to a location, station, industry, or town when publishing news.

replace/41b28d7194a279bdc17475d4fbe2ea6ec885a466
alberth 9 years ago
parent c639fb0d8e
commit 0143f486f2

@ -16,3 +16,10 @@ GSTown.SetGrowthRate <- function(town_id, days_between_town_growth)
if (days_between_town_growth == 0) days_between_town_growth = GSTown.TOWN_GROWTH_NORMAL;
return GSTown._SetGrowthRate(town_id, days_between_town_growth);
}
/* 1.5 adds a game element reference to the news. */
GSNews._Create <- GSNews.Create;
GSNews.Create <- function(type, text, company)
{
return GSNews._Create(type, text, company, GSNews.NR_NONE, 0);
}

@ -16,3 +16,10 @@ GSTown.SetGrowthRate <- function(town_id, days_between_town_growth)
if (days_between_town_growth == 0) days_between_town_growth = GSTown.TOWN_GROWTH_NORMAL;
return GSTown._SetGrowthRate(town_id, days_between_town_growth);
}
/* 1.5 adds a game element reference to the news. */
GSNews._Create <- GSNews.Create;
GSNews.Create <- function(type, text, company)
{
return GSNews._Create(type, text, company, GSNews.NR_NONE, 0);
}

@ -8,3 +8,10 @@
*/
GSLog.Info("1.4 API compatibility in effect.");
/* 1.5 adds a game element reference to the news. */
GSNews._Create <- GSNews.Create;
GSNews.Create <- function(type, text, company)
{
return GSNews._Create(type, text, company, GSNews.NR_NONE, 0);
}

@ -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);
}

@ -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

@ -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<Text> 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);
}

@ -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 */

@ -15,6 +15,8 @@ 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; }
template <> inline ScriptNews::NewsReferenceType GetParam(ForceType<ScriptNews::NewsReferenceType>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return (ScriptNews::NewsReferenceType)tmp; }
template <> inline int Return<ScriptNews::NewsReferenceType>(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<ScriptNews *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (ScriptNews *)instance; }

Loading…
Cancel
Save