summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2007-10-02 16:56:45 +0000
committerrubidium <rubidium@openttd.org>2007-10-02 16:56:45 +0000
commit531fe3e07012670f56eaaf59f85a0ad99208c032 (patch)
tree1d46101c1e0fc0626c63928a6ef4b691f90c32c0 /src
parent7979674717cb807d4294eaffccabb5fb08aec9a4 (diff)
downloadopenttd-531fe3e07012670f56eaaf59f85a0ad99208c032.tar.xz
(svn r11193) -Fix: be more compliant with the specifications of callback #2F (and undocumented side effects in TTDP in corner cases).
Diffstat (limited to 'src')
-rw-r--r--src/industry_cmd.cpp39
-rw-r--r--src/newgrf_industrytiles.cpp13
-rw-r--r--src/newgrf_industrytiles.h2
3 files changed, 31 insertions, 23 deletions
diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp
index 1816adc4c..c8ce02be0 100644
--- a/src/industry_cmd.cpp
+++ b/src/industry_cmd.cpp
@@ -1179,7 +1179,23 @@ static const Town *CheckMultipleIndustryInTown(TileIndex tile, int type)
return t;
}
-static bool CheckIfIndustryTilesAreFree(TileIndex tile, const IndustryTileTable *it, int type, bool *custom_shape_check = NULL)
+bool IsSlopeRefused(Slope current, Slope refused)
+{
+ if (current != SLOPE_FLAT) {
+ if (refused & SLOPE_STEEP) return true;
+
+ Slope t = ComplementSlope(current);
+
+ if (refused & 1 && (t & SLOPE_NW)) return false;
+ if (refused & 2 && (t & SLOPE_NE)) return false;
+ if (refused & 4 && (t & SLOPE_SW)) return false;
+ if (refused & 8 && (t & SLOPE_SE)) return false;
+ }
+
+ return false;
+}
+
+static bool CheckIfIndustryTilesAreFree(TileIndex tile, const IndustryTileTable *it, uint itspec_index, int type, bool *custom_shape_check = NULL)
{
_error_message = STR_0239_SITE_UNSUITABLE;
@@ -1207,7 +1223,7 @@ static bool CheckIfIndustryTilesAreFree(TileIndex tile, const IndustryTileTable
if (HASBIT(its->callback_flags, CBM_INDT_SHAPE_CHECK)) {
if (custom_shape_check != NULL) *custom_shape_check = true;
- if (!PerformIndustryTileSlopeCheck(cur_tile, its, type, gfx)) return false;
+ if (!PerformIndustryTileSlopeCheck(tile, cur_tile, its, type, gfx, itspec_index)) return false;
} else {
if (ind_behav & INDUSTRYBEH_BUILT_ONWATER) {
/* As soon as the tile is not water, bail out.
@@ -1226,19 +1242,7 @@ static bool CheckIfIndustryTilesAreFree(TileIndex tile, const IndustryTileTable
/* It is almost impossible to have a fully flat land in TG, so what we
* do is that we check if we can make the land flat later on. See
* CheckIfCanLevelIndustryPlatform(). */
- if (tileh != SLOPE_FLAT) {
- Slope t;
- byte bits = its->slopes_refused;
-
- if (bits & 0x10) return false;
-
- t = ComplementSlope(tileh);
-
- if (bits & 1 && (t & SLOPE_NW)) return false;
- if (bits & 2 && (t & SLOPE_NE)) return false;
- if (bits & 4 && (t & SLOPE_SW)) return false;
- if (bits & 8 && (t & SLOPE_SE)) return false;
- }
+ if (IsSlopeRefused(tileh, its->slopes_refused)) return false;
}
}
}
@@ -1541,7 +1545,7 @@ static Industry *CreateNewIndustryHelper(TileIndex tile, IndustryType type, uint
const IndustryTileTable *it = indspec->table[itspec_index];
bool custom_shape_check = false;
- if (!CheckIfIndustryTilesAreFree(tile, it, type, &custom_shape_check)) return NULL;
+ if (!CheckIfIndustryTilesAreFree(tile, it, itspec_index, type, &custom_shape_check)) return NULL;
if (HASBIT(GetIndustrySpec(type)->callback_flags, CBM_IND_LOCATION)) {
if (!CheckIfCallBackAllowsCreation(tile, type, itspec_index)) return NULL;
@@ -1582,7 +1586,6 @@ CommandCost CmdBuildIndustry(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
{
int num;
const IndustryTileTable * const *itt;
- const IndustryTileTable *it;
const IndustrySpec *indspec;
SET_EXPENSES_TYPE(EXPENSES_OTHER);
@@ -1626,7 +1629,7 @@ CommandCost CmdBuildIndustry(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
do {
if (--num < 0) return_cmd_error(STR_0239_SITE_UNSUITABLE);
- } while (!CheckIfIndustryTilesAreFree(tile, it = itt[num], p1));
+ } while (!CheckIfIndustryTilesAreFree(tile, itt[num], num, p1));
if (CreateNewIndustryHelper(tile, p1, flags, indspec, num) == NULL) return CMD_ERROR;
}
diff --git a/src/newgrf_industrytiles.cpp b/src/newgrf_industrytiles.cpp
index 6c3c40c99..1c1d74199 100644
--- a/src/newgrf_industrytiles.cpp
+++ b/src/newgrf_industrytiles.cpp
@@ -247,18 +247,23 @@ bool DrawNewIndustryTile(TileInfo *ti, Industry *i, IndustryGfx gfx, const Indus
}
}
-bool PerformIndustryTileSlopeCheck(TileIndex tile, const IndustryTileSpec *its, IndustryType type, IndustryGfx gfx)
+extern bool IsSlopeRefused(Slope current, Slope refused);
+
+bool PerformIndustryTileSlopeCheck(TileIndex ind_base_tile, TileIndex ind_tile, const IndustryTileSpec *its, IndustryType type, IndustryGfx gfx, uint itspec_index)
{
Industry ind;
- ind.xy = 0;
+ ind.index = INVALID_INDUSTRY;
+ ind.xy = ind_base_tile;
ind.width = 0;
ind.type = type;
- uint16 callback_res = GetIndustryTileCallback(CBID_INDTILE_SHAPE_CHECK, 0, 0, gfx, &ind, tile);
+ uint16 callback_res = GetIndustryTileCallback(CBID_INDTILE_SHAPE_CHECK, 0, itspec_index, gfx, &ind, ind_tile);
+ if (callback_res == CALLBACK_FAILED) {
+ return !IsSlopeRefused(GetTileSlope(ind_tile, NULL), its->slopes_refused);
+ }
if (its->grf_prop.grffile->grf_version < 7) {
return callback_res != 0;
}
- if (callback_res == CALLBACK_FAILED) return false;
switch (callback_res) {
case 0x400: return true;
diff --git a/src/newgrf_industrytiles.h b/src/newgrf_industrytiles.h
index a65fb35db..4a7794c62 100644
--- a/src/newgrf_industrytiles.h
+++ b/src/newgrf_industrytiles.h
@@ -15,7 +15,7 @@ enum IndustryAnimationTrigger {
bool DrawNewIndustryTile(TileInfo *ti, Industry *i, IndustryGfx gfx, const IndustryTileSpec *inds);
uint16 GetIndustryTileCallback(CallbackID callback, uint32 param1, uint32 param2, IndustryGfx gfx_id, Industry *industry, TileIndex tile);
-bool PerformIndustryTileSlopeCheck(TileIndex tile, const IndustryTileSpec *its, IndustryType type, IndustryGfx gfx);
+bool PerformIndustryTileSlopeCheck(TileIndex ind_base_tile, TileIndex ind_tile, const IndustryTileSpec *its, IndustryType type, IndustryGfx gfx, uint itspec_index);
void AnimateNewIndustryTile(TileIndex tile);
bool StartStopIndustryTileAnimation(TileIndex tile, IndustryAnimationTrigger iat, uint32 random = Random());