Fix some daylength issues, possible division by zero in main menu.
[openttd-joker.git] / src / script / api / script_news.cpp
blobb8963c1b5ad7743d9e9f27e7d4fd7c20a3ecc159
1 /* $Id: script_news.cpp 24982 2013-02-08 20:34:27Z rubidium $ */
3 /*
4 * This file is part of OpenTTD.
5 * 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.
6 * 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.
7 * 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/>.
8 */
10 /** @file script_news.cpp Implementation of ScriptNews. */
12 #include "../../stdafx.h"
13 #include "script_news.hpp"
14 #include "script_industry.hpp"
15 #include "script_station.hpp"
16 #include "script_map.hpp"
17 #include "script_town.hpp"
18 #include "script_error.hpp"
19 #include "../../command_type.h"
20 #include "../../string_func.h"
22 #include "../../safeguards.h"
24 /* static */ bool ScriptNews::Create(NewsType type, Text *text, ScriptCompany::CompanyID company, NewsReferenceType ref_type, uint32 reference)
26 CCountedPtr<Text> counter(text);
28 EnforcePrecondition(false, text != NULL);
29 const char *encoded = text->GetEncodedText();
30 EnforcePreconditionEncodedText(false, encoded);
31 EnforcePrecondition(false, type == NT_ECONOMY || type == NT_SUBSIDIES || type == NT_GENERAL);
32 EnforcePrecondition(false, company == ScriptCompany::COMPANY_INVALID || ScriptCompany::ResolveCompanyID(company) != ScriptCompany::COMPANY_INVALID);
33 EnforcePrecondition(false, (ref_type == NR_NONE) ||
34 (ref_type == NR_TILE && ScriptMap::IsValidTile(reference)) ||
35 (ref_type == NR_STATION && ScriptStation::IsValidStation(reference)) ||
36 (ref_type == NR_INDUSTRY && ScriptIndustry::IsValidIndustry(reference)) ||
37 (ref_type == NR_TOWN && ScriptTown::IsValidTown(reference)));
39 uint8 c = company;
40 if (company == ScriptCompany::COMPANY_INVALID) c = INVALID_COMPANY;
42 if (ref_type == NR_NONE) reference = 0;
43 return ScriptObject::DoCommand(0, type | (ref_type << 8) | (c << 16), reference, CMD_CUSTOM_NEWS_ITEM, encoded);