summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2007-07-08 17:40:04 +0000
committerrubidium <rubidium@openttd.org>2007-07-08 17:40:04 +0000
commit95ea8fd2f192cc0bcf7538ec4cd97e4dddcff9d5 (patch)
treee8b08f0eebf44557962f1210eb8b7887d9d999bf
parent064c1ea89e4f5395654ea3cad060422b5d495b59 (diff)
downloadopenttd-95ea8fd2f192cc0bcf7538ec4cd97e4dddcff9d5.tar.xz
(svn r10477) -Codechange: add some callbacks to customise the acceptance of industries.
-rw-r--r--src/economy.cpp12
-rw-r--r--src/industry_cmd.cpp32
-rw-r--r--src/newgrf_callbacks.h10
-rw-r--r--src/newgrf_cargo.cpp17
-rw-r--r--src/newgrf_cargo.h1
5 files changed, 57 insertions, 15 deletions
diff --git a/src/economy.cpp b/src/economy.cpp
index 46f3c14d6..713af79a7 100644
--- a/src/economy.cpp
+++ b/src/economy.cpp
@@ -1211,18 +1211,18 @@ static void DeliverGoodsToIndustry(TileIndex xy, CargoID cargo_type, int num_pie
indspec = GetIndustrySpec(ind->type);
uint i;
- if (indspec->produced_cargo[0] == CT_INVALID) continue;
-
for (i = 0; i < lengthof(indspec->accepts_cargo); i++) {
- if (cargo_type == indspec->accepts_cargo[i] &&
- (indspec->input_cargo_multiplier[i][0] != 0 || indspec->input_cargo_multiplier[i][1] != 0)) {
- break;
- }
+ if (cargo_type == indspec->accepts_cargo[i]) break;
}
/* Check if matching cargo has been found */
if (i == lengthof(indspec->accepts_cargo)) continue;
+ if (HASBIT(indspec->callback_flags, CBM_IND_REFUSE_CARGO)) {
+ uint16 res = GetIndustryCallback(CBID_INDUSTRY_REFUSE_CARGO, 0, GetReverseCargoTranslation(cargo_type, indspec->grf_prop.grffile), ind, ind->type, ind->xy);
+ if (res == 0) continue;
+ }
+
uint dist = DistanceManhattan(ind->xy, xy);
if (dist < best_dist) {
diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp
index 0162f7ce5..6429f2ff1 100644
--- a/src/industry_cmd.cpp
+++ b/src/industry_cmd.cpp
@@ -330,12 +330,36 @@ static Slope GetSlopeTileh_Industry(TileIndex tile, Slope tileh)
static void GetAcceptedCargo_Industry(TileIndex tile, AcceptedCargo ac)
{
- const IndustryTileSpec *itspec = GetIndustryTileSpec(GetIndustryGfx(tile));
- CargoID a;
+ IndustryGfx gfx = GetIndustryGfx(tile);
+ const IndustryTileSpec *itspec = GetIndustryTileSpec(gfx);
+
+ /* When we have to use a callback, we put our data in the next two variables */
+ CargoID raw_accepts_cargo[lengthof(itspec->accepts_cargo)];
+ uint8 raw_acceptance[lengthof(itspec->acceptance)];
+
+ /* And then these will always point to a same sized array with the required data */
+ const CargoID *accepts_cargo = itspec->accepts_cargo;
+ const uint8 *acceptance = itspec->acceptance;
+
+ if (HASBIT(itspec->callback_flags, CBM_INDT_ACCEPT_CARGO)) {
+ uint16 res = GetIndustryTileCallback(CBID_INDTILE_ACCEPT_CARGO, 0, 0, gfx, GetIndustryByTile(tile), tile);
+ if (res != CALLBACK_FAILED) {
+ accepts_cargo = raw_accepts_cargo;
+ for (uint i = 0; i < lengthof(itspec->accepts_cargo); i++) raw_accepts_cargo[i] = GetCargoTranslation(GB(res, i * 5, 5), itspec->grf_prop.grffile);
+ }
+ }
+
+ if (HASBIT(itspec->callback_flags, CBM_INDT_CARGO_ACCEPTANCE)) {
+ uint16 res = GetIndustryTileCallback(CBID_INDTILE_CARGO_ACCEPTANCE, 0, 0, gfx, GetIndustryByTile(tile), tile);
+ if (res != CALLBACK_FAILED) {
+ acceptance = raw_acceptance;
+ for (uint i = 0; i < lengthof(itspec->accepts_cargo); i++) raw_acceptance[i] = GB(res, i * 4, 4);
+ }
+ }
for (byte i = 0; i < lengthof(itspec->accepts_cargo); i++) {
- a = itspec->accepts_cargo[i];
- if (a != CT_INVALID) ac[a] = itspec->acceptance[i];
+ CargoID a = accepts_cargo[i];
+ if (a != CT_INVALID) ac[a] = acceptance[i];
}
}
diff --git a/src/newgrf_callbacks.h b/src/newgrf_callbacks.h
index 129285afe..29bb174a5 100644
--- a/src/newgrf_callbacks.h
+++ b/src/newgrf_callbacks.h
@@ -107,10 +107,10 @@ enum CallbackID {
CBID_HOUSE_ACCEPT_CARGO = 0x2A,
/* Called to query the cargo acceptance of the industry tile */
- CBID_INDTILE_ACCEPT_CARGO = 0x2B, // not yet implemented
+ CBID_INDTILE_CARGO_ACCEPTANCE = 0x2B,
/* Called to determine which cargoes an industry should accept. */
- CBID_INDUSTRY_ACCEPT_CARGO = 0x2C, // not yet implemented
+ CBID_INDTILE_ACCEPT_CARGO = 0x2C,
/* Called to determine if a specific colour map should be used for a vehicle
* instead of the default livery */
@@ -158,8 +158,8 @@ enum CallbackID {
/* Called to determine if industry can alter the ground below industry tile */
CBID_INDUSTRY_AUTOSLOPE = 0x3C, // not yet implemented
- /* Called to determine if the industry can still accept or refuse more cargo arrival */
- CBID_INDUSTRY_REFUSE_CARGO = 0x3D, // not yet implemented
+ /* Called to determine if the industry can still accept or refuse more cargo arrival */
+ CBID_INDUSTRY_REFUSE_CARGO = 0x3D,
/* Called (if appropriate bit in callback mask set) to determine whether a
* town building can be destroyed. */
@@ -240,7 +240,7 @@ enum IndustryCallbackMask {
enum IndustryTileCallbackMask {
CBM_INDT_ANIM_NEXT_FRAME = 0, ///< decides next animation frame
CBM_INDT_ANIM_SPEED = 1, ///< decides animation speed
- CBM_INDT_ACCEPTANCE_CARGO = 2, ///< decides amount of cargo acceptance
+ CBM_INDT_CARGO_ACCEPTANCE = 2, ///< decides amount of cargo acceptance
CBM_INDT_ACCEPT_CARGO = 3, ///< decides accepted types
CBM_INDT_SHAPE_CHECK = 4, ///< decides slope suitability
CBM_INDT_DRAW_FOUNDATIONS = 5, ///< decides if default foundations need to be drawn
diff --git a/src/newgrf_cargo.cpp b/src/newgrf_cargo.cpp
index 6724edb53..ff9a633bc 100644
--- a/src/newgrf_cargo.cpp
+++ b/src/newgrf_cargo.cpp
@@ -110,3 +110,20 @@ CargoID GetCargoTranslation(uint8 cargo, const GRFFile *grffile)
/* Else the cargo value is a 'climate independent' 'bitnum' */
return GetCargoIDByBitnum(cargo);
}
+
+uint8 GetReverseCargoTranslation(CargoID cargo, const GRFFile *grffile)
+{
+ /* Pre-version 7 uses the 'climate dependent' ID, i.e. cargo is the cargo ID */
+ if (grffile->grf_version < 7) return cargo;
+
+ const CargoSpec *cs = GetCargo(cargo);
+
+ /* If the GRF contains a translation table (and the cargo is in the table)
+ * then get the cargo ID for the label */
+ for (uint i = 0; i < grffile->cargo_max; i++) {
+ if (cs->label == grffile->cargo_list[i]) return i;
+ }
+
+ /* No matching label was found, so we return the 'climate independent' 'bitnum' */
+ return cs->bitnum;;
+}
diff --git a/src/newgrf_cargo.h b/src/newgrf_cargo.h
index 55df3729b..e3f544d61 100644
--- a/src/newgrf_cargo.h
+++ b/src/newgrf_cargo.h
@@ -28,5 +28,6 @@ struct GRFFile;
SpriteID GetCustomCargoSprite(const CargoSpec *cs);
uint16 GetCargoCallback(uint16 callback, uint32 param1, uint32 param2, const CargoSpec *cs);
CargoID GetCargoTranslation(uint8 cargo, const GRFFile *grffile);
+uint8 GetReverseCargoTranslation(CargoID cargo, const GRFFile *grffile);
#endif /* NEWGRF_CARGO_H */