37 |
37 |
38 if (parameter != 0) tile = GetNearbyTile(parameter, tile); // only perform if it is required |
38 if (parameter != 0) tile = GetNearbyTile(parameter, tile); // only perform if it is required |
39 is_same_industry = (IsTileType(tile, MP_INDUSTRY) && GetIndustryIndex(tile) == index); |
39 is_same_industry = (IsTileType(tile, MP_INDUSTRY) && GetIndustryIndex(tile) == index); |
40 tile_type = GetTerrainType(tile) << 2 | (IsTileType(tile, MP_WATER) ? 1 : 0) << 1 | (is_same_industry ? 1 : 0); |
40 tile_type = GetTerrainType(tile) << 2 | (IsTileType(tile, MP_WATER) ? 1 : 0) << 1 | (is_same_industry ? 1 : 0); |
41 |
41 |
42 return GetTileType(tile) << 24 | (TileHeight(tile) * 8) << 16 | tile_type << 8 | GetTileSlope(tile, NULL); |
42 uint z; |
|
43 Slope tileh = GetTileSlope(tile, &z); |
|
44 return GetTileType(tile) << 24 | z << 16 | tile_type << 8 | tileh; |
43 } |
45 } |
44 |
46 |
45 /** This is the position of the tile relative to the northernmost tile of the industry. |
47 /** This is the position of the tile relative to the northernmost tile of the industry. |
46 * Format: 00yxYYXX |
48 * Format: 00yxYYXX |
47 * Variable Content |
49 * Variable Content |
110 { |
112 { |
111 /* IndustryTile do not have 'real' groups. Or do they?? */ |
113 /* IndustryTile do not have 'real' groups. Or do they?? */ |
112 return NULL; |
114 return NULL; |
113 } |
115 } |
114 |
116 |
115 uint32 IndustryTileGetRandomBits(const ResolverObject *object) |
117 static uint32 IndustryTileGetRandomBits(const ResolverObject *object) |
116 { |
118 { |
117 const TileIndex tile = object->u.industry.tile; |
119 const TileIndex tile = object->u.industry.tile; |
118 return (tile == INVALID_TILE || !IsTileType(tile, MP_INDUSTRY)) ? 0 : GetIndustryRandomBits(tile); |
120 if (tile == INVALID_TILE || !IsTileType(tile, MP_INDUSTRY)) return 0; |
119 } |
121 return (object->scope == VSG_SCOPE_SELF) ? GetIndustryRandomBits(tile) : 0; //GetIndustryByTile(tile)->random_bits; |
120 |
122 } |
121 uint32 IndustryTileGetTriggers(const ResolverObject *object) |
123 |
|
124 static uint32 IndustryTileGetTriggers(const ResolverObject *object) |
122 { |
125 { |
123 const TileIndex tile = object->u.industry.tile; |
126 const TileIndex tile = object->u.industry.tile; |
124 return (tile == INVALID_TILE || !IsTileType(tile, MP_INDUSTRY)) ? 0 : GetIndustryTriggers(tile); |
127 if (tile == INVALID_TILE || !IsTileType(tile, MP_INDUSTRY)) return 0; |
125 } |
128 return (object->scope == VSG_SCOPE_SELF) ? GetIndustryTriggers(tile) : 0; //GetIndustryByTile(tile)->triggers; |
126 |
129 } |
127 void IndustryTileSetTriggers(const ResolverObject *object, int triggers) |
130 |
|
131 static void IndustryTileSetTriggers(const ResolverObject *object, int triggers) |
128 { |
132 { |
129 const TileIndex tile = object->u.industry.tile; |
133 const TileIndex tile = object->u.industry.tile; |
130 if (IsTileType(tile, MP_INDUSTRY)) SetIndustryTriggers(tile, triggers); |
134 if (tile == INVALID_TILE || !IsTileType(tile, MP_INDUSTRY)) return; |
|
135 |
|
136 if (object->scope != VSG_SCOPE_SELF) { |
|
137 SetIndustryTriggers(tile, triggers); |
|
138 } else { |
|
139 //GetIndustryByTile(tile)->triggers = triggers; |
|
140 } |
131 } |
141 } |
132 |
142 |
133 static void NewIndustryTileResolver(ResolverObject *res, IndustryGfx gfx, TileIndex tile, Industry *indus) |
143 static void NewIndustryTileResolver(ResolverObject *res, IndustryGfx gfx, TileIndex tile, Industry *indus) |
134 { |
144 { |
135 res->GetRandomBits = IndustryTileGetRandomBits; |
145 res->GetRandomBits = IndustryTileGetRandomBits; |
136 res->GetTriggers = IndustryTileGetTriggers; |
146 res->GetTriggers = IndustryTileGetTriggers; |
137 res->SetTriggers = IndustryTileSetTriggers; |
147 res->SetTriggers = IndustryTileSetTriggers; |
138 res->GetVariable = IndustryTileGetVariable; |
148 res->GetVariable = IndustryTileGetVariable; |
139 res->ResolveReal = IndustryTileResolveReal; |
149 res->ResolveReal = IndustryTileResolveReal; |
140 |
150 |
|
151 res->psa = &indus->psa; |
141 res->u.industry.tile = tile; |
152 res->u.industry.tile = tile; |
142 res->u.industry.ind = indus; |
153 res->u.industry.ind = indus; |
143 res->u.industry.gfx = gfx; |
154 res->u.industry.gfx = gfx; |
144 |
155 |
145 res->callback = CBID_NO_CALLBACK; |
156 res->callback = CBID_NO_CALLBACK; |
156 const DrawTileSeqStruct *dtss; |
167 const DrawTileSeqStruct *dtss; |
157 |
168 |
158 SpriteID image = dts->ground_sprite; |
169 SpriteID image = dts->ground_sprite; |
159 SpriteID pal = dts->ground_pal; |
170 SpriteID pal = dts->ground_pal; |
160 |
171 |
|
172 if (IS_CUSTOM_SPRITE(image)) image += stage; |
|
173 |
161 if (GB(image, 0, SPRITE_WIDTH) != 0) DrawGroundSprite(image, pal); |
174 if (GB(image, 0, SPRITE_WIDTH) != 0) DrawGroundSprite(image, pal); |
162 |
175 |
163 foreach_draw_tile_seq(dtss, dts->seq) { |
176 foreach_draw_tile_seq(dtss, dts->seq) { |
164 if (GB(dtss->image, 0, SPRITE_WIDTH) == 0) continue; |
177 if (GB(dtss->image, 0, SPRITE_WIDTH) == 0) continue; |
165 |
178 |
166 image = dtss->image + stage; |
179 image = dtss->image; |
167 pal = dtss->pal; |
180 pal = dtss->pal; |
|
181 |
|
182 if (IS_CUSTOM_SPRITE(image)) image += stage; |
168 |
183 |
169 if (HASBIT(image, PALETTE_MODIFIER_COLOR)) { |
184 if (HASBIT(image, PALETTE_MODIFIER_COLOR)) { |
170 pal = GENERAL_SPRITE_COLOR(rnd_color); |
185 pal = GENERAL_SPRITE_COLOR(rnd_color); |
171 } else { |
186 } else { |
172 pal = PAL_NONE; |
187 pal = PAL_NONE; |
179 dtss->size_x, dtss->size_y, |
194 dtss->size_x, dtss->size_y, |
180 dtss->size_z, ti->z + dtss->delta_z, |
195 dtss->size_z, ti->z + dtss->delta_z, |
181 !HASBIT(image, SPRITE_MODIFIER_OPAQUE) && HASBIT(_transparent_opt, TO_INDUSTRIES) |
196 !HASBIT(image, SPRITE_MODIFIER_OPAQUE) && HASBIT(_transparent_opt, TO_INDUSTRIES) |
182 ); |
197 ); |
183 } else { |
198 } else { |
184 AddChildSpriteScreen(image, pal, dtss->delta_x, dtss->delta_y); |
199 AddChildSpriteScreen(image, pal, dtss->delta_x, dtss->delta_y, HASBIT(_transparent_opt, TO_INDUSTRIES)); |
185 } |
200 } |
186 } |
201 } |
187 } |
202 } |
188 |
203 |
189 uint16 GetIndustryTileCallback(CallbackID callback, uint32 param1, uint32 param2, IndustryGfx gfx_id, Industry *industry, TileIndex tile) |
204 uint16 GetIndustryTileCallback(CallbackID callback, uint32 param1, uint32 param2, IndustryGfx gfx_id, Industry *industry, TileIndex tile) |
230 IndustryDrawTileLayout(ti, group, i->random_color, stage, gfx); |
245 IndustryDrawTileLayout(ti, group, i->random_color, stage, gfx); |
231 return true; |
246 return true; |
232 } |
247 } |
233 } |
248 } |
234 |
249 |
235 bool PerformIndustryTileSlopeCheck(TileIndex tile, const IndustryTileSpec *its, IndustryType type, IndustryGfx gfx) |
250 extern bool IsSlopeRefused(Slope current, Slope refused); |
|
251 |
|
252 bool PerformIndustryTileSlopeCheck(TileIndex ind_base_tile, TileIndex ind_tile, const IndustryTileSpec *its, IndustryType type, IndustryGfx gfx, uint itspec_index) |
236 { |
253 { |
237 Industry ind; |
254 Industry ind; |
238 ind.xy = 0; |
255 ind.index = INVALID_INDUSTRY; |
|
256 ind.xy = ind_base_tile; |
239 ind.width = 0; |
257 ind.width = 0; |
240 ind.type = type; |
258 ind.type = type; |
241 |
259 |
242 uint16 callback_res = GetIndustryTileCallback(CBID_INDTILE_SHAPE_CHECK, 0, 0, gfx, &ind, tile); |
260 uint16 callback_res = GetIndustryTileCallback(CBID_INDTILE_SHAPE_CHECK, 0, itspec_index, gfx, &ind, ind_tile); |
|
261 if (callback_res == CALLBACK_FAILED) { |
|
262 return !IsSlopeRefused(GetTileSlope(ind_tile, NULL), its->slopes_refused); |
|
263 } |
243 if (its->grf_prop.grffile->grf_version < 7) { |
264 if (its->grf_prop.grffile->grf_version < 7) { |
244 return callback_res != 0; |
265 return callback_res != 0; |
245 } |
266 } |
246 if (callback_res == CALLBACK_FAILED) return false; |
|
247 |
267 |
248 switch (callback_res) { |
268 switch (callback_res) { |
249 case 0x400: return true; |
269 case 0x400: return true; |
250 case 0x401: _error_message = STR_0239_SITE_UNSUITABLE; return false; |
270 case 0x401: _error_message = STR_0239_SITE_UNSUITABLE; return false; |
251 case 0x402: _error_message = STR_0317_CAN_ONLY_BE_BUILT_IN_RAINFOREST; return false; |
271 case 0x402: _error_message = STR_0317_CAN_ONLY_BE_BUILT_IN_RAINFOREST; return false; |
345 { |
365 { |
346 bool ret = true; |
366 bool ret = true; |
347 uint32 random = Random(); |
367 uint32 random = Random(); |
348 BEGIN_TILE_LOOP(tile, ind->width, ind->height, ind->xy) |
368 BEGIN_TILE_LOOP(tile, ind->width, ind->height, ind->xy) |
349 if (IsTileType(tile, MP_INDUSTRY) && GetIndustryIndex(tile) == ind->index) { |
369 if (IsTileType(tile, MP_INDUSTRY) && GetIndustryIndex(tile) == ind->index) { |
350 ret &= StartStopIndustryTileAnimation(tile, iat, random); |
370 if (StartStopIndustryTileAnimation(tile, iat, random)) { |
351 SB(random, 0, 16, Random()); |
371 SB(random, 0, 16, Random()); |
|
372 } else { |
|
373 ret = false; |
|
374 } |
352 } |
375 } |
353 END_TILE_LOOP(tile, ind->width, ind->height, ind->xy) |
376 END_TILE_LOOP(tile, ind->width, ind->height, ind->xy) |
354 |
377 |
355 return ret; |
378 return ret; |
356 } |
379 } |