src/newgrf_industries.cpp
author rubidium
Wed, 23 Apr 2008 20:56:08 +0000
changeset 10314 9cfcdd5b5ddb
parent 10230 bf81856a1101
child 10429 1b99254f9607
permissions -rw-r--r--
(svn r12855) -Codechange: do not use autoptr's for testing whether certain objects can be build, but check it directly in the pool so we do not have to call destructors in the testing phase. Stations still use the autoptr though.
7331
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
     1
/* $Id$ */
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
     2
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
     3
/** @file newgrf_industries.cpp */
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
     4
0a7f00fed4e6 (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"
0a7f00fed4e6 (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"
0a7f00fed4e6 (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"
7703
bc4b879b7324 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7691
diff changeset
     8
#include "variables.h"
bc4b879b7324 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7691
diff changeset
     9
#include "landscape.h"
7331
0a7f00fed4e6 (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"
7364
f72f9b742c34 (svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents: 7331
diff changeset
    11
#include "industry_map.h"
7331
0a7f00fed4e6 (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"
0a7f00fed4e6 (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"
0a7f00fed4e6 (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"
0a7f00fed4e6 (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"
8356
4d72bac74977 (svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents: 8344
diff changeset
    16
#include "newgrf_industrytiles.h"
7331
0a7f00fed4e6 (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"
7703
bc4b879b7324 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7691
diff changeset
    18
#include "newgrf_text.h"
bc4b879b7324 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7691
diff changeset
    19
#include "newgrf_town.h"
8627
448ebf3a8291 (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: 8609
diff changeset
    20
#include "window_func.h"
8709
4187ad809fe7 (svn r11776) -Codechange: more header splittings to reduce the dependencies.
rubidium
parents: 8659
diff changeset
    21
#include "town.h"
8750
fdd6054e7bae (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents: 8733
diff changeset
    22
#include "player_func.h"
fdd6054e7bae (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents: 8733
diff changeset
    23
#include "player_base.h"
8771
f7ad4dba14bf (svn r11839) -Codechange: move some variables from variables.h to a more logical location.
rubidium
parents: 8760
diff changeset
    24
#include "command_func.h"
7331
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    25
8760
ce0891c412ce (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8750
diff changeset
    26
#include "table/strings.h"
ce0891c412ce (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8750
diff changeset
    27
9185
514feeaebf63 (svn r12362) -Fix (r11985, r12006): Randomize variable 8F only once per callback 28.
frosch
parents: 9130
diff changeset
    28
static uint32 _industry_creation_random_bits;
8932
989fe2280933 (svn r12006) -Fix: implement FS#1697 without the nasty side effects as specified in FS#1712.
rubidium
parents: 8923
diff changeset
    29
7331
0a7f00fed4e6 (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
0a7f00fed4e6 (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
0a7f00fed4e6 (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. */
0a7f00fed4e6 (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);
7496
628e1191ee45 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 7380
diff changeset
    34
IndustryTileOverrideManager _industile_mngr(NEW_INDUSTRYTILEOFFSET, NUM_INDUSTRYTILES, INVALID_INDUSTRYTILE);
7331
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    35
7729
21b3ddd80928 (svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents: 7705
diff changeset
    36
IndustryType MapNewGRFIndustryType(IndustryType grf_type, uint32 grf_id)
21b3ddd80928 (svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents: 7705
diff changeset
    37
{
21b3ddd80928 (svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents: 7705
diff changeset
    38
	if (grf_type == IT_INVALID) return IT_INVALID;
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8418
diff changeset
    39
	if (!HasBit(grf_type, 7)) return GB(grf_type, 0, 6);
7729
21b3ddd80928 (svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents: 7705
diff changeset
    40
21b3ddd80928 (svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents: 7705
diff changeset
    41
	return _industry_mngr.GetID(GB(grf_type, 0, 6), grf_id);
21b3ddd80928 (svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents: 7705
diff changeset
    42
}
21b3ddd80928 (svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents: 7705
diff changeset
    43
8586
d79873568898 (svn r11651) -Codechange [FS#1555]: implement GRF parameter querying for industries and fix a 'bug' as side effect.
rubidium
parents: 8544
diff changeset
    44
static uint32 GetGRFParameter(IndustryType ind_id, byte parameter)
d79873568898 (svn r11651) -Codechange [FS#1555]: implement GRF parameter querying for industries and fix a 'bug' as side effect.
rubidium
parents: 8544
diff changeset
    45
{
d79873568898 (svn r11651) -Codechange [FS#1555]: implement GRF parameter querying for industries and fix a 'bug' as side effect.
rubidium
parents: 8544
diff changeset
    46
	const IndustrySpec *indspec = GetIndustrySpec(ind_id);
d79873568898 (svn r11651) -Codechange [FS#1555]: implement GRF parameter querying for industries and fix a 'bug' as side effect.
rubidium
parents: 8544
diff changeset
    47
	const GRFFile *file = indspec->grf_prop.grffile;
d79873568898 (svn r11651) -Codechange [FS#1555]: implement GRF parameter querying for industries and fix a 'bug' as side effect.
rubidium
parents: 8544
diff changeset
    48
d79873568898 (svn r11651) -Codechange [FS#1555]: implement GRF parameter querying for industries and fix a 'bug' as side effect.
rubidium
parents: 8544
diff changeset
    49
	if (parameter >= file->param_end) return 0;
d79873568898 (svn r11651) -Codechange [FS#1555]: implement GRF parameter querying for industries and fix a 'bug' as side effect.
rubidium
parents: 8544
diff changeset
    50
	return file->param[parameter];
d79873568898 (svn r11651) -Codechange [FS#1555]: implement GRF parameter querying for industries and fix a 'bug' as side effect.
rubidium
parents: 8544
diff changeset
    51
}
d79873568898 (svn r11651) -Codechange [FS#1555]: implement GRF parameter querying for industries and fix a 'bug' as side effect.
rubidium
parents: 8544
diff changeset
    52
7331
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    53
/**
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    54
 * Finds the distance for the closest tile with water/land given a tile
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    55
 * @param tile  the tile to find the distance too
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    56
 * @param water whether to find water or land
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    57
 * @note FAILS when an industry should be seen as water
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    58
 */
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    59
static uint GetClosestWaterDistance(TileIndex tile, bool water)
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    60
{
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    61
	TileIndex t;
7732
f25c8aa26cc3 (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: 7730
diff changeset
    62
	int best_dist;
f25c8aa26cc3 (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: 7730
diff changeset
    63
	for (t = 0; t < MapSize(); t++) {
7331
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    64
		if (IsTileType(t, MP_WATER) == water) break;
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    65
	}
8095
1ecfd01f30af (svn r11126) -Fix: the algorithm to determine the closest water/land was flawed.
rubidium
parents: 7958
diff changeset
    66
	if (t == MapSize() && !water) return 0x200;
7331
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    67
	best_dist = DistanceManhattan(tile, t);
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    68
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    69
	for (; t < MapSize(); t++) {
7732
f25c8aa26cc3 (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: 7730
diff changeset
    70
		int dist = DistanceManhattan(tile, t);
7331
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    71
		if (dist < best_dist) {
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    72
			if (IsTileType(t, MP_WATER) == water) best_dist = dist;
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    73
		} else {
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    74
			/* When the Y distance between the current row and the 'source' tile
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    75
			 * is larger than the best distance, we've found the best distance */
7732
f25c8aa26cc3 (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: 7730
diff changeset
    76
			if ((int)TileY(t) - (int)TileY(tile) > best_dist) break;
8100
3fcfa8594d0f (svn r11131) -Fix (r11126): forgot to commit the changes that performed the actual fix.
rubidium
parents: 8095
diff changeset
    77
			if ((int)TileX(t) - (int)TileX(tile) > best_dist) {
7331
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    78
				/* We can safely skip this many tiles; from here all tiles have a
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    79
				 * higher or equal distance than the best distance */
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    80
				t |= MapMaxX();
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    81
				continue;
8100
3fcfa8594d0f (svn r11131) -Fix (r11126): forgot to commit the changes that performed the actual fix.
rubidium
parents: 8095
diff changeset
    82
			} else if (TileX(tile) < TileX(t)) {
7331
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    83
				/* We can safely skip this many tiles; up to here all tiles have a
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    84
				 * higher or equal distance than the best distance */
7732
f25c8aa26cc3 (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: 7730
diff changeset
    85
				t += max(best_dist - dist, 0);
7331
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    86
				continue;
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    87
			}
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    88
		}
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    89
	}
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    90
8095
1ecfd01f30af (svn r11126) -Fix: the algorithm to determine the closest water/land was flawed.
rubidium
parents: 7958
diff changeset
    91
	return min(best_dist, water ? 0x7F : 0x1FF);
7331
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    92
}
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    93
7364
f72f9b742c34 (svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents: 7331
diff changeset
    94
/** Make an analysis of a tile and check for its belonging to the same
f72f9b742c34 (svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents: 7331
diff changeset
    95
 * industry, and/or the same grf file
8118
644c9acc640c (svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents: 8117
diff changeset
    96
 * @param tile TileIndex of the tile to query
644c9acc640c (svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents: 8117
diff changeset
    97
 * @param i Industry to which to compare the tile to
7364
f72f9b742c34 (svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents: 7331
diff changeset
    98
 * @return value encoded as per NFO specs */
8118
644c9acc640c (svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents: 8117
diff changeset
    99
uint32 GetIndustryIDAtOffset(TileIndex tile, const Industry *i)
7364
f72f9b742c34 (svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents: 7331
diff changeset
   100
{
8202
ec7e5b2d35c9 (svn r11240) -Fix [FS#1323] (r11152): forgot to invert a test
glx
parents: 8181
diff changeset
   101
	if (!IsTileType(tile, MP_INDUSTRY) || GetIndustryIndex(tile) != i->index) {
8118
644c9acc640c (svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents: 8117
diff changeset
   102
		/* No industry and/or the tile does not have the same industry as the one we match it with */
644c9acc640c (svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents: 8117
diff changeset
   103
		return 0xFFFF;
644c9acc640c (svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents: 8117
diff changeset
   104
	}
7364
f72f9b742c34 (svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents: 7331
diff changeset
   105
8118
644c9acc640c (svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents: 8117
diff changeset
   106
	IndustryGfx gfx = GetCleanIndustryGfx(tile);
644c9acc640c (svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents: 8117
diff changeset
   107
	const IndustryTileSpec *indtsp = GetIndustryTileSpec(gfx);
644c9acc640c (svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents: 8117
diff changeset
   108
	const IndustrySpec *indold = GetIndustrySpec(i->type);
7364
f72f9b742c34 (svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents: 7331
diff changeset
   109
8118
644c9acc640c (svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents: 8117
diff changeset
   110
	if (gfx < NEW_INDUSTRYOFFSET) { // Does it belongs to an old type?
644c9acc640c (svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents: 8117
diff changeset
   111
		/* It is an old tile.  We have to see if it's been overriden */
644c9acc640c (svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents: 8117
diff changeset
   112
		if (indtsp->grf_prop.override == INVALID_INDUSTRYTILE) { // has it been overridden?
644c9acc640c (svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents: 8117
diff changeset
   113
			return 0xFF << 8 | gfx; // no. Tag FF + the gfx id of that tile
644c9acc640c (svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents: 8117
diff changeset
   114
		}
644c9acc640c (svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents: 8117
diff changeset
   115
		/* Not overriden */
644c9acc640c (svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents: 8117
diff changeset
   116
		const IndustryTileSpec *tile_ovr = GetIndustryTileSpec(indtsp->grf_prop.override);
644c9acc640c (svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents: 8117
diff changeset
   117
644c9acc640c (svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents: 8117
diff changeset
   118
		if (tile_ovr->grf_prop.grffile->grfid == indold->grf_prop.grffile->grfid) {
644c9acc640c (svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents: 8117
diff changeset
   119
			return tile_ovr->grf_prop.local_id; // same grf file
644c9acc640c (svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents: 8117
diff changeset
   120
		} else {
644c9acc640c (svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents: 8117
diff changeset
   121
			return 0xFFFE; // not the same grf file
7364
f72f9b742c34 (svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents: 7331
diff changeset
   122
		}
f72f9b742c34 (svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents: 7331
diff changeset
   123
	}
8118
644c9acc640c (svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents: 8117
diff changeset
   124
	/* Not an 'old type' tile */
644c9acc640c (svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents: 8117
diff changeset
   125
	if (indtsp->grf_prop.spritegroup != NULL) { // tile has a spritegroup ?
644c9acc640c (svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents: 8117
diff changeset
   126
		if (indtsp->grf_prop.grffile->grfid == indold->grf_prop.grffile->grfid) { // same industry, same grf ?
644c9acc640c (svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents: 8117
diff changeset
   127
			return indtsp->grf_prop.local_id;
644c9acc640c (svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents: 8117
diff changeset
   128
		} else {
644c9acc640c (svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents: 8117
diff changeset
   129
			return 0xFFFE; // Defined in another grf file
644c9acc640c (svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents: 8117
diff changeset
   130
		}
644c9acc640c (svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents: 8117
diff changeset
   131
	}
644c9acc640c (svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents: 8117
diff changeset
   132
	/* The tile has no spritegroup */
644c9acc640c (svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents: 8117
diff changeset
   133
	return 0xFF << 8 | indtsp->grf_prop.subst_id; // so just give him the substitute
7364
f72f9b742c34 (svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents: 7331
diff changeset
   134
}
f72f9b742c34 (svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents: 7331
diff changeset
   135
7729
21b3ddd80928 (svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents: 7705
diff changeset
   136
static uint32 GetClosestIndustry(TileIndex tile, IndustryType type, const Industry *current)
21b3ddd80928 (svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents: 7705
diff changeset
   137
{
21b3ddd80928 (svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents: 7705
diff changeset
   138
	uint32 best_dist = MAX_UVALUE(uint32);
21b3ddd80928 (svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents: 7705
diff changeset
   139
	const Industry *i;
21b3ddd80928 (svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents: 7705
diff changeset
   140
	FOR_ALL_INDUSTRIES(i) {
21b3ddd80928 (svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents: 7705
diff changeset
   141
		if (i->type != type || i == current) continue;
21b3ddd80928 (svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents: 7705
diff changeset
   142
21b3ddd80928 (svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents: 7705
diff changeset
   143
		best_dist = min(best_dist, DistanceManhattan(tile, i->xy));
21b3ddd80928 (svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents: 7705
diff changeset
   144
	}
21b3ddd80928 (svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents: 7705
diff changeset
   145
21b3ddd80928 (svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents: 7705
diff changeset
   146
	return best_dist;
21b3ddd80928 (svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents: 7705
diff changeset
   147
}
21b3ddd80928 (svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents: 7705
diff changeset
   148
7947
f3ad4a2663bc (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7941
diff changeset
   149
/** Implementation of both var 67 and 68
f3ad4a2663bc (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7941
diff changeset
   150
 * since the mechanism is almost the same, it is easier to regroup them on the same
f3ad4a2663bc (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7941
diff changeset
   151
 * function.
f3ad4a2663bc (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7941
diff changeset
   152
 * @param param_setID parameter given to the callback, which is the set id, or the local id, in our terminology
f3ad4a2663bc (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7941
diff changeset
   153
 * @param layout_filter on what layout do we filter?
f3ad4a2663bc (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7941
diff changeset
   154
 * @param current Industry for which the inquiry is made
f3ad4a2663bc (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7941
diff changeset
   155
 * @return the formatted answer to the callback : rr(reserved) cc(count) dddd(manhattan distance of closest sister)
f3ad4a2663bc (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7941
diff changeset
   156
 */
f3ad4a2663bc (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7941
diff changeset
   157
static uint32 GetCountAndDistanceOfClosestInstance(byte param_setID, byte layout_filter, const Industry *current)
f3ad4a2663bc (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7941
diff changeset
   158
{
f3ad4a2663bc (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7941
diff changeset
   159
	uint32 GrfID = GetRegister(0x100);  ///< Get the GRFID of the definition to look for in register 100h
f3ad4a2663bc (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7941
diff changeset
   160
	IndustryType ind_index;
f3ad4a2663bc (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7941
diff changeset
   161
	uint32 closest_dist = MAX_UVALUE(uint32);
f3ad4a2663bc (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7941
diff changeset
   162
	byte count = 0;
f3ad4a2663bc (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7941
diff changeset
   163
f3ad4a2663bc (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7941
diff changeset
   164
	/* Determine what will be the industry type to look for */
f3ad4a2663bc (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7941
diff changeset
   165
	switch (GrfID) {
f3ad4a2663bc (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7941
diff changeset
   166
		case 0:  // this is a default industry type
f3ad4a2663bc (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7941
diff changeset
   167
			ind_index = param_setID;
f3ad4a2663bc (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7941
diff changeset
   168
			break;
f3ad4a2663bc (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7941
diff changeset
   169
f3ad4a2663bc (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7941
diff changeset
   170
		case 0xFFFFFFFF: // current grf
8164
741aea099d50 (svn r11199) -Fix: variable 67 and 68 not working correctly.
rubidium
parents: 8154
diff changeset
   171
			GrfID = GetIndustrySpec(current->type)->grf_prop.grffile->grfid;
741aea099d50 (svn r11199) -Fix: variable 67 and 68 not working correctly.
rubidium
parents: 8154
diff changeset
   172
			/* Fall through */
7947
f3ad4a2663bc (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7941
diff changeset
   173
f3ad4a2663bc (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7941
diff changeset
   174
		default: //use the grfid specified in register 100h
8427
143b0be22af1 (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents: 8424
diff changeset
   175
			SetBit(param_setID, 7); // bit 7 means it is not an old type
7947
f3ad4a2663bc (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7941
diff changeset
   176
			ind_index = MapNewGRFIndustryType(param_setID, GrfID);
f3ad4a2663bc (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7941
diff changeset
   177
			break;
f3ad4a2663bc (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7941
diff changeset
   178
	}
f3ad4a2663bc (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7941
diff changeset
   179
f3ad4a2663bc (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7941
diff changeset
   180
	if (layout_filter == 0) {
f3ad4a2663bc (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7941
diff changeset
   181
		/* If the filter is 0, it could be because none was specified as well as being really a 0.
f3ad4a2663bc (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7941
diff changeset
   182
		 * In either case, just do the regular var67 */
f3ad4a2663bc (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7941
diff changeset
   183
		closest_dist = GetClosestIndustry(current->xy, ind_index, current);
f3ad4a2663bc (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7941
diff changeset
   184
		count = GetIndustryTypeCount(ind_index);
f3ad4a2663bc (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7941
diff changeset
   185
	} else {
f3ad4a2663bc (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7941
diff changeset
   186
		/* Count only those who match the same industry type and layout filter
f3ad4a2663bc (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7941
diff changeset
   187
		 * Unfortunately, we have to do it manually */
f3ad4a2663bc (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7941
diff changeset
   188
		const Industry *i;
f3ad4a2663bc (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7941
diff changeset
   189
		FOR_ALL_INDUSTRIES(i) {
f3ad4a2663bc (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7941
diff changeset
   190
			if (i->type == ind_index && i != current && i->selected_layout == layout_filter) {
f3ad4a2663bc (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7941
diff changeset
   191
				closest_dist = min(closest_dist, DistanceManhattan(current->xy, i->xy));
f3ad4a2663bc (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7941
diff changeset
   192
				count++;
f3ad4a2663bc (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7941
diff changeset
   193
			}
f3ad4a2663bc (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7941
diff changeset
   194
		}
f3ad4a2663bc (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7941
diff changeset
   195
	}
f3ad4a2663bc (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7941
diff changeset
   196
f3ad4a2663bc (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7941
diff changeset
   197
	return count << 16 | GB(closest_dist, 0, 16);
f3ad4a2663bc (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7941
diff changeset
   198
}
f3ad4a2663bc (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7941
diff changeset
   199
7331
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   200
/** This function implements the industries variables that newGRF defines.
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   201
 * @param variable that is queried
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   202
 * @param parameter unused
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   203
 * @param available will return false if ever the variable asked for does not exist
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   204
 * @param ind is of course the industry we are inquiring
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   205
 * @return the value stored in the corresponding variable*/
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   206
uint32 IndustryGetVariable(const ResolverObject *object, byte variable, byte parameter, bool *available)
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   207
{
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   208
	const Industry *industry = object->u.industry.ind;
7703
bc4b879b7324 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7691
diff changeset
   209
	TileIndex tile = object->u.industry.tile;
8729
395e46c2109b (svn r11797) -Fix: Add protection against not already created industry while doing industry callback.
belugas
parents: 8709
diff changeset
   210
	IndustryType type = object->u.industry.type;
395e46c2109b (svn r11797) -Fix: Add protection against not already created industry while doing industry callback.
belugas
parents: 8709
diff changeset
   211
	const IndustrySpec *indspec = GetIndustrySpec(type);
395e46c2109b (svn r11797) -Fix: Add protection against not already created industry while doing industry callback.
belugas
parents: 8709
diff changeset
   212
395e46c2109b (svn r11797) -Fix: Add protection against not already created industry while doing industry callback.
belugas
parents: 8709
diff changeset
   213
	if (industry == NULL) {
395e46c2109b (svn r11797) -Fix: Add protection against not already created industry while doing industry callback.
belugas
parents: 8709
diff changeset
   214
		/* industry does not exist, only use those variables that are "safe" */
395e46c2109b (svn r11797) -Fix: Add protection against not already created industry while doing industry callback.
belugas
parents: 8709
diff changeset
   215
		switch (variable) {
395e46c2109b (svn r11797) -Fix: Add protection against not already created industry while doing industry callback.
belugas
parents: 8709
diff changeset
   216
			/* Read GRF parameter */
395e46c2109b (svn r11797) -Fix: Add protection against not already created industry while doing industry callback.
belugas
parents: 8709
diff changeset
   217
			case 0x7F: return GetGRFParameter(type, parameter);
395e46c2109b (svn r11797) -Fix: Add protection against not already created industry while doing industry callback.
belugas
parents: 8709
diff changeset
   218
			/* Manhattan distance of closes dry/water tile */
395e46c2109b (svn r11797) -Fix: Add protection against not already created industry while doing industry callback.
belugas
parents: 8709
diff changeset
   219
			case 0x43: return GetClosestWaterDistance(tile, (indspec->behaviour & INDUSTRYBEH_BUILT_ONWATER) == 0);
395e46c2109b (svn r11797) -Fix: Add protection against not already created industry while doing industry callback.
belugas
parents: 8709
diff changeset
   220
		}
395e46c2109b (svn r11797) -Fix: Add protection against not already created industry while doing industry callback.
belugas
parents: 8709
diff changeset
   221
395e46c2109b (svn r11797) -Fix: Add protection against not already created industry while doing industry callback.
belugas
parents: 8709
diff changeset
   222
		DEBUG(grf, 1, "Unhandled property 0x%X (no available industry) in callback 0x%x", variable, object->callback);
395e46c2109b (svn r11797) -Fix: Add protection against not already created industry while doing industry callback.
belugas
parents: 8709
diff changeset
   223
395e46c2109b (svn r11797) -Fix: Add protection against not already created industry while doing industry callback.
belugas
parents: 8709
diff changeset
   224
		*available = false;
395e46c2109b (svn r11797) -Fix: Add protection against not already created industry while doing industry callback.
belugas
parents: 8709
diff changeset
   225
		return UINT_MAX;
395e46c2109b (svn r11797) -Fix: Add protection against not already created industry while doing industry callback.
belugas
parents: 8709
diff changeset
   226
	}
7331
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   227
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   228
	switch (variable) {
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   229
		case 0x40:
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   230
		case 0x41:
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   231
		case 0x42: { // waiting cargo, but only if those two callback flags are set
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   232
			uint16 callback = indspec->callback_flags;
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8418
diff changeset
   233
			if (HasBit(callback, CBM_IND_PRODUCTION_CARGO_ARRIVAL) || HasBit(callback, CBM_IND_PRODUCTION_256_TICKS)) {
8454
77ed1a71175c (svn r11514) -Change: implement the automatic multiplier handler for NewGRF industries.
rubidium
parents: 8427
diff changeset
   234
				if ((indspec->behaviour & INDUSTRYBEH_PROD_MULTI_HNDLING) != 0) {
77ed1a71175c (svn r11514) -Change: implement the automatic multiplier handler for NewGRF industries.
rubidium
parents: 8427
diff changeset
   235
					return min(industry->incoming_cargo_waiting[variable - 0x40] / industry->prod_level, (uint16)0xFFFF);
77ed1a71175c (svn r11514) -Change: implement the automatic multiplier handler for NewGRF industries.
rubidium
parents: 8427
diff changeset
   236
				} else {
77ed1a71175c (svn r11514) -Change: implement the automatic multiplier handler for NewGRF industries.
rubidium
parents: 8427
diff changeset
   237
					return min(industry->incoming_cargo_waiting[variable - 0x40], (uint16)0xFFFF);
77ed1a71175c (svn r11514) -Change: implement the automatic multiplier handler for NewGRF industries.
rubidium
parents: 8427
diff changeset
   238
				}
7331
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   239
			} else {
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   240
				return 0;
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   241
			}
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   242
		}
7703
bc4b879b7324 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7691
diff changeset
   243
bc4b879b7324 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7691
diff changeset
   244
		/* Manhattan distance of closes dry/water tile */
8164
741aea099d50 (svn r11199) -Fix: variable 67 and 68 not working correctly.
rubidium
parents: 8154
diff changeset
   245
		case 0x43: return GetClosestWaterDistance(tile, (indspec->behaviour & INDUSTRYBEH_BUILT_ONWATER) == 0);
7331
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   246
7941
ddf9d11e6df8 (svn r10903) -Feature: [NewGRF] Add support for variable 44 of Variational Action 2 for Industries
belugas
parents: 7833
diff changeset
   247
		/* Layout number */
ddf9d11e6df8 (svn r10903) -Feature: [NewGRF] Add support for variable 44 of Variational Action 2 for Industries
belugas
parents: 7833
diff changeset
   248
		case 0x44: return industry->selected_layout;
ddf9d11e6df8 (svn r10903) -Feature: [NewGRF] Add support for variable 44 of Variational Action 2 for Industries
belugas
parents: 7833
diff changeset
   249
8167
eac4f5b693bc (svn r11202) -Feature: [NewGRF] Add support for var 45 for Industries.
belugas
parents: 8164
diff changeset
   250
		/* player info */
eac4f5b693bc (svn r11202) -Feature: [NewGRF] Add support for var 45 for Industries.
belugas
parents: 8164
diff changeset
   251
		case 0x45: {
8181
074de85b0f1a (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: 8167
diff changeset
   252
			byte colours;
8167
eac4f5b693bc (svn r11202) -Feature: [NewGRF] Add support for var 45 for Industries.
belugas
parents: 8164
diff changeset
   253
			bool is_ai = false;
8181
074de85b0f1a (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: 8167
diff changeset
   254
8167
eac4f5b693bc (svn r11202) -Feature: [NewGRF] Add support for var 45 for Industries.
belugas
parents: 8164
diff changeset
   255
			if (IsValidPlayer(industry->founder)) {
eac4f5b693bc (svn r11202) -Feature: [NewGRF] Add support for var 45 for Industries.
belugas
parents: 8164
diff changeset
   256
				const Player *p = GetPlayer(industry->founder);
eac4f5b693bc (svn r11202) -Feature: [NewGRF] Add support for var 45 for Industries.
belugas
parents: 8164
diff changeset
   257
				const Livery *l = &p->livery[LS_DEFAULT];
8181
074de85b0f1a (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: 8167
diff changeset
   258
8167
eac4f5b693bc (svn r11202) -Feature: [NewGRF] Add support for var 45 for Industries.
belugas
parents: 8164
diff changeset
   259
				is_ai = p->is_ai;
8181
074de85b0f1a (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: 8167
diff changeset
   260
				colours = l->colour1 + l->colour2 * 16;
074de85b0f1a (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: 8167
diff changeset
   261
			} else {
074de85b0f1a (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: 8167
diff changeset
   262
				colours = GB(Random(), 0, 8);
8167
eac4f5b693bc (svn r11202) -Feature: [NewGRF] Add support for var 45 for Industries.
belugas
parents: 8164
diff changeset
   263
			}
8181
074de85b0f1a (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: 8167
diff changeset
   264
074de85b0f1a (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: 8167
diff changeset
   265
			return industry->founder | (is_ai ? 0x10000 : 0) | (colours << 24);
8167
eac4f5b693bc (svn r11202) -Feature: [NewGRF] Add support for var 45 for Industries.
belugas
parents: 8164
diff changeset
   266
		}
eac4f5b693bc (svn r11202) -Feature: [NewGRF] Add support for var 45 for Industries.
belugas
parents: 8164
diff changeset
   267
7364
f72f9b742c34 (svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents: 7331
diff changeset
   268
		/* Get industry ID at offset param */
8118
644c9acc640c (svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents: 8117
diff changeset
   269
		case 0x60: return GetIndustryIDAtOffset(GetNearbyTile(parameter, industry->xy), industry);
7331
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   270
8117
6f265223b5fa (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: 8110
diff changeset
   271
		/* Get random tile bits at offset param */
6f265223b5fa (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: 8110
diff changeset
   272
		case 0x61:
6f265223b5fa (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: 8110
diff changeset
   273
			tile = GetNearbyTile(parameter, tile);
6f265223b5fa (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: 8110
diff changeset
   274
			return (IsTileType(tile, MP_INDUSTRY) && GetIndustryByTile(tile) == industry) ? GetIndustryRandomBits(tile) : 0;
7331
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   275
7730
a7b31d4fcc40 (svn r10515) -Codechange: allow getting some more data about the environment of an industry.
rubidium
parents: 7729
diff changeset
   276
		/* Land info of nearby tiles */
a7b31d4fcc40 (svn r10515) -Codechange: allow getting some more data about the environment of an industry.
rubidium
parents: 7729
diff changeset
   277
		case 0x62: return GetNearbyIndustryTileInformation(parameter, tile, INVALID_INDUSTRY);
a7b31d4fcc40 (svn r10515) -Codechange: allow getting some more data about the environment of an industry.
rubidium
parents: 7729
diff changeset
   278
a7b31d4fcc40 (svn r10515) -Codechange: allow getting some more data about the environment of an industry.
rubidium
parents: 7729
diff changeset
   279
		/* Animation stage of nearby tiles */
8117
6f265223b5fa (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: 8110
diff changeset
   280
		case 0x63:
7730
a7b31d4fcc40 (svn r10515) -Codechange: allow getting some more data about the environment of an industry.
rubidium
parents: 7729
diff changeset
   281
			tile = GetNearbyTile(parameter, tile);
a7b31d4fcc40 (svn r10515) -Codechange: allow getting some more data about the environment of an industry.
rubidium
parents: 7729
diff changeset
   282
			if (IsTileType(tile, MP_INDUSTRY) && GetIndustryByTile(tile) == industry) {
a7b31d4fcc40 (svn r10515) -Codechange: allow getting some more data about the environment of an industry.
rubidium
parents: 7729
diff changeset
   283
				return GetIndustryAnimationState(tile);
a7b31d4fcc40 (svn r10515) -Codechange: allow getting some more data about the environment of an industry.
rubidium
parents: 7729
diff changeset
   284
			}
a7b31d4fcc40 (svn r10515) -Codechange: allow getting some more data about the environment of an industry.
rubidium
parents: 7729
diff changeset
   285
			return 0xFFFFFFFF;
a7b31d4fcc40 (svn r10515) -Codechange: allow getting some more data about the environment of an industry.
rubidium
parents: 7729
diff changeset
   286
a7b31d4fcc40 (svn r10515) -Codechange: allow getting some more data about the environment of an industry.
rubidium
parents: 7729
diff changeset
   287
		/* Distance of nearest industry of given type */
7810
182353b0ad23 (svn r10669) -Codechange: Removed redundant comment
belugas
parents: 7756
diff changeset
   288
		case 0x64: return GetClosestIndustry(tile, MapNewGRFIndustryType(parameter, indspec->grf_prop.grffile->grfid), industry);
7331
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   289
		/* Get town zone and Manhattan distance of closest town */
10230
bf81856a1101 (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: 9252
diff changeset
   290
		case 0x65: return GetTownRadiusGroup(industry->town, tile) << 16 | min(DistanceManhattan(tile, industry->town->xy), 0xFFFF);
7331
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   291
		/* Get square of Euclidian distance of closes town */
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   292
		case 0x66: return GetTownRadiusGroup(industry->town, tile) << 16 | min(DistanceSquare(tile, industry->town->xy), 0xFFFF);
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   293
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   294
		/* Count of industry, distance of closest instance
7947
f3ad4a2663bc (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7941
diff changeset
   295
		 * 68 is the same as 67, but with a filtering on selected layout */
f3ad4a2663bc (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7941
diff changeset
   296
		case 0x67:
f3ad4a2663bc (svn r10926) -Feature: [NewGRF] Add support for variable 67(for real this time) and 68 of Variational Action 2 for Industries
belugas
parents: 7941
diff changeset
   297
		case 0x68: return GetCountAndDistanceOfClosestInstance(parameter, variable == 0x68 ? GB(GetRegister(0x101), 0, 8) : 0, industry);
7331
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   298
8106
9f527cc360cf (svn r11139) -Codechange: add support for persistent storage for NewGRFs.
rubidium
parents: 8100
diff changeset
   299
		/* Get a variable from the persistent storage */
9f527cc360cf (svn r11139) -Codechange: add support for persistent storage for NewGRFs.
rubidium
parents: 8100
diff changeset
   300
		case 0x7C: return industry->psa.Get(parameter);
9f527cc360cf (svn r11139) -Codechange: add support for persistent storage for NewGRFs.
rubidium
parents: 8100
diff changeset
   301
8586
d79873568898 (svn r11651) -Codechange [FS#1555]: implement GRF parameter querying for industries and fix a 'bug' as side effect.
rubidium
parents: 8544
diff changeset
   302
		/* Read GRF parameter */
8729
395e46c2109b (svn r11797) -Fix: Add protection against not already created industry while doing industry callback.
belugas
parents: 8709
diff changeset
   303
		case 0x7F: return GetGRFParameter(type, parameter);
8586
d79873568898 (svn r11651) -Codechange [FS#1555]: implement GRF parameter querying for industries and fix a 'bug' as side effect.
rubidium
parents: 8544
diff changeset
   304
7331
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   305
		/* Industry structure access*/
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   306
		case 0x80: return industry->xy;
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   307
		case 0x81: return GB(industry->xy, 8, 8);
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   308
		/* Pointer to the town the industry is associated with */
7687
0ed68892bc29 (svn r10466) -Fix: the minimum amount of waiting cargo shouldn't be 65535; that should be the maximum amount of waiting cargo.
rubidium
parents: 7682
diff changeset
   309
		case 0x82: return industry->town->index;
7331
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   310
		case 0x83:
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   311
		case 0x84:
7682
263dbeceba12 (svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries.
rubidium
parents: 7664
diff changeset
   312
		case 0x85: DEBUG(grf, 0, "NewGRFs shouldn't be doing pointer magic"); break; // not supported
7331
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   313
		case 0x86: return industry->width;
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   314
		case 0x87: return industry->height;// xy dimensions
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   315
		/*  */
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   316
		case 0x88:
8141
c052dc0dc029 (svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents: 8118
diff changeset
   317
		case 0x89: return industry->produced_cargo[variable - 0x88];
7661
40c7a63ad9a1 (svn r10439) -Codechange: initial steps for customized industry productions.
rubidium
parents: 7598
diff changeset
   318
		case 0x8A: return industry->produced_cargo_waiting[0];
40c7a63ad9a1 (svn r10439) -Codechange: initial steps for customized industry productions.
rubidium
parents: 7598
diff changeset
   319
		case 0x8B: return GB(industry->produced_cargo_waiting[0], 8, 8);
40c7a63ad9a1 (svn r10439) -Codechange: initial steps for customized industry productions.
rubidium
parents: 7598
diff changeset
   320
		case 0x8C: return industry->produced_cargo_waiting[1];
40c7a63ad9a1 (svn r10439) -Codechange: initial steps for customized industry productions.
rubidium
parents: 7598
diff changeset
   321
		case 0x8D: return GB(industry->produced_cargo_waiting[1], 8, 8);
7331
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   322
		case 0x8E:
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   323
		case 0x8F: return industry->production_rate[variable - 0x8E];
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   324
		case 0x90:
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   325
		case 0x91:
8141
c052dc0dc029 (svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
glx
parents: 8118
diff changeset
   326
		case 0x92: return industry->accepts_cargo[variable - 0x90];
7331
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   327
		case 0x93: return industry->prod_level;
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   328
		/* amount of cargo produced so far THIS month. */
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   329
		case 0x94: return industry->this_month_production[0];
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   330
		case 0x95: return GB(industry->this_month_production[0], 8, 8);
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   331
		case 0x96: return industry->this_month_production[1];
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   332
		case 0x97: return GB(industry->this_month_production[1], 8, 8);
0a7f00fed4e6 (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 transported so far THIS month. */
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   334
		case 0x98: return industry->this_month_transported[0];
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   335
		case 0x99: return GB(industry->this_month_transported[0], 8, 8);
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   336
		case 0x9A: return industry->this_month_transported[1];
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   337
		case 0x9B: return GB(industry->this_month_transported[0], 8, 8);
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   338
		/* fraction of cargo transported LAST month. */
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   339
		case 0x9C:
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   340
		case 0x9D: return industry->last_month_pct_transported[variable - 0x9C];
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   341
		/* amount of cargo produced LAST month. */
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   342
		case 0x9E: return industry->last_month_production[0];
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   343
		case 0x9F: return GB(industry->last_month_production[0], 8, 8);
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   344
		case 0xA0: return industry->last_month_production[1];
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   345
		case 0xA1: return GB(industry->last_month_production[1], 8, 8);
0a7f00fed4e6 (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 transported last month. */
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   347
		case 0xA2: return industry->last_month_transported[0];
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   348
		case 0xA3: return GB(industry->last_month_transported[0], 8, 8);
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   349
		case 0xA4: return industry->last_month_transported[1];
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   350
		case 0xA5: return GB(industry->last_month_transported[0], 8, 8);
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   351
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   352
		case 0xA6: return industry->type;
7682
263dbeceba12 (svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries.
rubidium
parents: 7664
diff changeset
   353
		case 0xA7: return industry->founder;
7331
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   354
		case 0xA8: return industry->random_color;
9130
4c439f6c8ba4 (svn r12246) -Fix (r10460): Proper usage of Clamp().
frosch
parents: 8932
diff changeset
   355
		case 0xA9: return Clamp(industry->last_prod_year - ORIGINAL_BASE_YEAR, 0, 255);
7331
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   356
		case 0xAA: return industry->counter;
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   357
		case 0xAB: return GB(industry->counter, 8, 8);
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   358
		case 0xAC: return industry->was_cargo_delivered;
7682
263dbeceba12 (svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries.
rubidium
parents: 7664
diff changeset
   359
9130
4c439f6c8ba4 (svn r12246) -Fix (r10460): Proper usage of Clamp().
frosch
parents: 8932
diff changeset
   360
		case 0xB0: return Clamp(industry->construction_date - DAYS_TILL_ORIGINAL_BASE_YEAR, 0, 65535); // Date when built since 1920 (in days)
7682
263dbeceba12 (svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries.
rubidium
parents: 7664
diff changeset
   361
		case 0xB3: return industry->construction_type; // Construction type
9130
4c439f6c8ba4 (svn r12246) -Fix (r10460): Proper usage of Clamp().
frosch
parents: 8932
diff changeset
   362
		case 0xB4: return Clamp(industry->last_cargo_accepted_at - DAYS_TILL_ORIGINAL_BASE_YEAR, 0, 65535); // Date last cargo accepted since 1920 (in days)
7331
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   363
	}
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   364
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   365
	DEBUG(grf, 1, "Unhandled industry property 0x%X", variable);
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   366
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   367
	*available = false;
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   368
	return (uint32)-1;
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   369
}
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   370
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   371
static const SpriteGroup *IndustryResolveReal(const ResolverObject *object, const SpriteGroup *group)
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   372
{
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   373
	/* IndustryTile do not have 'real' groups */
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   374
	return NULL;
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   375
}
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   376
8117
6f265223b5fa (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: 8110
diff changeset
   377
static uint32 IndustryGetRandomBits(const ResolverObject *object)
6f265223b5fa (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: 8110
diff changeset
   378
{
8356
4d72bac74977 (svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents: 8344
diff changeset
   379
	return object->u.industry.ind == NULL ? 0 : object->u.industry.ind->random;
8117
6f265223b5fa (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: 8110
diff changeset
   380
}
6f265223b5fa (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: 8110
diff changeset
   381
6f265223b5fa (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: 8110
diff changeset
   382
static uint32 IndustryGetTriggers(const ResolverObject *object)
6f265223b5fa (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: 8110
diff changeset
   383
{
8356
4d72bac74977 (svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents: 8344
diff changeset
   384
	return object->u.industry.ind == NULL ? 0 : object->u.industry.ind->random_triggers;
8117
6f265223b5fa (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: 8110
diff changeset
   385
}
6f265223b5fa (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: 8110
diff changeset
   386
6f265223b5fa (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: 8110
diff changeset
   387
static void IndustrySetTriggers(const ResolverObject *object, int triggers)
6f265223b5fa (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: 8110
diff changeset
   388
{
6f265223b5fa (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: 8110
diff changeset
   389
	if (object->u.industry.ind == NULL) return;
8356
4d72bac74977 (svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents: 8344
diff changeset
   390
	object->u.industry.ind->random_triggers = triggers;
8117
6f265223b5fa (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: 8110
diff changeset
   391
}
6f265223b5fa (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: 8110
diff changeset
   392
8729
395e46c2109b (svn r11797) -Fix: Add protection against not already created industry while doing industry callback.
belugas
parents: 8709
diff changeset
   393
static void NewIndustryResolver(ResolverObject *res, TileIndex tile, Industry *indus, IndustryType type)
7331
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   394
{
8117
6f265223b5fa (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: 8110
diff changeset
   395
	res->GetRandomBits = IndustryGetRandomBits;
6f265223b5fa (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: 8110
diff changeset
   396
	res->GetTriggers   = IndustryGetTriggers;
6f265223b5fa (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: 8110
diff changeset
   397
	res->SetTriggers   = IndustrySetTriggers;
7331
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   398
	res->GetVariable   = IndustryGetVariable;
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   399
	res->ResolveReal   = IndustryResolveReal;
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   400
8106
9f527cc360cf (svn r11139) -Codechange: add support for persistent storage for NewGRFs.
rubidium
parents: 8100
diff changeset
   401
	res->psa             = &indus->psa;
7331
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   402
	res->u.industry.tile = tile;
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   403
	res->u.industry.ind  = indus;
7380
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents: 7364
diff changeset
   404
	res->u.industry.gfx  = INVALID_INDUSTRYTILE;
8729
395e46c2109b (svn r11797) -Fix: Add protection against not already created industry while doing industry callback.
belugas
parents: 8709
diff changeset
   405
	res->u.industry.type = type;
7331
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   406
7823
cad4dec2b899 (svn r10690) -Codechange: use the enum that describes all callback IDs in favor of "just" using an untyped integer.
rubidium
parents: 7810
diff changeset
   407
	res->callback        = CBID_NO_CALLBACK;
7331
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   408
	res->callback_param1 = 0;
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   409
	res->callback_param2 = 0;
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   410
	res->last_value      = 0;
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   411
	res->trigger         = 0;
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   412
	res->reseed          = 0;
9252
92e05c28a994 (svn r12452) -Feature: [NewGRF] Add random action 2 type 84. For vehicles only.
glx
parents: 9185
diff changeset
   413
	res->count           = 0;
7331
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   414
}
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   415
7823
cad4dec2b899 (svn r10690) -Codechange: use the enum that describes all callback IDs in favor of "just" using an untyped integer.
rubidium
parents: 7810
diff changeset
   416
uint16 GetIndustryCallback(CallbackID callback, uint32 param1, uint32 param2, Industry *industry, IndustryType type, TileIndex tile)
7331
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   417
{
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   418
	ResolverObject object;
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   419
	const SpriteGroup *group;
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   420
8729
395e46c2109b (svn r11797) -Fix: Add protection against not already created industry while doing industry callback.
belugas
parents: 8709
diff changeset
   421
	NewIndustryResolver(&object, tile, industry, type);
7331
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   422
	object.callback = callback;
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   423
	object.callback_param1 = param1;
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   424
	object.callback_param2 = param2;
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   425
7598
c12c2d7e0b55 (svn r10369) -Codechange: Add the IndustryType parameter to the GetIndustryCallback function.
belugas
parents: 7496
diff changeset
   426
	group = Resolve(GetIndustrySpec(type)->grf_prop.spritegroup, &object);
7331
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   427
	if (group == NULL || group->type != SGT_CALLBACK) return CALLBACK_FAILED;
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   428
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   429
	return group->g.callback.result;
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   430
}
7664
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7662
diff changeset
   431
7703
bc4b879b7324 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7691
diff changeset
   432
uint32 IndustryLocationGetVariable(const ResolverObject *object, byte variable, byte parameter, bool *available)
bc4b879b7324 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7691
diff changeset
   433
{
8164
741aea099d50 (svn r11199) -Fix: variable 67 and 68 not working correctly.
rubidium
parents: 8154
diff changeset
   434
	const Industry *industry = object->u.industry.ind;
741aea099d50 (svn r11199) -Fix: variable 67 and 68 not working correctly.
rubidium
parents: 8154
diff changeset
   435
	TileIndex tile = object->u.industry.tile;
7703
bc4b879b7324 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7691
diff changeset
   436
bc4b879b7324 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7691
diff changeset
   437
	if (object->scope == VSG_SCOPE_PARENT) {
8164
741aea099d50 (svn r11199) -Fix: variable 67 and 68 not working correctly.
rubidium
parents: 8154
diff changeset
   438
		return TownGetVariable(variable, parameter, available, industry->town);
7703
bc4b879b7324 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7691
diff changeset
   439
	}
bc4b879b7324 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7691
diff changeset
   440
bc4b879b7324 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7691
diff changeset
   441
	switch (variable) {
bc4b879b7324 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7691
diff changeset
   442
		case 0x80: return tile;
bc4b879b7324 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7691
diff changeset
   443
		case 0x81: return GB(tile, 8, 8);
7730
a7b31d4fcc40 (svn r10515) -Codechange: allow getting some more data about the environment of an industry.
rubidium
parents: 7729
diff changeset
   444
7703
bc4b879b7324 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7691
diff changeset
   445
		/* Pointer to the town the industry is associated with */
8164
741aea099d50 (svn r11199) -Fix: variable 67 and 68 not working correctly.
rubidium
parents: 8154
diff changeset
   446
		case 0x82: return industry->town->index;
7703
bc4b879b7324 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7691
diff changeset
   447
		case 0x83:
bc4b879b7324 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7691
diff changeset
   448
		case 0x84:
bc4b879b7324 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7691
diff changeset
   449
		case 0x85: DEBUG(grf, 0, "NewGRFs shouldn't be doing pointer magic"); break; // not supported
bc4b879b7324 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7691
diff changeset
   450
bc4b879b7324 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7691
diff changeset
   451
		/* Number of the layout */
8164
741aea099d50 (svn r11199) -Fix: variable 67 and 68 not working correctly.
rubidium
parents: 8154
diff changeset
   452
		case 0x86: return industry->selected_layout;
7703
bc4b879b7324 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7691
diff changeset
   453
bc4b879b7324 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7691
diff changeset
   454
		/* Ground type */
bc4b879b7324 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7691
diff changeset
   455
		case 0x87: return GetTerrainType(tile);
bc4b879b7324 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7691
diff changeset
   456
bc4b879b7324 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7691
diff changeset
   457
		/* Town zone */
8164
741aea099d50 (svn r11199) -Fix: variable 67 and 68 not working correctly.
rubidium
parents: 8154
diff changeset
   458
		case 0x88: return GetTownRadiusGroup(industry->town, tile);
7703
bc4b879b7324 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7691
diff changeset
   459
bc4b879b7324 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7691
diff changeset
   460
		/* Manhattan distance of the closest town */
8164
741aea099d50 (svn r11199) -Fix: variable 67 and 68 not working correctly.
rubidium
parents: 8154
diff changeset
   461
		case 0x89: return min(DistanceManhattan(industry->town->xy, tile), 255);
7703
bc4b879b7324 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7691
diff changeset
   462
bc4b879b7324 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7691
diff changeset
   463
		/* Lowest height of the tile */
bc4b879b7324 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7691
diff changeset
   464
		case 0x8A: return GetTileZ(tile);
bc4b879b7324 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7691
diff changeset
   465
bc4b879b7324 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7691
diff changeset
   466
		/* Distance to the nearest water/land tile */
8164
741aea099d50 (svn r11199) -Fix: variable 67 and 68 not working correctly.
rubidium
parents: 8154
diff changeset
   467
		case 0x8B: return GetClosestWaterDistance(tile, (GetIndustrySpec(industry->type)->behaviour & INDUSTRYBEH_BUILT_ONWATER) == 0);
7703
bc4b879b7324 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7691
diff changeset
   468
bc4b879b7324 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7691
diff changeset
   469
		/* Square of Euclidian distance from town */
8164
741aea099d50 (svn r11199) -Fix: variable 67 and 68 not working correctly.
rubidium
parents: 8154
diff changeset
   470
		case 0x8D: return min(DistanceSquare(industry->town->xy, tile), 65535);
8911
06c7912f14b9 (svn r11985) -Feature[FS#1697, newGRF]: Implement var 8F(random bits) during callback 28 (Industry location permissibility)
belugas
parents: 8771
diff changeset
   471
8932
989fe2280933 (svn r12006) -Fix: implement FS#1697 without the nasty side effects as specified in FS#1712.
rubidium
parents: 8923
diff changeset
   472
		/* 32 random bits */
9185
514feeaebf63 (svn r12362) -Fix (r11985, r12006): Randomize variable 8F only once per callback 28.
frosch
parents: 9130
diff changeset
   473
		case 0x8F: return _industry_creation_random_bits;
7703
bc4b879b7324 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7691
diff changeset
   474
	}
bc4b879b7324 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7691
diff changeset
   475
8164
741aea099d50 (svn r11199) -Fix: variable 67 and 68 not working correctly.
rubidium
parents: 8154
diff changeset
   476
	/* None of the special ones, so try the general ones */
741aea099d50 (svn r11199) -Fix: variable 67 and 68 not working correctly.
rubidium
parents: 8154
diff changeset
   477
	return IndustryGetVariable(object, variable, parameter, available);
7703
bc4b879b7324 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7691
diff changeset
   478
}
bc4b879b7324 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7691
diff changeset
   479
8932
989fe2280933 (svn r12006) -Fix: implement FS#1697 without the nasty side effects as specified in FS#1712.
rubidium
parents: 8923
diff changeset
   480
bool CheckIfCallBackAllowsCreation(TileIndex tile, IndustryType type, uint itspec_index, uint32 seed)
7703
bc4b879b7324 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7691
diff changeset
   481
{
bc4b879b7324 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7691
diff changeset
   482
	const IndustrySpec *indspec = GetIndustrySpec(type);
bc4b879b7324 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7691
diff changeset
   483
bc4b879b7324 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7691
diff changeset
   484
	ResolverObject object;
bc4b879b7324 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7691
diff changeset
   485
	const SpriteGroup *group;
bc4b879b7324 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7691
diff changeset
   486
8164
741aea099d50 (svn r11199) -Fix: variable 67 and 68 not working correctly.
rubidium
parents: 8154
diff changeset
   487
	Industry ind;
741aea099d50 (svn r11199) -Fix: variable 67 and 68 not working correctly.
rubidium
parents: 8154
diff changeset
   488
	ind.index = INVALID_INDUSTRY;
741aea099d50 (svn r11199) -Fix: variable 67 and 68 not working correctly.
rubidium
parents: 8154
diff changeset
   489
	ind.xy = tile;
741aea099d50 (svn r11199) -Fix: variable 67 and 68 not working correctly.
rubidium
parents: 8154
diff changeset
   490
	ind.width = 0;
741aea099d50 (svn r11199) -Fix: variable 67 and 68 not working correctly.
rubidium
parents: 8154
diff changeset
   491
	ind.type = type;
741aea099d50 (svn r11199) -Fix: variable 67 and 68 not working correctly.
rubidium
parents: 8154
diff changeset
   492
	ind.selected_layout = itspec_index;
741aea099d50 (svn r11199) -Fix: variable 67 and 68 not working correctly.
rubidium
parents: 8154
diff changeset
   493
	ind.town = ClosestTownFromTile(tile, (uint)-1);
741aea099d50 (svn r11199) -Fix: variable 67 and 68 not working correctly.
rubidium
parents: 8154
diff changeset
   494
8729
395e46c2109b (svn r11797) -Fix: Add protection against not already created industry while doing industry callback.
belugas
parents: 8709
diff changeset
   495
	NewIndustryResolver(&object, tile, &ind, type);
7703
bc4b879b7324 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7691
diff changeset
   496
	object.GetVariable = IndustryLocationGetVariable;
bc4b879b7324 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7691
diff changeset
   497
	object.callback = CBID_INDUSTRY_LOCATION;
9185
514feeaebf63 (svn r12362) -Fix (r11985, r12006): Randomize variable 8F only once per callback 28.
frosch
parents: 9130
diff changeset
   498
	_industry_creation_random_bits = seed;
7703
bc4b879b7324 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7691
diff changeset
   499
bc4b879b7324 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7691
diff changeset
   500
	group = Resolve(GetIndustrySpec(type)->grf_prop.spritegroup, &object);
bc4b879b7324 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7691
diff changeset
   501
8154
2b19f04b49fb (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: 8141
diff changeset
   502
	/* Unlike the "normal" cases, not having a valid result means we allow
2b19f04b49fb (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: 8141
diff changeset
   503
	 * the building of the industry, as that's how it's done in TTDP. */
2b19f04b49fb (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: 8141
diff changeset
   504
	if (group == NULL || group->type != SGT_CALLBACK) return true;
7703
bc4b879b7324 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7691
diff changeset
   505
8246
ff7b892d8a28 (svn r11287) -Codechange: add support for pushing paramaters into NewIndustries' error messages. Patch by Csaboka.
rubidium
parents: 8202
diff changeset
   506
	/* Copy some parameters from the registers to the error message text ref. stack */
ff7b892d8a28 (svn r11287) -Codechange: add support for pushing paramaters into NewIndustries' error messages. Patch by Csaboka.
rubidium
parents: 8202
diff changeset
   507
	SwitchToErrorRefStack();
ff7b892d8a28 (svn r11287) -Codechange: add support for pushing paramaters into NewIndustries' error messages. Patch by Csaboka.
rubidium
parents: 8202
diff changeset
   508
	PrepareTextRefStackUsage(4);
ff7b892d8a28 (svn r11287) -Codechange: add support for pushing paramaters into NewIndustries' error messages. Patch by Csaboka.
rubidium
parents: 8202
diff changeset
   509
	SwitchToNormalRefStack();
ff7b892d8a28 (svn r11287) -Codechange: add support for pushing paramaters into NewIndustries' error messages. Patch by Csaboka.
rubidium
parents: 8202
diff changeset
   510
7703
bc4b879b7324 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7691
diff changeset
   511
	switch (group->g.callback.result) {
bc4b879b7324 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7691
diff changeset
   512
		case 0x400: return true;
7705
c605a86e5713 (svn r10487) -Fix: forgot some breaks in a switch statement.
rubidium
parents: 7703
diff changeset
   513
		case 0x401: _error_message = STR_0239_SITE_UNSUITABLE; break;
c605a86e5713 (svn r10487) -Fix: forgot some breaks in a switch statement.
rubidium
parents: 7703
diff changeset
   514
		case 0x402: _error_message = STR_0317_CAN_ONLY_BE_BUILT_IN_RAINFOREST; break;
c605a86e5713 (svn r10487) -Fix: forgot some breaks in a switch statement.
rubidium
parents: 7703
diff changeset
   515
		case 0x403: _error_message = STR_0318_CAN_ONLY_BE_BUILT_IN_DESERT; break;
c605a86e5713 (svn r10487) -Fix: forgot some breaks in a switch statement.
rubidium
parents: 7703
diff changeset
   516
		default: _error_message = GetGRFStringID(indspec->grf_prop.grffile->grfid, 0xD000 + group->g.callback.result); break;
7703
bc4b879b7324 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7691
diff changeset
   517
	}
bc4b879b7324 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7691
diff changeset
   518
bc4b879b7324 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7691
diff changeset
   519
	return false;
bc4b879b7324 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7691
diff changeset
   520
}
bc4b879b7324 (svn r10485) -Codechange: add a callback mechanism to determine whether building an industry is allowed at a given location.
rubidium
parents: 7691
diff changeset
   521
7756
47e4498a0119 (svn r10572) -Codechange: Add function CheckIfCallBackAllowsAvailability for industries
belugas
parents: 7733
diff changeset
   522
bool CheckIfCallBackAllowsAvailability(IndustryType type, IndustryAvailabilityCallType creation_type)
47e4498a0119 (svn r10572) -Codechange: Add function CheckIfCallBackAllowsAvailability for industries
belugas
parents: 7733
diff changeset
   523
{
47e4498a0119 (svn r10572) -Codechange: Add function CheckIfCallBackAllowsAvailability for industries
belugas
parents: 7733
diff changeset
   524
	const IndustrySpec *indspec = GetIndustrySpec(type);
47e4498a0119 (svn r10572) -Codechange: Add function CheckIfCallBackAllowsAvailability for industries
belugas
parents: 7733
diff changeset
   525
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8418
diff changeset
   526
	if (HasBit(indspec->callback_flags, CBM_IND_AVAILABLE)) {
7756
47e4498a0119 (svn r10572) -Codechange: Add function CheckIfCallBackAllowsAvailability for industries
belugas
parents: 7733
diff changeset
   527
		uint16 res = GetIndustryCallback(CBID_INDUSTRY_AVAILABLE, 0, creation_type, NULL, type, INVALID_TILE);
47e4498a0119 (svn r10572) -Codechange: Add function CheckIfCallBackAllowsAvailability for industries
belugas
parents: 7733
diff changeset
   528
		if (res != CALLBACK_FAILED) {
47e4498a0119 (svn r10572) -Codechange: Add function CheckIfCallBackAllowsAvailability for industries
belugas
parents: 7733
diff changeset
   529
			return (res == 0);
47e4498a0119 (svn r10572) -Codechange: Add function CheckIfCallBackAllowsAvailability for industries
belugas
parents: 7733
diff changeset
   530
		}
47e4498a0119 (svn r10572) -Codechange: Add function CheckIfCallBackAllowsAvailability for industries
belugas
parents: 7733
diff changeset
   531
	}
47e4498a0119 (svn r10572) -Codechange: Add function CheckIfCallBackAllowsAvailability for industries
belugas
parents: 7733
diff changeset
   532
	return true;
47e4498a0119 (svn r10572) -Codechange: Add function CheckIfCallBackAllowsAvailability for industries
belugas
parents: 7733
diff changeset
   533
}
47e4498a0119 (svn r10572) -Codechange: Add function CheckIfCallBackAllowsAvailability for industries
belugas
parents: 7733
diff changeset
   534
7664
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7662
diff changeset
   535
static int32 DerefIndProd(uint field, bool use_register)
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7662
diff changeset
   536
{
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7662
diff changeset
   537
	return use_register ? (int32)GetRegister(field) : field;
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7662
diff changeset
   538
}
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7662
diff changeset
   539
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7662
diff changeset
   540
/**
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7662
diff changeset
   541
 * Get the industry production callback and apply it to the industry.
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7662
diff changeset
   542
 * @param ind    the industry this callback has to be called for
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7662
diff changeset
   543
 * @param reason the reason it is called (0 = incoming cargo, 1 = periodic tick callback)
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7662
diff changeset
   544
 */
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7662
diff changeset
   545
void IndustryProductionCallback(Industry *ind, int reason)
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7662
diff changeset
   546
{
8110
120abf2bfe82 (svn r11143) -Fix: the random bits were not set for the production callback when the NewGRF asked for it.
rubidium
parents: 8106
diff changeset
   547
	const IndustrySpec *spec = GetIndustrySpec(ind->type);
7664
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7662
diff changeset
   548
	ResolverObject object;
8729
395e46c2109b (svn r11797) -Fix: Add protection against not already created industry while doing industry callback.
belugas
parents: 8709
diff changeset
   549
	NewIndustryResolver(&object, ind->xy, ind, ind->type);
8110
120abf2bfe82 (svn r11143) -Fix: the random bits were not set for the production callback when the NewGRF asked for it.
rubidium
parents: 8106
diff changeset
   550
	if ((spec->behaviour & INDUSTRYBEH_PRODCALLBACK_RANDOM) != 0) object.callback_param1 = Random();
8454
77ed1a71175c (svn r11514) -Change: implement the automatic multiplier handler for NewGRF industries.
rubidium
parents: 8427
diff changeset
   551
	int multiplier = 1;
77ed1a71175c (svn r11514) -Change: implement the automatic multiplier handler for NewGRF industries.
rubidium
parents: 8427
diff changeset
   552
	if ((spec->behaviour & INDUSTRYBEH_PROD_MULTI_HNDLING) != 0) multiplier = ind->prod_level;
7664
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7662
diff changeset
   553
	object.callback_param2 = reason;
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7662
diff changeset
   554
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7662
diff changeset
   555
	for (uint loop = 0;; loop++) {
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7662
diff changeset
   556
		SB(object.callback_param2, 8, 16, loop);
8110
120abf2bfe82 (svn r11143) -Fix: the random bits were not set for the production callback when the NewGRF asked for it.
rubidium
parents: 8106
diff changeset
   557
		const SpriteGroup *group = Resolve(spec->grf_prop.spritegroup, &object);
7664
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7662
diff changeset
   558
		if (group == NULL || group->type != SGT_INDUSTRY_PRODUCTION) break;
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7662
diff changeset
   559
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7662
diff changeset
   560
		bool deref = (group->g.indprod.version == 1);
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7662
diff changeset
   561
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7662
diff changeset
   562
		for (uint i = 0; i < 3; i++) {
8454
77ed1a71175c (svn r11514) -Change: implement the automatic multiplier handler for NewGRF industries.
rubidium
parents: 8427
diff changeset
   563
			ind->incoming_cargo_waiting[i] = Clamp(ind->incoming_cargo_waiting[i] - DerefIndProd(group->g.indprod.substract_input[i], deref) * multiplier, 0, 0xFFFF);
7664
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7662
diff changeset
   564
		}
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7662
diff changeset
   565
		for (uint i = 0; i < 2; i++) {
8454
77ed1a71175c (svn r11514) -Change: implement the automatic multiplier handler for NewGRF industries.
rubidium
parents: 8427
diff changeset
   566
			ind->produced_cargo_waiting[i] = Clamp(ind->produced_cargo_waiting[i] + max(DerefIndProd(group->g.indprod.add_output[i], deref), 0) * multiplier, 0, 0xFFFF);
7664
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7662
diff changeset
   567
		}
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7662
diff changeset
   568
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7662
diff changeset
   569
		int32 again = DerefIndProd(group->g.indprod.again, deref);
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7662
diff changeset
   570
		if (again == 0) break;
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7662
diff changeset
   571
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7662
diff changeset
   572
		SB(object.callback_param2, 24, 8, again);
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7662
diff changeset
   573
	}
7691
64063937da38 (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: 7687
diff changeset
   574
64063937da38 (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: 7687
diff changeset
   575
	InvalidateWindow(WC_INDUSTRY_VIEW, ind->index);
7664
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7662
diff changeset
   576
}