2011-12-19 22:01:03 +01:00
|
|
|
/*
|
|
|
|
* 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"
|
2015-02-22 18:25:29 +01:00
|
|
|
#include "script_industry.hpp"
|
|
|
|
#include "script_station.hpp"
|
|
|
|
#include "script_map.hpp"
|
|
|
|
#include "script_town.hpp"
|
2011-12-19 22:01:03 +01:00
|
|
|
#include "script_error.hpp"
|
|
|
|
#include "../../command_type.h"
|
|
|
|
#include "../../string_func.h"
|
2021-11-01 21:30:34 +01:00
|
|
|
#include "../../news_cmd.h"
|
2011-12-19 22:01:03 +01:00
|
|
|
|
2014-04-23 22:13:33 +02:00
|
|
|
#include "../../safeguards.h"
|
|
|
|
|
2023-03-04 17:45:03 +01:00
|
|
|
/* static */ bool ScriptNews::Create(NewsType type, Text *text, ScriptCompany::CompanyID company, NewsReferenceType ref_type, SQInteger reference)
|
2011-12-19 22:01:03 +01:00
|
|
|
{
|
2011-12-19 22:06:06 +01:00
|
|
|
CCountedPtr<Text> counter(text);
|
|
|
|
|
2019-04-10 23:07:06 +02:00
|
|
|
EnforcePrecondition(false, text != nullptr);
|
2023-02-16 02:05:54 +01:00
|
|
|
const std::string &encoded = text->GetEncodedText();
|
2013-02-08 21:34:27 +01:00
|
|
|
EnforcePreconditionEncodedText(false, encoded);
|
2012-02-11 21:08:31 +01:00
|
|
|
EnforcePrecondition(false, type == NT_ECONOMY || type == NT_SUBSIDIES || type == NT_GENERAL);
|
2011-12-19 22:01:03 +01:00
|
|
|
EnforcePrecondition(false, company == ScriptCompany::COMPANY_INVALID || ScriptCompany::ResolveCompanyID(company) != ScriptCompany::COMPANY_INVALID);
|
2015-02-22 18:25:29 +01:00
|
|
|
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)));
|
2011-12-19 22:01:03 +01:00
|
|
|
|
|
|
|
uint8 c = company;
|
|
|
|
if (company == ScriptCompany::COMPANY_INVALID) c = INVALID_COMPANY;
|
|
|
|
|
2015-02-22 18:25:29 +01:00
|
|
|
if (ref_type == NR_NONE) reference = 0;
|
2021-11-23 01:05:58 +01:00
|
|
|
return ScriptObject::Command<CMD_CUSTOM_NEWS_ITEM>::Do((::NewsType)type, (::NewsReferenceType)ref_type, (::CompanyID)c, reference, encoded);
|
2011-12-19 22:01:03 +01:00
|
|
|
}
|