src/newgrf_industries.cpp
author rubidium
Sat, 08 Sep 2007 09:52:02 +0000
changeset 8035 a0200ced6d9f
parent 7958 86754174b58f
child 8095 1ecfd01f30af
permissions -rw-r--r--
(svn r11059) -Fix [FS#1182]: inconsistency between Rail<->ElRail conversions of different kinds of rail containing tiles (normal rail, stations, depots, etc). Patch by SmatZ.
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"
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
     8
#include "functions.h"
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
     9
#include "macros.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
    10
#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
    11
#include "landscape.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
    12
#include "table/strings.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
    13
#include "industry.h"
7364
f72f9b742c34 (svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents: 7331
diff changeset
    14
#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
    15
#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
    16
#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
    17
#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
    18
#include "newgrf_industries.h"
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    19
#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
    20
#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
    21
#include "newgrf_town.h"
7682
263dbeceba12 (svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries.
rubidium
parents: 7664
diff changeset
    22
#include "date.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
    23
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    24
/* 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
    25
 * 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
    26
 * 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
    27
IndustryOverrideManager _industry_mngr(NEW_INDUSTRYOFFSET, NUM_INDUSTRYTYPES, INVALID_INDUSTRYTYPE);
7496
628e1191ee45 (svn r10256) -Add: Addition of IndustryTileOverrideManager
belugas
parents: 7380
diff changeset
    28
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
    29
7729
21b3ddd80928 (svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents: 7705
diff changeset
    30
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
    31
{
21b3ddd80928 (svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents: 7705
diff changeset
    32
	if (grf_type == IT_INVALID) return IT_INVALID;
21b3ddd80928 (svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents: 7705
diff changeset
    33
	if (!HASBIT(grf_type, 7)) return GB(grf_type, 0, 6);
21b3ddd80928 (svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents: 7705
diff changeset
    34
21b3ddd80928 (svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents: 7705
diff changeset
    35
	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
    36
}
21b3ddd80928 (svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents: 7705
diff changeset
    37
7331
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    38
/**
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    39
 * 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
    40
 * @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
    41
 * @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
    42
 * @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
    43
 */
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    44
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
    45
{
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    46
	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
    47
	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
    48
	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
    49
		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
    50
	}
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    51
	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
    52
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    53
	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
    54
		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
    55
		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
    56
			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
    57
		} else {
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    58
			/* 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
    59
			 * 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
    60
			if ((int)TileY(t) - (int)TileY(tile) > best_dist) break;
7331
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    61
			if (TileX(tile) > TileX(t)) {
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    62
				/* 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
    63
				 * 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
    64
				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
    65
				continue;
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    66
			} else {
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    67
				/* 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
    68
				 * 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
    69
				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
    70
				continue;
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    71
			}
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    72
		}
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    73
	}
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    74
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    75
	return 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
    76
}
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
    77
7364
f72f9b742c34 (svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents: 7331
diff changeset
    78
/** 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
    79
 * industry, and/or the same grf file
f72f9b742c34 (svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents: 7331
diff changeset
    80
 * @param new_tile TileIndex of the tile to query
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
    81
 * @param old_tile TileIndex of the reference tile
7364
f72f9b742c34 (svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents: 7331
diff changeset
    82
 * @param i Industry to which old_tile belongs to
f72f9b742c34 (svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents: 7331
diff changeset
    83
 * @return value encoded as per NFO specs */
f72f9b742c34 (svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents: 7331
diff changeset
    84
uint32 GetIndustryIDAtOffset(TileIndex new_tile, TileIndex old_tile, const Industry *i)
f72f9b742c34 (svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents: 7331
diff changeset
    85
{
f72f9b742c34 (svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents: 7331
diff changeset
    86
	if (IsTileType(new_tile, MP_INDUSTRY)) {  // Is this an industry tile?
f72f9b742c34 (svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents: 7331
diff changeset
    87
f72f9b742c34 (svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents: 7331
diff changeset
    88
		if (GetIndustryIndex(new_tile) == i->index) {  // Does it belong to the same industry?
f72f9b742c34 (svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents: 7331
diff changeset
    89
			IndustryGfx gfx = GetIndustryGfx(new_tile);
7958
86754174b58f (svn r10963) -Revert(10700): Although the idea was good, it was more prone of errors than usefull.
belugas
parents: 7947
diff changeset
    90
			const IndustryTileSpec *indtsp = GetIndustryTileSpec(gfx);
86754174b58f (svn r10963) -Revert(10700): Although the idea was good, it was more prone of errors than usefull.
belugas
parents: 7947
diff changeset
    91
			const IndustryTileSpec *indold = GetIndustryTileSpec(GetIndustryGfx(old_tile));
7364
f72f9b742c34 (svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents: 7331
diff changeset
    92
f72f9b742c34 (svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents: 7331
diff changeset
    93
			if (gfx < NEW_INDUSTRYOFFSET) {  // Does it belongs to an old type?
f72f9b742c34 (svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents: 7331
diff changeset
    94
				/* It is an old tile.  We have to see if it's been overriden */
f72f9b742c34 (svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents: 7331
diff changeset
    95
				if (indtsp->grf_prop.override == INVALID_INDUSTRYTILE) {  // has it been overridden?
f72f9b742c34 (svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents: 7331
diff changeset
    96
					return 0xFF << 8 | gfx; // no. Tag FF + the gfx id of that tile
f72f9b742c34 (svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents: 7331
diff changeset
    97
				} else { // yes.  FInd out if it is from the same grf file or not
f72f9b742c34 (svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents: 7331
diff changeset
    98
					const IndustryTileSpec *old_tile_ovr = GetIndustryTileSpec(indtsp->grf_prop.override);
f72f9b742c34 (svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents: 7331
diff changeset
    99
f72f9b742c34 (svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents: 7331
diff changeset
   100
					if (old_tile_ovr->grf_prop.grffile->grfid == indold->grf_prop.grffile->grfid) {
f72f9b742c34 (svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents: 7331
diff changeset
   101
						return old_tile_ovr->grf_prop.local_id; // same grf file
f72f9b742c34 (svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents: 7331
diff changeset
   102
					} else {
f72f9b742c34 (svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents: 7331
diff changeset
   103
						return 0xFFFE; // not the same grf file
f72f9b742c34 (svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents: 7331
diff changeset
   104
					}
f72f9b742c34 (svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents: 7331
diff changeset
   105
				}
f72f9b742c34 (svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents: 7331
diff changeset
   106
			} else {
f72f9b742c34 (svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents: 7331
diff changeset
   107
				if (indtsp->grf_prop.spritegroup != NULL) {  // tile has a spritegroup ?
f72f9b742c34 (svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents: 7331
diff changeset
   108
					if (indtsp->grf_prop.grffile->grfid == indold->grf_prop.grffile->grfid) {  // same industry, same grf ?
f72f9b742c34 (svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents: 7331
diff changeset
   109
						return indtsp->grf_prop.local_id;
f72f9b742c34 (svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents: 7331
diff changeset
   110
					} else {
f72f9b742c34 (svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents: 7331
diff changeset
   111
						return 0xFFFE;  // Defined in another grf file
f72f9b742c34 (svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents: 7331
diff changeset
   112
					}
f72f9b742c34 (svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents: 7331
diff changeset
   113
				} else {  // tile has no spritegroup
f72f9b742c34 (svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents: 7331
diff changeset
   114
					return 0xFF << 8 | indtsp->grf_prop.subst_id;  // so just give him the substitute
f72f9b742c34 (svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents: 7331
diff changeset
   115
				}
f72f9b742c34 (svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents: 7331
diff changeset
   116
			}
f72f9b742c34 (svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents: 7331
diff changeset
   117
		}
f72f9b742c34 (svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents: 7331
diff changeset
   118
	}
f72f9b742c34 (svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents: 7331
diff changeset
   119
f72f9b742c34 (svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents: 7331
diff changeset
   120
	return 0xFFFF; // tile is not an industry one or  does not belong to the current industry
f72f9b742c34 (svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents: 7331
diff changeset
   121
}
f72f9b742c34 (svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents: 7331
diff changeset
   122
7729
21b3ddd80928 (svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents: 7705
diff changeset
   123
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
   124
{
21b3ddd80928 (svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents: 7705
diff changeset
   125
	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
   126
	const Industry *i;
21b3ddd80928 (svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents: 7705
diff changeset
   127
	FOR_ALL_INDUSTRIES(i) {
21b3ddd80928 (svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents: 7705
diff changeset
   128
		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
   129
21b3ddd80928 (svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents: 7705
diff changeset
   130
		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
   131
	}
21b3ddd80928 (svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents: 7705
diff changeset
   132
21b3ddd80928 (svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents: 7705
diff changeset
   133
	return best_dist;
21b3ddd80928 (svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents: 7705
diff changeset
   134
}
21b3ddd80928 (svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents: 7705
diff changeset
   135
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
   136
/** 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
   137
 * 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
   138
 * 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
   139
 * @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
   140
 * @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
   141
 * @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
   142
 * @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
   143
 */
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
   144
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
   145
{
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
   146
	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
   147
	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
   148
	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
   149
	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
   150
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
	/* 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
   152
	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
   153
		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
   154
			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
   155
			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
   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
		case 0xFFFFFFFF: // current grf
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
			ind_index = GetIndustrySpec(current->type)->grf_prop.grffile->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
   159
			/*Fall through*/
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
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
		default: //use the grfid specified 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
   162
			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
   163
			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
   164
	}
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
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
	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
   167
		/* 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
   168
		 * 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
   169
		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
   170
		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
   171
	} 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
   172
		/* 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
   173
		 * 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
   174
		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
   175
		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
   176
			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
   177
				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
   178
				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
   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
		}
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
	}
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
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
	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
   184
}
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
7331
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   186
/** 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
   187
 * @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
   188
 * @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
   189
 * @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
   190
 * @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
   191
 * @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
   192
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
   193
{
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   194
	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
   195
	TileIndex tile = object->u.industry.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
   196
	const IndustrySpec *indspec = GetIndustrySpec(industry->type);
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   197
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   198
	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
   199
		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
   200
		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
   201
		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
   202
			uint16 callback = indspec->callback_flags;
7662
60f877c832d9 (svn r10440) -Fix: CBM_IND defines bits to be set, not bitsets.
rubidium
parents: 7661
diff changeset
   203
			if (HASBIT(callback, CBM_IND_PRODUCTION_CARGO_ARRIVAL) || HASBIT(callback, CBM_IND_PRODUCTION_256_TICKS)) {
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
   204
				return min(industry->incoming_cargo_waiting[variable - 0x40], (uint16)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
   205
			} else {
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   206
				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
   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
		}
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
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
   210
		/* Manhattan distance of closes dry/water 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
   211
		case 0x43: return GetClosestWaterDistance(tile, (object->u.industry_location.spec->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
   212
7941
ddf9d11e6df8 (svn r10903) -Feature: [NewGRF] Add support for variable 44 of Variational Action 2 for Industries
belugas
parents: 7833
diff changeset
   213
		/* Layout number */
ddf9d11e6df8 (svn r10903) -Feature: [NewGRF] Add support for variable 44 of Variational Action 2 for Industries
belugas
parents: 7833
diff changeset
   214
		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
   215
7364
f72f9b742c34 (svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents: 7331
diff changeset
   216
		/* Get industry ID at offset param */
f72f9b742c34 (svn r10108) -Codechange: implement variable 0x60 (Get industry tile ID at offset) for industries.
belugas
parents: 7331
diff changeset
   217
		case 0x60: return GetIndustryIDAtOffset(GetNearbyTile(parameter, industry->xy), tile, 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
   218
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   219
		case 0x61: return 0; // Get random tile bits at offset param
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   220
7730
a7b31d4fcc40 (svn r10515) -Codechange: allow getting some more data about the environment of an industry.
rubidium
parents: 7729
diff changeset
   221
		/* 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
   222
		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
   223
a7b31d4fcc40 (svn r10515) -Codechange: allow getting some more data about the environment of an industry.
rubidium
parents: 7729
diff changeset
   224
		/* Animation stage of nearby tiles */
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
   225
		case 0x63: {
7730
a7b31d4fcc40 (svn r10515) -Codechange: allow getting some more data about the environment of an industry.
rubidium
parents: 7729
diff changeset
   226
			tile = GetNearbyTile(parameter, tile);
a7b31d4fcc40 (svn r10515) -Codechange: allow getting some more data about the environment of an industry.
rubidium
parents: 7729
diff changeset
   227
			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
   228
				return GetIndustryAnimationState(tile);
a7b31d4fcc40 (svn r10515) -Codechange: allow getting some more data about the environment of an industry.
rubidium
parents: 7729
diff changeset
   229
			}
a7b31d4fcc40 (svn r10515) -Codechange: allow getting some more data about the environment of an industry.
rubidium
parents: 7729
diff changeset
   230
			return 0xFFFFFFFF;
a7b31d4fcc40 (svn r10515) -Codechange: allow getting some more data about the environment of an industry.
rubidium
parents: 7729
diff changeset
   231
		}
a7b31d4fcc40 (svn r10515) -Codechange: allow getting some more data about the environment of an industry.
rubidium
parents: 7729
diff changeset
   232
a7b31d4fcc40 (svn r10515) -Codechange: allow getting some more data about the environment of an industry.
rubidium
parents: 7729
diff changeset
   233
		/* Distance of nearest industry of given type */
7810
182353b0ad23 (svn r10669) -Codechange: Removed redundant comment
belugas
parents: 7756
diff changeset
   234
		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
   235
		/* Get town zone and Manhattan distance of closest town */
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   236
 		case 0x65: return GetTownRadiusGroup(industry->town, tile) << 16 | min(DistanceManhattan(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
   237
		/* 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
   238
		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
   239
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   240
		/* 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
   241
		 * 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
   242
		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
   243
		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
   244
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   245
		/* 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
   246
		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
   247
		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
   248
		/* 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
   249
		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
   250
		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
   251
		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
   252
		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
   253
		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
   254
		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
   255
		/*  */
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   256
		case 0x88:
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   257
		case 0x89: return indspec->produced_cargo[variable - 0x88];
7661
40c7a63ad9a1 (svn r10439) -Codechange: initial steps for customized industry productions.
rubidium
parents: 7598
diff changeset
   258
		case 0x8A: return industry->produced_cargo_waiting[0];
40c7a63ad9a1 (svn r10439) -Codechange: initial steps for customized industry productions.
rubidium
parents: 7598
diff changeset
   259
		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
   260
		case 0x8C: return industry->produced_cargo_waiting[1];
40c7a63ad9a1 (svn r10439) -Codechange: initial steps for customized industry productions.
rubidium
parents: 7598
diff changeset
   261
		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
   262
		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
   263
		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
   264
		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
   265
		case 0x91:
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   266
		case 0x92: return indspec->accepts_cargo[variable - 0x90];
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   267
		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
   268
		/* 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
   269
		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
   270
		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
   271
		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
   272
		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
   273
		/* 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
   274
		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
   275
		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
   276
		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
   277
		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
   278
		/* 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
   279
		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
   280
		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
   281
		/* 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
   282
		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
   283
		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
   284
		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
   285
		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
   286
		/* 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
   287
		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
   288
		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
   289
		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
   290
		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
   291
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 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
   293
		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
   294
		case 0xA8: return industry->random_color;
7682
263dbeceba12 (svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries.
rubidium
parents: 7664
diff changeset
   295
		case 0xA9: return clamp(0, industry->last_prod_year - 1920, 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
   296
		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
   297
		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
   298
		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
   299
263dbeceba12 (svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries.
rubidium
parents: 7664
diff changeset
   300
		case 0xB0: return clamp(0, industry->construction_date - DAYS_TILL_ORIGINAL_BASE_YEAR, 65535); // Date when built since 1920 (in days)
263dbeceba12 (svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries.
rubidium
parents: 7664
diff changeset
   301
		case 0xB3: return industry->construction_type; // Construction type
263dbeceba12 (svn r10460) -Codechange: add some more variables needed for newindustries regarding to the creation of the industries.
rubidium
parents: 7664
diff changeset
   302
		case 0xB4: return clamp(0, industry->last_cargo_accepted_at - DAYS_TILL_ORIGINAL_BASE_YEAR, 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
   303
	}
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   304
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   305
	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
   306
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   307
	*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
   308
	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
   309
}
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   310
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   311
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
   312
{
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   313
	/* 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
   314
	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
   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
7380
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents: 7364
diff changeset
   317
static void NewIndustryResolver(ResolverObject *res, TileIndex tile, Industry *indus)
7331
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   318
{
7380
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents: 7364
diff changeset
   319
	res->GetRandomBits = IndustryTileGetRandomBits;
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents: 7364
diff changeset
   320
	res->GetTriggers   = IndustryTileGetTriggers;
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents: 7364
diff changeset
   321
	res->SetTriggers   = IndustryTileSetTriggers;
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
	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
   323
	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
   324
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   325
	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
   326
	res->u.industry.ind  = indus;
7380
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents: 7364
diff changeset
   327
	res->u.industry.gfx  = 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
   328
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
   329
	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
   330
	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
   331
	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
   332
	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
   333
	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
   334
	res->reseed          = 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
}
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   336
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
   337
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
   338
{
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   339
	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
   340
	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
   341
7380
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents: 7364
diff changeset
   342
	NewIndustryResolver(&object, tile, 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
   343
	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
   344
	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
   345
	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
   346
7598
c12c2d7e0b55 (svn r10369) -Codechange: Add the IndustryType parameter to the GetIndustryCallback function.
belugas
parents: 7496
diff changeset
   347
	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
   348
	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
   349
0a7f00fed4e6 (svn r10074) -Add: Addition of IndustryOverrideManager as well as the basic (and unfinished) support for callbacks for industries
belugas
parents:
diff changeset
   350
	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
   351
}
7664
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7662
diff changeset
   352
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
   353
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
   354
{
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
   355
	TileIndex tile = object->u.industry_location.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
   356
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
   357
	if (object->scope == VSG_SCOPE_PARENT) {
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
   358
		return TownGetVariable(variable, parameter, available, ClosestTownFromTile(tile, (uint)-1));
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
   359
	}
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
   360
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
   361
	switch (variable) {
7730
a7b31d4fcc40 (svn r10515) -Codechange: allow getting some more data about the environment of an industry.
rubidium
parents: 7729
diff changeset
   362
		/* 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
   363
		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
   364
a7b31d4fcc40 (svn r10515) -Codechange: allow getting some more data about the environment of an industry.
rubidium
parents: 7729
diff changeset
   365
		/* Distance of nearest industry of given type */
a7b31d4fcc40 (svn r10515) -Codechange: allow getting some more data about the environment of an industry.
rubidium
parents: 7729
diff changeset
   366
		case 0x64: return GetClosestIndustry(tile, MapNewGRFIndustryType(parameter, object->u.industry_location.spec->grf_prop.grffile->grfid), NULL);
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
   367
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
   368
		/* Location where to build the industry */
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
   369
		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
   370
		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
   371
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
   372
		/* Pointer to the town the industry is associated with */
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
   373
		case 0x82: return ClosestTownFromTile(tile, (uint)-1)->index;
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
   374
		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
   375
		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
   376
		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
   377
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
   378
		/* Number of the layout */
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
   379
		case 0x86: return object->u.industry_location.itspec_index;
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
   380
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
   381
		/* 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
   382
		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
   383
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
   384
		/* Town zone */
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
   385
		case 0x88: return GetTownRadiusGroup(ClosestTownFromTile(tile, (uint)-1), 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
   386
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
   387
		/* Manhattan distance of the closest town */
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
   388
		case 0x89: return min(DistanceManhattan(ClosestTownFromTile(tile, (uint)-1)->xy, tile), 255);
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
   389
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
   390
		/* 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
   391
		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
   392
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
   393
		/* Distance to the nearest water/land 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
   394
		case 0x8B: return GetClosestWaterDistance(tile, (object->u.industry_location.spec->behaviour & INDUSTRYBEH_BUILT_ONWATER) == 0);
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
   395
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
   396
		/* Square of Euclidian distance from town */
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
   397
		case 0x8D: return min(DistanceSquare(ClosestTownFromTile(tile, (uint)-1)->xy, tile), 65535);
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
   398
	}
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
   399
7729
21b3ddd80928 (svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents: 7705
diff changeset
   400
	DEBUG(grf, 1, "Unhandled location industry property 0x%X", variable);
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
   401
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
   402
	*available = 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
   403
	return (uint32)-1;
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
   404
}
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
   405
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
   406
bool CheckIfCallBackAllowsCreation(TileIndex tile, IndustryType type, uint itspec_index)
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
   407
{
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
   408
	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
   409
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
   410
	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
   411
	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
   412
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
   413
	NewIndustryResolver(&object, tile, NULL);
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
   414
	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
   415
	object.callback = CBID_INDUSTRY_LOCATION;
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
   416
	object.u.industry_location.tile = 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
   417
	object.u.industry_location.spec = indspec;
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
   418
	object.u.industry_location.itspec_index = itspec_index;
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
   419
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
   420
	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
   421
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
   422
	if (group == NULL || group->type != SGT_CALLBACK) 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
   423
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
   424
	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
   425
		case 0x400: return true;
7705
c605a86e5713 (svn r10487) -Fix: forgot some breaks in a switch statement.
rubidium
parents: 7703
diff changeset
   426
		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
   427
		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
   428
		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
   429
		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
   430
	}
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
   431
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
	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
   433
}
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
   434
7756
47e4498a0119 (svn r10572) -Codechange: Add function CheckIfCallBackAllowsAvailability for industries
belugas
parents: 7733
diff changeset
   435
bool CheckIfCallBackAllowsAvailability(IndustryType type, IndustryAvailabilityCallType creation_type)
47e4498a0119 (svn r10572) -Codechange: Add function CheckIfCallBackAllowsAvailability for industries
belugas
parents: 7733
diff changeset
   436
{
47e4498a0119 (svn r10572) -Codechange: Add function CheckIfCallBackAllowsAvailability for industries
belugas
parents: 7733
diff changeset
   437
	const IndustrySpec *indspec = GetIndustrySpec(type);
47e4498a0119 (svn r10572) -Codechange: Add function CheckIfCallBackAllowsAvailability for industries
belugas
parents: 7733
diff changeset
   438
47e4498a0119 (svn r10572) -Codechange: Add function CheckIfCallBackAllowsAvailability for industries
belugas
parents: 7733
diff changeset
   439
	if (HASBIT(indspec->callback_flags, CBM_IND_AVAILABLE)) {
47e4498a0119 (svn r10572) -Codechange: Add function CheckIfCallBackAllowsAvailability for industries
belugas
parents: 7733
diff changeset
   440
		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
   441
		if (res != CALLBACK_FAILED) {
47e4498a0119 (svn r10572) -Codechange: Add function CheckIfCallBackAllowsAvailability for industries
belugas
parents: 7733
diff changeset
   442
			return (res == 0);
47e4498a0119 (svn r10572) -Codechange: Add function CheckIfCallBackAllowsAvailability for industries
belugas
parents: 7733
diff changeset
   443
		}
47e4498a0119 (svn r10572) -Codechange: Add function CheckIfCallBackAllowsAvailability for industries
belugas
parents: 7733
diff changeset
   444
	}
47e4498a0119 (svn r10572) -Codechange: Add function CheckIfCallBackAllowsAvailability for industries
belugas
parents: 7733
diff changeset
   445
	return true;
47e4498a0119 (svn r10572) -Codechange: Add function CheckIfCallBackAllowsAvailability for industries
belugas
parents: 7733
diff changeset
   446
}
47e4498a0119 (svn r10572) -Codechange: Add function CheckIfCallBackAllowsAvailability for industries
belugas
parents: 7733
diff changeset
   447
7664
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7662
diff changeset
   448
static int32 DerefIndProd(uint field, bool use_register)
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7662
diff changeset
   449
{
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7662
diff changeset
   450
	return use_register ? (int32)GetRegister(field) : field;
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7662
diff changeset
   451
}
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7662
diff changeset
   452
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7662
diff changeset
   453
/**
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7662
diff changeset
   454
 * 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
   455
 * @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
   456
 * @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
   457
 */
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7662
diff changeset
   458
void IndustryProductionCallback(Industry *ind, int reason)
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7662
diff changeset
   459
{
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7662
diff changeset
   460
	ResolverObject object;
7733
262c3a8de735 (svn r10518) -Fix: use the location of the industry and not INVALID_TILE for production callbacks; makes looking at the environment of an industry a lot more useful.
rubidium
parents: 7732
diff changeset
   461
	NewIndustryResolver(&object, ind->xy, ind);
7664
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7662
diff changeset
   462
	object.callback_param2 = reason;
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7662
diff changeset
   463
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7662
diff changeset
   464
	for (uint loop = 0;; loop++) {
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7662
diff changeset
   465
		SB(object.callback_param2, 8, 16, loop);
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7662
diff changeset
   466
		const SpriteGroup *group = Resolve(GetIndustrySpec(ind->type)->grf_prop.spritegroup, &object);
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7662
diff changeset
   467
		if (group == NULL || group->type != SGT_INDUSTRY_PRODUCTION) break;
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7662
diff changeset
   468
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7662
diff changeset
   469
		bool deref = (group->g.indprod.version == 1);
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7662
diff changeset
   470
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7662
diff changeset
   471
		for (uint i = 0; i < 3; i++) {
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7662
diff changeset
   472
			ind->incoming_cargo_waiting[i] = clamp(ind->incoming_cargo_waiting[i] - DerefIndProd(group->g.indprod.substract_input[i], deref), 0, 0xFFFF);
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7662
diff changeset
   473
		}
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7662
diff changeset
   474
		for (uint i = 0; i < 2; i++) {
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7662
diff changeset
   475
			ind->produced_cargo_waiting[i] = clamp(ind->produced_cargo_waiting[i] + DerefIndProd(group->g.indprod.add_output[i], deref), 0, 0xFFFF);
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7662
diff changeset
   476
		}
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7662
diff changeset
   477
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7662
diff changeset
   478
		int32 again = DerefIndProd(group->g.indprod.again, deref);
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7662
diff changeset
   479
		if (again == 0) break;
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7662
diff changeset
   480
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7662
diff changeset
   481
		SB(object.callback_param2, 24, 8, again);
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7662
diff changeset
   482
	}
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
   483
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
   484
	InvalidateWindow(WC_INDUSTRY_VIEW, ind->index);
7664
81c35390400e (svn r10442) -Codechange: implement the industry production callback.
rubidium
parents: 7662
diff changeset
   485
}