src/newgrf_industrytiles.cpp
author convert-repo
Mon, 07 Apr 2008 16:21:55 +0000
changeset 10076 dfd70e42c4ae
parent 9302 4aa3c4a44b16
child 10227 ef1901f80235
permissions -rw-r--r--
update tags
7380
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
     1
/* $Id$ */
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
     2
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
     3
/** @file newgrf_industrytiles.cpp */
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
     4
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
     5
#include "stdafx.h"
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
     6
#include "openttd.h"
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
     7
#include "variables.h"
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
     8
#include "debug.h"
8721
b7971ad9bdd9 (svn r11788) -Fix (11787): makedepend doesn't mark delete files as changed...
rubidium
parents: 8709
diff changeset
     9
#include "viewport_func.h"
7380
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
    10
#include "landscape.h"
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
    11
#include "newgrf.h"
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
    12
#include "industry.h"
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
    13
#include "newgrf_commons.h"
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
    14
#include "newgrf_spritegroup.h"
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
    15
#include "newgrf_callbacks.h"
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
    16
#include "newgrf_industries.h"
7725
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
    17
#include "newgrf_industrytiles.h"
7708
595630b38fbf (svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents: 7704
diff changeset
    18
#include "newgrf_text.h"
7380
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
    19
#include "industry_map.h"
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
    20
#include "clear_map.h"
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
    21
#include "sprite.h"
8345
6caa3fdb972c (svn r11399) -Feature(ette): transparency settings can now be saved and thus remembered.
belugas
parents: 8321
diff changeset
    22
#include "transparency.h"
8627
448ebf3a8291 (svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium
parents: 8586
diff changeset
    23
#include "functions.h"
8709
4187ad809fe7 (svn r11776) -Codechange: more header splittings to reduce the dependencies.
rubidium
parents: 8627
diff changeset
    24
#include "town.h"
8771
f7ad4dba14bf (svn r11839) -Codechange: move some variables from variables.h to a more logical location.
rubidium
parents: 8760
diff changeset
    25
#include "command_func.h"
7380
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
    26
8760
ce0891c412ce (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8736
diff changeset
    27
#include "table/sprites.h"
ce0891c412ce (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8736
diff changeset
    28
#include "table/strings.h"
ce0891c412ce (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8736
diff changeset
    29
8586
d79873568898 (svn r11651) -Codechange [FS#1555]: implement GRF parameter querying for industries and fix a 'bug' as side effect.
rubidium
parents: 8544
diff changeset
    30
static uint32 GetGRFParameter(IndustryGfx indtile_id, byte parameter)
d79873568898 (svn r11651) -Codechange [FS#1555]: implement GRF parameter querying for industries and fix a 'bug' as side effect.
rubidium
parents: 8544
diff changeset
    31
{
d79873568898 (svn r11651) -Codechange [FS#1555]: implement GRF parameter querying for industries and fix a 'bug' as side effect.
rubidium
parents: 8544
diff changeset
    32
	const IndustryTileSpec *indtspec = GetIndustryTileSpec(indtile_id);
d79873568898 (svn r11651) -Codechange [FS#1555]: implement GRF parameter querying for industries and fix a 'bug' as side effect.
rubidium
parents: 8544
diff changeset
    33
	const GRFFile *file = indtspec->grf_prop.grffile;
d79873568898 (svn r11651) -Codechange [FS#1555]: implement GRF parameter querying for industries and fix a 'bug' as side effect.
rubidium
parents: 8544
diff changeset
    34
d79873568898 (svn r11651) -Codechange [FS#1555]: implement GRF parameter querying for industries and fix a 'bug' as side effect.
rubidium
parents: 8544
diff changeset
    35
	if (parameter >= file->param_end) return 0;
d79873568898 (svn r11651) -Codechange [FS#1555]: implement GRF parameter querying for industries and fix a 'bug' as side effect.
rubidium
parents: 8544
diff changeset
    36
	return file->param[parameter];
d79873568898 (svn r11651) -Codechange [FS#1555]: implement GRF parameter querying for industries and fix a 'bug' as side effect.
rubidium
parents: 8544
diff changeset
    37
}
d79873568898 (svn r11651) -Codechange [FS#1555]: implement GRF parameter querying for industries and fix a 'bug' as side effect.
rubidium
parents: 8544
diff changeset
    38
7380
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
    39
/**
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
    40
 * Based on newhouses equivalent, but adapted for newindustries
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
    41
 * @param parameter from callback.  It's in fact a pair of coordinates
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
    42
 * @param tile TileIndex from which the callback was initiated
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
    43
 * @param index of the industry been queried for
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
    44
 * @return a construction of bits obeying the newgrf format
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
    45
 */
7730
a7b31d4fcc40 (svn r10515) -Codechange: allow getting some more data about the environment of an industry.
rubidium
parents: 7729
diff changeset
    46
uint32 GetNearbyIndustryTileInformation(byte parameter, TileIndex tile, IndustryID index)
7380
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
    47
{
7942
9f7797968d6d (svn r10904) -Fix: When using a temporary industry, make sure you do not clear some unreachable tiles upon its destruction.
belugas
parents: 7831
diff changeset
    48
	if (parameter != 0) tile = GetNearbyTile(parameter, tile); // only perform if it is required
8954
ca1d17502817 (svn r12028) -Codechange: Split common part of station var 0x67, house var 0x62, indtile var 0x60 and industry var 0x62 to 'newgrf_commons.cpp'.
frosch
parents: 8771
diff changeset
    49
	bool is_same_industry = (IsTileType(tile, MP_INDUSTRY) && GetIndustryIndex(tile) == index);
7380
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
    50
8954
ca1d17502817 (svn r12028) -Codechange: Split common part of station var 0x67, house var 0x62, indtile var 0x60 and industry var 0x62 to 'newgrf_commons.cpp'.
frosch
parents: 8771
diff changeset
    51
	return GetNearbyTileInformation(tile) | (is_same_industry ? 1 : 0) << 8;
7380
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
    52
}
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
    53
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
    54
/** This is the position of the tile relative to the northernmost tile of the industry.
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
    55
 * Format: 00yxYYXX
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
    56
 * Variable  Content
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
    57
 * x         the x offset from the northernmost tile
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
    58
 * XX        same, but stored in a byte instead of a nibble
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
    59
 * y         the y offset from the northernmost tile
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
    60
 * YY        same, but stored in a byte instead of a nibble
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
    61
 * @param tile TileIndex of the tile to evaluate
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
    62
 * @param ind_tile northernmost tile of the industry
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
    63
 */
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
    64
static uint32 GetRelativePosition(TileIndex tile, TileIndex ind_tile)
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
    65
{
7415
36ea2aa930eb (svn r10172) -Fix(r10127): Wrong evaluation order on variable 0x41 for industry tile.
belugas
parents: 7395
diff changeset
    66
	byte x = TileX(tile) - TileX(ind_tile);
36ea2aa930eb (svn r10172) -Fix(r10127): Wrong evaluation order on variable 0x41 for industry tile.
belugas
parents: 7395
diff changeset
    67
	byte y = TileY(tile) - TileY(ind_tile);
7380
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
    68
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
    69
	return ((y & 0xF) << 20) | ((x & 0xF) << 16) | (y << 8) | x;
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
    70
}
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
    71
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
    72
static uint32 IndustryTileGetVariable(const ResolverObject *object, byte variable, byte parameter, bool *available)
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
    73
{
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
    74
	const Industry *inds = object->u.industry.ind;
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
    75
	TileIndex tile       = object->u.industry.tile;
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
    76
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
    77
	if (object->scope == VSG_SCOPE_PARENT) {
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
    78
		return IndustryGetVariable(object, variable, parameter, available);
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
    79
	}
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
    80
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
    81
	switch (variable) {
7395
ed1cf28fb1b4 (svn r10146) -Codechange: Silence a compiler warning
belugas
parents: 7380
diff changeset
    82
		 /* Construction state of the tile: a value between 0 and 3 */
ed1cf28fb1b4 (svn r10146) -Codechange: Silence a compiler warning
belugas
parents: 7380
diff changeset
    83
		case 0x40 : return (IsTileType(tile, MP_INDUSTRY)) ? GetIndustryConstructionStage(tile) : 0;
7380
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
    84
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
    85
		case 0x41 : return GetTerrainType(tile);
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
    86
7395
ed1cf28fb1b4 (svn r10146) -Codechange: Silence a compiler warning
belugas
parents: 7380
diff changeset
    87
		/* Current town zone of the tile in the nearest town */
ed1cf28fb1b4 (svn r10146) -Codechange: Silence a compiler warning
belugas
parents: 7380
diff changeset
    88
		case 0x42 : return GetTownRadiusGroup(ClosestTownFromTile(tile, (uint)-1), tile);
7380
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
    89
7395
ed1cf28fb1b4 (svn r10146) -Codechange: Silence a compiler warning
belugas
parents: 7380
diff changeset
    90
		/* Relative position */
ed1cf28fb1b4 (svn r10146) -Codechange: Silence a compiler warning
belugas
parents: 7380
diff changeset
    91
		case 0x43 : return GetRelativePosition(tile, inds->xy);
7380
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
    92
7395
ed1cf28fb1b4 (svn r10146) -Codechange: Silence a compiler warning
belugas
parents: 7380
diff changeset
    93
		/* Animation frame. Like house variable 46 but can contain anything 0..FF. */
ed1cf28fb1b4 (svn r10146) -Codechange: Silence a compiler warning
belugas
parents: 7380
diff changeset
    94
		case 0x44 : return (IsTileType(tile, MP_INDUSTRY)) ? GetIndustryAnimationState(tile) : 0;
7380
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
    95
7395
ed1cf28fb1b4 (svn r10146) -Codechange: Silence a compiler warning
belugas
parents: 7380
diff changeset
    96
		/* Land info of nearby tiles */
7708
595630b38fbf (svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents: 7704
diff changeset
    97
		case 0x60 : return GetNearbyIndustryTileInformation(parameter, tile, inds == NULL ? (IndustryID)INVALID_INDUSTRY : inds->index);
7380
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
    98
7730
a7b31d4fcc40 (svn r10515) -Codechange: allow getting some more data about the environment of an industry.
rubidium
parents: 7729
diff changeset
    99
		/* Animation stage of nearby tiles */
a7b31d4fcc40 (svn r10515) -Codechange: allow getting some more data about the environment of an industry.
rubidium
parents: 7729
diff changeset
   100
		case 0x61 : {
7380
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
   101
			tile = GetNearbyTile(parameter, tile);
7395
ed1cf28fb1b4 (svn r10146) -Codechange: Silence a compiler warning
belugas
parents: 7380
diff changeset
   102
			if (IsTileType(tile, MP_INDUSTRY) && GetIndustryByTile(tile) == inds) {
ed1cf28fb1b4 (svn r10146) -Codechange: Silence a compiler warning
belugas
parents: 7380
diff changeset
   103
				return GetIndustryAnimationState(tile);
ed1cf28fb1b4 (svn r10146) -Codechange: Silence a compiler warning
belugas
parents: 7380
diff changeset
   104
			}
ed1cf28fb1b4 (svn r10146) -Codechange: Silence a compiler warning
belugas
parents: 7380
diff changeset
   105
			return 0xFFFFFFFF;
7380
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
   106
		}
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
   107
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
   108
		/* Get industry tile ID at offset */
8118
644c9acc640c (svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents: 8117
diff changeset
   109
		case 0x62 : return GetIndustryIDAtOffset(GetNearbyTile(parameter, tile), inds);
8586
d79873568898 (svn r11651) -Codechange [FS#1555]: implement GRF parameter querying for industries and fix a 'bug' as side effect.
rubidium
parents: 8544
diff changeset
   110
d79873568898 (svn r11651) -Codechange [FS#1555]: implement GRF parameter querying for industries and fix a 'bug' as side effect.
rubidium
parents: 8544
diff changeset
   111
		/* Read GRF parameter */
d79873568898 (svn r11651) -Codechange [FS#1555]: implement GRF parameter querying for industries and fix a 'bug' as side effect.
rubidium
parents: 8544
diff changeset
   112
		case 0x7F: return GetGRFParameter(GetIndustryGfx(tile), parameter);
7380
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
   113
	}
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
   114
7729
21b3ddd80928 (svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents: 7725
diff changeset
   115
	DEBUG(grf, 1, "Unhandled industry tile property 0x%X", variable);
21b3ddd80928 (svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents: 7725
diff changeset
   116
21b3ddd80928 (svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents: 7725
diff changeset
   117
	*available = false;
21b3ddd80928 (svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents: 7725
diff changeset
   118
	return (uint32)-1;
7380
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
   119
}
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
   120
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
   121
static const SpriteGroup *IndustryTileResolveReal(const ResolverObject *object, const SpriteGroup *group)
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
   122
{
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
   123
	/* IndustryTile do not have 'real' groups.  Or do they?? */
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
   124
	return NULL;
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
   125
}
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
   126
8117
6f265223b5fa (svn r11151) -Codechange: add (partial) support for randomizing industry triggers (part of the backend for it). Furthermore update the documentation of the map's bits wrt to industries.
rubidium
parents: 8106
diff changeset
   127
static uint32 IndustryTileGetRandomBits(const ResolverObject *object)
7380
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
   128
{
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
   129
	const TileIndex tile = object->u.industry.tile;
8117
6f265223b5fa (svn r11151) -Codechange: add (partial) support for randomizing industry triggers (part of the backend for it). Furthermore update the documentation of the map's bits wrt to industries.
rubidium
parents: 8106
diff changeset
   130
	if (tile == INVALID_TILE || !IsTileType(tile, MP_INDUSTRY)) return 0;
8356
4d72bac74977 (svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents: 8345
diff changeset
   131
	return (object->scope == VSG_SCOPE_SELF) ? GetIndustryRandomBits(tile) : GetIndustryByTile(tile)->random;
7380
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
   132
}
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
   133
8117
6f265223b5fa (svn r11151) -Codechange: add (partial) support for randomizing industry triggers (part of the backend for it). Furthermore update the documentation of the map's bits wrt to industries.
rubidium
parents: 8106
diff changeset
   134
static uint32 IndustryTileGetTriggers(const ResolverObject *object)
7380
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
   135
{
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
   136
	const TileIndex tile = object->u.industry.tile;
8117
6f265223b5fa (svn r11151) -Codechange: add (partial) support for randomizing industry triggers (part of the backend for it). Furthermore update the documentation of the map's bits wrt to industries.
rubidium
parents: 8106
diff changeset
   137
	if (tile == INVALID_TILE || !IsTileType(tile, MP_INDUSTRY)) return 0;
8356
4d72bac74977 (svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents: 8345
diff changeset
   138
	return (object->scope == VSG_SCOPE_SELF) ? GetIndustryTriggers(tile) : GetIndustryByTile(tile)->random_triggers;
7380
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
   139
}
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
   140
8117
6f265223b5fa (svn r11151) -Codechange: add (partial) support for randomizing industry triggers (part of the backend for it). Furthermore update the documentation of the map's bits wrt to industries.
rubidium
parents: 8106
diff changeset
   141
static void IndustryTileSetTriggers(const ResolverObject *object, int triggers)
7380
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
   142
{
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
   143
	const TileIndex tile = object->u.industry.tile;
8117
6f265223b5fa (svn r11151) -Codechange: add (partial) support for randomizing industry triggers (part of the backend for it). Furthermore update the documentation of the map's bits wrt to industries.
rubidium
parents: 8106
diff changeset
   144
	if (tile == INVALID_TILE || !IsTileType(tile, MP_INDUSTRY)) return;
6f265223b5fa (svn r11151) -Codechange: add (partial) support for randomizing industry triggers (part of the backend for it). Furthermore update the documentation of the map's bits wrt to industries.
rubidium
parents: 8106
diff changeset
   145
8356
4d72bac74977 (svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents: 8345
diff changeset
   146
	if (object->scope == VSG_SCOPE_SELF) {
8117
6f265223b5fa (svn r11151) -Codechange: add (partial) support for randomizing industry triggers (part of the backend for it). Furthermore update the documentation of the map's bits wrt to industries.
rubidium
parents: 8106
diff changeset
   147
		SetIndustryTriggers(tile, triggers);
6f265223b5fa (svn r11151) -Codechange: add (partial) support for randomizing industry triggers (part of the backend for it). Furthermore update the documentation of the map's bits wrt to industries.
rubidium
parents: 8106
diff changeset
   148
	} else {
8356
4d72bac74977 (svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents: 8345
diff changeset
   149
		GetIndustryByTile(tile)->random_triggers = triggers;
8117
6f265223b5fa (svn r11151) -Codechange: add (partial) support for randomizing industry triggers (part of the backend for it). Furthermore update the documentation of the map's bits wrt to industries.
rubidium
parents: 8106
diff changeset
   150
	}
7380
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
   151
}
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
   152
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
   153
static void NewIndustryTileResolver(ResolverObject *res, IndustryGfx gfx, TileIndex tile, Industry *indus)
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
   154
{
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
   155
	res->GetRandomBits = IndustryTileGetRandomBits;
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
   156
	res->GetTriggers   = IndustryTileGetTriggers;
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
   157
	res->SetTriggers   = IndustryTileSetTriggers;
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
   158
	res->GetVariable   = IndustryTileGetVariable;
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
   159
	res->ResolveReal   = IndustryTileResolveReal;
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
   160
8106
9f527cc360cf (svn r11139) -Codechange: add support for persistent storage for NewGRFs.
rubidium
parents: 8019
diff changeset
   161
	res->psa             = &indus->psa;
7380
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
   162
	res->u.industry.tile = tile;
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
   163
	res->u.industry.ind  = indus;
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
   164
	res->u.industry.gfx  = gfx;
8736
980e65a5d4ca (svn r11804) -Fix(r11797,FS#1636): Industry tiles should receive the same medecine as indstries themselves regarding the resolver's object
belugas
parents: 8721
diff changeset
   165
	res->u.industry.type = indus->type;
7380
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
   166
7823
cad4dec2b899 (svn r10690) -Codechange: use the enum that describes all callback IDs in favor of "just" using an untyped integer.
rubidium
parents: 7735
diff changeset
   167
	res->callback        = CBID_NO_CALLBACK;
7380
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
   168
	res->callback_param1 = 0;
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
   169
	res->callback_param2 = 0;
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
   170
	res->last_value      = 0;
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
   171
	res->trigger         = 0;
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
   172
	res->reseed          = 0;
9252
92e05c28a994 (svn r12452) -Feature: [NewGRF] Add random action 2 type 84. For vehicles only.
glx
parents: 9182
diff changeset
   173
	res->count           = 0;
7380
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
   174
}
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
   175
7466
01be88d1c0a6 (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 7415
diff changeset
   176
void IndustryDrawTileLayout(const TileInfo *ti, const SpriteGroup *group, byte rnd_color, byte stage, IndustryGfx gfx)
01be88d1c0a6 (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 7415
diff changeset
   177
{
01be88d1c0a6 (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 7415
diff changeset
   178
	const DrawTileSprites *dts = group->g.layout.dts;
01be88d1c0a6 (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 7415
diff changeset
   179
	const DrawTileSeqStruct *dtss;
01be88d1c0a6 (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 7415
diff changeset
   180
9067
88f2bc991236 (svn r12149) -Codechange: Merge 'ground_sprite' and 'ground_pal' of DrawTileSprites into one PalSpriteID
frosch
parents: 9066
diff changeset
   181
	SpriteID image = dts->ground.sprite;
88f2bc991236 (svn r12149) -Codechange: Merge 'ground_sprite' and 'ground_pal' of DrawTileSprites into one PalSpriteID
frosch
parents: 9066
diff changeset
   182
	SpriteID pal   = dts->ground.pal;
7466
01be88d1c0a6 (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 7415
diff changeset
   183
8152
4f4c9ffa4297 (svn r11187) -Fix: what holds for houses in r11149 also holds for industries.
rubidium
parents: 8123
diff changeset
   184
	if (IS_CUSTOM_SPRITE(image)) image += stage;
4f4c9ffa4297 (svn r11187) -Fix: what holds for houses in r11149 also holds for industries.
rubidium
parents: 8123
diff changeset
   185
7466
01be88d1c0a6 (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 7415
diff changeset
   186
	if (GB(image, 0, SPRITE_WIDTH) != 0) DrawGroundSprite(image, pal);
01be88d1c0a6 (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 7415
diff changeset
   187
9302
4aa3c4a44b16 (svn r12547) -Feature: invisibility options to make objects invisible instead of transparent
smatz
parents: 9252
diff changeset
   188
	/* End now if industries are invisible */
4aa3c4a44b16 (svn r12547) -Feature: invisibility options to make objects invisible instead of transparent
smatz
parents: 9252
diff changeset
   189
	if (IsInvisibilitySet(TO_INDUSTRIES)) return;
4aa3c4a44b16 (svn r12547) -Feature: invisibility options to make objects invisible instead of transparent
smatz
parents: 9252
diff changeset
   190
7466
01be88d1c0a6 (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 7415
diff changeset
   191
	foreach_draw_tile_seq(dtss, dts->seq) {
9066
29d5a0dfc329 (svn r12148) -Codechange: Merge 'image' and 'pal' of DrawTileSeqStruct into one PalSpriteID
frosch
parents: 8954
diff changeset
   192
		if (GB(dtss->image.sprite, 0, SPRITE_WIDTH) == 0) continue;
7466
01be88d1c0a6 (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 7415
diff changeset
   193
9066
29d5a0dfc329 (svn r12148) -Codechange: Merge 'image' and 'pal' of DrawTileSeqStruct into one PalSpriteID
frosch
parents: 8954
diff changeset
   194
		image = dtss->image.sprite;
29d5a0dfc329 (svn r12148) -Codechange: Merge 'image' and 'pal' of DrawTileSeqStruct into one PalSpriteID
frosch
parents: 8954
diff changeset
   195
		pal   = dtss->image.pal;
7466
01be88d1c0a6 (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 7415
diff changeset
   196
8152
4f4c9ffa4297 (svn r11187) -Fix: what holds for houses in r11149 also holds for industries.
rubidium
parents: 8123
diff changeset
   197
		if (IS_CUSTOM_SPRITE(image)) image += stage;
4f4c9ffa4297 (svn r11187) -Fix: what holds for houses in r11149 also holds for industries.
rubidium
parents: 8123
diff changeset
   198
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8418
diff changeset
   199
		if (HasBit(image, PALETTE_MODIFIER_COLOR)) {
8321
ab57909e30ed (svn r11375) -Fix [FS#1397]: the industry recolour map was always applied when recolouring was turned on, instead of only applying it when the colour translation is '0'.
rubidium
parents: 8246
diff changeset
   200
			if (pal == 0) {
ab57909e30ed (svn r11375) -Fix [FS#1397]: the industry recolour map was always applied when recolouring was turned on, instead of only applying it when the colour translation is '0'.
rubidium
parents: 8246
diff changeset
   201
				pal = GENERAL_SPRITE_COLOR(rnd_color);
ab57909e30ed (svn r11375) -Fix [FS#1397]: the industry recolour map was always applied when recolouring was turned on, instead of only applying it when the colour translation is '0'.
rubidium
parents: 8246
diff changeset
   202
			}
7466
01be88d1c0a6 (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 7415
diff changeset
   203
		} else {
01be88d1c0a6 (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 7415
diff changeset
   204
			pal = PAL_NONE;
01be88d1c0a6 (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 7415
diff changeset
   205
		}
01be88d1c0a6 (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 7415
diff changeset
   206
01be88d1c0a6 (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 7415
diff changeset
   207
		if ((byte)dtss->delta_z != 0x80) {
01be88d1c0a6 (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 7415
diff changeset
   208
			AddSortableSpriteToDraw(
01be88d1c0a6 (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 7415
diff changeset
   209
				image, pal,
01be88d1c0a6 (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 7415
diff changeset
   210
				ti->x + dtss->delta_x, ti->y + dtss->delta_y,
01be88d1c0a6 (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 7415
diff changeset
   211
				dtss->size_x, dtss->size_y,
7829
88883899c9e6 (svn r10696) -Codechange: remove duplication of the "make sprite transparent" code.
rubidium
parents: 7823
diff changeset
   212
				dtss->size_z, ti->z + dtss->delta_z,
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8418
diff changeset
   213
				!HasBit(image, SPRITE_MODIFIER_OPAQUE) && IsTransparencySet(TO_INDUSTRIES)
7466
01be88d1c0a6 (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 7415
diff changeset
   214
			);
01be88d1c0a6 (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 7415
diff changeset
   215
		} else {
8345
6caa3fdb972c (svn r11399) -Feature(ette): transparency settings can now be saved and thus remembered.
belugas
parents: 8321
diff changeset
   216
			AddChildSpriteScreen(image, pal, (byte)dtss->delta_x, (byte)dtss->delta_y, IsTransparencySet(TO_INDUSTRIES));
7466
01be88d1c0a6 (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 7415
diff changeset
   217
		}
01be88d1c0a6 (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 7415
diff changeset
   218
	}
01be88d1c0a6 (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 7415
diff changeset
   219
}
01be88d1c0a6 (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 7415
diff changeset
   220
7823
cad4dec2b899 (svn r10690) -Codechange: use the enum that describes all callback IDs in favor of "just" using an untyped integer.
rubidium
parents: 7735
diff changeset
   221
uint16 GetIndustryTileCallback(CallbackID callback, uint32 param1, uint32 param2, IndustryGfx gfx_id, Industry *industry, TileIndex tile)
7380
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
   222
{
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
   223
	ResolverObject object;
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
   224
	const SpriteGroup *group;
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
   225
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
   226
	NewIndustryTileResolver(&object, gfx_id, tile, industry);
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
   227
	object.callback = callback;
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
   228
	object.callback_param1 = param1;
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
   229
	object.callback_param2 = param2;
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
   230
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
   231
	group = Resolve(GetIndustryTileSpec(gfx_id)->grf_prop.spritegroup, &object);
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
   232
	if (group == NULL || group->type != SGT_CALLBACK) return CALLBACK_FAILED;
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
   233
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
   234
	return group->g.callback.result;
a9d0047b015c (svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff changeset
   235
}
7466
01be88d1c0a6 (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 7415
diff changeset
   236
01be88d1c0a6 (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 7415
diff changeset
   237
bool DrawNewIndustryTile(TileInfo *ti, Industry *i, IndustryGfx gfx, const IndustryTileSpec *inds)
01be88d1c0a6 (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 7415
diff changeset
   238
{
01be88d1c0a6 (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 7415
diff changeset
   239
	const SpriteGroup *group;
01be88d1c0a6 (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 7415
diff changeset
   240
	ResolverObject object;
01be88d1c0a6 (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 7415
diff changeset
   241
01be88d1c0a6 (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 7415
diff changeset
   242
	if (ti->tileh != SLOPE_FLAT) {
01be88d1c0a6 (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 7415
diff changeset
   243
		bool draw_old_one = true;
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8418
diff changeset
   244
		if (HasBit(inds->callback_flags, CBM_INDT_DRAW_FOUNDATIONS)) {
7466
01be88d1c0a6 (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 7415
diff changeset
   245
			/* Called to determine the type (if any) of foundation to draw for industry tile */
01be88d1c0a6 (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 7415
diff changeset
   246
			uint32 callback_res = GetIndustryTileCallback(CBID_INDUSTRY_DRAW_FOUNDATIONS, 0, 0, gfx, i, ti->tile);
7704
f5961e82f08a (svn r10486) -Fix: do not draw foundations when the "should I draw foundations" callbacks says to do so.
rubidium
parents: 7466
diff changeset
   247
			draw_old_one = callback_res != 0;
7466
01be88d1c0a6 (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 7415
diff changeset
   248
		}
01be88d1c0a6 (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 7415
diff changeset
   249
7831
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7829
diff changeset
   250
		if (draw_old_one) DrawFoundation(ti, FOUNDATION_LEVELED);
7466
01be88d1c0a6 (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 7415
diff changeset
   251
	}
01be88d1c0a6 (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 7415
diff changeset
   252
01be88d1c0a6 (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 7415
diff changeset
   253
	NewIndustryTileResolver(&object, gfx, ti->tile, i);
01be88d1c0a6 (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 7415
diff changeset
   254
01be88d1c0a6 (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 7415
diff changeset
   255
	group = Resolve(inds->grf_prop.spritegroup, &object);
01be88d1c0a6 (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 7415
diff changeset
   256
	if (group == NULL || group->type != SGT_TILELAYOUT) {
01be88d1c0a6 (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 7415
diff changeset
   257
		return false;
01be88d1c0a6 (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 7415
diff changeset
   258
	} else {
01be88d1c0a6 (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 7415
diff changeset
   259
		/* Limit the building stage to the number of stages supplied. */
01be88d1c0a6 (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 7415
diff changeset
   260
		byte stage = GetIndustryConstructionStage(ti->tile);
8418
b49fc6be1ab9 (svn r11475) -Codechange: rename clamp and clampu to Clamp and ClampU to fit with the coding style
skidd13
parents: 8356
diff changeset
   261
		stage = Clamp(stage - 4 + group->g.layout.num_sprites, 0, group->g.layout.num_sprites - 1);
7466
01be88d1c0a6 (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 7415
diff changeset
   262
		IndustryDrawTileLayout(ti, group, i->random_color, stage, gfx);
01be88d1c0a6 (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 7415
diff changeset
   263
		return true;
01be88d1c0a6 (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 7415
diff changeset
   264
	}
01be88d1c0a6 (svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents: 7415
diff changeset
   265
}
7708
595630b38fbf (svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents: 7704
diff changeset
   266
8158
84c773075796 (svn r11193) -Fix: be more compliant with the specifications of callback #2F (and undocumented side effects in TTDP in corner cases).
rubidium
parents: 8155
diff changeset
   267
extern bool IsSlopeRefused(Slope current, Slope refused);
84c773075796 (svn r11193) -Fix: be more compliant with the specifications of callback #2F (and undocumented side effects in TTDP in corner cases).
rubidium
parents: 8155
diff changeset
   268
84c773075796 (svn r11193) -Fix: be more compliant with the specifications of callback #2F (and undocumented side effects in TTDP in corner cases).
rubidium
parents: 8155
diff changeset
   269
bool PerformIndustryTileSlopeCheck(TileIndex ind_base_tile, TileIndex ind_tile, const IndustryTileSpec *its, IndustryType type, IndustryGfx gfx, uint itspec_index)
7708
595630b38fbf (svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents: 7704
diff changeset
   270
{
7712
e217909bd0d5 (svn r10494) -Fix (r10490): possible null dereference in some exotic newgrfs.
rubidium
parents: 7708
diff changeset
   271
	Industry ind;
8158
84c773075796 (svn r11193) -Fix: be more compliant with the specifications of callback #2F (and undocumented side effects in TTDP in corner cases).
rubidium
parents: 8155
diff changeset
   272
	ind.index = INVALID_INDUSTRY;
84c773075796 (svn r11193) -Fix: be more compliant with the specifications of callback #2F (and undocumented side effects in TTDP in corner cases).
rubidium
parents: 8155
diff changeset
   273
	ind.xy = ind_base_tile;
7942
9f7797968d6d (svn r10904) -Fix: When using a temporary industry, make sure you do not clear some unreachable tiles upon its destruction.
belugas
parents: 7831
diff changeset
   274
	ind.width = 0;
7712
e217909bd0d5 (svn r10494) -Fix (r10490): possible null dereference in some exotic newgrfs.
rubidium
parents: 7708
diff changeset
   275
	ind.type = type;
e217909bd0d5 (svn r10494) -Fix (r10490): possible null dereference in some exotic newgrfs.
rubidium
parents: 7708
diff changeset
   276
8158
84c773075796 (svn r11193) -Fix: be more compliant with the specifications of callback #2F (and undocumented side effects in TTDP in corner cases).
rubidium
parents: 8155
diff changeset
   277
	uint16 callback_res = GetIndustryTileCallback(CBID_INDTILE_SHAPE_CHECK, 0, itspec_index, gfx, &ind, ind_tile);
84c773075796 (svn r11193) -Fix: be more compliant with the specifications of callback #2F (and undocumented side effects in TTDP in corner cases).
rubidium
parents: 8155
diff changeset
   278
	if (callback_res == CALLBACK_FAILED) {
84c773075796 (svn r11193) -Fix: be more compliant with the specifications of callback #2F (and undocumented side effects in TTDP in corner cases).
rubidium
parents: 8155
diff changeset
   279
		return !IsSlopeRefused(GetTileSlope(ind_tile, NULL), its->slopes_refused);
84c773075796 (svn r11193) -Fix: be more compliant with the specifications of callback #2F (and undocumented side effects in TTDP in corner cases).
rubidium
parents: 8155
diff changeset
   280
	}
7708
595630b38fbf (svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents: 7704
diff changeset
   281
	if (its->grf_prop.grffile->grf_version < 7) {
9182
3c6eb660d4e5 (svn r12358) -Fix: Callback 2F returns 15 bit results starting from grf version 7.
frosch
parents: 9067
diff changeset
   282
		return (callback_res & 0xFF) != 0; // mask to 8 bit callback result
7708
595630b38fbf (svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents: 7704
diff changeset
   283
	}
595630b38fbf (svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents: 7704
diff changeset
   284
8246
ff7b892d8a28 (svn r11287) -Codechange: add support for pushing paramaters into NewIndustries' error messages. Patch by Csaboka.
rubidium
parents: 8203
diff changeset
   285
	/* Copy some parameters from the registers to the error message text ref. stack */
ff7b892d8a28 (svn r11287) -Codechange: add support for pushing paramaters into NewIndustries' error messages. Patch by Csaboka.
rubidium
parents: 8203
diff changeset
   286
	SwitchToErrorRefStack();
ff7b892d8a28 (svn r11287) -Codechange: add support for pushing paramaters into NewIndustries' error messages. Patch by Csaboka.
rubidium
parents: 8203
diff changeset
   287
	PrepareTextRefStackUsage(4);
ff7b892d8a28 (svn r11287) -Codechange: add support for pushing paramaters into NewIndustries' error messages. Patch by Csaboka.
rubidium
parents: 8203
diff changeset
   288
	SwitchToNormalRefStack();
ff7b892d8a28 (svn r11287) -Codechange: add support for pushing paramaters into NewIndustries' error messages. Patch by Csaboka.
rubidium
parents: 8203
diff changeset
   289
7708
595630b38fbf (svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents: 7704
diff changeset
   290
	switch (callback_res) {
595630b38fbf (svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents: 7704
diff changeset
   291
		case 0x400: return true;
595630b38fbf (svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents: 7704
diff changeset
   292
		case 0x401: _error_message = STR_0239_SITE_UNSUITABLE;                 return false;
595630b38fbf (svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents: 7704
diff changeset
   293
		case 0x402: _error_message = STR_0317_CAN_ONLY_BE_BUILT_IN_RAINFOREST; return false;
595630b38fbf (svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents: 7704
diff changeset
   294
		case 0x403: _error_message = STR_0318_CAN_ONLY_BE_BUILT_IN_DESERT;     return false;
595630b38fbf (svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents: 7704
diff changeset
   295
		default: _error_message = GetGRFStringID(its->grf_prop.grffile->grfid, 0xD000 + callback_res); return false;
595630b38fbf (svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents: 7704
diff changeset
   296
	}
595630b38fbf (svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents: 7704
diff changeset
   297
}
7725
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   298
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   299
void AnimateNewIndustryTile(TileIndex tile)
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   300
{
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   301
	Industry *ind = GetIndustryByTile(tile);
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   302
	IndustryGfx gfx = GetIndustryGfx(tile);
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   303
	const IndustryTileSpec *itspec = GetIndustryTileSpec(gfx);
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   304
	byte animation_speed = itspec->animation_speed;
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   305
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8418
diff changeset
   306
	if (HasBit(itspec->callback_flags, CBM_INDT_ANIM_SPEED)) {
7725
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   307
		uint16 callback_res = GetIndustryTileCallback(CBID_INDTILE_ANIMATION_SPEED, 0, 0, gfx, ind, tile);
8418
b49fc6be1ab9 (svn r11475) -Codechange: rename clamp and clampu to Clamp and ClampU to fit with the coding style
skidd13
parents: 8356
diff changeset
   308
		if (callback_res != CALLBACK_FAILED) animation_speed = Clamp(callback_res & 0xFF, 0, 16);
7725
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   309
	}
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   310
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   311
	/* An animation speed of 2 means the animation frame changes 4 ticks, and
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   312
	 * increasing this value by one doubles the wait. 0 is the minimum value
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   313
	 * allowed for animation_speed, which corresponds to 30ms, and 16 is the
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   314
	 * maximum, corresponding to around 33 minutes. */
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   315
	if ((_tick_counter % (1 << animation_speed)) != 0) return;
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   316
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   317
	bool frame_set_by_callback = false;
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   318
	byte frame = GetIndustryAnimationState(tile);
8203
c2fa2ac2c65d (svn r11241) -Fix: Obiwan error on industry animated tiles. Spotted and fixed by Csaboka
belugas
parents: 8187
diff changeset
   319
	uint16 num_frames = GB(itspec->animation_info, 0, 8);
7725
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   320
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8418
diff changeset
   321
	if (HasBit(itspec->callback_flags, CBM_INDT_ANIM_NEXT_FRAME)) {
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8418
diff changeset
   322
		uint16 callback_res = GetIndustryTileCallback(CBID_INDTILE_ANIM_NEXT_FRAME, HasBit(itspec->animation_special_flags, 0) ? Random() : 0, 0, gfx, ind, tile);
7725
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   323
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   324
		if (callback_res != CALLBACK_FAILED) {
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   325
			frame_set_by_callback = true;
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   326
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   327
			switch (callback_res & 0xFF) {
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   328
				case 0xFF:
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   329
					DeleteAnimatedTile(tile);
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   330
					break;
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   331
				case 0xFE:
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   332
					/* Carry on as normal. */
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   333
					frame_set_by_callback = false;
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   334
					break;
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   335
				default:
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   336
					frame = callback_res & 0xFF;
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   337
					break;
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   338
			}
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   339
		}
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   340
	}
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   341
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   342
	if (!frame_set_by_callback) {
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   343
		if (frame < num_frames) {
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   344
			frame++;
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   345
		} else if (frame == num_frames && GB(itspec->animation_info, 8, 8) == 1) {
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   346
			/* This animation loops, so start again from the beginning */
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   347
			frame = 0;
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   348
		} else {
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   349
			/* This animation doesn't loop, so stay here */
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   350
			DeleteAnimatedTile(tile);
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   351
		}
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   352
	}
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   353
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   354
	SetIndustryAnimationState(tile, frame);
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   355
	MarkTileDirtyByTile(tile);
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   356
}
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   357
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   358
static void ChangeIndustryTileAnimationFrame(TileIndex tile, IndustryAnimationTrigger iat, uint32 random_bits, IndustryGfx gfx, Industry *ind)
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   359
{
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   360
	uint16 callback_res = GetIndustryTileCallback(CBID_INDTILE_ANIM_START_STOP, random_bits, iat, gfx, ind, tile);
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   361
	if (callback_res == CALLBACK_FAILED) return;
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   362
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   363
	switch (callback_res & 0xFF) {
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   364
		case 0xFD: /* Do nothing. */         break;
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   365
		case 0xFE: AddAnimatedTile(tile);    break;
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   366
		case 0xFF: DeleteAnimatedTile(tile); break;
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   367
		default:
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   368
			SetIndustryAnimationState(tile, callback_res & 0xFF);
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   369
			AddAnimatedTile(tile);
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   370
			break;
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   371
	}
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   372
}
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   373
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   374
bool StartStopIndustryTileAnimation(TileIndex tile, IndustryAnimationTrigger iat, uint32 random)
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   375
{
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   376
	IndustryGfx gfx = GetIndustryGfx(tile);
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   377
	const IndustryTileSpec *itspec = GetIndustryTileSpec(gfx);
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   378
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8418
diff changeset
   379
	if (!HasBit(itspec->animation_triggers, iat)) return false;
7725
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   380
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   381
	Industry *ind = GetIndustryByTile(tile);
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   382
	ChangeIndustryTileAnimationFrame(tile, iat, random, gfx, ind);
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   383
	return true;
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   384
}
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   385
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   386
bool StartStopIndustryTileAnimation(const Industry *ind, IndustryAnimationTrigger iat)
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   387
{
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   388
	bool ret = true;
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   389
	uint32 random = Random();
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   390
	BEGIN_TILE_LOOP(tile, ind->width, ind->height, ind->xy)
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   391
		if (IsTileType(tile, MP_INDUSTRY) && GetIndustryIndex(tile) == ind->index) {
8123
2f8dfb527d7c (svn r11158) -Codechange: reduce the amount of Random calls needed when we do not have NewGRF industries that actually need the random bits.
rubidium
parents: 8118
diff changeset
   392
			if (StartStopIndustryTileAnimation(tile, iat, random)) {
2f8dfb527d7c (svn r11158) -Codechange: reduce the amount of Random calls needed when we do not have NewGRF industries that actually need the random bits.
rubidium
parents: 8118
diff changeset
   393
				SB(random, 0, 16, Random());
2f8dfb527d7c (svn r11158) -Codechange: reduce the amount of Random calls needed when we do not have NewGRF industries that actually need the random bits.
rubidium
parents: 8118
diff changeset
   394
			} else {
2f8dfb527d7c (svn r11158) -Codechange: reduce the amount of Random calls needed when we do not have NewGRF industries that actually need the random bits.
rubidium
parents: 8118
diff changeset
   395
				ret = false;
2f8dfb527d7c (svn r11158) -Codechange: reduce the amount of Random calls needed when we do not have NewGRF industries that actually need the random bits.
rubidium
parents: 8118
diff changeset
   396
			}
7725
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   397
		}
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   398
	END_TILE_LOOP(tile, ind->width, ind->height, ind->xy)
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   399
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   400
	return ret;
e3892b38aa14 (svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents: 7712
diff changeset
   401
}
8356
4d72bac74977 (svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents: 8345
diff changeset
   402
4d72bac74977 (svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents: 8345
diff changeset
   403
static void DoTriggerIndustryTile(TileIndex tile, IndustryTileTrigger trigger, Industry *ind)
4d72bac74977 (svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents: 8345
diff changeset
   404
{
4d72bac74977 (svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents: 8345
diff changeset
   405
	ResolverObject object;
4d72bac74977 (svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents: 8345
diff changeset
   406
4d72bac74977 (svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents: 8345
diff changeset
   407
	IndustryGfx gfx = GetIndustryGfx(tile);
4d72bac74977 (svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents: 8345
diff changeset
   408
	const IndustryTileSpec *itspec = GetIndustryTileSpec(gfx);
4d72bac74977 (svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents: 8345
diff changeset
   409
4d72bac74977 (svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents: 8345
diff changeset
   410
	NewIndustryTileResolver(&object, gfx, tile, ind);
4d72bac74977 (svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents: 8345
diff changeset
   411
4d72bac74977 (svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents: 8345
diff changeset
   412
	object.callback = CBID_RANDOM_TRIGGER;
4d72bac74977 (svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents: 8345
diff changeset
   413
	object.trigger = trigger;
4d72bac74977 (svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents: 8345
diff changeset
   414
4d72bac74977 (svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents: 8345
diff changeset
   415
	const SpriteGroup *group = Resolve(itspec->grf_prop.spritegroup, &object);
4d72bac74977 (svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents: 8345
diff changeset
   416
	if (group == NULL) return;
4d72bac74977 (svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents: 8345
diff changeset
   417
4d72bac74977 (svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents: 8345
diff changeset
   418
	byte new_random_bits = Random();
4d72bac74977 (svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents: 8345
diff changeset
   419
	byte random_bits = GetIndustryRandomBits(tile);
4d72bac74977 (svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents: 8345
diff changeset
   420
	random_bits &= ~object.reseed;
4d72bac74977 (svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents: 8345
diff changeset
   421
	random_bits |= new_random_bits & object.reseed;
4d72bac74977 (svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents: 8345
diff changeset
   422
	SetIndustryRandomBits(tile, random_bits);
4d72bac74977 (svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents: 8345
diff changeset
   423
}
4d72bac74977 (svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents: 8345
diff changeset
   424
4d72bac74977 (svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents: 8345
diff changeset
   425
void TriggerIndustryTile(TileIndex tile, IndustryTileTrigger trigger)
4d72bac74977 (svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents: 8345
diff changeset
   426
{
4d72bac74977 (svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents: 8345
diff changeset
   427
	DoTriggerIndustryTile(tile, trigger, GetIndustryByTile(tile));
4d72bac74977 (svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents: 8345
diff changeset
   428
}
4d72bac74977 (svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents: 8345
diff changeset
   429
4d72bac74977 (svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents: 8345
diff changeset
   430
void TriggerIndustry(Industry *ind, IndustryTileTrigger trigger)
4d72bac74977 (svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents: 8345
diff changeset
   431
{
4d72bac74977 (svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents: 8345
diff changeset
   432
	BEGIN_TILE_LOOP(tile, ind->width, ind->height, ind->xy)
4d72bac74977 (svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents: 8345
diff changeset
   433
		if (IsTileType(tile, MP_INDUSTRY) && GetIndustryIndex(tile) == ind->index) {
4d72bac74977 (svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents: 8345
diff changeset
   434
			DoTriggerIndustryTile(tile, trigger, ind);
4d72bac74977 (svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents: 8345
diff changeset
   435
		}
4d72bac74977 (svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents: 8345
diff changeset
   436
	END_TILE_LOOP(tile, ind->width, ind->height, ind->xy)
4d72bac74977 (svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents: 8345
diff changeset
   437
}