mirror of https://github.com/OpenTTD/OpenTTD
(svn r15241) -Fix (r15027): NoAI API was not aware of certain newindustries 'features'.
parent
7b5bccb329
commit
a1d4b792e8
|
@ -45,10 +45,10 @@
|
||||||
if (!AICargo::IsValidCargo(cargo_id)) return -1;
|
if (!AICargo::IsValidCargo(cargo_id)) return -1;
|
||||||
|
|
||||||
const Industry *i = ::GetIndustry(industry_id);
|
const Industry *i = ::GetIndustry(industry_id);
|
||||||
const IndustrySpec *indsp = ::GetIndustrySpec(i->type);
|
|
||||||
|
|
||||||
for (byte j = 0; j < lengthof(indsp->produced_cargo); j++)
|
for (byte j = 0; j < lengthof(i->produced_cargo); j++) {
|
||||||
if (indsp->produced_cargo[j] == cargo_id) return i->production_rate[j] * 8;
|
if (i->produced_cargo[j] == cargo_id) return i->production_rate[j] * 8;
|
||||||
|
}
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -59,10 +59,10 @@
|
||||||
if (!AICargo::IsValidCargo(cargo_id)) return false;
|
if (!AICargo::IsValidCargo(cargo_id)) return false;
|
||||||
|
|
||||||
const Industry *i = ::GetIndustry(industry_id);
|
const Industry *i = ::GetIndustry(industry_id);
|
||||||
const IndustrySpec *indsp = ::GetIndustrySpec(i->type);
|
|
||||||
|
|
||||||
for (byte j = 0; j < lengthof(indsp->accepts_cargo); j++)
|
for (byte j = 0; j < lengthof(i->accepts_cargo); j++) {
|
||||||
if (indsp->accepts_cargo[j] == cargo_id) return true;
|
if (i->accepts_cargo[j] == cargo_id) return true;
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -89,10 +89,10 @@
|
||||||
if (!AICargo::IsValidCargo(cargo_id)) return -1;
|
if (!AICargo::IsValidCargo(cargo_id)) return -1;
|
||||||
|
|
||||||
const Industry *i = ::GetIndustry(industry_id);
|
const Industry *i = ::GetIndustry(industry_id);
|
||||||
const IndustrySpec *indsp = ::GetIndustrySpec(i->type);
|
|
||||||
|
|
||||||
for (byte j = 0; j < lengthof(indsp->produced_cargo); j++)
|
for (byte j = 0; j < lengthof(i->produced_cargo); j++) {
|
||||||
if (indsp->produced_cargo[j] == cargo_id) return i->last_month_production[j];
|
if (i->produced_cargo[j] == cargo_id) return i->last_month_production[j];
|
||||||
|
}
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -103,10 +103,10 @@
|
||||||
if (!AICargo::IsValidCargo(cargo_id)) return -1;
|
if (!AICargo::IsValidCargo(cargo_id)) return -1;
|
||||||
|
|
||||||
const Industry *i = ::GetIndustry(industry_id);
|
const Industry *i = ::GetIndustry(industry_id);
|
||||||
const IndustrySpec *indsp = ::GetIndustrySpec(i->type);
|
|
||||||
|
|
||||||
for (byte j = 0; j < lengthof(indsp->produced_cargo); j++)
|
for (byte j = 0; j < lengthof(i->produced_cargo); j++) {
|
||||||
if (indsp->produced_cargo[j] == cargo_id) return i->last_month_transported[j];
|
if (i->produced_cargo[j] == cargo_id) return i->last_month_transported[j];
|
||||||
|
}
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,6 +47,10 @@ public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the production of a cargo of the industry.
|
* 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 industry_id The index of the industry.
|
||||||
* @param cargo_id The index of the cargo.
|
* @param cargo_id The index of the cargo.
|
||||||
* @pre IsValidIndustry(industry_id).
|
* @pre IsValidIndustry(industry_id).
|
||||||
|
@ -62,7 +66,7 @@ public:
|
||||||
* @param cargo_id The index of the cargo.
|
* @param cargo_id The index of the cargo.
|
||||||
* @pre IsValidIndustry(industry_id).
|
* @pre IsValidIndustry(industry_id).
|
||||||
* @pre AICargo::IsValidCargo(cargo_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);
|
static bool IsCargoAccepted(IndustryID industry_id, CargoID cargo_id);
|
||||||
|
|
||||||
|
|
|
@ -18,25 +18,21 @@ AIIndustryList::AIIndustryList()
|
||||||
AIIndustryList_CargoAccepting::AIIndustryList_CargoAccepting(CargoID cargo_id)
|
AIIndustryList_CargoAccepting::AIIndustryList_CargoAccepting(CargoID cargo_id)
|
||||||
{
|
{
|
||||||
const Industry *i;
|
const Industry *i;
|
||||||
const IndustrySpec *indsp;
|
|
||||||
|
|
||||||
FOR_ALL_INDUSTRIES(i) {
|
FOR_ALL_INDUSTRIES(i) {
|
||||||
indsp = ::GetIndustrySpec(i->type);
|
for (byte j = 0; j < lengthof(i->accepts_cargo); j++) {
|
||||||
|
if (i->accepts_cargo[j] == cargo_id) this->AddItem(i->index);
|
||||||
for (byte j = 0; j < lengthof(indsp->accepts_cargo); j++)
|
}
|
||||||
if (indsp->accepts_cargo[j] == cargo_id) this->AddItem(i->index);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AIIndustryList_CargoProducing::AIIndustryList_CargoProducing(CargoID cargo_id)
|
AIIndustryList_CargoProducing::AIIndustryList_CargoProducing(CargoID cargo_id)
|
||||||
{
|
{
|
||||||
const Industry *i;
|
const Industry *i;
|
||||||
const IndustrySpec *indsp;
|
|
||||||
|
|
||||||
FOR_ALL_INDUSTRIES(i) {
|
FOR_ALL_INDUSTRIES(i) {
|
||||||
indsp = ::GetIndustrySpec(i->type);
|
for (byte j = 0; j < lengthof(i->produced_cargo); j++) {
|
||||||
|
if (i->produced_cargo[j] == cargo_id) this->AddItem(i->index);
|
||||||
for (byte j = 0; j < lengthof(indsp->produced_cargo); j++)
|
}
|
||||||
if (indsp->produced_cargo[j] == cargo_id) this->AddItem(i->index);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,8 @@ public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a list of CargoID possible produced by this industry-type.
|
* 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.
|
* @param industry_type The type to get the CargoIDs for.
|
||||||
* @pre IsValidIndustryType(industry_type).
|
* @pre IsValidIndustryType(industry_type).
|
||||||
* @return The CargoIDs of all cargotypes this industry could produce.
|
* @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.
|
* 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.
|
* @param industry_type The type to get the CargoIDs for.
|
||||||
* @pre IsValidIndustryType(industry_type).
|
* @pre IsValidIndustryType(industry_type).
|
||||||
* @return The CargoIDs of all cargotypes this industry accepts.
|
* @return The CargoIDs of all cargotypes this industry accepts.
|
||||||
|
|
|
@ -78,13 +78,12 @@ AITileList_IndustryAccepting::AITileList_IndustryAccepting(IndustryID industry_i
|
||||||
if (!AIIndustry::IsValidIndustry(industry_id)) return;
|
if (!AIIndustry::IsValidIndustry(industry_id)) return;
|
||||||
|
|
||||||
const Industry *i = ::GetIndustry(industry_id);
|
const Industry *i = ::GetIndustry(industry_id);
|
||||||
const IndustrySpec *indsp = ::GetIndustrySpec(i->type);
|
|
||||||
|
|
||||||
/* Check if this industry accepts anything */
|
/* Check if this industry accepts anything */
|
||||||
{
|
{
|
||||||
bool cargo_accepts = false;
|
bool cargo_accepts = false;
|
||||||
for (byte j = 0; j < lengthof(indsp->accepts_cargo); j++) {
|
for (byte j = 0; j < lengthof(i->accepts_cargo); j++) {
|
||||||
if (indsp->accepts_cargo[j] != CT_INVALID) cargo_accepts = true;
|
if (i->accepts_cargo[j] != CT_INVALID) cargo_accepts = true;
|
||||||
}
|
}
|
||||||
if (!cargo_accepts) return;
|
if (!cargo_accepts) return;
|
||||||
}
|
}
|
||||||
|
@ -102,8 +101,8 @@ AITileList_IndustryAccepting::AITileList_IndustryAccepting(IndustryID industry_i
|
||||||
::GetAcceptanceAroundTiles(accepts, cur_tile, 1, 1, radius);
|
::GetAcceptanceAroundTiles(accepts, cur_tile, 1, 1, radius);
|
||||||
{
|
{
|
||||||
bool cargo_accepts = false;
|
bool cargo_accepts = false;
|
||||||
for (byte j = 0; j < lengthof(indsp->accepts_cargo); j++) {
|
for (byte j = 0; j < lengthof(i->accepts_cargo); j++) {
|
||||||
if (indsp->accepts_cargo[j] != CT_INVALID && accepts[indsp->accepts_cargo[j]] != 0) cargo_accepts = true;
|
if (i->accepts_cargo[j] != CT_INVALID && accepts[i->accepts_cargo[j]] != 0) cargo_accepts = true;
|
||||||
}
|
}
|
||||||
if (!cargo_accepts) continue;
|
if (!cargo_accepts) continue;
|
||||||
}
|
}
|
||||||
|
@ -117,13 +116,12 @@ AITileList_IndustryProducing::AITileList_IndustryProducing(IndustryID industry_i
|
||||||
if (!AIIndustry::IsValidIndustry(industry_id)) return;
|
if (!AIIndustry::IsValidIndustry(industry_id)) return;
|
||||||
|
|
||||||
const Industry *i = ::GetIndustry(industry_id);
|
const Industry *i = ::GetIndustry(industry_id);
|
||||||
const IndustrySpec *indsp = ::GetIndustrySpec(i->type);
|
|
||||||
|
|
||||||
/* Check if this industry produces anything */
|
/* Check if this industry produces anything */
|
||||||
{
|
{
|
||||||
bool cargo_produces = false;
|
bool cargo_produces = false;
|
||||||
for (byte j = 0; j < lengthof(indsp->produced_cargo); j++) {
|
for (byte j = 0; j < lengthof(i->produced_cargo); j++) {
|
||||||
if (indsp->produced_cargo[j] != CT_INVALID) cargo_produces = true;
|
if (i->produced_cargo[j] != CT_INVALID) cargo_produces = true;
|
||||||
}
|
}
|
||||||
if (!cargo_produces) return;
|
if (!cargo_produces) return;
|
||||||
}
|
}
|
||||||
|
@ -141,8 +139,8 @@ AITileList_IndustryProducing::AITileList_IndustryProducing(IndustryID industry_i
|
||||||
::GetProductionAroundTiles(produces, cur_tile, 1, 1, radius);
|
::GetProductionAroundTiles(produces, cur_tile, 1, 1, radius);
|
||||||
{
|
{
|
||||||
bool cargo_produces = false;
|
bool cargo_produces = false;
|
||||||
for (byte j = 0; j < lengthof(indsp->produced_cargo); j++) {
|
for (byte j = 0; j < lengthof(i->produced_cargo); j++) {
|
||||||
if (indsp->produced_cargo[j] != CT_INVALID && produces[indsp->produced_cargo[j]] != 0) cargo_produces = true;
|
if (i->produced_cargo[j] != CT_INVALID && produces[i->produced_cargo[j]] != 0) cargo_produces = true;
|
||||||
}
|
}
|
||||||
if (!cargo_produces) continue;
|
if (!cargo_produces) continue;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue