summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2007-10-27 11:20:47 +0000
committerrubidium <rubidium@openttd.org>2007-10-27 11:20:47 +0000
commit21981fd8cb00380c79e34a85609598ea805c6e74 (patch)
tree6c17e530a7d48ad0d0ccae9ef1975ef83bd3a7d8 /src
parent27bf599ae2565fe98b7c929c30e79b60c82e41b4 (diff)
downloadopenttd-21981fd8cb00380c79e34a85609598ea805c6e74.tar.xz
(svn r11349) -Fix [FS#1372]: crash when moving "invalid" cargo to a station.
Diffstat (limited to 'src')
-rw-r--r--src/industry_cmd.cpp45
1 files changed, 19 insertions, 26 deletions
diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp
index 9f7650b3f..edce756fc 100644
--- a/src/industry_cmd.cpp
+++ b/src/industry_cmd.cpp
@@ -405,41 +405,34 @@ static void TransportIndustryGoods(TileIndex tile)
{
Industry *i = GetIndustryByTile(tile);
const IndustrySpec *indspec = GetIndustrySpec(i->type);
- uint cw, am;
+ bool moved_cargo = false;
- cw = min(i->produced_cargo_waiting[0], 255);
- if (cw > indspec->minimal_cargo/* && i->produced_cargo[0] != 0xFF*/) {
- i->produced_cargo_waiting[0] -= cw;
+ for (uint j = 0; j < lengthof(i->produced_cargo_waiting); j++) {
+ uint cw = min(i->produced_cargo_waiting[j], 255);
+ if (cw > indspec->minimal_cargo && i->produced_cargo[j] != CT_INVALID) {
+ i->produced_cargo_waiting[j] -= cw;
- /* fluctuating economy? */
- if (_economy.fluct <= 0) cw = (cw + 1) / 2;
+ /* fluctuating economy? */
+ if (_economy.fluct <= 0) cw = (cw + 1) / 2;
- i->this_month_production[0] += cw;
+ i->this_month_production[j] += cw;
- am = MoveGoodsToStation(i->xy, i->width, i->height, i->produced_cargo[0], cw);
- i->this_month_transported[0] += am;
- if (am != 0 && !StartStopIndustryTileAnimation(i, IAT_INDUSTRY_DISTRIBUTES_CARGO)) {
- uint newgfx = GetIndustryTileSpec(GetIndustryGfx(tile))->anim_production;
+ uint am = MoveGoodsToStation(i->xy, i->width, i->height, i->produced_cargo[j], cw);
+ i->this_month_transported[j] += am;
- if (newgfx != INDUSTRYTILE_NOANIM) {
- ResetIndustryConstructionStage(tile);
- SetIndustryCompleted(tile, true);
- SetIndustryGfx(tile, newgfx);
- MarkTileDirtyByTile(tile);
- }
+ moved_cargo |= (am != 0);
}
}
- cw = min(i->produced_cargo_waiting[1], 255);
- if (cw > indspec->minimal_cargo) {
- i->produced_cargo_waiting[1] -= cw;
-
- if (_economy.fluct <= 0) cw = (cw + 1) / 2;
-
- i->this_month_production[1] += cw;
+ if (moved_cargo && !StartStopIndustryTileAnimation(i, IAT_INDUSTRY_DISTRIBUTES_CARGO)) {
+ uint newgfx = GetIndustryTileSpec(GetIndustryGfx(tile))->anim_production;
- am = MoveGoodsToStation(i->xy, i->width, i->height, i->produced_cargo[1], cw);
- i->this_month_transported[1] += am;
+ if (newgfx != INDUSTRYTILE_NOANIM) {
+ ResetIndustryConstructionStage(tile);
+ SetIndustryCompleted(tile, true);
+ SetIndustryGfx(tile, newgfx);
+ MarkTileDirtyByTile(tile);
+ }
}
}