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