script_news.cpp

Go to the documentation of this file.
00001 /* $Id$ */
00002 
00003 /*
00004  * This file is part of OpenTTD.
00005  * 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.
00006  * 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.
00007  * 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/>.
00008  */
00009 
00012 #include "../../stdafx.h"
00013 #include "script_news.hpp"
00014 #include "script_error.hpp"
00015 #include "../../news_func.h"
00016 #include "../../strings_func.h"
00017 #include "../../command_type.h"
00018 #include "../../string_func.h"
00019 #include "table/strings.h"
00020 
00021 /* static */ bool ScriptNews::Create(NewsType type, Text *text, ScriptCompany::CompanyID company)
00022 {
00023   CCountedPtr<Text> counter(text);
00024 
00025   EnforcePrecondition(false, text != NULL);
00026   EnforcePrecondition(false, !StrEmpty(text->GetEncodedText()));
00027   EnforcePrecondition(false, type >= NT_ARRIVAL_COMPANY && type <= NT_GENERAL);
00028   EnforcePrecondition(false, company == ScriptCompany::COMPANY_INVALID || ScriptCompany::ResolveCompanyID(company) != ScriptCompany::COMPANY_INVALID);
00029 
00030   uint8 c = company;
00031   if (company == ScriptCompany::COMPANY_INVALID) c = INVALID_COMPANY;
00032 
00033   return ScriptObject::DoCommand(0, type | (NR_NONE << 8) | (c << 16), 0, CMD_CUSTOM_NEWS_ITEM, text->GetEncodedText());
00034 }