2009-07-01 18:45:05 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
/** @file subsidy_base.h Subsidy base class. */
|
|
|
|
|
|
|
|
#ifndef SUBSIDY_BASE_H
|
|
|
|
#define SUBSIDY_BASE_H
|
|
|
|
|
|
|
|
#include "cargo_type.h"
|
|
|
|
#include "company_type.h"
|
2009-08-07 20:24:33 +00:00
|
|
|
#include "station_type.h"
|
2009-07-01 18:45:05 +00:00
|
|
|
|
2009-07-02 12:47:52 +00:00
|
|
|
typedef uint16 SubsidyID; ///< ID of a subsidy
|
|
|
|
|
2009-07-01 18:45:05 +00:00
|
|
|
/** Struct about subsidies, offered and awarded */
|
|
|
|
struct Subsidy {
|
2009-08-07 22:23:34 +00:00
|
|
|
CargoID cargo_type; ///< Cargo type involved in this subsidy, CT_INVALID for invalid subsidy
|
|
|
|
byte age; ///< Subsidy age; < 12 is unawarded, >= 12 is awarded
|
|
|
|
SourceTypeByte src_type; ///< Source of subsidised path
|
|
|
|
SourceTypeByte dst_type; ///< Destination of subsidised path
|
|
|
|
uint16 src; ///< Index of source. Either TownID, IndustryID or StationID, when awarded
|
|
|
|
uint16 dst; ///< Index of destination. Either TownID, IndustryID or StationID, when awarded
|
2009-07-01 18:45:05 +00:00
|
|
|
|
2009-07-18 19:54:35 +00:00
|
|
|
/**
|
|
|
|
* Tests whether this subsidy has been awarded to someone
|
|
|
|
* @return is this subsidy awarded?
|
|
|
|
*/
|
|
|
|
FORCEINLINE bool IsAwarded() const
|
|
|
|
{
|
|
|
|
return this->age >= 12;
|
|
|
|
}
|
|
|
|
|
2009-08-07 20:24:33 +00:00
|
|
|
void AwardTo(StationID from, StationID to, CompanyID company);
|
|
|
|
|
2009-07-01 18:45:05 +00:00
|
|
|
/**
|
|
|
|
* Determines index of this subsidy
|
|
|
|
* @return index (in the Subsidy::array array)
|
|
|
|
*/
|
2009-07-02 12:47:52 +00:00
|
|
|
FORCEINLINE SubsidyID Index() const
|
2009-07-01 18:45:05 +00:00
|
|
|
{
|
|
|
|
return this - Subsidy::array;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests for validity of this subsidy
|
|
|
|
* @return is this subsidy valid?
|
|
|
|
*/
|
|
|
|
FORCEINLINE bool IsValid() const
|
|
|
|
{
|
|
|
|
return this->cargo_type != CT_INVALID;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static Subsidy array[MAX_COMPANIES]; ///< Array holding all subsidies
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Total number of subsidies, both valid and invalid
|
|
|
|
* @return length of Subsidy::array
|
|
|
|
*/
|
|
|
|
static FORCEINLINE size_t GetArraySize()
|
|
|
|
{
|
|
|
|
return lengthof(Subsidy::array);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests whether given index is an index of valid subsidy
|
|
|
|
* @param index index to check
|
|
|
|
* @return can this index be used to access a valid subsidy?
|
|
|
|
*/
|
|
|
|
static FORCEINLINE bool IsValidID(size_t index)
|
|
|
|
{
|
|
|
|
return index < Subsidy::GetArraySize() && Subsidy::Get(index)->IsValid();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns pointer to subsidy with given index
|
|
|
|
* @param index index of subsidy
|
|
|
|
* @return pointer to subsidy with given index
|
|
|
|
*/
|
|
|
|
static FORCEINLINE Subsidy *Get(size_t index)
|
|
|
|
{
|
|
|
|
assert(index < Subsidy::GetArraySize());
|
|
|
|
return &Subsidy::array[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
static Subsidy *AllocateItem();
|
|
|
|
static void Clean();
|
|
|
|
};
|
|
|
|
|
|
|
|
#define FOR_ALL_SUBSIDIES_FROM(var, start) for (size_t subsidy_index = start; var = NULL, subsidy_index < Subsidy::GetArraySize(); subsidy_index++) \
|
|
|
|
if ((var = Subsidy::Get(subsidy_index))->IsValid())
|
|
|
|
#define FOR_ALL_SUBSIDIES(var) FOR_ALL_SUBSIDIES_FROM(var, 0)
|
|
|
|
|
|
|
|
#endif /* SUBSIDY_BASE_H */
|