From afdb67a3534f85b4efbd3327ece8137211042d7b Mon Sep 17 00:00:00 2001 From: truebrain Date: Tue, 29 Nov 2011 23:07:38 +0000 Subject: (svn r23354) -Codechange: move all src/ai/api/ai_*.[hc]pp files to src/script/api/script_* (Rubidium) --- src/script/api/script_subsidy.cpp | 85 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 src/script/api/script_subsidy.cpp (limited to 'src/script/api/script_subsidy.cpp') diff --git a/src/script/api/script_subsidy.cpp b/src/script/api/script_subsidy.cpp new file mode 100644 index 000000000..f770d29f7 --- /dev/null +++ b/src/script/api/script_subsidy.cpp @@ -0,0 +1,85 @@ +/* $Id$ */ + +/* + * 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 . + */ + +/** @file script_subsidy.cpp Implementation of AISubsidy. */ + +#include "../../stdafx.h" +#include "script_subsidy.hpp" +#include "script_date.hpp" +#include "../../subsidy_base.h" +#include "../../station_base.h" + +/* static */ bool AISubsidy::IsValidSubsidy(SubsidyID subsidy_id) +{ + return ::Subsidy::IsValidID(subsidy_id); +} + +/* static */ bool AISubsidy::IsAwarded(SubsidyID subsidy_id) +{ + if (!IsValidSubsidy(subsidy_id)) return false; + + return ::Subsidy::Get(subsidy_id)->IsAwarded(); +} + +/* static */ AICompany::CompanyID AISubsidy::GetAwardedTo(SubsidyID subsidy_id) +{ + if (!IsAwarded(subsidy_id)) return AICompany::COMPANY_INVALID; + + return (AICompany::CompanyID)((byte)::Subsidy::Get(subsidy_id)->awarded); +} + +/* static */ int32 AISubsidy::GetExpireDate(SubsidyID subsidy_id) +{ + if (!IsValidSubsidy(subsidy_id)) return -1; + + int year = AIDate::GetYear(AIDate::GetCurrentDate()); + int month = AIDate::GetMonth(AIDate::GetCurrentDate()); + + month += ::Subsidy::Get(subsidy_id)->remaining; + + year += (month - 1) / 12; + month = ((month - 1) % 12) + 1; + + return AIDate::GetDate(year, month, 1); +} + +/* static */ CargoID AISubsidy::GetCargoType(SubsidyID subsidy_id) +{ + if (!IsValidSubsidy(subsidy_id)) return CT_INVALID; + + return ::Subsidy::Get(subsidy_id)->cargo_type; +} + +/* static */ AISubsidy::SubsidyParticipantType AISubsidy::GetSourceType(SubsidyID subsidy_id) +{ + if (!IsValidSubsidy(subsidy_id)) return SPT_INVALID; + + return (SubsidyParticipantType)(uint)::Subsidy::Get(subsidy_id)->src_type; +} + +/* static */ int32 AISubsidy::GetSourceIndex(SubsidyID subsidy_id) +{ + if (!IsValidSubsidy(subsidy_id)) return INVALID_STATION; + + return ::Subsidy::Get(subsidy_id)->src; +} + +/* static */ AISubsidy::SubsidyParticipantType AISubsidy::GetDestinationType(SubsidyID subsidy_id) +{ + if (!IsValidSubsidy(subsidy_id)) return SPT_INVALID; + + return (SubsidyParticipantType)(uint)::Subsidy::Get(subsidy_id)->dst_type; +} + +/* static */ int32 AISubsidy::GetDestinationIndex(SubsidyID subsidy_id) +{ + if (!IsValidSubsidy(subsidy_id)) return INVALID_STATION; + + return ::Subsidy::Get(subsidy_id)->dst; +} -- cgit v1.2.3-54-g00ecf