author | peter1138 |
Sun, 03 Aug 2008 17:35:08 +0000 | |
changeset 9834 | 7474149531c1 |
parent 9750 | 7114408dd1fa |
child 10236 | 50afe9dd466e |
permissions | -rw-r--r-- |
6884
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
1 |
/* $Id$ */ |
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
2 |
|
9111
48ce04029fe4
(svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents:
9028
diff
changeset
|
3 |
/** @file newgrf_industrytiles.cpp NewGRF handling of industry tiles. */ |
6884
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
4 |
|
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
5 |
#include "stdafx.h" |
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
6 |
#include "openttd.h" |
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
7 |
#include "variables.h" |
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
8 |
#include "debug.h" |
8225
cd84a95b6630
(svn r11788) -Fix (11787): makedepend doesn't mark delete files as changed...
rubidium
parents:
8213
diff
changeset
|
9 |
#include "viewport_func.h" |
6884
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
10 |
#include "landscape.h" |
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
11 |
#include "newgrf.h" |
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
12 |
#include "industry.h" |
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
13 |
#include "newgrf_commons.h" |
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
14 |
#include "newgrf_spritegroup.h" |
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
15 |
#include "newgrf_callbacks.h" |
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
16 |
#include "newgrf_industries.h" |
7229
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
17 |
#include "newgrf_industrytiles.h" |
9018
403898e0b54e
(svn r12817) -Feature: the ability to play NewGRF sounds for industries and stations.
rubidium
parents:
9005
diff
changeset
|
18 |
#include "newgrf_sound.h" |
7212
5d99296fb545
(svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents:
7208
diff
changeset
|
19 |
#include "newgrf_text.h" |
6884
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
20 |
#include "industry_map.h" |
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
21 |
#include "clear_map.h" |
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
22 |
#include "sprite.h" |
7849
0a1c0af2c96c
(svn r11399) -Feature(ette): transparency settings can now be saved and thus remembered.
belugas
parents:
7825
diff
changeset
|
23 |
#include "transparency.h" |
8131
160939e24ed3
(svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium
parents:
8090
diff
changeset
|
24 |
#include "functions.h" |
8213
7bdd7593eb9b
(svn r11776) -Codechange: more header splittings to reduce the dependencies.
rubidium
parents:
8131
diff
changeset
|
25 |
#include "town.h" |
8275
f17d0c863ee3
(svn r11839) -Codechange: move some variables from variables.h to a more logical location.
rubidium
parents:
8264
diff
changeset
|
26 |
#include "command_func.h" |
9005
d6b0e0a54ef2
(svn r12800) -Codechange: move the animated tile related functions out of texteff.cpp (it isn't a text effect after all). Also remove a few more functions from functions.
rubidium
parents:
8967
diff
changeset
|
27 |
#include "animated_tile_func.h" |
9718
4b7468076d31
(svn r13838) -Codechange: Make industry tiles aware of WaterClasses.
frosch
parents:
9549
diff
changeset
|
28 |
#include "water.h" |
6884
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
29 |
|
8264
b1e85998c7d3
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8240
diff
changeset
|
30 |
#include "table/sprites.h" |
b1e85998c7d3
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8240
diff
changeset
|
31 |
#include "table/strings.h" |
b1e85998c7d3
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8240
diff
changeset
|
32 |
|
6884
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
33 |
/** |
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
34 |
* Based on newhouses equivalent, but adapted for newindustries |
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
35 |
* @param parameter from callback. It's in fact a pair of coordinates |
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
36 |
* @param tile TileIndex from which the callback was initiated |
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
37 |
* @param index of the industry been queried for |
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
38 |
* @return a construction of bits obeying the newgrf format |
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
39 |
*/ |
7234
c6d0e14ae80b
(svn r10515) -Codechange: allow getting some more data about the environment of an industry.
rubidium
parents:
7233
diff
changeset
|
40 |
uint32 GetNearbyIndustryTileInformation(byte parameter, TileIndex tile, IndustryID index) |
6884
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
41 |
{ |
7446
2d84d980b04c
(svn r10904) -Fix: When using a temporary industry, make sure you do not clear some unreachable tiles upon its destruction.
belugas
parents:
7335
diff
changeset
|
42 |
if (parameter != 0) tile = GetNearbyTile(parameter, tile); // only perform if it is required |
8458
38fe72ff1402
(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:
8275
diff
changeset
|
43 |
bool is_same_industry = (IsTileType(tile, MP_INDUSTRY) && GetIndustryIndex(tile) == index); |
6884
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
44 |
|
8458
38fe72ff1402
(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:
8275
diff
changeset
|
45 |
return GetNearbyTileInformation(tile) | (is_same_industry ? 1 : 0) << 8; |
6884
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
46 |
} |
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
47 |
|
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
48 |
/** This is the position of the tile relative to the northernmost tile of the industry. |
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
49 |
* Format: 00yxYYXX |
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
50 |
* Variable Content |
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
51 |
* x the x offset from the northernmost tile |
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
52 |
* XX same, but stored in a byte instead of a nibble |
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
53 |
* y the y offset from the northernmost tile |
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
54 |
* YY same, but stored in a byte instead of a nibble |
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
55 |
* @param tile TileIndex of the tile to evaluate |
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
56 |
* @param ind_tile northernmost tile of the industry |
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
57 |
*/ |
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
58 |
static uint32 GetRelativePosition(TileIndex tile, TileIndex ind_tile) |
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
59 |
{ |
6919
4f62b4f5a81f
(svn r10172) -Fix(r10127): Wrong evaluation order on variable 0x41 for industry tile.
belugas
parents:
6899
diff
changeset
|
60 |
byte x = TileX(tile) - TileX(ind_tile); |
4f62b4f5a81f
(svn r10172) -Fix(r10127): Wrong evaluation order on variable 0x41 for industry tile.
belugas
parents:
6899
diff
changeset
|
61 |
byte y = TileY(tile) - TileY(ind_tile); |
6884
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
62 |
|
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
63 |
return ((y & 0xF) << 20) | ((x & 0xF) << 16) | (y << 8) | x; |
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
64 |
} |
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
65 |
|
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
66 |
static uint32 IndustryTileGetVariable(const ResolverObject *object, byte variable, byte parameter, bool *available) |
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
67 |
{ |
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
68 |
const Industry *inds = object->u.industry.ind; |
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
69 |
TileIndex tile = object->u.industry.tile; |
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
70 |
|
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
71 |
if (object->scope == VSG_SCOPE_PARENT) { |
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
72 |
return IndustryGetVariable(object, variable, parameter, available); |
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
73 |
} |
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
74 |
|
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
75 |
switch (variable) { |
6899
7edc4e4b1fd8
(svn r10146) -Codechange: Silence a compiler warning
belugas
parents:
6884
diff
changeset
|
76 |
/* Construction state of the tile: a value between 0 and 3 */ |
7edc4e4b1fd8
(svn r10146) -Codechange: Silence a compiler warning
belugas
parents:
6884
diff
changeset
|
77 |
case 0x40 : return (IsTileType(tile, MP_INDUSTRY)) ? GetIndustryConstructionStage(tile) : 0; |
6884
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
78 |
|
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
79 |
case 0x41 : return GetTerrainType(tile); |
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
80 |
|
6899
7edc4e4b1fd8
(svn r10146) -Codechange: Silence a compiler warning
belugas
parents:
6884
diff
changeset
|
81 |
/* Current town zone of the tile in the nearest town */ |
7edc4e4b1fd8
(svn r10146) -Codechange: Silence a compiler warning
belugas
parents:
6884
diff
changeset
|
82 |
case 0x42 : return GetTownRadiusGroup(ClosestTownFromTile(tile, (uint)-1), tile); |
6884
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
83 |
|
6899
7edc4e4b1fd8
(svn r10146) -Codechange: Silence a compiler warning
belugas
parents:
6884
diff
changeset
|
84 |
/* Relative position */ |
7edc4e4b1fd8
(svn r10146) -Codechange: Silence a compiler warning
belugas
parents:
6884
diff
changeset
|
85 |
case 0x43 : return GetRelativePosition(tile, inds->xy); |
6884
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
86 |
|
6899
7edc4e4b1fd8
(svn r10146) -Codechange: Silence a compiler warning
belugas
parents:
6884
diff
changeset
|
87 |
/* Animation frame. Like house variable 46 but can contain anything 0..FF. */ |
7edc4e4b1fd8
(svn r10146) -Codechange: Silence a compiler warning
belugas
parents:
6884
diff
changeset
|
88 |
case 0x44 : return (IsTileType(tile, MP_INDUSTRY)) ? GetIndustryAnimationState(tile) : 0; |
6884
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
89 |
|
6899
7edc4e4b1fd8
(svn r10146) -Codechange: Silence a compiler warning
belugas
parents:
6884
diff
changeset
|
90 |
/* Land info of nearby tiles */ |
7212
5d99296fb545
(svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents:
7208
diff
changeset
|
91 |
case 0x60 : return GetNearbyIndustryTileInformation(parameter, tile, inds == NULL ? (IndustryID)INVALID_INDUSTRY : inds->index); |
6884
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
92 |
|
7234
c6d0e14ae80b
(svn r10515) -Codechange: allow getting some more data about the environment of an industry.
rubidium
parents:
7233
diff
changeset
|
93 |
/* Animation stage of nearby tiles */ |
c6d0e14ae80b
(svn r10515) -Codechange: allow getting some more data about the environment of an industry.
rubidium
parents:
7233
diff
changeset
|
94 |
case 0x61 : { |
6884
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
95 |
tile = GetNearbyTile(parameter, tile); |
6899
7edc4e4b1fd8
(svn r10146) -Codechange: Silence a compiler warning
belugas
parents:
6884
diff
changeset
|
96 |
if (IsTileType(tile, MP_INDUSTRY) && GetIndustryByTile(tile) == inds) { |
7edc4e4b1fd8
(svn r10146) -Codechange: Silence a compiler warning
belugas
parents:
6884
diff
changeset
|
97 |
return GetIndustryAnimationState(tile); |
7edc4e4b1fd8
(svn r10146) -Codechange: Silence a compiler warning
belugas
parents:
6884
diff
changeset
|
98 |
} |
7edc4e4b1fd8
(svn r10146) -Codechange: Silence a compiler warning
belugas
parents:
6884
diff
changeset
|
99 |
return 0xFFFFFFFF; |
6884
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
100 |
} |
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
101 |
|
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
102 |
/* Get industry tile ID at offset */ |
7622
12388e4d86bb
(svn r11152) -Fix: GetIndustryIDAtOffset crashed when translation of the GFX ID would be needed. Fix by Belugas.
rubidium
parents:
7621
diff
changeset
|
103 |
case 0x62 : return GetIndustryIDAtOffset(GetNearbyTile(parameter, tile), inds); |
6884
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
104 |
} |
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
105 |
|
7233
aadfbb505671
(svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents:
7229
diff
changeset
|
106 |
DEBUG(grf, 1, "Unhandled industry tile property 0x%X", variable); |
aadfbb505671
(svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents:
7229
diff
changeset
|
107 |
|
aadfbb505671
(svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents:
7229
diff
changeset
|
108 |
*available = false; |
aadfbb505671
(svn r10514) -Codechange: add support for getting the nearest industry with a given type.
rubidium
parents:
7229
diff
changeset
|
109 |
return (uint32)-1; |
6884
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
110 |
} |
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
111 |
|
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
112 |
static const SpriteGroup *IndustryTileResolveReal(const ResolverObject *object, const SpriteGroup *group) |
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
113 |
{ |
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
114 |
/* IndustryTile do not have 'real' groups. Or do they?? */ |
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
115 |
return NULL; |
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
116 |
} |
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
117 |
|
7621
09824471f144
(svn r11151) -Codechange: add (partial) support for randomizing industry triggers (part of the backend for it). Furthermore update the documentation of the map's bits wrt to industries.
rubidium
parents:
7610
diff
changeset
|
118 |
static uint32 IndustryTileGetRandomBits(const ResolverObject *object) |
6884
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
119 |
{ |
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
120 |
const TileIndex tile = object->u.industry.tile; |
7621
09824471f144
(svn r11151) -Codechange: add (partial) support for randomizing industry triggers (part of the backend for it). Furthermore update the documentation of the map's bits wrt to industries.
rubidium
parents:
7610
diff
changeset
|
121 |
if (tile == INVALID_TILE || !IsTileType(tile, MP_INDUSTRY)) return 0; |
7860
5cdd0d914013
(svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents:
7849
diff
changeset
|
122 |
return (object->scope == VSG_SCOPE_SELF) ? GetIndustryRandomBits(tile) : GetIndustryByTile(tile)->random; |
6884
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
123 |
} |
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
124 |
|
7621
09824471f144
(svn r11151) -Codechange: add (partial) support for randomizing industry triggers (part of the backend for it). Furthermore update the documentation of the map's bits wrt to industries.
rubidium
parents:
7610
diff
changeset
|
125 |
static uint32 IndustryTileGetTriggers(const ResolverObject *object) |
6884
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
126 |
{ |
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
127 |
const TileIndex tile = object->u.industry.tile; |
7621
09824471f144
(svn r11151) -Codechange: add (partial) support for randomizing industry triggers (part of the backend for it). Furthermore update the documentation of the map's bits wrt to industries.
rubidium
parents:
7610
diff
changeset
|
128 |
if (tile == INVALID_TILE || !IsTileType(tile, MP_INDUSTRY)) return 0; |
7860
5cdd0d914013
(svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents:
7849
diff
changeset
|
129 |
return (object->scope == VSG_SCOPE_SELF) ? GetIndustryTriggers(tile) : GetIndustryByTile(tile)->random_triggers; |
6884
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
130 |
} |
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
131 |
|
7621
09824471f144
(svn r11151) -Codechange: add (partial) support for randomizing industry triggers (part of the backend for it). Furthermore update the documentation of the map's bits wrt to industries.
rubidium
parents:
7610
diff
changeset
|
132 |
static void IndustryTileSetTriggers(const ResolverObject *object, int triggers) |
6884
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
133 |
{ |
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
134 |
const TileIndex tile = object->u.industry.tile; |
7621
09824471f144
(svn r11151) -Codechange: add (partial) support for randomizing industry triggers (part of the backend for it). Furthermore update the documentation of the map's bits wrt to industries.
rubidium
parents:
7610
diff
changeset
|
135 |
if (tile == INVALID_TILE || !IsTileType(tile, MP_INDUSTRY)) return; |
09824471f144
(svn r11151) -Codechange: add (partial) support for randomizing industry triggers (part of the backend for it). Furthermore update the documentation of the map's bits wrt to industries.
rubidium
parents:
7610
diff
changeset
|
136 |
|
7860
5cdd0d914013
(svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents:
7849
diff
changeset
|
137 |
if (object->scope == VSG_SCOPE_SELF) { |
7621
09824471f144
(svn r11151) -Codechange: add (partial) support for randomizing industry triggers (part of the backend for it). Furthermore update the documentation of the map's bits wrt to industries.
rubidium
parents:
7610
diff
changeset
|
138 |
SetIndustryTriggers(tile, triggers); |
09824471f144
(svn r11151) -Codechange: add (partial) support for randomizing industry triggers (part of the backend for it). Furthermore update the documentation of the map's bits wrt to industries.
rubidium
parents:
7610
diff
changeset
|
139 |
} else { |
7860
5cdd0d914013
(svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents:
7849
diff
changeset
|
140 |
GetIndustryByTile(tile)->random_triggers = triggers; |
7621
09824471f144
(svn r11151) -Codechange: add (partial) support for randomizing industry triggers (part of the backend for it). Furthermore update the documentation of the map's bits wrt to industries.
rubidium
parents:
7610
diff
changeset
|
141 |
} |
6884
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
142 |
} |
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
143 |
|
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
144 |
static void NewIndustryTileResolver(ResolverObject *res, IndustryGfx gfx, TileIndex tile, Industry *indus) |
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
145 |
{ |
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
146 |
res->GetRandomBits = IndustryTileGetRandomBits; |
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
147 |
res->GetTriggers = IndustryTileGetTriggers; |
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
148 |
res->SetTriggers = IndustryTileSetTriggers; |
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
149 |
res->GetVariable = IndustryTileGetVariable; |
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
150 |
res->ResolveReal = IndustryTileResolveReal; |
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
151 |
|
7610
13b7d9e247d2
(svn r11139) -Codechange: add support for persistent storage for NewGRFs.
rubidium
parents:
7523
diff
changeset
|
152 |
res->psa = &indus->psa; |
6884
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
153 |
res->u.industry.tile = tile; |
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
154 |
res->u.industry.ind = indus; |
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
155 |
res->u.industry.gfx = gfx; |
8240
0a10b565233a
(svn r11804) -Fix(r11797,FS#1636): Industry tiles should receive the same medecine as indstries themselves regarding the resolver's object
belugas
parents:
8225
diff
changeset
|
156 |
res->u.industry.type = indus->type; |
6884
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
157 |
|
7327
d810677fb909
(svn r10690) -Codechange: use the enum that describes all callback IDs in favor of "just" using an untyped integer.
rubidium
parents:
7239
diff
changeset
|
158 |
res->callback = CBID_NO_CALLBACK; |
6884
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
159 |
res->callback_param1 = 0; |
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
160 |
res->callback_param2 = 0; |
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
161 |
res->last_value = 0; |
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
162 |
res->trigger = 0; |
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
163 |
res->reseed = 0; |
8756
b6f8dc6a246f
(svn r12452) -Feature: [NewGRF] Add random action 2 type 84. For vehicles only.
glx
parents:
8686
diff
changeset
|
164 |
res->count = 0; |
9750
7114408dd1fa
(svn r13885) -Fix [FS#2168]: Var 0x7F is not feature-specific.
frosch
parents:
9718
diff
changeset
|
165 |
|
7114408dd1fa
(svn r13885) -Fix [FS#2168]: Var 0x7F is not feature-specific.
frosch
parents:
9718
diff
changeset
|
166 |
const IndustryTileSpec *its = GetIndustryTileSpec(gfx); |
7114408dd1fa
(svn r13885) -Fix [FS#2168]: Var 0x7F is not feature-specific.
frosch
parents:
9718
diff
changeset
|
167 |
res->grffile = (its != NULL ? its->grf_prop.grffile : NULL); |
6884
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
168 |
} |
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
169 |
|
6970
b489d8ec5d4a
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
6919
diff
changeset
|
170 |
void IndustryDrawTileLayout(const TileInfo *ti, const SpriteGroup *group, byte rnd_color, byte stage, IndustryGfx gfx) |
b489d8ec5d4a
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
6919
diff
changeset
|
171 |
{ |
b489d8ec5d4a
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
6919
diff
changeset
|
172 |
const DrawTileSprites *dts = group->g.layout.dts; |
b489d8ec5d4a
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
6919
diff
changeset
|
173 |
const DrawTileSeqStruct *dtss; |
b489d8ec5d4a
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
6919
diff
changeset
|
174 |
|
8571
53c94d717e99
(svn r12149) -Codechange: Merge 'ground_sprite' and 'ground_pal' of DrawTileSprites into one PalSpriteID
frosch
parents:
8570
diff
changeset
|
175 |
SpriteID image = dts->ground.sprite; |
53c94d717e99
(svn r12149) -Codechange: Merge 'ground_sprite' and 'ground_pal' of DrawTileSprites into one PalSpriteID
frosch
parents:
8570
diff
changeset
|
176 |
SpriteID pal = dts->ground.pal; |
6970
b489d8ec5d4a
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
6919
diff
changeset
|
177 |
|
7656
2c4110e04e37
(svn r11187) -Fix: what holds for houses in r11149 also holds for industries.
rubidium
parents:
7627
diff
changeset
|
178 |
if (IS_CUSTOM_SPRITE(image)) image += stage; |
2c4110e04e37
(svn r11187) -Fix: what holds for houses in r11149 also holds for industries.
rubidium
parents:
7627
diff
changeset
|
179 |
|
9718
4b7468076d31
(svn r13838) -Codechange: Make industry tiles aware of WaterClasses.
frosch
parents:
9549
diff
changeset
|
180 |
if (GB(image, 0, SPRITE_WIDTH) != 0) { |
4b7468076d31
(svn r13838) -Codechange: Make industry tiles aware of WaterClasses.
frosch
parents:
9549
diff
changeset
|
181 |
/* If the ground sprite is the default flat water sprite, draw also canal/river borders |
4b7468076d31
(svn r13838) -Codechange: Make industry tiles aware of WaterClasses.
frosch
parents:
9549
diff
changeset
|
182 |
* Do not do this if the tile's WaterClass is 'land'. */ |
4b7468076d31
(svn r13838) -Codechange: Make industry tiles aware of WaterClasses.
frosch
parents:
9549
diff
changeset
|
183 |
if (image == SPR_FLAT_WATER_TILE && IsIndustryTileOnWater(ti->tile)) { |
4b7468076d31
(svn r13838) -Codechange: Make industry tiles aware of WaterClasses.
frosch
parents:
9549
diff
changeset
|
184 |
DrawWaterClassGround(ti); |
4b7468076d31
(svn r13838) -Codechange: Make industry tiles aware of WaterClasses.
frosch
parents:
9549
diff
changeset
|
185 |
} else { |
4b7468076d31
(svn r13838) -Codechange: Make industry tiles aware of WaterClasses.
frosch
parents:
9549
diff
changeset
|
186 |
DrawGroundSprite(image, pal); |
4b7468076d31
(svn r13838) -Codechange: Make industry tiles aware of WaterClasses.
frosch
parents:
9549
diff
changeset
|
187 |
} |
4b7468076d31
(svn r13838) -Codechange: Make industry tiles aware of WaterClasses.
frosch
parents:
9549
diff
changeset
|
188 |
} |
6970
b489d8ec5d4a
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
6919
diff
changeset
|
189 |
|
b489d8ec5d4a
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
6919
diff
changeset
|
190 |
foreach_draw_tile_seq(dtss, dts->seq) { |
8570
f50de4804ff1
(svn r12148) -Codechange: Merge 'image' and 'pal' of DrawTileSeqStruct into one PalSpriteID
frosch
parents:
8458
diff
changeset
|
191 |
if (GB(dtss->image.sprite, 0, SPRITE_WIDTH) == 0) continue; |
6970
b489d8ec5d4a
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
6919
diff
changeset
|
192 |
|
8570
f50de4804ff1
(svn r12148) -Codechange: Merge 'image' and 'pal' of DrawTileSeqStruct into one PalSpriteID
frosch
parents:
8458
diff
changeset
|
193 |
image = dtss->image.sprite; |
f50de4804ff1
(svn r12148) -Codechange: Merge 'image' and 'pal' of DrawTileSeqStruct into one PalSpriteID
frosch
parents:
8458
diff
changeset
|
194 |
pal = dtss->image.pal; |
6970
b489d8ec5d4a
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
6919
diff
changeset
|
195 |
|
9549
41ec95418e84
(svn r13565) -Change [FS#2077]: when invisibility is set, sprite sequences are now drawn until first non-opaque sprite is found (bit 14 not set)
smatz
parents:
9111
diff
changeset
|
196 |
/* Stop drawing sprite sequence once we meet a sprite that doesn't have to be opaque */ |
41ec95418e84
(svn r13565) -Change [FS#2077]: when invisibility is set, sprite sequences are now drawn until first non-opaque sprite is found (bit 14 not set)
smatz
parents:
9111
diff
changeset
|
197 |
if (IsInvisibilitySet(TO_INDUSTRIES) && !HasBit(image, SPRITE_MODIFIER_OPAQUE)) return; |
41ec95418e84
(svn r13565) -Change [FS#2077]: when invisibility is set, sprite sequences are now drawn until first non-opaque sprite is found (bit 14 not set)
smatz
parents:
9111
diff
changeset
|
198 |
|
7656
2c4110e04e37
(svn r11187) -Fix: what holds for houses in r11149 also holds for industries.
rubidium
parents:
7627
diff
changeset
|
199 |
if (IS_CUSTOM_SPRITE(image)) image += stage; |
2c4110e04e37
(svn r11187) -Fix: what holds for houses in r11149 also holds for industries.
rubidium
parents:
7627
diff
changeset
|
200 |
|
7928
63e18de69e50
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
7922
diff
changeset
|
201 |
if (HasBit(image, PALETTE_MODIFIER_COLOR)) { |
7825
88509e87fe7d
(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:
7750
diff
changeset
|
202 |
if (pal == 0) { |
88509e87fe7d
(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:
7750
diff
changeset
|
203 |
pal = GENERAL_SPRITE_COLOR(rnd_color); |
88509e87fe7d
(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:
7750
diff
changeset
|
204 |
} |
6970
b489d8ec5d4a
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
6919
diff
changeset
|
205 |
} else { |
b489d8ec5d4a
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
6919
diff
changeset
|
206 |
pal = PAL_NONE; |
b489d8ec5d4a
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
6919
diff
changeset
|
207 |
} |
b489d8ec5d4a
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
6919
diff
changeset
|
208 |
|
b489d8ec5d4a
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
6919
diff
changeset
|
209 |
if ((byte)dtss->delta_z != 0x80) { |
b489d8ec5d4a
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
6919
diff
changeset
|
210 |
AddSortableSpriteToDraw( |
b489d8ec5d4a
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
6919
diff
changeset
|
211 |
image, pal, |
b489d8ec5d4a
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
6919
diff
changeset
|
212 |
ti->x + dtss->delta_x, ti->y + dtss->delta_y, |
b489d8ec5d4a
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
6919
diff
changeset
|
213 |
dtss->size_x, dtss->size_y, |
7333
e48228e44be8
(svn r10696) -Codechange: remove duplication of the "make sprite transparent" code.
rubidium
parents:
7327
diff
changeset
|
214 |
dtss->size_z, ti->z + dtss->delta_z, |
7928
63e18de69e50
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
7922
diff
changeset
|
215 |
!HasBit(image, SPRITE_MODIFIER_OPAQUE) && IsTransparencySet(TO_INDUSTRIES) |
6970
b489d8ec5d4a
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
6919
diff
changeset
|
216 |
); |
b489d8ec5d4a
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
6919
diff
changeset
|
217 |
} else { |
7849
0a1c0af2c96c
(svn r11399) -Feature(ette): transparency settings can now be saved and thus remembered.
belugas
parents:
7825
diff
changeset
|
218 |
AddChildSpriteScreen(image, pal, (byte)dtss->delta_x, (byte)dtss->delta_y, IsTransparencySet(TO_INDUSTRIES)); |
6970
b489d8ec5d4a
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
6919
diff
changeset
|
219 |
} |
b489d8ec5d4a
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
6919
diff
changeset
|
220 |
} |
b489d8ec5d4a
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
6919
diff
changeset
|
221 |
} |
b489d8ec5d4a
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
6919
diff
changeset
|
222 |
|
7327
d810677fb909
(svn r10690) -Codechange: use the enum that describes all callback IDs in favor of "just" using an untyped integer.
rubidium
parents:
7239
diff
changeset
|
223 |
uint16 GetIndustryTileCallback(CallbackID callback, uint32 param1, uint32 param2, IndustryGfx gfx_id, Industry *industry, TileIndex tile) |
6884
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
224 |
{ |
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
225 |
ResolverObject object; |
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
226 |
const SpriteGroup *group; |
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
227 |
|
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
228 |
NewIndustryTileResolver(&object, gfx_id, tile, industry); |
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
229 |
object.callback = callback; |
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
230 |
object.callback_param1 = param1; |
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
231 |
object.callback_param2 = param2; |
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
232 |
|
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
233 |
group = Resolve(GetIndustryTileSpec(gfx_id)->grf_prop.spritegroup, &object); |
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
234 |
if (group == NULL || group->type != SGT_CALLBACK) return CALLBACK_FAILED; |
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
235 |
|
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
236 |
return group->g.callback.result; |
a931841e9df4
(svn r10127) -Add: Addition of basic structure for industry tiles callbacks (unfinished).
belugas
parents:
diff
changeset
|
237 |
} |
6970
b489d8ec5d4a
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
6919
diff
changeset
|
238 |
|
b489d8ec5d4a
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
6919
diff
changeset
|
239 |
bool DrawNewIndustryTile(TileInfo *ti, Industry *i, IndustryGfx gfx, const IndustryTileSpec *inds) |
b489d8ec5d4a
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
6919
diff
changeset
|
240 |
{ |
b489d8ec5d4a
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
6919
diff
changeset
|
241 |
const SpriteGroup *group; |
b489d8ec5d4a
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
6919
diff
changeset
|
242 |
ResolverObject object; |
b489d8ec5d4a
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
6919
diff
changeset
|
243 |
|
b489d8ec5d4a
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
6919
diff
changeset
|
244 |
if (ti->tileh != SLOPE_FLAT) { |
b489d8ec5d4a
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
6919
diff
changeset
|
245 |
bool draw_old_one = true; |
7928
63e18de69e50
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
7922
diff
changeset
|
246 |
if (HasBit(inds->callback_flags, CBM_INDT_DRAW_FOUNDATIONS)) { |
6970
b489d8ec5d4a
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
6919
diff
changeset
|
247 |
/* Called to determine the type (if any) of foundation to draw for industry tile */ |
b489d8ec5d4a
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
6919
diff
changeset
|
248 |
uint32 callback_res = GetIndustryTileCallback(CBID_INDUSTRY_DRAW_FOUNDATIONS, 0, 0, gfx, i, ti->tile); |
7208
e875325a4291
(svn r10486) -Fix: do not draw foundations when the "should I draw foundations" callbacks says to do so.
rubidium
parents:
6970
diff
changeset
|
249 |
draw_old_one = callback_res != 0; |
6970
b489d8ec5d4a
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
6919
diff
changeset
|
250 |
} |
b489d8ec5d4a
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
6919
diff
changeset
|
251 |
|
7335
141c6b86ec1f
(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:
7333
diff
changeset
|
252 |
if (draw_old_one) DrawFoundation(ti, FOUNDATION_LEVELED); |
6970
b489d8ec5d4a
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
6919
diff
changeset
|
253 |
} |
b489d8ec5d4a
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
6919
diff
changeset
|
254 |
|
b489d8ec5d4a
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
6919
diff
changeset
|
255 |
NewIndustryTileResolver(&object, gfx, ti->tile, i); |
b489d8ec5d4a
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
6919
diff
changeset
|
256 |
|
b489d8ec5d4a
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
6919
diff
changeset
|
257 |
group = Resolve(inds->grf_prop.spritegroup, &object); |
b489d8ec5d4a
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
6919
diff
changeset
|
258 |
if (group == NULL || group->type != SGT_TILELAYOUT) { |
b489d8ec5d4a
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
6919
diff
changeset
|
259 |
return false; |
b489d8ec5d4a
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
6919
diff
changeset
|
260 |
} else { |
b489d8ec5d4a
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
6919
diff
changeset
|
261 |
/* Limit the building stage to the number of stages supplied. */ |
b489d8ec5d4a
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
6919
diff
changeset
|
262 |
byte stage = GetIndustryConstructionStage(ti->tile); |
7922
a7e266f966d9
(svn r11475) -Codechange: rename clamp and clampu to Clamp and ClampU to fit with the coding style
skidd13
parents:
7860
diff
changeset
|
263 |
stage = Clamp(stage - 4 + group->g.layout.num_sprites, 0, group->g.layout.num_sprites - 1); |
6970
b489d8ec5d4a
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
6919
diff
changeset
|
264 |
IndustryDrawTileLayout(ti, group, i->random_color, stage, gfx); |
b489d8ec5d4a
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
6919
diff
changeset
|
265 |
return true; |
b489d8ec5d4a
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
6919
diff
changeset
|
266 |
} |
b489d8ec5d4a
(svn r10226) -Codechange: Add support for newindustry tiles drawing.
belugas
parents:
6919
diff
changeset
|
267 |
} |
7212
5d99296fb545
(svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents:
7208
diff
changeset
|
268 |
|
7662
b9da9d79a9a9
(svn r11193) -Fix: be more compliant with the specifications of callback #2F (and undocumented side effects in TTDP in corner cases).
rubidium
parents:
7659
diff
changeset
|
269 |
extern bool IsSlopeRefused(Slope current, Slope refused); |
b9da9d79a9a9
(svn r11193) -Fix: be more compliant with the specifications of callback #2F (and undocumented side effects in TTDP in corner cases).
rubidium
parents:
7659
diff
changeset
|
270 |
|
b9da9d79a9a9
(svn r11193) -Fix: be more compliant with the specifications of callback #2F (and undocumented side effects in TTDP in corner cases).
rubidium
parents:
7659
diff
changeset
|
271 |
bool PerformIndustryTileSlopeCheck(TileIndex ind_base_tile, TileIndex ind_tile, const IndustryTileSpec *its, IndustryType type, IndustryGfx gfx, uint itspec_index) |
7212
5d99296fb545
(svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents:
7208
diff
changeset
|
272 |
{ |
7216
2bb13ff061b1
(svn r10494) -Fix (r10490): possible null dereference in some exotic newgrfs.
rubidium
parents:
7212
diff
changeset
|
273 |
Industry ind; |
7662
b9da9d79a9a9
(svn r11193) -Fix: be more compliant with the specifications of callback #2F (and undocumented side effects in TTDP in corner cases).
rubidium
parents:
7659
diff
changeset
|
274 |
ind.index = INVALID_INDUSTRY; |
b9da9d79a9a9
(svn r11193) -Fix: be more compliant with the specifications of callback #2F (and undocumented side effects in TTDP in corner cases).
rubidium
parents:
7659
diff
changeset
|
275 |
ind.xy = ind_base_tile; |
7446
2d84d980b04c
(svn r10904) -Fix: When using a temporary industry, make sure you do not clear some unreachable tiles upon its destruction.
belugas
parents:
7335
diff
changeset
|
276 |
ind.width = 0; |
7216
2bb13ff061b1
(svn r10494) -Fix (r10490): possible null dereference in some exotic newgrfs.
rubidium
parents:
7212
diff
changeset
|
277 |
ind.type = type; |
2bb13ff061b1
(svn r10494) -Fix (r10490): possible null dereference in some exotic newgrfs.
rubidium
parents:
7212
diff
changeset
|
278 |
|
7662
b9da9d79a9a9
(svn r11193) -Fix: be more compliant with the specifications of callback #2F (and undocumented side effects in TTDP in corner cases).
rubidium
parents:
7659
diff
changeset
|
279 |
uint16 callback_res = GetIndustryTileCallback(CBID_INDTILE_SHAPE_CHECK, 0, itspec_index, gfx, &ind, ind_tile); |
b9da9d79a9a9
(svn r11193) -Fix: be more compliant with the specifications of callback #2F (and undocumented side effects in TTDP in corner cases).
rubidium
parents:
7659
diff
changeset
|
280 |
if (callback_res == CALLBACK_FAILED) { |
b9da9d79a9a9
(svn r11193) -Fix: be more compliant with the specifications of callback #2F (and undocumented side effects in TTDP in corner cases).
rubidium
parents:
7659
diff
changeset
|
281 |
return !IsSlopeRefused(GetTileSlope(ind_tile, NULL), its->slopes_refused); |
b9da9d79a9a9
(svn r11193) -Fix: be more compliant with the specifications of callback #2F (and undocumented side effects in TTDP in corner cases).
rubidium
parents:
7659
diff
changeset
|
282 |
} |
7212
5d99296fb545
(svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents:
7208
diff
changeset
|
283 |
if (its->grf_prop.grffile->grf_version < 7) { |
8967
885904c2bf73
(svn r12759) -Fix(r12358): There is no need to mask callback result for pre-version7 since CBID_INDTILE_SHAPE_CHECK (cb2F) is really 15 bits.
belugas
parents:
8806
diff
changeset
|
284 |
return callback_res != 0; |
7212
5d99296fb545
(svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents:
7208
diff
changeset
|
285 |
} |
5d99296fb545
(svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents:
7208
diff
changeset
|
286 |
|
7750
7afbef1235e0
(svn r11287) -Codechange: add support for pushing paramaters into NewIndustries' error messages. Patch by Csaboka.
rubidium
parents:
7707
diff
changeset
|
287 |
/* Copy some parameters from the registers to the error message text ref. stack */ |
7afbef1235e0
(svn r11287) -Codechange: add support for pushing paramaters into NewIndustries' error messages. Patch by Csaboka.
rubidium
parents:
7707
diff
changeset
|
288 |
SwitchToErrorRefStack(); |
7afbef1235e0
(svn r11287) -Codechange: add support for pushing paramaters into NewIndustries' error messages. Patch by Csaboka.
rubidium
parents:
7707
diff
changeset
|
289 |
PrepareTextRefStackUsage(4); |
7afbef1235e0
(svn r11287) -Codechange: add support for pushing paramaters into NewIndustries' error messages. Patch by Csaboka.
rubidium
parents:
7707
diff
changeset
|
290 |
SwitchToNormalRefStack(); |
7afbef1235e0
(svn r11287) -Codechange: add support for pushing paramaters into NewIndustries' error messages. Patch by Csaboka.
rubidium
parents:
7707
diff
changeset
|
291 |
|
7212
5d99296fb545
(svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents:
7208
diff
changeset
|
292 |
switch (callback_res) { |
5d99296fb545
(svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents:
7208
diff
changeset
|
293 |
case 0x400: return true; |
5d99296fb545
(svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents:
7208
diff
changeset
|
294 |
case 0x401: _error_message = STR_0239_SITE_UNSUITABLE; return false; |
5d99296fb545
(svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents:
7208
diff
changeset
|
295 |
case 0x402: _error_message = STR_0317_CAN_ONLY_BE_BUILT_IN_RAINFOREST; return false; |
5d99296fb545
(svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents:
7208
diff
changeset
|
296 |
case 0x403: _error_message = STR_0318_CAN_ONLY_BE_BUILT_IN_DESERT; return false; |
5d99296fb545
(svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents:
7208
diff
changeset
|
297 |
default: _error_message = GetGRFStringID(its->grf_prop.grffile->grfid, 0xD000 + callback_res); return false; |
5d99296fb545
(svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents:
7208
diff
changeset
|
298 |
} |
5d99296fb545
(svn r10490) -Codechange: add support for industries on non-flat surfaces.
rubidium
parents:
7208
diff
changeset
|
299 |
} |
7229
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
300 |
|
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
301 |
void AnimateNewIndustryTile(TileIndex tile) |
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
302 |
{ |
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
303 |
Industry *ind = GetIndustryByTile(tile); |
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
304 |
IndustryGfx gfx = GetIndustryGfx(tile); |
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
305 |
const IndustryTileSpec *itspec = GetIndustryTileSpec(gfx); |
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
306 |
byte animation_speed = itspec->animation_speed; |
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
307 |
|
7928
63e18de69e50
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
7922
diff
changeset
|
308 |
if (HasBit(itspec->callback_flags, CBM_INDT_ANIM_SPEED)) { |
7229
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
309 |
uint16 callback_res = GetIndustryTileCallback(CBID_INDTILE_ANIMATION_SPEED, 0, 0, gfx, ind, tile); |
7922
a7e266f966d9
(svn r11475) -Codechange: rename clamp and clampu to Clamp and ClampU to fit with the coding style
skidd13
parents:
7860
diff
changeset
|
310 |
if (callback_res != CALLBACK_FAILED) animation_speed = Clamp(callback_res & 0xFF, 0, 16); |
7229
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
311 |
} |
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
312 |
|
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
313 |
/* An animation speed of 2 means the animation frame changes 4 ticks, and |
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
314 |
* increasing this value by one doubles the wait. 0 is the minimum value |
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
315 |
* allowed for animation_speed, which corresponds to 30ms, and 16 is the |
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
316 |
* maximum, corresponding to around 33 minutes. */ |
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
317 |
if ((_tick_counter % (1 << animation_speed)) != 0) return; |
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
318 |
|
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
319 |
bool frame_set_by_callback = false; |
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
320 |
byte frame = GetIndustryAnimationState(tile); |
7707
6e71b2a41025
(svn r11241) -Fix: Obiwan error on industry animated tiles. Spotted and fixed by Csaboka
belugas
parents:
7691
diff
changeset
|
321 |
uint16 num_frames = GB(itspec->animation_info, 0, 8); |
7229
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
322 |
|
7928
63e18de69e50
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
7922
diff
changeset
|
323 |
if (HasBit(itspec->callback_flags, CBM_INDT_ANIM_NEXT_FRAME)) { |
63e18de69e50
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
7922
diff
changeset
|
324 |
uint16 callback_res = GetIndustryTileCallback(CBID_INDTILE_ANIM_NEXT_FRAME, HasBit(itspec->animation_special_flags, 0) ? Random() : 0, 0, gfx, ind, tile); |
7229
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
325 |
|
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
326 |
if (callback_res != CALLBACK_FAILED) { |
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
327 |
frame_set_by_callback = true; |
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
328 |
|
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
329 |
switch (callback_res & 0xFF) { |
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
330 |
case 0xFF: |
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
331 |
DeleteAnimatedTile(tile); |
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
332 |
break; |
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
333 |
case 0xFE: |
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
334 |
/* Carry on as normal. */ |
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
335 |
frame_set_by_callback = false; |
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
336 |
break; |
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
337 |
default: |
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
338 |
frame = callback_res & 0xFF; |
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
339 |
break; |
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
340 |
} |
9018
403898e0b54e
(svn r12817) -Feature: the ability to play NewGRF sounds for industries and stations.
rubidium
parents:
9005
diff
changeset
|
341 |
|
403898e0b54e
(svn r12817) -Feature: the ability to play NewGRF sounds for industries and stations.
rubidium
parents:
9005
diff
changeset
|
342 |
/* If the lower 7 bits of the upper byte of the callback |
403898e0b54e
(svn r12817) -Feature: the ability to play NewGRF sounds for industries and stations.
rubidium
parents:
9005
diff
changeset
|
343 |
* result are not empty, it is a sound effect. */ |
403898e0b54e
(svn r12817) -Feature: the ability to play NewGRF sounds for industries and stations.
rubidium
parents:
9005
diff
changeset
|
344 |
if (GB(callback_res, 8, 7) != 0) PlayTileSound(itspec->grf_prop.grffile, GB(callback_res, 8, 7), tile); |
7229
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
345 |
} |
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
346 |
} |
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
347 |
|
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
348 |
if (!frame_set_by_callback) { |
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
349 |
if (frame < num_frames) { |
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
350 |
frame++; |
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
351 |
} else if (frame == num_frames && GB(itspec->animation_info, 8, 8) == 1) { |
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
352 |
/* This animation loops, so start again from the beginning */ |
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
353 |
frame = 0; |
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
354 |
} else { |
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
355 |
/* This animation doesn't loop, so stay here */ |
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
356 |
DeleteAnimatedTile(tile); |
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
357 |
} |
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
358 |
} |
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
359 |
|
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
360 |
SetIndustryAnimationState(tile, frame); |
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
361 |
MarkTileDirtyByTile(tile); |
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
362 |
} |
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
363 |
|
9018
403898e0b54e
(svn r12817) -Feature: the ability to play NewGRF sounds for industries and stations.
rubidium
parents:
9005
diff
changeset
|
364 |
static void ChangeIndustryTileAnimationFrame(const IndustryTileSpec *itspec, TileIndex tile, IndustryAnimationTrigger iat, uint32 random_bits, IndustryGfx gfx, Industry *ind) |
7229
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
365 |
{ |
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
366 |
uint16 callback_res = GetIndustryTileCallback(CBID_INDTILE_ANIM_START_STOP, random_bits, iat, gfx, ind, tile); |
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
367 |
if (callback_res == CALLBACK_FAILED) return; |
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
368 |
|
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
369 |
switch (callback_res & 0xFF) { |
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
370 |
case 0xFD: /* Do nothing. */ break; |
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
371 |
case 0xFE: AddAnimatedTile(tile); break; |
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
372 |
case 0xFF: DeleteAnimatedTile(tile); break; |
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
373 |
default: |
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
374 |
SetIndustryAnimationState(tile, callback_res & 0xFF); |
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
375 |
AddAnimatedTile(tile); |
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
376 |
break; |
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
377 |
} |
9018
403898e0b54e
(svn r12817) -Feature: the ability to play NewGRF sounds for industries and stations.
rubidium
parents:
9005
diff
changeset
|
378 |
|
403898e0b54e
(svn r12817) -Feature: the ability to play NewGRF sounds for industries and stations.
rubidium
parents:
9005
diff
changeset
|
379 |
/* If the lower 7 bits of the upper byte of the callback |
403898e0b54e
(svn r12817) -Feature: the ability to play NewGRF sounds for industries and stations.
rubidium
parents:
9005
diff
changeset
|
380 |
* result are not empty, it is a sound effect. */ |
403898e0b54e
(svn r12817) -Feature: the ability to play NewGRF sounds for industries and stations.
rubidium
parents:
9005
diff
changeset
|
381 |
if (GB(callback_res, 8, 7) != 0) PlayTileSound(itspec->grf_prop.grffile, GB(callback_res, 8, 7), tile); |
7229
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
382 |
} |
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
383 |
|
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
384 |
bool StartStopIndustryTileAnimation(TileIndex tile, IndustryAnimationTrigger iat, uint32 random) |
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
385 |
{ |
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
386 |
IndustryGfx gfx = GetIndustryGfx(tile); |
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
387 |
const IndustryTileSpec *itspec = GetIndustryTileSpec(gfx); |
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
388 |
|
7928
63e18de69e50
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
7922
diff
changeset
|
389 |
if (!HasBit(itspec->animation_triggers, iat)) return false; |
7229
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
390 |
|
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
391 |
Industry *ind = GetIndustryByTile(tile); |
9018
403898e0b54e
(svn r12817) -Feature: the ability to play NewGRF sounds for industries and stations.
rubidium
parents:
9005
diff
changeset
|
392 |
ChangeIndustryTileAnimationFrame(itspec, tile, iat, random, gfx, ind); |
7229
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
393 |
return true; |
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
394 |
} |
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
395 |
|
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
396 |
bool StartStopIndustryTileAnimation(const Industry *ind, IndustryAnimationTrigger iat) |
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
397 |
{ |
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
398 |
bool ret = true; |
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
399 |
uint32 random = Random(); |
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
400 |
BEGIN_TILE_LOOP(tile, ind->width, ind->height, ind->xy) |
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
401 |
if (IsTileType(tile, MP_INDUSTRY) && GetIndustryIndex(tile) == ind->index) { |
7627
9a215ee83593
(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:
7622
diff
changeset
|
402 |
if (StartStopIndustryTileAnimation(tile, iat, random)) { |
9a215ee83593
(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:
7622
diff
changeset
|
403 |
SB(random, 0, 16, Random()); |
9a215ee83593
(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:
7622
diff
changeset
|
404 |
} else { |
9a215ee83593
(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:
7622
diff
changeset
|
405 |
ret = false; |
9a215ee83593
(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:
7622
diff
changeset
|
406 |
} |
7229
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
407 |
} |
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
408 |
END_TILE_LOOP(tile, ind->width, ind->height, ind->xy) |
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
409 |
|
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
410 |
return ret; |
a5f262f6df1b
(svn r10508) -Codechange: allow customizable animation schemes for industries.
rubidium
parents:
7216
diff
changeset
|
411 |
} |
7860
5cdd0d914013
(svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents:
7849
diff
changeset
|
412 |
|
5cdd0d914013
(svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents:
7849
diff
changeset
|
413 |
static void DoTriggerIndustryTile(TileIndex tile, IndustryTileTrigger trigger, Industry *ind) |
5cdd0d914013
(svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents:
7849
diff
changeset
|
414 |
{ |
5cdd0d914013
(svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents:
7849
diff
changeset
|
415 |
ResolverObject object; |
5cdd0d914013
(svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents:
7849
diff
changeset
|
416 |
|
5cdd0d914013
(svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents:
7849
diff
changeset
|
417 |
IndustryGfx gfx = GetIndustryGfx(tile); |
5cdd0d914013
(svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents:
7849
diff
changeset
|
418 |
const IndustryTileSpec *itspec = GetIndustryTileSpec(gfx); |
5cdd0d914013
(svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents:
7849
diff
changeset
|
419 |
|
9028
f60408bc972b
(svn r12844) -Fix: the industry tick trigger should only be triggered once every 256 ticks, not every tick... Also bail out of the triggers a little earlier if you know they are not going to happen anyway.
rubidium
parents:
9018
diff
changeset
|
420 |
if (itspec->grf_prop.spritegroup == NULL) return; |
f60408bc972b
(svn r12844) -Fix: the industry tick trigger should only be triggered once every 256 ticks, not every tick... Also bail out of the triggers a little earlier if you know they are not going to happen anyway.
rubidium
parents:
9018
diff
changeset
|
421 |
|
7860
5cdd0d914013
(svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents:
7849
diff
changeset
|
422 |
NewIndustryTileResolver(&object, gfx, tile, ind); |
5cdd0d914013
(svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents:
7849
diff
changeset
|
423 |
|
5cdd0d914013
(svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents:
7849
diff
changeset
|
424 |
object.callback = CBID_RANDOM_TRIGGER; |
5cdd0d914013
(svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents:
7849
diff
changeset
|
425 |
object.trigger = trigger; |
5cdd0d914013
(svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents:
7849
diff
changeset
|
426 |
|
5cdd0d914013
(svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents:
7849
diff
changeset
|
427 |
const SpriteGroup *group = Resolve(itspec->grf_prop.spritegroup, &object); |
5cdd0d914013
(svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents:
7849
diff
changeset
|
428 |
if (group == NULL) return; |
5cdd0d914013
(svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents:
7849
diff
changeset
|
429 |
|
5cdd0d914013
(svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents:
7849
diff
changeset
|
430 |
byte new_random_bits = Random(); |
5cdd0d914013
(svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents:
7849
diff
changeset
|
431 |
byte random_bits = GetIndustryRandomBits(tile); |
5cdd0d914013
(svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents:
7849
diff
changeset
|
432 |
random_bits &= ~object.reseed; |
5cdd0d914013
(svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents:
7849
diff
changeset
|
433 |
random_bits |= new_random_bits & object.reseed; |
5cdd0d914013
(svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents:
7849
diff
changeset
|
434 |
SetIndustryRandomBits(tile, random_bits); |
5cdd0d914013
(svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents:
7849
diff
changeset
|
435 |
} |
5cdd0d914013
(svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents:
7849
diff
changeset
|
436 |
|
5cdd0d914013
(svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents:
7849
diff
changeset
|
437 |
void TriggerIndustryTile(TileIndex tile, IndustryTileTrigger trigger) |
5cdd0d914013
(svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents:
7849
diff
changeset
|
438 |
{ |
5cdd0d914013
(svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents:
7849
diff
changeset
|
439 |
DoTriggerIndustryTile(tile, trigger, GetIndustryByTile(tile)); |
5cdd0d914013
(svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents:
7849
diff
changeset
|
440 |
} |
5cdd0d914013
(svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents:
7849
diff
changeset
|
441 |
|
5cdd0d914013
(svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents:
7849
diff
changeset
|
442 |
void TriggerIndustry(Industry *ind, IndustryTileTrigger trigger) |
5cdd0d914013
(svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents:
7849
diff
changeset
|
443 |
{ |
5cdd0d914013
(svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents:
7849
diff
changeset
|
444 |
BEGIN_TILE_LOOP(tile, ind->width, ind->height, ind->xy) |
5cdd0d914013
(svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents:
7849
diff
changeset
|
445 |
if (IsTileType(tile, MP_INDUSTRY) && GetIndustryIndex(tile) == ind->index) { |
5cdd0d914013
(svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents:
7849
diff
changeset
|
446 |
DoTriggerIndustryTile(tile, trigger, ind); |
5cdd0d914013
(svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents:
7849
diff
changeset
|
447 |
} |
5cdd0d914013
(svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents:
7849
diff
changeset
|
448 |
END_TILE_LOOP(tile, ind->width, ind->height, ind->xy) |
5cdd0d914013
(svn r11410) -Codechange: implement random triggers for industries.
rubidium
parents:
7849
diff
changeset
|
449 |
} |