summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsmatz <smatz@openttd.org>2009-08-08 16:53:22 +0000
committersmatz <smatz@openttd.org>2009-08-08 16:53:22 +0000
commitb43fd7266e2cc66028a7d15a1cee75bf89f6988e (patch)
tree26fb37af2c6fed35dc5fe1bdadc05679715ce917 /src
parentab9c71f0d95da7b9eef0271484ee4b7a93c4c376 (diff)
downloadopenttd-b43fd7266e2cc66028a7d15a1cee75bf89f6988e.tar.xz
(svn r17115) -Add [NoAI]: AISubsidy::SubsidyParticipantType, AISubsidy::GetSourceType, AISubsidy::GetSourceIndex, AISubsidy::GetDestinationType, AISubsidy::GetDestinationIndex for better subsidy management
-Change [NoAI]: mark AISubsidy::SourceIsTown, AISubsidy::GetSource, AISubsidy::GetDestinationType, AISubsidy::GetDestination as deprecated
Diffstat (limited to 'src')
-rw-r--r--src/ai/api/ai_changelog.hpp11
-rw-r--r--src/ai/api/ai_subsidy.cpp32
-rw-r--r--src/ai/api/ai_subsidy.hpp50
-rw-r--r--src/ai/api/ai_subsidy.hpp.sq30
4 files changed, 113 insertions, 10 deletions
diff --git a/src/ai/api/ai_changelog.hpp b/src/ai/api/ai_changelog.hpp
index a8e511030..42a67ad17 100644
--- a/src/ai/api/ai_changelog.hpp
+++ b/src/ai/api/ai_changelog.hpp
@@ -12,6 +12,10 @@
* \li AISign::GetMaxSignID
* \li AITile::GetHeight
* \li AIBaseStation::WAYPOINT_INVALID
+ * \li AISubsidy::SourceIsTown
+ * \li AISubsidy::GetSource
+ * \li AISubsidy::DestinationIsTown
+ * \li AISubsidy::GetDestination
*
* \b 0.8.0
*
@@ -19,6 +23,11 @@
* \li AIBaseStation
* \li AIBuoyList
* \li AIRail::RemoveRailWaypointTileRect
+ * \li AISubsidy::SubsidyParticipantType
+ * \li AISubsidy::GetSourceType
+ * \li AISubsidy::GetSourceIndex
+ * \li AISubsidy::GetDestinationType
+ * \li AISubsidy::GetDestinationIndex
*
* Other changes:
* \li The GetName / SetName / GetLocation functions were moved from AIStation
@@ -30,7 +39,7 @@
* savegames are invalid
* \li WAYPOINT_INVALID is now deprecated, use STATION_INVALID instead
* \li AISubsidy::GetSource and AISubsidy::GetDestination return STATION_INVALID
- * for awarded subsidies
+ * for awarded subsidies. They are deprecated as well
* \li AIs can create subclasses of API classes and use API constants as part
* of their own constants
* \li AIVehicleList_Station now also works for waypoints
diff --git a/src/ai/api/ai_subsidy.cpp b/src/ai/api/ai_subsidy.cpp
index 39358e963..df6889ac7 100644
--- a/src/ai/api/ai_subsidy.cpp
+++ b/src/ai/api/ai_subsidy.cpp
@@ -52,6 +52,7 @@
/* static */ bool AISubsidy::SourceIsTown(SubsidyID subsidy_id)
{
+ AILog::Warning("AISubsidy::SourceIsTown is deprecated and will be removed soon, please use AISubsidy::GetSourceType instead.");
if (!IsValidSubsidy(subsidy_id) || IsAwarded(subsidy_id)) return false;
return ::Subsidy::Get(subsidy_id)->src_type == ST_TOWN;
@@ -59,6 +60,7 @@
/* static */ int32 AISubsidy::GetSource(SubsidyID subsidy_id)
{
+ AILog::Warning("AISubsidy::GetSource is deprecated and will be removed soon, please use AISubsidy::GetSourceIndex instead.");
if (!IsValidSubsidy(subsidy_id)) return INVALID_STATION;
if (IsAwarded(subsidy_id)) {
@@ -69,8 +71,23 @@
return ::Subsidy::Get(subsidy_id)->src;
}
+/* 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 */ bool AISubsidy::DestinationIsTown(SubsidyID subsidy_id)
{
+ AILog::Warning("AISubsidy::DestinationIsTown is deprecated and will be removed soon, please use AISubsidy::GetDestinationType instead.");
if (!IsValidSubsidy(subsidy_id) || IsAwarded(subsidy_id)) return false;
return ::Subsidy::Get(subsidy_id)->dst_type == ST_TOWN;
@@ -78,6 +95,7 @@
/* static */ int32 AISubsidy::GetDestination(SubsidyID subsidy_id)
{
+ AILog::Warning("AISubsidy::GetDestination is deprecated and will be removed soon, please use AISubsidy::GetDestinationIndex instead.");
if (!IsValidSubsidy(subsidy_id)) return INVALID_STATION;
if (IsAwarded(subsidy_id)) {
@@ -87,3 +105,17 @@
return ::Subsidy::Get(subsidy_id)->dst;
}
+
+/* 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;
+}
diff --git a/src/ai/api/ai_subsidy.hpp b/src/ai/api/ai_subsidy.hpp
index 96ad92c31..b4d190bbf 100644
--- a/src/ai/api/ai_subsidy.hpp
+++ b/src/ai/api/ai_subsidy.hpp
@@ -16,6 +16,16 @@ public:
static const char *GetClassName() { return "AISubsidy"; }
/**
+ * Enumeration for source and destination of a subsidy.
+ * @note The list of values may grow in future.
+ */
+ enum SubsidyParticipantType {
+ SPT_INDUSTRY = 0, //!< Subsidy participant is an industry
+ SPT_TOWN = 1, //!< Subsidy participant is a town
+ SPT_INVALID = 0xFF, //!< Invalid/unknown participant type
+ };
+
+ /**
* Check whether this is a valid SubsidyID.
* @param subsidy_id The SubsidyID to check.
* @return True if and only if this subsidy is still valid.
@@ -64,6 +74,7 @@ public:
* @param subsidy_id The SubsidyID to check.
* @pre IsValidSubsidy(subsidy_id) && !IsAwarded(subsidy_id).
* @return True if the source is a town, false if it is an industry.
+ * @deprecated Use GetSourceType() instead.
*/
static bool SourceIsTown(SubsidyID subsidy_id);
@@ -75,14 +86,34 @@ public:
* @param subsidy_id The SubsidyID to check.
* @pre IsValidSubsidy(subsidy_id).
* @return One of TownID/IndustryID/INVALID_STATION.
+ * @deprecated Use GetSourceIndex() instead.
*/
static int32 GetSource(SubsidyID subsidy_id);
/**
+ * Returns the type of source of subsidy.
+ * @param subsidy_id The SubsidyID to check.
+ * @pre IsValidSubsidy(subsidy_id).
+ * @return Type of source of subsidy.
+ */
+ static SubsidyParticipantType GetSourceType(SubsidyID subsidy_id);
+
+ /**
+ * Return the source IndustryID/TownID the subsidy is for.
+ * \li GetSourceType(subsidy_id) == SPT_INDUSTRY -> return the IndustryID.
+ * \li GetSourceType(subsidy_id) == SPT_TOWN -> return the TownID.
+ * @param subsidy_id The SubsidyID to check.
+ * @pre IsValidSubsidy(subsidy_id).
+ * @return One of TownID/IndustryID.
+ */
+ static int32 GetSourceIndex(SubsidyID subsidy_id);
+
+ /**
* Is the destination of the subsidy a town or an industry.
* @param subsidy_id The SubsidyID to check.
* @pre IsValidSubsidy(subsidy_id) && !IsAwarded(subsidy_id).
* @return True if the destination is a town, false if it is an industry.
+ * @deprecated Use GetDestinationType() instead.
*/
static bool DestinationIsTown(SubsidyID subsidy_id);
@@ -94,8 +125,27 @@ public:
* @param subsidy_id the SubsidyID to check.
* @pre IsValidSubsidy(subsidy_id).
* @return One of TownID/IndustryID/INVALID_STATION.
+ * @deprecated Use GetDestinationIndex() instead.
*/
static int32 GetDestination(SubsidyID subsidy_id);
+
+ /**
+ * Returns the type of destination of subsidy.
+ * @param subsidy_id The SubsidyID to check.
+ * @pre IsValidSubsidy(subsidy_id).
+ * @return Type of destination of subsidy.
+ */
+ static SubsidyParticipantType GetDestinationType(SubsidyID subsidy_id);
+
+ /**
+ * Return the destination IndustryID/TownID the subsidy is for.
+ * \li GetDestinationType(subsidy_id) == SPT_INDUSTRY -> return the IndustryID.
+ * \li GetDestinationType(subsidy_id) == SPT_TOWN -> return the TownID.
+ * @param subsidy_id the SubsidyID to check.
+ * @pre IsValidSubsidy(subsidy_id).
+ * @return One of TownID/IndustryID.
+ */
+ static int32 GetDestinationIndex(SubsidyID subsidy_id);
};
#endif /* AI_SUBSIDY_HPP */
diff --git a/src/ai/api/ai_subsidy.hpp.sq b/src/ai/api/ai_subsidy.hpp.sq
index a87f9101b..8221e2338 100644
--- a/src/ai/api/ai_subsidy.hpp.sq
+++ b/src/ai/api/ai_subsidy.hpp.sq
@@ -4,6 +4,10 @@
#include "ai_subsidy.hpp"
namespace SQConvert {
+ /* Allow enums to be used as Squirrel parameters */
+ template <> AISubsidy::SubsidyParticipantType GetParam(ForceType<AISubsidy::SubsidyParticipantType>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return (AISubsidy::SubsidyParticipantType)tmp; }
+ template <> int Return<AISubsidy::SubsidyParticipantType>(HSQUIRRELVM vm, AISubsidy::SubsidyParticipantType res) { sq_pushinteger(vm, (int32)res); return 1; }
+
/* Allow AISubsidy to be used as Squirrel parameter */
template <> AISubsidy *GetParam(ForceType<AISubsidy *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (AISubsidy *)instance; }
template <> AISubsidy &GetParam(ForceType<AISubsidy &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(AISubsidy *)instance; }
@@ -17,15 +21,23 @@ void SQAISubsidy_Register(Squirrel *engine) {
SQAISubsidy.PreRegister(engine);
SQAISubsidy.AddConstructor<void (AISubsidy::*)(), 1>(engine, "x");
- SQAISubsidy.DefSQStaticMethod(engine, &AISubsidy::IsValidSubsidy, "IsValidSubsidy", 2, ".i");
- SQAISubsidy.DefSQStaticMethod(engine, &AISubsidy::IsAwarded, "IsAwarded", 2, ".i");
- SQAISubsidy.DefSQStaticMethod(engine, &AISubsidy::GetAwardedTo, "GetAwardedTo", 2, ".i");
- SQAISubsidy.DefSQStaticMethod(engine, &AISubsidy::GetExpireDate, "GetExpireDate", 2, ".i");
- SQAISubsidy.DefSQStaticMethod(engine, &AISubsidy::GetCargoType, "GetCargoType", 2, ".i");
- SQAISubsidy.DefSQStaticMethod(engine, &AISubsidy::SourceIsTown, "SourceIsTown", 2, ".i");
- SQAISubsidy.DefSQStaticMethod(engine, &AISubsidy::GetSource, "GetSource", 2, ".i");
- SQAISubsidy.DefSQStaticMethod(engine, &AISubsidy::DestinationIsTown, "DestinationIsTown", 2, ".i");
- SQAISubsidy.DefSQStaticMethod(engine, &AISubsidy::GetDestination, "GetDestination", 2, ".i");
+ SQAISubsidy.DefSQConst(engine, AISubsidy::SPT_INDUSTRY, "SPT_INDUSTRY");
+ SQAISubsidy.DefSQConst(engine, AISubsidy::SPT_TOWN, "SPT_TOWN");
+ SQAISubsidy.DefSQConst(engine, AISubsidy::SPT_INVALID, "SPT_INVALID");
+
+ SQAISubsidy.DefSQStaticMethod(engine, &AISubsidy::IsValidSubsidy, "IsValidSubsidy", 2, ".i");
+ SQAISubsidy.DefSQStaticMethod(engine, &AISubsidy::IsAwarded, "IsAwarded", 2, ".i");
+ SQAISubsidy.DefSQStaticMethod(engine, &AISubsidy::GetAwardedTo, "GetAwardedTo", 2, ".i");
+ SQAISubsidy.DefSQStaticMethod(engine, &AISubsidy::GetExpireDate, "GetExpireDate", 2, ".i");
+ SQAISubsidy.DefSQStaticMethod(engine, &AISubsidy::GetCargoType, "GetCargoType", 2, ".i");
+ SQAISubsidy.DefSQStaticMethod(engine, &AISubsidy::SourceIsTown, "SourceIsTown", 2, ".i");
+ SQAISubsidy.DefSQStaticMethod(engine, &AISubsidy::GetSource, "GetSource", 2, ".i");
+ SQAISubsidy.DefSQStaticMethod(engine, &AISubsidy::GetSourceType, "GetSourceType", 2, ".i");
+ SQAISubsidy.DefSQStaticMethod(engine, &AISubsidy::GetSourceIndex, "GetSourceIndex", 2, ".i");
+ SQAISubsidy.DefSQStaticMethod(engine, &AISubsidy::DestinationIsTown, "DestinationIsTown", 2, ".i");
+ SQAISubsidy.DefSQStaticMethod(engine, &AISubsidy::GetDestination, "GetDestination", 2, ".i");
+ SQAISubsidy.DefSQStaticMethod(engine, &AISubsidy::GetDestinationType, "GetDestinationType", 2, ".i");
+ SQAISubsidy.DefSQStaticMethod(engine, &AISubsidy::GetDestinationIndex, "GetDestinationIndex", 2, ".i");
SQAISubsidy.PostRegister(engine);
}