# ai_subsidy.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 "ai_subsidy.hpp"
    00013 #include "ai_date.hpp"
    00014 #include "../../subsidy_base.h"
    00015 #include "../../station_base.h"
    00016
    00017 /* static */ bool AISubsidy::IsValidSubsidy(SubsidyID subsidy_id)
    00018 {
    00019   return ::Subsidy::IsValidID(subsidy_id);
    00020 }
    00021
    00022 /* static */ bool AISubsidy::IsAwarded(SubsidyID subsidy_id)
    00023 {
    00024   if (!IsValidSubsidy(subsidy_id)) return false;
    00025
    00026   return ::Subsidy::Get(subsidy_id)->IsAwarded();
    00027 }
    00028
    00029 /* static */ AICompany::CompanyID AISubsidy::GetAwardedTo(SubsidyID subsidy_id)
    00030 {
    00031   if (!IsAwarded(subsidy_id)) return AICompany::COMPANY_INVALID;
    00032
    00033   return (AICompany::CompanyID)((byte)::Subsidy::Get(subsidy_id)->awarded);
    00034 }
    00035
    00036 /* static */ int32 AISubsidy::GetExpireDate(SubsidyID subsidy_id)
    00037 {
    00038   if (!IsValidSubsidy(subsidy_id)) return -1;
    00039
    00040   int year = AIDate::GetYear(AIDate::GetCurrentDate());
    00041   int month = AIDate::GetMonth(AIDate::GetCurrentDate());
    00042
    00043   month += ::Subsidy::Get(subsidy_id)->remaining;
    00044
    00045   year += (month - 1) / 12;
    00046   month = ((month - 1) % 12) + 1;
    00047
    00048   return AIDate::GetDate(year, month, 1);
    00049 }
    00050
    00051 /* static */ CargoID AISubsidy::GetCargoType(SubsidyID subsidy_id)
    00052 {
    00053   if (!IsValidSubsidy(subsidy_id)) return CT_INVALID;
    00054
    00055   return ::Subsidy::Get(subsidy_id)->cargo_type;
    00056 }
    00057
    00058 /* static */ AISubsidy::SubsidyParticipantType AISubsidy::GetSourceType(SubsidyID subsidy_id)
    00059 {
    00060   if (!IsValidSubsidy(subsidy_id)) return SPT_INVALID;
    00061
    00062   return (SubsidyParticipantType)(uint)::Subsidy::Get(subsidy_id)->src_type;
    00063 }
    00064
    00065 /* static */ int32 AISubsidy::GetSourceIndex(SubsidyID subsidy_id)
    00066 {
    00067   if (!IsValidSubsidy(subsidy_id)) return INVALID_STATION;
    00068
    00069   return ::Subsidy::Get(subsidy_id)->src;
    00070 }
    00071
    00072 /* static */ AISubsidy::SubsidyParticipantType AISubsidy::GetDestinationType(SubsidyID subsidy_id)
    00073 {
    00074   if (!IsValidSubsidy(subsidy_id)) return SPT_INVALID;
    00075
    00076   return (SubsidyParticipantType)(uint)::Subsidy::Get(subsidy_id)->dst_type;
    00077 }
    00078
    00079 /* static */ int32 AISubsidy::GetDestinationIndex(SubsidyID subsidy_id)
    00080 {
    00081   if (!IsValidSubsidy(subsidy_id)) return INVALID_STATION;
    00082
    00083   return ::Subsidy::Get(subsidy_id)->dst;
    00084 }