summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2009-01-23 22:09:31 +0000
committerfrosch <frosch@openttd.org>2009-01-23 22:09:31 +0000
commita1d4b792e8b412f9b4a3525554257fada2302124 (patch)
treea684a4b2e814389040ffa69997da5301631bfe62
parent7b5bccb3299543c42b3fd14d2830e9d9aa37b62d (diff)
downloadopenttd-a1d4b792e8b412f9b4a3525554257fada2302124.tar.xz
(svn r15241) -Fix (r15027): NoAI API was not aware of certain newindustries 'features'.
-rw-r--r--src/ai/api/ai_industry.cpp24
-rw-r--r--src/ai/api/ai_industry.hpp6
-rw-r--r--src/ai/api/ai_industrylist.cpp16
-rw-r--r--src/ai/api/ai_industrytype.hpp4
-rw-r--r--src/ai/api/ai_tilelist.cpp18
5 files changed, 35 insertions, 33 deletions
diff --git a/src/ai/api/ai_industry.cpp b/src/ai/api/ai_industry.cpp
index 772df722e..10178ed7e 100644
--- a/src/ai/api/ai_industry.cpp
+++ b/src/ai/api/ai_industry.cpp
@@ -45,10 +45,10 @@
if (!AICargo::IsValidCargo(cargo_id)) return -1;
const Industry *i = ::GetIndustry(industry_id);
- const IndustrySpec *indsp = ::GetIndustrySpec(i->type);
- for (byte j = 0; j < lengthof(indsp->produced_cargo); j++)
- if (indsp->produced_cargo[j] == cargo_id) return i->production_rate[j] * 8;
+ for (byte j = 0; j < lengthof(i->produced_cargo); j++) {
+ if (i->produced_cargo[j] == cargo_id) return i->production_rate[j] * 8;
+ }
return -1;
}
@@ -59,10 +59,10 @@
if (!AICargo::IsValidCargo(cargo_id)) return false;
const Industry *i = ::GetIndustry(industry_id);
- const IndustrySpec *indsp = ::GetIndustrySpec(i->type);
- for (byte j = 0; j < lengthof(indsp->accepts_cargo); j++)
- if (indsp->accepts_cargo[j] == cargo_id) return true;
+ for (byte j = 0; j < lengthof(i->accepts_cargo); j++) {
+ if (i->accepts_cargo[j] == cargo_id) return true;
+ }
return false;
}
@@ -89,10 +89,10 @@
if (!AICargo::IsValidCargo(cargo_id)) return -1;
const Industry *i = ::GetIndustry(industry_id);
- const IndustrySpec *indsp = ::GetIndustrySpec(i->type);
- for (byte j = 0; j < lengthof(indsp->produced_cargo); j++)
- if (indsp->produced_cargo[j] == cargo_id) return i->last_month_production[j];
+ for (byte j = 0; j < lengthof(i->produced_cargo); j++) {
+ if (i->produced_cargo[j] == cargo_id) return i->last_month_production[j];
+ }
return -1;
}
@@ -103,10 +103,10 @@
if (!AICargo::IsValidCargo(cargo_id)) return -1;
const Industry *i = ::GetIndustry(industry_id);
- const IndustrySpec *indsp = ::GetIndustrySpec(i->type);
- for (byte j = 0; j < lengthof(indsp->produced_cargo); j++)
- if (indsp->produced_cargo[j] == cargo_id) return i->last_month_transported[j];
+ for (byte j = 0; j < lengthof(i->produced_cargo); j++) {
+ if (i->produced_cargo[j] == cargo_id) return i->last_month_transported[j];
+ }
return -1;
}
diff --git a/src/ai/api/ai_industry.hpp b/src/ai/api/ai_industry.hpp
index ed44cada5..501b06087 100644
--- a/src/ai/api/ai_industry.hpp
+++ b/src/ai/api/ai_industry.hpp
@@ -47,6 +47,10 @@ public:
/**
* Gets the production of a cargo of the industry.
+ * WARNING This function does not neccessarily return useful values for newindustries.
+ * An industry produces at least the returned amount per month,
+ * but the function can also return 0, when the industry produces lots of cargo.
+ * GetLastMonthProduction() is more robust.
* @param industry_id The index of the industry.
* @param cargo_id The index of the cargo.
* @pre IsValidIndustry(industry_id).
@@ -62,7 +66,7 @@ public:
* @param cargo_id The index of the cargo.
* @pre IsValidIndustry(industry_id).
* @pre AICargo::IsValidCargo(cargo_id).
- * @return The production of the cargo for this industry.
+ * @return True if and only if the industry accepts the cargo.
*/
static bool IsCargoAccepted(IndustryID industry_id, CargoID cargo_id);
diff --git a/src/ai/api/ai_industrylist.cpp b/src/ai/api/ai_industrylist.cpp
index be8fbcfa4..8917e9cc0 100644
--- a/src/ai/api/ai_industrylist.cpp
+++ b/src/ai/api/ai_industrylist.cpp
@@ -18,25 +18,21 @@ AIIndustryList::AIIndustryList()
AIIndustryList_CargoAccepting::AIIndustryList_CargoAccepting(CargoID cargo_id)
{
const Industry *i;
- const IndustrySpec *indsp;
FOR_ALL_INDUSTRIES(i) {
- indsp = ::GetIndustrySpec(i->type);
-
- for (byte j = 0; j < lengthof(indsp->accepts_cargo); j++)
- if (indsp->accepts_cargo[j] == cargo_id) this->AddItem(i->index);
+ for (byte j = 0; j < lengthof(i->accepts_cargo); j++) {
+ if (i->accepts_cargo[j] == cargo_id) this->AddItem(i->index);
+ }
}
}
AIIndustryList_CargoProducing::AIIndustryList_CargoProducing(CargoID cargo_id)
{
const Industry *i;
- const IndustrySpec *indsp;
FOR_ALL_INDUSTRIES(i) {
- indsp = ::GetIndustrySpec(i->type);
-
- for (byte j = 0; j < lengthof(indsp->produced_cargo); j++)
- if (indsp->produced_cargo[j] == cargo_id) this->AddItem(i->index);
+ for (byte j = 0; j < lengthof(i->produced_cargo); j++) {
+ if (i->produced_cargo[j] == cargo_id) this->AddItem(i->index);
+ }
}
}
diff --git a/src/ai/api/ai_industrytype.hpp b/src/ai/api/ai_industrytype.hpp
index 2e38166b3..a7ef9acc1 100644
--- a/src/ai/api/ai_industrytype.hpp
+++ b/src/ai/api/ai_industrytype.hpp
@@ -33,6 +33,8 @@ public:
/**
* Get a list of CargoID possible produced by this industry-type.
+ * WARNING This is function only returns the default cargos of the industry type.
+ * Industries can specify new cargotypes on construction.
* @param industry_type The type to get the CargoIDs for.
* @pre IsValidIndustryType(industry_type).
* @return The CargoIDs of all cargotypes this industry could produce.
@@ -41,6 +43,8 @@ public:
/**
* Get a list of CargoID accepted by this industry-type.
+ * WARNING This is function only returns the default cargos of the industry type.
+ * Industries can specify new cargotypes on construction.
* @param industry_type The type to get the CargoIDs for.
* @pre IsValidIndustryType(industry_type).
* @return The CargoIDs of all cargotypes this industry accepts.
diff --git a/src/ai/api/ai_tilelist.cpp b/src/ai/api/ai_tilelist.cpp
index 24575c697..2360765f4 100644
--- a/src/ai/api/ai_tilelist.cpp
+++ b/src/ai/api/ai_tilelist.cpp
@@ -78,13 +78,12 @@ AITileList_IndustryAccepting::AITileList_IndustryAccepting(IndustryID industry_i
if (!AIIndustry::IsValidIndustry(industry_id)) return;
const Industry *i = ::GetIndustry(industry_id);
- const IndustrySpec *indsp = ::GetIndustrySpec(i->type);
/* Check if this industry accepts anything */
{
bool cargo_accepts = false;
- for (byte j = 0; j < lengthof(indsp->accepts_cargo); j++) {
- if (indsp->accepts_cargo[j] != CT_INVALID) cargo_accepts = true;
+ for (byte j = 0; j < lengthof(i->accepts_cargo); j++) {
+ if (i->accepts_cargo[j] != CT_INVALID) cargo_accepts = true;
}
if (!cargo_accepts) return;
}
@@ -102,8 +101,8 @@ AITileList_IndustryAccepting::AITileList_IndustryAccepting(IndustryID industry_i
::GetAcceptanceAroundTiles(accepts, cur_tile, 1, 1, radius);
{
bool cargo_accepts = false;
- for (byte j = 0; j < lengthof(indsp->accepts_cargo); j++) {
- if (indsp->accepts_cargo[j] != CT_INVALID && accepts[indsp->accepts_cargo[j]] != 0) cargo_accepts = true;
+ for (byte j = 0; j < lengthof(i->accepts_cargo); j++) {
+ if (i->accepts_cargo[j] != CT_INVALID && accepts[i->accepts_cargo[j]] != 0) cargo_accepts = true;
}
if (!cargo_accepts) continue;
}
@@ -117,13 +116,12 @@ AITileList_IndustryProducing::AITileList_IndustryProducing(IndustryID industry_i
if (!AIIndustry::IsValidIndustry(industry_id)) return;
const Industry *i = ::GetIndustry(industry_id);
- const IndustrySpec *indsp = ::GetIndustrySpec(i->type);
/* Check if this industry produces anything */
{
bool cargo_produces = false;
- for (byte j = 0; j < lengthof(indsp->produced_cargo); j++) {
- if (indsp->produced_cargo[j] != CT_INVALID) cargo_produces = true;
+ for (byte j = 0; j < lengthof(i->produced_cargo); j++) {
+ if (i->produced_cargo[j] != CT_INVALID) cargo_produces = true;
}
if (!cargo_produces) return;
}
@@ -141,8 +139,8 @@ AITileList_IndustryProducing::AITileList_IndustryProducing(IndustryID industry_i
::GetProductionAroundTiles(produces, cur_tile, 1, 1, radius);
{
bool cargo_produces = false;
- for (byte j = 0; j < lengthof(indsp->produced_cargo); j++) {
- if (indsp->produced_cargo[j] != CT_INVALID && produces[indsp->produced_cargo[j]] != 0) cargo_produces = true;
+ for (byte j = 0; j < lengthof(i->produced_cargo); j++) {
+ if (i->produced_cargo[j] != CT_INVALID && produces[i->produced_cargo[j]] != 0) cargo_produces = true;
}
if (!cargo_produces) continue;
}