(svn r20396) -Codechange: introduce a helper function to test whether an industry temporarily refues to accept some cargo

This commit is contained in:
yexo 2010-08-07 20:11:27 +00:00
parent 50fe2264ec
commit e80f339086
4 changed files with 26 additions and 16 deletions

View File

@ -909,8 +909,6 @@ static uint DeliverGoodsToIndustry(const Station *st, CargoID cargo_type, uint n
Industry *ind = st->industries_near[i];
if (ind->index == source) continue;
const IndustrySpec *indspec = GetIndustrySpec(ind->type);
uint cargo_index;
for (cargo_index = 0; cargo_index < lengthof(ind->accepts_cargo); cargo_index++) {
if (cargo_type == ind->accepts_cargo[cargo_index]) break;
@ -919,10 +917,7 @@ static uint DeliverGoodsToIndustry(const Station *st, CargoID cargo_type, uint n
if (cargo_index >= lengthof(ind->accepts_cargo)) continue;
/* Check if industry temporarily refuses acceptance */
if (HasBit(indspec->callback_mask, CBM_IND_REFUSE_CARGO)) {
uint16 res = GetIndustryCallback(CBID_INDUSTRY_REFUSE_CARGO, 0, GetReverseCargoTranslation(cargo_type, indspec->grf_prop.grffile), ind, ind->type, ind->location.tile);
if (res == 0) continue;
}
if (IndustryTemporarilyRefusesCargo(ind, cargo_type)) continue;
/* Insert the industry into _cargo_delivery_destinations, if not yet contained */
_cargo_delivery_destinations.Include(ind);

View File

@ -2065,18 +2065,11 @@ static bool CheckIndustryCloseDownProtection(IndustryType type)
*/
static void CanCargoServiceIndustry(CargoID cargo, Industry *ind, bool *c_accepts, bool *c_produces)
{
const IndustrySpec *indspec = GetIndustrySpec(ind->type);
if (cargo == CT_INVALID) return;
/* Check for acceptance of cargo */
for (byte j = 0; j < lengthof(ind->accepts_cargo); j++) {
if (ind->accepts_cargo[j] == CT_INVALID) continue;
if (cargo == ind->accepts_cargo[j]) {
if (HasBit(indspec->callback_mask, CBM_IND_REFUSE_CARGO)) {
uint16 res = GetIndustryCallback(CBID_INDUSTRY_REFUSE_CARGO,
0, GetReverseCargoTranslation(cargo, indspec->grf_prop.grffile),
ind, ind->type, ind->location.tile);
if (res == 0) continue;
}
if (cargo == ind->accepts_cargo[j] && !IndustryTemporarilyRefusesCargo(ind, cargo)) {
*c_accepts = true;
break;
}
@ -2084,7 +2077,6 @@ static void CanCargoServiceIndustry(CargoID cargo, Industry *ind, bool *c_accept
/* Check for produced cargo */
for (byte j = 0; j < lengthof(ind->produced_cargo); j++) {
if (ind->produced_cargo[j] == CT_INVALID) continue;
if (cargo == ind->produced_cargo[j]) {
*c_produces = true;
break;

View File

@ -17,6 +17,7 @@
#include "newgrf_commons.h"
#include "newgrf_text.h"
#include "newgrf_town.h"
#include "newgrf_cargo.h"
#include "window_func.h"
#include "town.h"
#include "company_base.h"
@ -583,3 +584,24 @@ void GetIndustryResolver(ResolverObject *ro, uint index)
Industry *i = Industry::Get(index);
NewIndustryResolver(ro, i->location.tile, i, i->type);
}
/**
* Check whether an industry temporarily refuses to accept a certain cargo.
* @param ind The industry to query.
* @param cargo_type The cargo to get information about.
* @pre cargo_type is in ind->accepts_cargo.
* @return Whether the given industry refuses to accept this cargo type.
*/
bool IndustryTemporarilyRefusesCargo(Industry *ind, CargoID cargo_type)
{
assert(cargo_type == ind->accepts_cargo[0] || cargo_type == ind->accepts_cargo[1] || cargo_type == ind->accepts_cargo[2]);
const IndustrySpec *indspec = GetIndustrySpec(ind->type);
if (HasBit(indspec->callback_mask, CBM_IND_REFUSE_CARGO)) {
uint16 res = GetIndustryCallback(CBID_INDUSTRY_REFUSE_CARGO,
0, GetReverseCargoTranslation(cargo_type, indspec->grf_prop.grffile),
ind, ind->type, ind->location.tile);
return res == 0;
}
return false;
}

View File

@ -39,6 +39,7 @@ uint32 GetIndustryIDAtOffset(TileIndex new_tile, const Industry *i, uint32 cur_g
void IndustryProductionCallback(Industry *ind, int reason);
CommandCost CheckIfCallBackAllowsCreation(TileIndex tile, IndustryType type, uint layout, uint32 seed, uint16 initial_random_bits, Owner founder);
bool CheckIfCallBackAllowsAvailability(IndustryType type, IndustryAvailabilityCallType creation_type);
bool IndustryTemporarilyRefusesCargo(Industry *ind, CargoID cargo_type);
IndustryType MapNewGRFIndustryType(IndustryType grf_type, uint32 grf_id);