2009-01-12 17:11:45 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2009-08-21 20:21:05 +00: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/>.
|
|
|
|
*/
|
|
|
|
|
2011-11-29 23:07:38 +00:00
|
|
|
/** @file script_subsidy.cpp Implementation of AISubsidy. */
|
2009-01-12 17:11:45 +00:00
|
|
|
|
2011-01-22 10:33:16 +00:00
|
|
|
#include "../../stdafx.h"
|
2011-11-29 23:07:38 +00:00
|
|
|
#include "script_subsidy.hpp"
|
|
|
|
#include "script_date.hpp"
|
2009-07-01 18:45:05 +00:00
|
|
|
#include "../../subsidy_base.h"
|
2009-01-12 17:11:45 +00:00
|
|
|
#include "../../station_base.h"
|
|
|
|
|
|
|
|
/* static */ bool AISubsidy::IsValidSubsidy(SubsidyID subsidy_id)
|
|
|
|
{
|
2009-08-07 22:23:34 +00:00
|
|
|
return ::Subsidy::IsValidID(subsidy_id);
|
2009-01-12 17:11:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ bool AISubsidy::IsAwarded(SubsidyID subsidy_id)
|
|
|
|
{
|
|
|
|
if (!IsValidSubsidy(subsidy_id)) return false;
|
|
|
|
|
2009-08-07 22:23:34 +00:00
|
|
|
return ::Subsidy::Get(subsidy_id)->IsAwarded();
|
2009-01-12 17:11:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ AICompany::CompanyID AISubsidy::GetAwardedTo(SubsidyID subsidy_id)
|
|
|
|
{
|
2009-01-16 00:05:26 +00:00
|
|
|
if (!IsAwarded(subsidy_id)) return AICompany::COMPANY_INVALID;
|
2009-01-12 17:11:45 +00:00
|
|
|
|
2009-08-08 16:42:55 +00:00
|
|
|
return (AICompany::CompanyID)((byte)::Subsidy::Get(subsidy_id)->awarded);
|
2009-01-12 17:11:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 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());
|
|
|
|
|
2009-08-08 16:42:55 +00:00
|
|
|
month += ::Subsidy::Get(subsidy_id)->remaining;
|
2009-01-12 17:11:45 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2009-08-07 22:23:34 +00:00
|
|
|
return ::Subsidy::Get(subsidy_id)->cargo_type;
|
2009-01-12 17:11:45 +00:00
|
|
|
}
|
|
|
|
|
2009-08-08 16:53:22 +00:00
|
|
|
/* 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;
|
|
|
|
}
|