src/newgrf_industries.cpp
author smatz
Wed, 24 Sep 2008 16:40:06 +0000
changeset 10184 bf4e3ff4cf16
parent 9750 7114408dd1fa
child 10202 2dcd2c490934
permissions -rw-r--r--
(svn r14395) -Fix [FS#2285]: crashes and GUI desyncs when order is deleted/modified while the timetable window is open
-Fix: close any dropdown and child windows in the Order and Timetable windows when selected order is deselected, deleted, ...
6835
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
     1
/* $Id$ */
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
     2
9111
48ce04029fe4 (svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents: 8970
diff changeset
     3
/** @file newgrf_industries.cpp Handling of NewGRF industries. */
6835
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
     4
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
     5
#include "stdafx.h"
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
     6
#include "openttd.h"
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
     7
#include "debug.h"
7207
277c6c315403 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7195
diff changeset
     8
#include "variables.h"
277c6c315403 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7195
diff changeset
     9
#include "landscape.h"
6835
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    10
#include "industry.h"
6868
abaf9e30691e (svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents: 6835
diff changeset
    11
#include "industry_map.h"
6835
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    12
#include "newgrf.h"
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    13
#include "newgrf_callbacks.h"
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    14
#include "newgrf_spritegroup.h"
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    15
#include "newgrf_industries.h"
7860
5cdd0d914013 (svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents: 7848
diff changeset
    16
#include "newgrf_industrytiles.h"
6835
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    17
#include "newgrf_commons.h"
7207
277c6c315403 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7195
diff changeset
    18
#include "newgrf_text.h"
277c6c315403 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7195
diff changeset
    19
#include "newgrf_town.h"
8131
160939e24ed3 (svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium
parents: 8113
diff changeset
    20
#include "window_func.h"
8213
7bdd7593eb9b (svn r11776) -Codechange: more header splittings to reduce the dependencies.
rubidium
parents: 8163
diff changeset
    21
#include "town.h"
8254
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents: 8237
diff changeset
    22
#include "player_func.h"
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents: 8237
diff changeset
    23
#include "player_base.h"
8275
f17d0c863ee3 (svn r11839) -Codechange: move some variables from variables.h to a more logical location.
rubidium
parents: 8264
diff changeset
    24
#include "command_func.h"
6835
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    25
8264
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8254
diff changeset
    26
#include "table/strings.h"
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8254
diff changeset
    27
8689
af0a4064b83e (svn r12362) -Fix (r11985, r12006): Randomize variable 8F only once per callback 28.
frosch
parents: 8634
diff changeset
    28
static uint32 _industry_creation_random_bits;
8436
c2600da0d3e3 (svn r12006) -Fix: implement FS#1697 without the nasty side effects as specified in FS#1712.
rubidium
parents: 8427
diff changeset
    29
6835
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    30
/* Since the industry IDs defined by the GRF file don't necessarily correlate
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    31
 * to those used by the game, the IDs used for overriding old industries must be
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    32
 * translated when the idustry spec is set. */
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    33
IndustryOverrideManager _industry_mngr(NEW_INDUSTRYOFFSET, NUM_INDUSTRYTYPES, INVALID_INDUSTRYTYPE);
7000
603a41cb93f8 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 6884
diff changeset
    34
IndustryTileOverrideManager _industile_mngr(NEW_INDUSTRYTILEOFFSET, NUM_INDUSTRYTILES, INVALID_INDUSTRYTILE);
6835
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    35
7233
aadfbb505671 (svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents: 7209
diff changeset
    36
IndustryType MapNewGRFIndustryType(IndustryType grf_type, uint32 grf_id)
aadfbb505671 (svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents: 7209
diff changeset
    37
{
aadfbb505671 (svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents: 7209
diff changeset
    38
	if (grf_type == IT_INVALID) return IT_INVALID;
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7922
diff changeset
    39
	if (!HasBit(grf_type, 7)) return GB(grf_type, 0, 6);
7233
aadfbb505671 (svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents: 7209
diff changeset
    40
aadfbb505671 (svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents: 7209
diff changeset
    41
	return _industry_mngr.GetID(GB(grf_type, 0, 6), grf_id);
aadfbb505671 (svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents: 7209
diff changeset
    42
}
aadfbb505671 (svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents: 7209
diff changeset
    43
6835
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    44
/**
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    45
 * Finds the distance for the closest tile with water/land given a tile
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    46
 * @param tile  the tile to find the distance too
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    47
 * @param water whether to find water or land
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    48
 * @note FAILS when an industry should be seen as water
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    49
 */
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    50
static uint GetClosestWaterDistance(TileIndex tile, bool water)
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    51
{
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    52
	TileIndex t;
7236
07ceb37a1b63 (svn r10517) -Fix: the "closest distance to water/land" calculation gave the distance to the north-eastern border instead of the closest water/land.
rubidium
parents: 7234
diff changeset
    53
	int best_dist;
07ceb37a1b63 (svn r10517) -Fix: the "closest distance to water/land" calculation gave the distance to the north-eastern border instead of the closest water/land.
rubidium
parents: 7234
diff changeset
    54
	for (t = 0; t < MapSize(); t++) {
6835
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    55
		if (IsTileType(t, MP_WATER) == water) break;
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    56
	}
7599
0d6d44f403c5 (svn r11126) -Fix: the algorithm to determine the closest water/land was flawed.
rubidium
parents: 7462
diff changeset
    57
	if (t == MapSize() && !water) return 0x200;
6835
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    58
	best_dist = DistanceManhattan(tile, t);
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    59
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    60
	for (; t < MapSize(); t++) {
7236
07ceb37a1b63 (svn r10517) -Fix: the "closest distance to water/land" calculation gave the distance to the north-eastern border instead of the closest water/land.
rubidium
parents: 7234
diff changeset
    61
		int dist = DistanceManhattan(tile, t);
6835
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    62
		if (dist < best_dist) {
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    63
			if (IsTileType(t, MP_WATER) == water) best_dist = dist;
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    64
		} else {
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    65
			/* When the Y distance between the current row and the 'source' tile
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    66
			 * is larger than the best distance, we've found the best distance */
7236
07ceb37a1b63 (svn r10517) -Fix: the "closest distance to water/land" calculation gave the distance to the north-eastern border instead of the closest water/land.
rubidium
parents: 7234
diff changeset
    67
			if ((int)TileY(t) - (int)TileY(tile) > best_dist) break;
7604
16666b8e91a4 (svn r11131) -Fix (r11126): forgot to commit the changes that performed the actual fix.
rubidium
parents: 7599
diff changeset
    68
			if ((int)TileX(t) - (int)TileX(tile) > best_dist) {
6835
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    69
				/* We can safely skip this many tiles; from here all tiles have a
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    70
				 * higher or equal distance than the best distance */
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    71
				t |= MapMaxX();
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    72
				continue;
7604
16666b8e91a4 (svn r11131) -Fix (r11126): forgot to commit the changes that performed the actual fix.
rubidium
parents: 7599
diff changeset
    73
			} else if (TileX(tile) < TileX(t)) {
6835
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    74
				/* We can safely skip this many tiles; up to here all tiles have a
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    75
				 * higher or equal distance than the best distance */
7236
07ceb37a1b63 (svn r10517) -Fix: the "closest distance to water/land" calculation gave the distance to the north-eastern border instead of the closest water/land.
rubidium
parents: 7234
diff changeset
    76
				t += max(best_dist - dist, 0);
6835
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    77
				continue;
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    78
			}
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    79
		}
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    80
	}
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    81
7599
0d6d44f403c5 (svn r11126) -Fix: the algorithm to determine the closest water/land was flawed.
rubidium
parents: 7462
diff changeset
    82
	return min(best_dist, water ? 0x7F : 0x1FF);
6835
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    83
}
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    84
6868
abaf9e30691e (svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents: 6835
diff changeset
    85
/** Make an analysis of a tile and check for its belonging to the same
abaf9e30691e (svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents: 6835
diff changeset
    86
 * industry, and/or the same grf file
7622
12388e4d86bb (svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents: 7621
diff changeset
    87
 * @param tile TileIndex of the tile to query
12388e4d86bb (svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents: 7621
diff changeset
    88
 * @param i Industry to which to compare the tile to
6868
abaf9e30691e (svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents: 6835
diff changeset
    89
 * @return value encoded as per NFO specs */
7622
12388e4d86bb (svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents: 7621
diff changeset
    90
uint32 GetIndustryIDAtOffset(TileIndex tile, const Industry *i)
6868
abaf9e30691e (svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents: 6835
diff changeset
    91
{
7706
bbf501d68106 (svn r11240) -Fix [FS#1323] (r11152): forgot to invert a test
glx
parents: 7685
diff changeset
    92
	if (!IsTileType(tile, MP_INDUSTRY) || GetIndustryIndex(tile) != i->index) {
7622
12388e4d86bb (svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents: 7621
diff changeset
    93
		/* No industry and/or the tile does not have the same industry as the one we match it with */
12388e4d86bb (svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents: 7621
diff changeset
    94
		return 0xFFFF;
12388e4d86bb (svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents: 7621
diff changeset
    95
	}
6868
abaf9e30691e (svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents: 6835
diff changeset
    96
7622
12388e4d86bb (svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents: 7621
diff changeset
    97
	IndustryGfx gfx = GetCleanIndustryGfx(tile);
12388e4d86bb (svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents: 7621
diff changeset
    98
	const IndustryTileSpec *indtsp = GetIndustryTileSpec(gfx);
12388e4d86bb (svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents: 7621
diff changeset
    99
	const IndustrySpec *indold = GetIndustrySpec(i->type);
6868
abaf9e30691e (svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents: 6835
diff changeset
   100
7622
12388e4d86bb (svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents: 7621
diff changeset
   101
	if (gfx < NEW_INDUSTRYOFFSET) { // Does it belongs to an old type?
12388e4d86bb (svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents: 7621
diff changeset
   102
		/* It is an old tile.  We have to see if it's been overriden */
12388e4d86bb (svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents: 7621
diff changeset
   103
		if (indtsp->grf_prop.override == INVALID_INDUSTRYTILE) { // has it been overridden?
12388e4d86bb (svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents: 7621
diff changeset
   104
			return 0xFF << 8 | gfx; // no. Tag FF + the gfx id of that tile
12388e4d86bb (svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents: 7621
diff changeset
   105
		}
12388e4d86bb (svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents: 7621
diff changeset
   106
		/* Not overriden */
12388e4d86bb (svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents: 7621
diff changeset
   107
		const IndustryTileSpec *tile_ovr = GetIndustryTileSpec(indtsp->grf_prop.override);
12388e4d86bb (svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents: 7621
diff changeset
   108
12388e4d86bb (svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents: 7621
diff changeset
   109
		if (tile_ovr->grf_prop.grffile->grfid == indold->grf_prop.grffile->grfid) {
12388e4d86bb (svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents: 7621
diff changeset
   110
			return tile_ovr->grf_prop.local_id; // same grf file
12388e4d86bb (svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents: 7621
diff changeset
   111
		} else {
12388e4d86bb (svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents: 7621
diff changeset
   112
			return 0xFFFE; // not the same grf file
6868
abaf9e30691e (svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents: 6835
diff changeset
   113
		}
abaf9e30691e (svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents: 6835
diff changeset
   114
	}
7622
12388e4d86bb (svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents: 7621
diff changeset
   115
	/* Not an 'old type' tile */
12388e4d86bb (svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents: 7621
diff changeset
   116
	if (indtsp->grf_prop.spritegroup != NULL) { // tile has a spritegroup ?
12388e4d86bb (svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents: 7621
diff changeset
   117
		if (indtsp->grf_prop.grffile->grfid == indold->grf_prop.grffile->grfid) { // same industry, same grf ?
12388e4d86bb (svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents: 7621
diff changeset
   118
			return indtsp->grf_prop.local_id;
12388e4d86bb (svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents: 7621
diff changeset
   119
		} else {
12388e4d86bb (svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents: 7621
diff changeset
   120
			return 0xFFFE; // Defined in another grf file
12388e4d86bb (svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents: 7621
diff changeset
   121
		}
12388e4d86bb (svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents: 7621
diff changeset
   122
	}
12388e4d86bb (svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents: 7621
diff changeset
   123
	/* The tile has no spritegroup */
12388e4d86bb (svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents: 7621
diff changeset
   124
	return 0xFF << 8 | indtsp->grf_prop.subst_id; // so just give him the substitute
6868
abaf9e30691e (svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents: 6835
diff changeset
   125
}
abaf9e30691e (svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents: 6835
diff changeset
   126
7233
aadfbb505671 (svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents: 7209
diff changeset
   127
static uint32 GetClosestIndustry(TileIndex tile, IndustryType type, const Industry *current)
aadfbb505671 (svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents: 7209
diff changeset
   128
{
9605
5a1897abd925 (svn r13647) -Codechange: replace MAX_UVALUE() for std types with the equivalent constant
skidd13
parents: 9487
diff changeset
   129
	uint32 best_dist = UINT32_MAX;
7233
aadfbb505671 (svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents: 7209
diff changeset
   130
	const Industry *i;
aadfbb505671 (svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents: 7209
diff changeset
   131
	FOR_ALL_INDUSTRIES(i) {
aadfbb505671 (svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents: 7209
diff changeset
   132
		if (i->type != type || i == current) continue;
aadfbb505671 (svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents: 7209
diff changeset
   133
aadfbb505671 (svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents: 7209
diff changeset
   134
		best_dist = min(best_dist, DistanceManhattan(tile, i->xy));
aadfbb505671 (svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents: 7209
diff changeset
   135
	}
aadfbb505671 (svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents: 7209
diff changeset
   136
aadfbb505671 (svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents: 7209
diff changeset
   137
	return best_dist;
aadfbb505671 (svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents: 7209
diff changeset
   138
}
aadfbb505671 (svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents: 7209
diff changeset
   139
7451
f2668c46aa21 (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7445
diff changeset
   140
/** Implementation of both var 67 and 68
f2668c46aa21 (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7445
diff changeset
   141
 * since the mechanism is almost the same, it is easier to regroup them on the same
f2668c46aa21 (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7445
diff changeset
   142
 * function.
f2668c46aa21 (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7445
diff changeset
   143
 * @param param_setID parameter given to the callback, which is the set id, or the local id, in our terminology
f2668c46aa21 (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7445
diff changeset
   144
 * @param layout_filter on what layout do we filter?
f2668c46aa21 (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7445
diff changeset
   145
 * @param current Industry for which the inquiry is made
f2668c46aa21 (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7445
diff changeset
   146
 * @return the formatted answer to the callback : rr(reserved) cc(count) dddd(manhattan distance of closest sister)
f2668c46aa21 (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7445
diff changeset
   147
 */
f2668c46aa21 (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7445
diff changeset
   148
static uint32 GetCountAndDistanceOfClosestInstance(byte param_setID, byte layout_filter, const Industry *current)
f2668c46aa21 (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7445
diff changeset
   149
{
f2668c46aa21 (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7445
diff changeset
   150
	uint32 GrfID = GetRegister(0x100);  ///< Get the GRFID of the definition to look for in register 100h
f2668c46aa21 (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7445
diff changeset
   151
	IndustryType ind_index;
9605
5a1897abd925 (svn r13647) -Codechange: replace MAX_UVALUE() for std types with the equivalent constant
skidd13
parents: 9487
diff changeset
   152
	uint32 closest_dist = UINT32_MAX;
7451
f2668c46aa21 (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7445
diff changeset
   153
	byte count = 0;
f2668c46aa21 (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7445
diff changeset
   154
f2668c46aa21 (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7445
diff changeset
   155
	/* Determine what will be the industry type to look for */
f2668c46aa21 (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7445
diff changeset
   156
	switch (GrfID) {
f2668c46aa21 (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7445
diff changeset
   157
		case 0:  // this is a default industry type
f2668c46aa21 (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7445
diff changeset
   158
			ind_index = param_setID;
f2668c46aa21 (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7445
diff changeset
   159
			break;
f2668c46aa21 (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7445
diff changeset
   160
f2668c46aa21 (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7445
diff changeset
   161
		case 0xFFFFFFFF: // current grf
7668
fd98cd8a83fd (svn r11199) -Fix: variable 67 and 68 not working correctly.
rubidium
parents: 7658
diff changeset
   162
			GrfID = GetIndustrySpec(current->type)->grf_prop.grffile->grfid;
fd98cd8a83fd (svn r11199) -Fix: variable 67 and 68 not working correctly.
rubidium
parents: 7658
diff changeset
   163
			/* Fall through */
7451
f2668c46aa21 (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7445
diff changeset
   164
f2668c46aa21 (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7445
diff changeset
   165
		default: //use the grfid specified in register 100h
7931
b0a46cd92225 (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents: 7928
diff changeset
   166
			SetBit(param_setID, 7); // bit 7 means it is not an old type
7451
f2668c46aa21 (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7445
diff changeset
   167
			ind_index = MapNewGRFIndustryType(param_setID, GrfID);
f2668c46aa21 (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7445
diff changeset
   168
			break;
f2668c46aa21 (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7445
diff changeset
   169
	}
f2668c46aa21 (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7445
diff changeset
   170
f2668c46aa21 (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7445
diff changeset
   171
	if (layout_filter == 0) {
f2668c46aa21 (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7445
diff changeset
   172
		/* If the filter is 0, it could be because none was specified as well as being really a 0.
f2668c46aa21 (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7445
diff changeset
   173
		 * In either case, just do the regular var67 */
f2668c46aa21 (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7445
diff changeset
   174
		closest_dist = GetClosestIndustry(current->xy, ind_index, current);
f2668c46aa21 (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7445
diff changeset
   175
		count = GetIndustryTypeCount(ind_index);
f2668c46aa21 (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7445
diff changeset
   176
	} else {
f2668c46aa21 (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7445
diff changeset
   177
		/* Count only those who match the same industry type and layout filter
f2668c46aa21 (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7445
diff changeset
   178
		 * Unfortunately, we have to do it manually */
f2668c46aa21 (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7445
diff changeset
   179
		const Industry *i;
f2668c46aa21 (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7445
diff changeset
   180
		FOR_ALL_INDUSTRIES(i) {
f2668c46aa21 (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7445
diff changeset
   181
			if (i->type == ind_index && i != current && i->selected_layout == layout_filter) {
f2668c46aa21 (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7445
diff changeset
   182
				closest_dist = min(closest_dist, DistanceManhattan(current->xy, i->xy));
f2668c46aa21 (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7445
diff changeset
   183
				count++;
f2668c46aa21 (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7445
diff changeset
   184
			}
f2668c46aa21 (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7445
diff changeset
   185
		}
f2668c46aa21 (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7445
diff changeset
   186
	}
f2668c46aa21 (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7445
diff changeset
   187
f2668c46aa21 (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7445
diff changeset
   188
	return count << 16 | GB(closest_dist, 0, 16);
f2668c46aa21 (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7445
diff changeset
   189
}
f2668c46aa21 (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7445
diff changeset
   190
6835
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   191
/** This function implements the industries variables that newGRF defines.
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   192
 * @param variable that is queried
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   193
 * @param parameter unused
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   194
 * @param available will return false if ever the variable asked for does not exist
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   195
 * @param ind is of course the industry we are inquiring
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   196
 * @return the value stored in the corresponding variable*/
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   197
uint32 IndustryGetVariable(const ResolverObject *object, byte variable, byte parameter, bool *available)
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   198
{
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   199
	const Industry *industry = object->u.industry.ind;
7207
277c6c315403 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7195
diff changeset
   200
	TileIndex tile = object->u.industry.tile;
8233
560ddd54f068 (svn r11797) -Fix: Add protection against not already created industry while doing industry callback.
belugas
parents: 8213
diff changeset
   201
	IndustryType type = object->u.industry.type;
560ddd54f068 (svn r11797) -Fix: Add protection against not already created industry while doing industry callback.
belugas
parents: 8213
diff changeset
   202
	const IndustrySpec *indspec = GetIndustrySpec(type);
560ddd54f068 (svn r11797) -Fix: Add protection against not already created industry while doing industry callback.
belugas
parents: 8213
diff changeset
   203
9736
1dde9f49db84 (svn r13868) -Fix: Parent scope of industry variables.
frosch
parents: 9652
diff changeset
   204
	/* Shall the variable get resolved in parent scope and are we not yet in parent scope? */
1dde9f49db84 (svn r13868) -Fix: Parent scope of industry variables.
frosch
parents: 9652
diff changeset
   205
	if (object->u.industry.gfx == INVALID_INDUSTRYTILE && object->scope == VSG_SCOPE_PARENT) {
1dde9f49db84 (svn r13868) -Fix: Parent scope of industry variables.
frosch
parents: 9652
diff changeset
   206
		/* Pass the request on to the town of the industry */
1dde9f49db84 (svn r13868) -Fix: Parent scope of industry variables.
frosch
parents: 9652
diff changeset
   207
		const Town *t;
1dde9f49db84 (svn r13868) -Fix: Parent scope of industry variables.
frosch
parents: 9652
diff changeset
   208
1dde9f49db84 (svn r13868) -Fix: Parent scope of industry variables.
frosch
parents: 9652
diff changeset
   209
		if (industry != NULL) {
1dde9f49db84 (svn r13868) -Fix: Parent scope of industry variables.
frosch
parents: 9652
diff changeset
   210
			t = industry->town;
1dde9f49db84 (svn r13868) -Fix: Parent scope of industry variables.
frosch
parents: 9652
diff changeset
   211
		} else if (tile != INVALID_TILE) {
1dde9f49db84 (svn r13868) -Fix: Parent scope of industry variables.
frosch
parents: 9652
diff changeset
   212
			t = ClosestTownFromTile(tile, UINT_MAX);
1dde9f49db84 (svn r13868) -Fix: Parent scope of industry variables.
frosch
parents: 9652
diff changeset
   213
		} else {
1dde9f49db84 (svn r13868) -Fix: Parent scope of industry variables.
frosch
parents: 9652
diff changeset
   214
			*available = false;
1dde9f49db84 (svn r13868) -Fix: Parent scope of industry variables.
frosch
parents: 9652
diff changeset
   215
			return UINT_MAX;
1dde9f49db84 (svn r13868) -Fix: Parent scope of industry variables.
frosch
parents: 9652
diff changeset
   216
		}
1dde9f49db84 (svn r13868) -Fix: Parent scope of industry variables.
frosch
parents: 9652
diff changeset
   217
1dde9f49db84 (svn r13868) -Fix: Parent scope of industry variables.
frosch
parents: 9652
diff changeset
   218
		return TownGetVariable(variable, parameter, available, t);
1dde9f49db84 (svn r13868) -Fix: Parent scope of industry variables.
frosch
parents: 9652
diff changeset
   219
	}
1dde9f49db84 (svn r13868) -Fix: Parent scope of industry variables.
frosch
parents: 9652
diff changeset
   220
8233
560ddd54f068 (svn r11797) -Fix: Add protection against not already created industry while doing industry callback.
belugas
parents: 8213
diff changeset
   221
	if (industry == NULL) {
560ddd54f068 (svn r11797) -Fix: Add protection against not already created industry while doing industry callback.
belugas
parents: 8213
diff changeset
   222
		/* industry does not exist, only use those variables that are "safe" */
560ddd54f068 (svn r11797) -Fix: Add protection against not already created industry while doing industry callback.
belugas
parents: 8213
diff changeset
   223
		switch (variable) {
560ddd54f068 (svn r11797) -Fix: Add protection against not already created industry while doing industry callback.
belugas
parents: 8213
diff changeset
   224
			/* Manhattan distance of closes dry/water tile */
560ddd54f068 (svn r11797) -Fix: Add protection against not already created industry while doing industry callback.
belugas
parents: 8213
diff changeset
   225
			case 0x43: return GetClosestWaterDistance(tile, (indspec->behaviour & INDUSTRYBEH_BUILT_ONWATER) == 0);
560ddd54f068 (svn r11797) -Fix: Add protection against not already created industry while doing industry callback.
belugas
parents: 8213
diff changeset
   226
		}
560ddd54f068 (svn r11797) -Fix: Add protection against not already created industry while doing industry callback.
belugas
parents: 8213
diff changeset
   227
560ddd54f068 (svn r11797) -Fix: Add protection against not already created industry while doing industry callback.
belugas
parents: 8213
diff changeset
   228
		DEBUG(grf, 1, "Unhandled property 0x%X (no available industry) in callback 0x%x", variable, object->callback);
560ddd54f068 (svn r11797) -Fix: Add protection against not already created industry while doing industry callback.
belugas
parents: 8213
diff changeset
   229
560ddd54f068 (svn r11797) -Fix: Add protection against not already created industry while doing industry callback.
belugas
parents: 8213
diff changeset
   230
		*available = false;
560ddd54f068 (svn r11797) -Fix: Add protection against not already created industry while doing industry callback.
belugas
parents: 8213
diff changeset
   231
		return UINT_MAX;
560ddd54f068 (svn r11797) -Fix: Add protection against not already created industry while doing industry callback.
belugas
parents: 8213
diff changeset
   232
	}
6835
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   233
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   234
	switch (variable) {
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   235
		case 0x40:
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   236
		case 0x41:
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   237
		case 0x42: { // waiting cargo, but only if those two callback flags are set
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   238
			uint16 callback = indspec->callback_flags;
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7922
diff changeset
   239
			if (HasBit(callback, CBM_IND_PRODUCTION_CARGO_ARRIVAL) || HasBit(callback, CBM_IND_PRODUCTION_256_TICKS)) {
7958
e42fa05eb045 (svn r11514) -Change: implement the automatic multiplier handler for NewGRF industries.
rubidium
parents: 7931
diff changeset
   240
				if ((indspec->behaviour & INDUSTRYBEH_PROD_MULTI_HNDLING) != 0) {
e42fa05eb045 (svn r11514) -Change: implement the automatic multiplier handler for NewGRF industries.
rubidium
parents: 7931
diff changeset
   241
					return min(industry->incoming_cargo_waiting[variable - 0x40] / industry->prod_level, (uint16)0xFFFF);
e42fa05eb045 (svn r11514) -Change: implement the automatic multiplier handler for NewGRF industries.
rubidium
parents: 7931
diff changeset
   242
				} else {
e42fa05eb045 (svn r11514) -Change: implement the automatic multiplier handler for NewGRF industries.
rubidium
parents: 7931
diff changeset
   243
					return min(industry->incoming_cargo_waiting[variable - 0x40], (uint16)0xFFFF);
e42fa05eb045 (svn r11514) -Change: implement the automatic multiplier handler for NewGRF industries.
rubidium
parents: 7931
diff changeset
   244
				}
6835
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   245
			} else {
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   246
				return 0;
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   247
			}
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   248
		}
7207
277c6c315403 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7195
diff changeset
   249
277c6c315403 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7195
diff changeset
   250
		/* Manhattan distance of closes dry/water tile */
7668
fd98cd8a83fd (svn r11199) -Fix: variable 67 and 68 not working correctly.
rubidium
parents: 7658
diff changeset
   251
		case 0x43: return GetClosestWaterDistance(tile, (indspec->behaviour & INDUSTRYBEH_BUILT_ONWATER) == 0);
6835
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   252
7445
4d96e6e94d88 (svn r10903) -Feature: [NewGRF] Add support for variable 44 of Variational Action 2 for Industries
belugas
parents: 7337
diff changeset
   253
		/* Layout number */
4d96e6e94d88 (svn r10903) -Feature: [NewGRF] Add support for variable 44 of Variational Action 2 for Industries
belugas
parents: 7337
diff changeset
   254
		case 0x44: return industry->selected_layout;
4d96e6e94d88 (svn r10903) -Feature: [NewGRF] Add support for variable 44 of Variational Action 2 for Industries
belugas
parents: 7337
diff changeset
   255
7671
21bc11c5265d (svn r11202) -Feature: [NewGRF] Add support for var 45 for Industries.
belugas
parents: 7668
diff changeset
   256
		/* player info */
21bc11c5265d (svn r11202) -Feature: [NewGRF] Add support for var 45 for Industries.
belugas
parents: 7668
diff changeset
   257
		case 0x45: {
7685
20852b29c17b (svn r11216) -Codechange: Protect the callback who would access var 45 against a randomness that could eventually cause desynchs. Instead, use a controlled random value.
belugas
parents: 7671
diff changeset
   258
			byte colours;
7671
21bc11c5265d (svn r11202) -Feature: [NewGRF] Add support for var 45 for Industries.
belugas
parents: 7668
diff changeset
   259
			bool is_ai = false;
7685
20852b29c17b (svn r11216) -Codechange: Protect the callback who would access var 45 against a randomness that could eventually cause desynchs. Instead, use a controlled random value.
belugas
parents: 7671
diff changeset
   260
9652
0405e98d8e96 (svn r13719) -Codechange: rename IsValidPlayer to IsValidPlayerID in line with all other structs/classes that are in a pool.
rubidium
parents: 9605
diff changeset
   261
			if (IsValidPlayerID(industry->founder)) {
7671
21bc11c5265d (svn r11202) -Feature: [NewGRF] Add support for var 45 for Industries.
belugas
parents: 7668
diff changeset
   262
				const Player *p = GetPlayer(industry->founder);
21bc11c5265d (svn r11202) -Feature: [NewGRF] Add support for var 45 for Industries.
belugas
parents: 7668
diff changeset
   263
				const Livery *l = &p->livery[LS_DEFAULT];
7685
20852b29c17b (svn r11216) -Codechange: Protect the callback who would access var 45 against a randomness that could eventually cause desynchs. Instead, use a controlled random value.
belugas
parents: 7671
diff changeset
   264
7671
21bc11c5265d (svn r11202) -Feature: [NewGRF] Add support for var 45 for Industries.
belugas
parents: 7668
diff changeset
   265
				is_ai = p->is_ai;
7685
20852b29c17b (svn r11216) -Codechange: Protect the callback who would access var 45 against a randomness that could eventually cause desynchs. Instead, use a controlled random value.
belugas
parents: 7671
diff changeset
   266
				colours = l->colour1 + l->colour2 * 16;
20852b29c17b (svn r11216) -Codechange: Protect the callback who would access var 45 against a randomness that could eventually cause desynchs. Instead, use a controlled random value.
belugas
parents: 7671
diff changeset
   267
			} else {
20852b29c17b (svn r11216) -Codechange: Protect the callback who would access var 45 against a randomness that could eventually cause desynchs. Instead, use a controlled random value.
belugas
parents: 7671
diff changeset
   268
				colours = GB(Random(), 0, 8);
7671
21bc11c5265d (svn r11202) -Feature: [NewGRF] Add support for var 45 for Industries.
belugas
parents: 7668
diff changeset
   269
			}
7685
20852b29c17b (svn r11216) -Codechange: Protect the callback who would access var 45 against a randomness that could eventually cause desynchs. Instead, use a controlled random value.
belugas
parents: 7671
diff changeset
   270
20852b29c17b (svn r11216) -Codechange: Protect the callback who would access var 45 against a randomness that could eventually cause desynchs. Instead, use a controlled random value.
belugas
parents: 7671
diff changeset
   271
			return industry->founder | (is_ai ? 0x10000 : 0) | (colours << 24);
7671
21bc11c5265d (svn r11202) -Feature: [NewGRF] Add support for var 45 for Industries.
belugas
parents: 7668
diff changeset
   272
		}
21bc11c5265d (svn r11202) -Feature: [NewGRF] Add support for var 45 for Industries.
belugas
parents: 7668
diff changeset
   273
9487
4b8dae4806bf (svn r13446) -Fix(r13443): changed the var previously introduced from 69 to 46, as no param was required (thanks frosch)
belugas
parents: 9484
diff changeset
   274
		case 0x46: return industry->construction_date; // Date when built - long format - (in days)
4b8dae4806bf (svn r13446) -Fix(r13443): changed the var previously introduced from 69 to 46, as no param was required (thanks frosch)
belugas
parents: 9484
diff changeset
   275
6868
abaf9e30691e (svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents: 6835
diff changeset
   276
		/* Get industry ID at offset param */
7622
12388e4d86bb (svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents: 7621
diff changeset
   277
		case 0x60: return GetIndustryIDAtOffset(GetNearbyTile(parameter, industry->xy), industry);
6835
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   278
7621
09824471f144 (svn r11151) -Codechange: add (partial) support for randomizing industry triggers (part of the backend for it). Furthermore update the documentation of the map's bits wrt to industries.
rubidium
parents: 7614
diff changeset
   279
		/* Get random tile bits at offset param */
09824471f144 (svn r11151) -Codechange: add (partial) support for randomizing industry triggers (part of the backend for it). Furthermore update the documentation of the map's bits wrt to industries.
rubidium
parents: 7614
diff changeset
   280
		case 0x61:
09824471f144 (svn r11151) -Codechange: add (partial) support for randomizing industry triggers (part of the backend for it). Furthermore update the documentation of the map's bits wrt to industries.
rubidium
parents: 7614
diff changeset
   281
			tile = GetNearbyTile(parameter, tile);
09824471f144 (svn r11151) -Codechange: add (partial) support for randomizing industry triggers (part of the backend for it). Furthermore update the documentation of the map's bits wrt to industries.
rubidium
parents: 7614
diff changeset
   282
			return (IsTileType(tile, MP_INDUSTRY) && GetIndustryByTile(tile) == industry) ? GetIndustryRandomBits(tile) : 0;
6835
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   283
7234
c6d0e14ae80b (svn r10515) -Codechange: allow getting some more data about the environment of an industry.
rubidium
parents: 7233
diff changeset
   284
		/* Land info of nearby tiles */
c6d0e14ae80b (svn r10515) -Codechange: allow getting some more data about the environment of an industry.
rubidium
parents: 7233
diff changeset
   285
		case 0x62: return GetNearbyIndustryTileInformation(parameter, tile, INVALID_INDUSTRY);
c6d0e14ae80b (svn r10515) -Codechange: allow getting some more data about the environment of an industry.
rubidium
parents: 7233
diff changeset
   286
c6d0e14ae80b (svn r10515) -Codechange: allow getting some more data about the environment of an industry.
rubidium
parents: 7233
diff changeset
   287
		/* Animation stage of nearby tiles */
7621
09824471f144 (svn r11151) -Codechange: add (partial) support for randomizing industry triggers (part of the backend for it). Furthermore update the documentation of the map's bits wrt to industries.
rubidium
parents: 7614
diff changeset
   288
		case 0x63:
7234
c6d0e14ae80b (svn r10515) -Codechange: allow getting some more data about the environment of an industry.
rubidium
parents: 7233
diff changeset
   289
			tile = GetNearbyTile(parameter, tile);
c6d0e14ae80b (svn r10515) -Codechange: allow getting some more data about the environment of an industry.
rubidium
parents: 7233
diff changeset
   290
			if (IsTileType(tile, MP_INDUSTRY) && GetIndustryByTile(tile) == industry) {
c6d0e14ae80b (svn r10515) -Codechange: allow getting some more data about the environment of an industry.
rubidium
parents: 7233
diff changeset
   291
				return GetIndustryAnimationState(tile);
c6d0e14ae80b (svn r10515) -Codechange: allow getting some more data about the environment of an industry.
rubidium
parents: 7233
diff changeset
   292
			}
c6d0e14ae80b (svn r10515) -Codechange: allow getting some more data about the environment of an industry.
rubidium
parents: 7233
diff changeset
   293
			return 0xFFFFFFFF;
c6d0e14ae80b (svn r10515) -Codechange: allow getting some more data about the environment of an industry.
rubidium
parents: 7233
diff changeset
   294
c6d0e14ae80b (svn r10515) -Codechange: allow getting some more data about the environment of an industry.
rubidium
parents: 7233
diff changeset
   295
		/* Distance of nearest industry of given type */
7314
bf53f5fe26a1 (svn r10669) -Codechange: Removed redundant comment
belugas
parents: 7260
diff changeset
   296
		case 0x64: return GetClosestIndustry(tile, MapNewGRFIndustryType(parameter, indspec->grf_prop.grffile->grfid), industry);
6835
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   297
		/* Get town zone and Manhattan distance of closest town */
8970
da7261f48b7e (svn r12762) -Fix: tabs after the first non-tab character are generally not okay (or lines starting with a space and then tabs).
rubidium
parents: 8756
diff changeset
   298
		case 0x65: return GetTownRadiusGroup(industry->town, tile) << 16 | min(DistanceManhattan(tile, industry->town->xy), 0xFFFF);
6835
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   299
		/* Get square of Euclidian distance of closes town */
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   300
		case 0x66: return GetTownRadiusGroup(industry->town, tile) << 16 | min(DistanceSquare(tile, industry->town->xy), 0xFFFF);
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   301
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   302
		/* Count of industry, distance of closest instance
7451
f2668c46aa21 (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7445
diff changeset
   303
		 * 68 is the same as 67, but with a filtering on selected layout */
f2668c46aa21 (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7445
diff changeset
   304
		case 0x67:
f2668c46aa21 (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7445
diff changeset
   305
		case 0x68: return GetCountAndDistanceOfClosestInstance(parameter, variable == 0x68 ? GB(GetRegister(0x101), 0, 8) : 0, industry);
6835
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   306
7610
13b7d9e247d2 (svn r11139) -Codechange: add support for persistent storage for NewGRFs.
rubidium
parents: 7604
diff changeset
   307
		/* Get a variable from the persistent storage */
13b7d9e247d2 (svn r11139) -Codechange: add support for persistent storage for NewGRFs.
rubidium
parents: 7604
diff changeset
   308
		case 0x7C: return industry->psa.Get(parameter);
13b7d9e247d2 (svn r11139) -Codechange: add support for persistent storage for NewGRFs.
rubidium
parents: 7604
diff changeset
   309
6835
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   310
		/* Industry structure access*/
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   311
		case 0x80: return industry->xy;
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   312
		case 0x81: return GB(industry->xy, 8, 8);
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   313
		/* Pointer to the town the industry is associated with */
7191
a877e27650aa (svn r10466) -Fix: the minimum amount of waiting cargo shouldn't be 65535; that should be the maximum amount of waiting cargo.
rubidium
parents: 7186
diff changeset
   314
		case 0x82: return industry->town->index;
6835
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   315
		case 0x83:
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   316
		case 0x84:
7186
818eba1f20d5 (svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries.
rubidium
parents: 7168
diff changeset
   317
		case 0x85: DEBUG(grf, 0, "NewGRFs shouldn't be doing pointer magic"); break; // not supported
6835
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   318
		case 0x86: return industry->width;
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   319
		case 0x87: return industry->height;// xy dimensions
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   320
		/*  */
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   321
		case 0x88:
7645
efa25fcf7917 (svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents: 7622
diff changeset
   322
		case 0x89: return industry->produced_cargo[variable - 0x88];
7165
fb78336b205f (svn r10439) -Codechange: initial steps for customized industry productions.
rubidium
parents: 7102
diff changeset
   323
		case 0x8A: return industry->produced_cargo_waiting[0];
fb78336b205f (svn r10439) -Codechange: initial steps for customized industry productions.
rubidium
parents: 7102
diff changeset
   324
		case 0x8B: return GB(industry->produced_cargo_waiting[0], 8, 8);
fb78336b205f (svn r10439) -Codechange: initial steps for customized industry productions.
rubidium
parents: 7102
diff changeset
   325
		case 0x8C: return industry->produced_cargo_waiting[1];
fb78336b205f (svn r10439) -Codechange: initial steps for customized industry productions.
rubidium
parents: 7102
diff changeset
   326
		case 0x8D: return GB(industry->produced_cargo_waiting[1], 8, 8);
6835
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   327
		case 0x8E:
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   328
		case 0x8F: return industry->production_rate[variable - 0x8E];
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   329
		case 0x90:
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   330
		case 0x91:
7645
efa25fcf7917 (svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents: 7622
diff changeset
   331
		case 0x92: return industry->accepts_cargo[variable - 0x90];
6835
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   332
		case 0x93: return industry->prod_level;
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   333
		/* amount of cargo produced so far THIS month. */
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   334
		case 0x94: return industry->this_month_production[0];
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   335
		case 0x95: return GB(industry->this_month_production[0], 8, 8);
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   336
		case 0x96: return industry->this_month_production[1];
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   337
		case 0x97: return GB(industry->this_month_production[1], 8, 8);
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   338
		/* amount of cargo transported so far THIS month. */
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   339
		case 0x98: return industry->this_month_transported[0];
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   340
		case 0x99: return GB(industry->this_month_transported[0], 8, 8);
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   341
		case 0x9A: return industry->this_month_transported[1];
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   342
		case 0x9B: return GB(industry->this_month_transported[0], 8, 8);
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   343
		/* fraction of cargo transported LAST month. */
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   344
		case 0x9C:
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   345
		case 0x9D: return industry->last_month_pct_transported[variable - 0x9C];
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   346
		/* amount of cargo produced LAST month. */
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   347
		case 0x9E: return industry->last_month_production[0];
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   348
		case 0x9F: return GB(industry->last_month_production[0], 8, 8);
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   349
		case 0xA0: return industry->last_month_production[1];
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   350
		case 0xA1: return GB(industry->last_month_production[1], 8, 8);
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   351
		/* amount of cargo transported last month. */
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   352
		case 0xA2: return industry->last_month_transported[0];
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   353
		case 0xA3: return GB(industry->last_month_transported[0], 8, 8);
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   354
		case 0xA4: return industry->last_month_transported[1];
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   355
		case 0xA5: return GB(industry->last_month_transported[0], 8, 8);
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   356
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   357
		case 0xA6: return industry->type;
7186
818eba1f20d5 (svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries.
rubidium
parents: 7168
diff changeset
   358
		case 0xA7: return industry->founder;
6835
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   359
		case 0xA8: return industry->random_color;
8634
496c3fb47daf (svn r12246) -Fix (r10460): Proper usage of Clamp().
frosch
parents: 8436
diff changeset
   360
		case 0xA9: return Clamp(industry->last_prod_year - ORIGINAL_BASE_YEAR, 0, 255);
6835
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   361
		case 0xAA: return industry->counter;
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   362
		case 0xAB: return GB(industry->counter, 8, 8);
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   363
		case 0xAC: return industry->was_cargo_delivered;
7186
818eba1f20d5 (svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries.
rubidium
parents: 7168
diff changeset
   364
8634
496c3fb47daf (svn r12246) -Fix (r10460): Proper usage of Clamp().
frosch
parents: 8436
diff changeset
   365
		case 0xB0: return Clamp(industry->construction_date - DAYS_TILL_ORIGINAL_BASE_YEAR, 0, 65535); // Date when built since 1920 (in days)
7186
818eba1f20d5 (svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries.
rubidium
parents: 7168
diff changeset
   366
		case 0xB3: return industry->construction_type; // Construction type
8634
496c3fb47daf (svn r12246) -Fix (r10460): Proper usage of Clamp().
frosch
parents: 8436
diff changeset
   367
		case 0xB4: return Clamp(industry->last_cargo_accepted_at - DAYS_TILL_ORIGINAL_BASE_YEAR, 0, 65535); // Date last cargo accepted since 1920 (in days)
6835
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   368
	}
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   369
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   370
	DEBUG(grf, 1, "Unhandled industry property 0x%X", variable);
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   371
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   372
	*available = false;
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   373
	return (uint32)-1;
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   374
}
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   375
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   376
static const SpriteGroup *IndustryResolveReal(const ResolverObject *object, const SpriteGroup *group)
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   377
{
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   378
	/* IndustryTile do not have 'real' groups */
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   379
	return NULL;
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   380
}
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   381
7621
09824471f144 (svn r11151) -Codechange: add (partial) support for randomizing industry triggers (part of the backend for it). Furthermore update the documentation of the map's bits wrt to industries.
rubidium
parents: 7614
diff changeset
   382
static uint32 IndustryGetRandomBits(const ResolverObject *object)
09824471f144 (svn r11151) -Codechange: add (partial) support for randomizing industry triggers (part of the backend for it). Furthermore update the documentation of the map's bits wrt to industries.
rubidium
parents: 7614
diff changeset
   383
{
7860
5cdd0d914013 (svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents: 7848
diff changeset
   384
	return object->u.industry.ind == NULL ? 0 : object->u.industry.ind->random;
7621
09824471f144 (svn r11151) -Codechange: add (partial) support for randomizing industry triggers (part of the backend for it). Furthermore update the documentation of the map's bits wrt to industries.
rubidium
parents: 7614
diff changeset
   385
}
09824471f144 (svn r11151) -Codechange: add (partial) support for randomizing industry triggers (part of the backend for it). Furthermore update the documentation of the map's bits wrt to industries.
rubidium
parents: 7614
diff changeset
   386
09824471f144 (svn r11151) -Codechange: add (partial) support for randomizing industry triggers (part of the backend for it). Furthermore update the documentation of the map's bits wrt to industries.
rubidium
parents: 7614
diff changeset
   387
static uint32 IndustryGetTriggers(const ResolverObject *object)
09824471f144 (svn r11151) -Codechange: add (partial) support for randomizing industry triggers (part of the backend for it). Furthermore update the documentation of the map's bits wrt to industries.
rubidium
parents: 7614
diff changeset
   388
{
7860
5cdd0d914013 (svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents: 7848
diff changeset
   389
	return object->u.industry.ind == NULL ? 0 : object->u.industry.ind->random_triggers;
7621
09824471f144 (svn r11151) -Codechange: add (partial) support for randomizing industry triggers (part of the backend for it). Furthermore update the documentation of the map's bits wrt to industries.
rubidium
parents: 7614
diff changeset
   390
}
09824471f144 (svn r11151) -Codechange: add (partial) support for randomizing industry triggers (part of the backend for it). Furthermore update the documentation of the map's bits wrt to industries.
rubidium
parents: 7614
diff changeset
   391
09824471f144 (svn r11151) -Codechange: add (partial) support for randomizing industry triggers (part of the backend for it). Furthermore update the documentation of the map's bits wrt to industries.
rubidium
parents: 7614
diff changeset
   392
static void IndustrySetTriggers(const ResolverObject *object, int triggers)
09824471f144 (svn r11151) -Codechange: add (partial) support for randomizing industry triggers (part of the backend for it). Furthermore update the documentation of the map's bits wrt to industries.
rubidium
parents: 7614
diff changeset
   393
{
09824471f144 (svn r11151) -Codechange: add (partial) support for randomizing industry triggers (part of the backend for it). Furthermore update the documentation of the map's bits wrt to industries.
rubidium
parents: 7614
diff changeset
   394
	if (object->u.industry.ind == NULL) return;
7860
5cdd0d914013 (svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents: 7848
diff changeset
   395
	object->u.industry.ind->random_triggers = triggers;
7621
09824471f144 (svn r11151) -Codechange: add (partial) support for randomizing industry triggers (part of the backend for it). Furthermore update the documentation of the map's bits wrt to industries.
rubidium
parents: 7614
diff changeset
   396
}
09824471f144 (svn r11151) -Codechange: add (partial) support for randomizing industry triggers (part of the backend for it). Furthermore update the documentation of the map's bits wrt to industries.
rubidium
parents: 7614
diff changeset
   397
8233
560ddd54f068 (svn r11797) -Fix: Add protection against not already created industry while doing industry callback.
belugas
parents: 8213
diff changeset
   398
static void NewIndustryResolver(ResolverObject *res, TileIndex tile, Industry *indus, IndustryType type)
6835
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   399
{
7621
09824471f144 (svn r11151) -Codechange: add (partial) support for randomizing industry triggers (part of the backend for it). Furthermore update the documentation of the map's bits wrt to industries.
rubidium
parents: 7614
diff changeset
   400
	res->GetRandomBits = IndustryGetRandomBits;
09824471f144 (svn r11151) -Codechange: add (partial) support for randomizing industry triggers (part of the backend for it). Furthermore update the documentation of the map's bits wrt to industries.
rubidium
parents: 7614
diff changeset
   401
	res->GetTriggers   = IndustryGetTriggers;
09824471f144 (svn r11151) -Codechange: add (partial) support for randomizing industry triggers (part of the backend for it). Furthermore update the documentation of the map's bits wrt to industries.
rubidium
parents: 7614
diff changeset
   402
	res->SetTriggers   = IndustrySetTriggers;
6835
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   403
	res->GetVariable   = IndustryGetVariable;
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   404
	res->ResolveReal   = IndustryResolveReal;
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   405
7610
13b7d9e247d2 (svn r11139) -Codechange: add support for persistent storage for NewGRFs.
rubidium
parents: 7604
diff changeset
   406
	res->psa             = &indus->psa;
6835
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   407
	res->u.industry.tile = tile;
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   408
	res->u.industry.ind  = indus;
6884
a931841e9df4 (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents: 6868
diff changeset
   409
	res->u.industry.gfx  = INVALID_INDUSTRYTILE;
8233
560ddd54f068 (svn r11797) -Fix: Add protection against not already created industry while doing industry callback.
belugas
parents: 8213
diff changeset
   410
	res->u.industry.type = type;
6835
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   411
7327
d810677fb909 (svn r10690) -Codechange: use the enum that describes all callback IDs in favor of "just" using an untyped integer.
rubidium
parents: 7314
diff changeset
   412
	res->callback        = CBID_NO_CALLBACK;
6835
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   413
	res->callback_param1 = 0;
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   414
	res->callback_param2 = 0;
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   415
	res->last_value      = 0;
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   416
	res->trigger         = 0;
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   417
	res->reseed          = 0;
8756
b6f8dc6a246f (svn r12452) -Feature: [NewGRF] Add random action 2 type 84. For vehicles only.
glx
parents: 8689
diff changeset
   418
	res->count           = 0;
9750
7114408dd1fa (svn r13885) -Fix [FS#2168]: Var 0x7F is not feature-specific.
frosch
parents: 9736
diff changeset
   419
7114408dd1fa (svn r13885) -Fix [FS#2168]: Var 0x7F is not feature-specific.
frosch
parents: 9736
diff changeset
   420
	const IndustrySpec *indspec = GetIndustrySpec(type);
7114408dd1fa (svn r13885) -Fix [FS#2168]: Var 0x7F is not feature-specific.
frosch
parents: 9736
diff changeset
   421
	res->grffile         = (indspec != NULL ? indspec->grf_prop.grffile : NULL);
6835
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   422
}
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   423
7327
d810677fb909 (svn r10690) -Codechange: use the enum that describes all callback IDs in favor of "just" using an untyped integer.
rubidium
parents: 7314
diff changeset
   424
uint16 GetIndustryCallback(CallbackID callback, uint32 param1, uint32 param2, Industry *industry, IndustryType type, TileIndex tile)
6835
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   425
{
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   426
	ResolverObject object;
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   427
	const SpriteGroup *group;
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   428
8233
560ddd54f068 (svn r11797) -Fix: Add protection against not already created industry while doing industry callback.
belugas
parents: 8213
diff changeset
   429
	NewIndustryResolver(&object, tile, industry, type);
6835
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   430
	object.callback = callback;
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   431
	object.callback_param1 = param1;
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   432
	object.callback_param2 = param2;
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   433
7102
fe01c264132b (svn r10369) -Codechange: Add the IndustryType parameter to the GetIndustryCallback function.
belugas
parents: 7000
diff changeset
   434
	group = Resolve(GetIndustrySpec(type)->grf_prop.spritegroup, &object);
6835
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   435
	if (group == NULL || group->type != SGT_CALLBACK) return CALLBACK_FAILED;
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   436
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   437
	return group->g.callback.result;
31c89aab2d61 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   438
}
7168
25e07ccb4a3d (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7166
diff changeset
   439
7207
277c6c315403 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7195
diff changeset
   440
uint32 IndustryLocationGetVariable(const ResolverObject *object, byte variable, byte parameter, bool *available)
277c6c315403 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7195
diff changeset
   441
{
7668
fd98cd8a83fd (svn r11199) -Fix: variable 67 and 68 not working correctly.
rubidium
parents: 7658
diff changeset
   442
	const Industry *industry = object->u.industry.ind;
fd98cd8a83fd (svn r11199) -Fix: variable 67 and 68 not working correctly.
rubidium
parents: 7658
diff changeset
   443
	TileIndex tile = object->u.industry.tile;
7207
277c6c315403 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7195
diff changeset
   444
277c6c315403 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7195
diff changeset
   445
	if (object->scope == VSG_SCOPE_PARENT) {
7668
fd98cd8a83fd (svn r11199) -Fix: variable 67 and 68 not working correctly.
rubidium
parents: 7658
diff changeset
   446
		return TownGetVariable(variable, parameter, available, industry->town);
7207
277c6c315403 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7195
diff changeset
   447
	}
277c6c315403 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7195
diff changeset
   448
277c6c315403 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7195
diff changeset
   449
	switch (variable) {
277c6c315403 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7195
diff changeset
   450
		case 0x80: return tile;
277c6c315403 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7195
diff changeset
   451
		case 0x81: return GB(tile, 8, 8);
7234
c6d0e14ae80b (svn r10515) -Codechange: allow getting some more data about the environment of an industry.
rubidium
parents: 7233
diff changeset
   452
7207
277c6c315403 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7195
diff changeset
   453
		/* Pointer to the town the industry is associated with */
7668
fd98cd8a83fd (svn r11199) -Fix: variable 67 and 68 not working correctly.
rubidium
parents: 7658
diff changeset
   454
		case 0x82: return industry->town->index;
7207
277c6c315403 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7195
diff changeset
   455
		case 0x83:
277c6c315403 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7195
diff changeset
   456
		case 0x84:
277c6c315403 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7195
diff changeset
   457
		case 0x85: DEBUG(grf, 0, "NewGRFs shouldn't be doing pointer magic"); break; // not supported
277c6c315403 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7195
diff changeset
   458
277c6c315403 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7195
diff changeset
   459
		/* Number of the layout */
7668
fd98cd8a83fd (svn r11199) -Fix: variable 67 and 68 not working correctly.
rubidium
parents: 7658
diff changeset
   460
		case 0x86: return industry->selected_layout;
7207
277c6c315403 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7195
diff changeset
   461
277c6c315403 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7195
diff changeset
   462
		/* Ground type */
277c6c315403 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7195
diff changeset
   463
		case 0x87: return GetTerrainType(tile);
277c6c315403 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7195
diff changeset
   464
277c6c315403 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7195
diff changeset
   465
		/* Town zone */
7668
fd98cd8a83fd (svn r11199) -Fix: variable 67 and 68 not working correctly.
rubidium
parents: 7658
diff changeset
   466
		case 0x88: return GetTownRadiusGroup(industry->town, tile);
7207
277c6c315403 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7195
diff changeset
   467
277c6c315403 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7195
diff changeset
   468
		/* Manhattan distance of the closest town */
7668
fd98cd8a83fd (svn r11199) -Fix: variable 67 and 68 not working correctly.
rubidium
parents: 7658
diff changeset
   469
		case 0x89: return min(DistanceManhattan(industry->town->xy, tile), 255);
7207
277c6c315403 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7195
diff changeset
   470
277c6c315403 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7195
diff changeset
   471
		/* Lowest height of the tile */
277c6c315403 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7195
diff changeset
   472
		case 0x8A: return GetTileZ(tile);
277c6c315403 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7195
diff changeset
   473
277c6c315403 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7195
diff changeset
   474
		/* Distance to the nearest water/land tile */
7668
fd98cd8a83fd (svn r11199) -Fix: variable 67 and 68 not working correctly.
rubidium
parents: 7658
diff changeset
   475
		case 0x8B: return GetClosestWaterDistance(tile, (GetIndustrySpec(industry->type)->behaviour & INDUSTRYBEH_BUILT_ONWATER) == 0);
7207
277c6c315403 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7195
diff changeset
   476
277c6c315403 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7195
diff changeset
   477
		/* Square of Euclidian distance from town */
7668
fd98cd8a83fd (svn r11199) -Fix: variable 67 and 68 not working correctly.
rubidium
parents: 7658
diff changeset
   478
		case 0x8D: return min(DistanceSquare(industry->town->xy, tile), 65535);
8415
41a623a9fdb5 (svn r11985) -Feature[FS#1697, newGRF]: Implement var 8F(random bits) during callback 28 (Industry location permissibility)
belugas
parents: 8275
diff changeset
   479
8436
c2600da0d3e3 (svn r12006) -Fix: implement FS#1697 without the nasty side effects as specified in FS#1712.
rubidium
parents: 8427
diff changeset
   480
		/* 32 random bits */
8689
af0a4064b83e (svn r12362) -Fix (r11985, r12006): Randomize variable 8F only once per callback 28.
frosch
parents: 8634
diff changeset
   481
		case 0x8F: return _industry_creation_random_bits;
7207
277c6c315403 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7195
diff changeset
   482
	}
277c6c315403 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7195
diff changeset
   483
7668
fd98cd8a83fd (svn r11199) -Fix: variable 67 and 68 not working correctly.
rubidium
parents: 7658
diff changeset
   484
	/* None of the special ones, so try the general ones */
fd98cd8a83fd (svn r11199) -Fix: variable 67 and 68 not working correctly.
rubidium
parents: 7658
diff changeset
   485
	return IndustryGetVariable(object, variable, parameter, available);
7207
277c6c315403 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7195
diff changeset
   486
}
277c6c315403 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7195
diff changeset
   487
8436
c2600da0d3e3 (svn r12006) -Fix: implement FS#1697 without the nasty side effects as specified in FS#1712.
rubidium
parents: 8427
diff changeset
   488
bool CheckIfCallBackAllowsCreation(TileIndex tile, IndustryType type, uint itspec_index, uint32 seed)
7207
277c6c315403 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7195
diff changeset
   489
{
277c6c315403 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7195
diff changeset
   490
	const IndustrySpec *indspec = GetIndustrySpec(type);
277c6c315403 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7195
diff changeset
   491
277c6c315403 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7195
diff changeset
   492
	ResolverObject object;
277c6c315403 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7195
diff changeset
   493
	const SpriteGroup *group;
277c6c315403 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7195
diff changeset
   494
7668
fd98cd8a83fd (svn r11199) -Fix: variable 67 and 68 not working correctly.
rubidium
parents: 7658
diff changeset
   495
	Industry ind;
fd98cd8a83fd (svn r11199) -Fix: variable 67 and 68 not working correctly.
rubidium
parents: 7658
diff changeset
   496
	ind.index = INVALID_INDUSTRY;
fd98cd8a83fd (svn r11199) -Fix: variable 67 and 68 not working correctly.
rubidium
parents: 7658
diff changeset
   497
	ind.xy = tile;
fd98cd8a83fd (svn r11199) -Fix: variable 67 and 68 not working correctly.
rubidium
parents: 7658
diff changeset
   498
	ind.width = 0;
fd98cd8a83fd (svn r11199) -Fix: variable 67 and 68 not working correctly.
rubidium
parents: 7658
diff changeset
   499
	ind.type = type;
fd98cd8a83fd (svn r11199) -Fix: variable 67 and 68 not working correctly.
rubidium
parents: 7658
diff changeset
   500
	ind.selected_layout = itspec_index;
fd98cd8a83fd (svn r11199) -Fix: variable 67 and 68 not working correctly.
rubidium
parents: 7658
diff changeset
   501
	ind.town = ClosestTownFromTile(tile, (uint)-1);
fd98cd8a83fd (svn r11199) -Fix: variable 67 and 68 not working correctly.
rubidium
parents: 7658
diff changeset
   502
8233
560ddd54f068 (svn r11797) -Fix: Add protection against not already created industry while doing industry callback.
belugas
parents: 8213
diff changeset
   503
	NewIndustryResolver(&object, tile, &ind, type);
7207
277c6c315403 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7195
diff changeset
   504
	object.GetVariable = IndustryLocationGetVariable;
277c6c315403 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7195
diff changeset
   505
	object.callback = CBID_INDUSTRY_LOCATION;
8689
af0a4064b83e (svn r12362) -Fix (r11985, r12006): Randomize variable 8F only once per callback 28.
frosch
parents: 8634
diff changeset
   506
	_industry_creation_random_bits = seed;
7207
277c6c315403 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7195
diff changeset
   507
277c6c315403 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7195
diff changeset
   508
	group = Resolve(GetIndustrySpec(type)->grf_prop.spritegroup, &object);
277c6c315403 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7195
diff changeset
   509
7658
509348d18665 (svn r11189) -Fix: if the location check callback results in something invalid (i.e. not a callback result), the industry should be allowed to be build as that's how TTDP does it.
rubidium
parents: 7645
diff changeset
   510
	/* Unlike the "normal" cases, not having a valid result means we allow
509348d18665 (svn r11189) -Fix: if the location check callback results in something invalid (i.e. not a callback result), the industry should be allowed to be build as that's how TTDP does it.
rubidium
parents: 7645
diff changeset
   511
	 * the building of the industry, as that's how it's done in TTDP. */
509348d18665 (svn r11189) -Fix: if the location check callback results in something invalid (i.e. not a callback result), the industry should be allowed to be build as that's how TTDP does it.
rubidium
parents: 7645
diff changeset
   512
	if (group == NULL || group->type != SGT_CALLBACK) return true;
7207
277c6c315403 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7195
diff changeset
   513
7750
7afbef1235e0 (svn r11287) -Codechange: add support for pushing paramaters into NewIndustries' error messages. Patch by Csaboka.
rubidium
parents: 7706
diff changeset
   514
	/* Copy some parameters from the registers to the error message text ref. stack */
7afbef1235e0 (svn r11287) -Codechange: add support for pushing paramaters into NewIndustries' error messages. Patch by Csaboka.
rubidium
parents: 7706
diff changeset
   515
	SwitchToErrorRefStack();
7afbef1235e0 (svn r11287) -Codechange: add support for pushing paramaters into NewIndustries' error messages. Patch by Csaboka.
rubidium
parents: 7706
diff changeset
   516
	PrepareTextRefStackUsage(4);
7afbef1235e0 (svn r11287) -Codechange: add support for pushing paramaters into NewIndustries' error messages. Patch by Csaboka.
rubidium
parents: 7706
diff changeset
   517
	SwitchToNormalRefStack();
7afbef1235e0 (svn r11287) -Codechange: add support for pushing paramaters into NewIndustries' error messages. Patch by Csaboka.
rubidium
parents: 7706
diff changeset
   518
7207
277c6c315403 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7195
diff changeset
   519
	switch (group->g.callback.result) {
277c6c315403 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7195
diff changeset
   520
		case 0x400: return true;
7209
30b3bc8c177b (svn r10487) -Fix: forgot some breaks in a switch statement.
rubidium
parents: 7207
diff changeset
   521
		case 0x401: _error_message = STR_0239_SITE_UNSUITABLE; break;
30b3bc8c177b (svn r10487) -Fix: forgot some breaks in a switch statement.
rubidium
parents: 7207
diff changeset
   522
		case 0x402: _error_message = STR_0317_CAN_ONLY_BE_BUILT_IN_RAINFOREST; break;
30b3bc8c177b (svn r10487) -Fix: forgot some breaks in a switch statement.
rubidium
parents: 7207
diff changeset
   523
		case 0x403: _error_message = STR_0318_CAN_ONLY_BE_BUILT_IN_DESERT; break;
30b3bc8c177b (svn r10487) -Fix: forgot some breaks in a switch statement.
rubidium
parents: 7207
diff changeset
   524
		default: _error_message = GetGRFStringID(indspec->grf_prop.grffile->grfid, 0xD000 + group->g.callback.result); break;
7207
277c6c315403 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7195
diff changeset
   525
	}
277c6c315403 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7195
diff changeset
   526
277c6c315403 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7195
diff changeset
   527
	return false;
277c6c315403 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7195
diff changeset
   528
}
277c6c315403 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7195
diff changeset
   529
7260
487c5de4fe2c (svn r10572) -Codechange: Add function CheckIfCallBackAllowsAvailability for industries
belugas
parents: 7237
diff changeset
   530
bool CheckIfCallBackAllowsAvailability(IndustryType type, IndustryAvailabilityCallType creation_type)
487c5de4fe2c (svn r10572) -Codechange: Add function CheckIfCallBackAllowsAvailability for industries
belugas
parents: 7237
diff changeset
   531
{
487c5de4fe2c (svn r10572) -Codechange: Add function CheckIfCallBackAllowsAvailability for industries
belugas
parents: 7237
diff changeset
   532
	const IndustrySpec *indspec = GetIndustrySpec(type);
487c5de4fe2c (svn r10572) -Codechange: Add function CheckIfCallBackAllowsAvailability for industries
belugas
parents: 7237
diff changeset
   533
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7922
diff changeset
   534
	if (HasBit(indspec->callback_flags, CBM_IND_AVAILABLE)) {
7260
487c5de4fe2c (svn r10572) -Codechange: Add function CheckIfCallBackAllowsAvailability for industries
belugas
parents: 7237
diff changeset
   535
		uint16 res = GetIndustryCallback(CBID_INDUSTRY_AVAILABLE, 0, creation_type, NULL, type, INVALID_TILE);
487c5de4fe2c (svn r10572) -Codechange: Add function CheckIfCallBackAllowsAvailability for industries
belugas
parents: 7237
diff changeset
   536
		if (res != CALLBACK_FAILED) {
487c5de4fe2c (svn r10572) -Codechange: Add function CheckIfCallBackAllowsAvailability for industries
belugas
parents: 7237
diff changeset
   537
			return (res == 0);
487c5de4fe2c (svn r10572) -Codechange: Add function CheckIfCallBackAllowsAvailability for industries
belugas
parents: 7237
diff changeset
   538
		}
487c5de4fe2c (svn r10572) -Codechange: Add function CheckIfCallBackAllowsAvailability for industries
belugas
parents: 7237
diff changeset
   539
	}
487c5de4fe2c (svn r10572) -Codechange: Add function CheckIfCallBackAllowsAvailability for industries
belugas
parents: 7237
diff changeset
   540
	return true;
487c5de4fe2c (svn r10572) -Codechange: Add function CheckIfCallBackAllowsAvailability for industries
belugas
parents: 7237
diff changeset
   541
}
487c5de4fe2c (svn r10572) -Codechange: Add function CheckIfCallBackAllowsAvailability for industries
belugas
parents: 7237
diff changeset
   542
7168
25e07ccb4a3d (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7166
diff changeset
   543
static int32 DerefIndProd(uint field, bool use_register)
25e07ccb4a3d (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7166
diff changeset
   544
{
25e07ccb4a3d (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7166
diff changeset
   545
	return use_register ? (int32)GetRegister(field) : field;
25e07ccb4a3d (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7166
diff changeset
   546
}
25e07ccb4a3d (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7166
diff changeset
   547
25e07ccb4a3d (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7166
diff changeset
   548
/**
25e07ccb4a3d (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7166
diff changeset
   549
 * Get the industry production callback and apply it to the industry.
25e07ccb4a3d (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7166
diff changeset
   550
 * @param ind    the industry this callback has to be called for
25e07ccb4a3d (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7166
diff changeset
   551
 * @param reason the reason it is called (0 = incoming cargo, 1 = periodic tick callback)
25e07ccb4a3d (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7166
diff changeset
   552
 */
25e07ccb4a3d (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7166
diff changeset
   553
void IndustryProductionCallback(Industry *ind, int reason)
25e07ccb4a3d (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7166
diff changeset
   554
{
7614
edf90d673e04 (svn r11143) -Fix: the random bits were not set for the production callback when the NewGRF asked for it.
rubidium
parents: 7610
diff changeset
   555
	const IndustrySpec *spec = GetIndustrySpec(ind->type);
7168
25e07ccb4a3d (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7166
diff changeset
   556
	ResolverObject object;
8233
560ddd54f068 (svn r11797) -Fix: Add protection against not already created industry while doing industry callback.
belugas
parents: 8213
diff changeset
   557
	NewIndustryResolver(&object, ind->xy, ind, ind->type);
7614
edf90d673e04 (svn r11143) -Fix: the random bits were not set for the production callback when the NewGRF asked for it.
rubidium
parents: 7610
diff changeset
   558
	if ((spec->behaviour & INDUSTRYBEH_PRODCALLBACK_RANDOM) != 0) object.callback_param1 = Random();
7958
e42fa05eb045 (svn r11514) -Change: implement the automatic multiplier handler for NewGRF industries.
rubidium
parents: 7931
diff changeset
   559
	int multiplier = 1;
e42fa05eb045 (svn r11514) -Change: implement the automatic multiplier handler for NewGRF industries.
rubidium
parents: 7931
diff changeset
   560
	if ((spec->behaviour & INDUSTRYBEH_PROD_MULTI_HNDLING) != 0) multiplier = ind->prod_level;
7168
25e07ccb4a3d (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7166
diff changeset
   561
	object.callback_param2 = reason;
25e07ccb4a3d (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7166
diff changeset
   562
25e07ccb4a3d (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7166
diff changeset
   563
	for (uint loop = 0;; loop++) {
25e07ccb4a3d (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7166
diff changeset
   564
		SB(object.callback_param2, 8, 16, loop);
7614
edf90d673e04 (svn r11143) -Fix: the random bits were not set for the production callback when the NewGRF asked for it.
rubidium
parents: 7610
diff changeset
   565
		const SpriteGroup *group = Resolve(spec->grf_prop.spritegroup, &object);
7168
25e07ccb4a3d (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7166
diff changeset
   566
		if (group == NULL || group->type != SGT_INDUSTRY_PRODUCTION) break;
25e07ccb4a3d (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7166
diff changeset
   567
25e07ccb4a3d (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7166
diff changeset
   568
		bool deref = (group->g.indprod.version == 1);
25e07ccb4a3d (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7166
diff changeset
   569
25e07ccb4a3d (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7166
diff changeset
   570
		for (uint i = 0; i < 3; i++) {
7958
e42fa05eb045 (svn r11514) -Change: implement the automatic multiplier handler for NewGRF industries.
rubidium
parents: 7931
diff changeset
   571
			ind->incoming_cargo_waiting[i] = Clamp(ind->incoming_cargo_waiting[i] - DerefIndProd(group->g.indprod.substract_input[i], deref) * multiplier, 0, 0xFFFF);
7168
25e07ccb4a3d (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7166
diff changeset
   572
		}
25e07ccb4a3d (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7166
diff changeset
   573
		for (uint i = 0; i < 2; i++) {
7958
e42fa05eb045 (svn r11514) -Change: implement the automatic multiplier handler for NewGRF industries.
rubidium
parents: 7931
diff changeset
   574
			ind->produced_cargo_waiting[i] = Clamp(ind->produced_cargo_waiting[i] + max(DerefIndProd(group->g.indprod.add_output[i], deref), 0) * multiplier, 0, 0xFFFF);
7168
25e07ccb4a3d (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7166
diff changeset
   575
		}
25e07ccb4a3d (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7166
diff changeset
   576
25e07ccb4a3d (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7166
diff changeset
   577
		int32 again = DerefIndProd(group->g.indprod.again, deref);
25e07ccb4a3d (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7166
diff changeset
   578
		if (again == 0) break;
25e07ccb4a3d (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7166
diff changeset
   579
25e07ccb4a3d (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7166
diff changeset
   580
		SB(object.callback_param2, 24, 8, again);
25e07ccb4a3d (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7166
diff changeset
   581
	}
7195
8c728b5fef43 (svn r10473) -Codechange: make the industry "window", the one that shows when you click on an industry, more flexible to allow easier integration with newindustries.
rubidium
parents: 7191
diff changeset
   582
8c728b5fef43 (svn r10473) -Codechange: make the industry "window", the one that shows when you click on an industry, more flexible to allow easier integration with newindustries.
rubidium
parents: 7191
diff changeset
   583
	InvalidateWindow(WC_INDUSTRY_VIEW, ind->index);
7168
25e07ccb4a3d (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7166
diff changeset
   584
}