183 uint32 tile_type; |
183 uint32 tile_type; |
184 |
184 |
185 tile = GetNearbyTile(parameter, tile); |
185 tile = GetNearbyTile(parameter, tile); |
186 tile_type = GetTerrainType(tile) << 2 | (IsTileType(tile, MP_WATER) ? 1 : 0) << 1; |
186 tile_type = GetTerrainType(tile) << 2 | (IsTileType(tile, MP_WATER) ? 1 : 0) << 1; |
187 |
187 |
188 return GetTileType(tile) << 24 | (TileHeight(tile) * 8) << 16 | tile_type << 8 | GetTileSlope(tile, NULL); |
188 uint z; |
|
189 Slope tileh = GetTileSlope(tile, &z); |
|
190 return GetTileType(tile) << 24 | z << 16 | tile_type << 8 | tileh; |
189 } |
191 } |
190 |
192 |
191 /** |
193 /** |
192 * HouseGetVariable(): |
194 * HouseGetVariable(): |
193 * |
195 * |
304 const DrawTileSeqStruct *dtss; |
306 const DrawTileSeqStruct *dtss; |
305 |
307 |
306 SpriteID image = dts->ground_sprite; |
308 SpriteID image = dts->ground_sprite; |
307 SpriteID pal = dts->ground_pal; |
309 SpriteID pal = dts->ground_pal; |
308 |
310 |
|
311 if (IS_CUSTOM_SPRITE(image)) image += stage; |
|
312 |
309 if (GB(image, 0, SPRITE_WIDTH) != 0) DrawGroundSprite(image, pal); |
313 if (GB(image, 0, SPRITE_WIDTH) != 0) DrawGroundSprite(image, pal); |
310 |
314 |
311 foreach_draw_tile_seq(dtss, dts->seq) { |
315 foreach_draw_tile_seq(dtss, dts->seq) { |
312 if (GB(dtss->image, 0, SPRITE_WIDTH) == 0) continue; |
316 if (GB(dtss->image, 0, SPRITE_WIDTH) == 0) continue; |
313 |
317 |
314 image = dtss->image + stage; |
318 image = dtss->image; |
315 pal = dtss->pal; |
319 pal = dtss->pal; |
|
320 |
|
321 if (IS_CUSTOM_SPRITE(image)) image += stage; |
316 |
322 |
317 if ((HASBIT(image, SPRITE_MODIFIER_OPAQUE) || !HASBIT(_transparent_opt, TO_HOUSES)) && HASBIT(image, PALETTE_MODIFIER_COLOR)) { |
323 if ((HASBIT(image, SPRITE_MODIFIER_OPAQUE) || !HASBIT(_transparent_opt, TO_HOUSES)) && HASBIT(image, PALETTE_MODIFIER_COLOR)) { |
318 if (pal == 0) { |
324 if (pal == 0) { |
319 const HouseSpec *hs = GetHouseSpecs(house_id); |
325 const HouseSpec *hs = GetHouseSpecs(house_id); |
320 if (HASBIT(hs->callback_mask, CBM_BUILDING_COLOUR)) { |
326 if (HASBIT(hs->callback_mask, CBM_HOUSE_COLOUR)) { |
321 uint16 callback = GetHouseCallback(CBID_BUILDING_COLOUR, 0, 0, house_id, GetTownByTile(ti->tile), ti->tile); |
327 uint16 callback = GetHouseCallback(CBID_HOUSE_COLOUR, 0, 0, house_id, GetTownByTile(ti->tile), ti->tile); |
322 if (callback != CALLBACK_FAILED) { |
328 if (callback != CALLBACK_FAILED) { |
323 /* If bit 14 is set, we should use a 2cc colour map, else use the callback value. */ |
329 /* If bit 14 is set, we should use a 2cc colour map, else use the callback value. */ |
324 pal = HASBIT(callback, 14) ? GB(callback, 0, 8) + SPR_2CCMAP_BASE : callback; |
330 pal = HASBIT(callback, 14) ? GB(callback, 0, 8) + SPR_2CCMAP_BASE : callback; |
325 } |
331 } |
326 } else { |
332 } else { |
338 dtss->size_x, dtss->size_y, |
344 dtss->size_x, dtss->size_y, |
339 dtss->size_z, ti->z + dtss->delta_z, |
345 dtss->size_z, ti->z + dtss->delta_z, |
340 HASBIT(_transparent_opt, TO_HOUSES) |
346 HASBIT(_transparent_opt, TO_HOUSES) |
341 ); |
347 ); |
342 } else { |
348 } else { |
343 AddChildSpriteScreen(image, pal, dtss->delta_x, dtss->delta_y); |
349 AddChildSpriteScreen(image, pal, dtss->delta_x, dtss->delta_y, HASBIT(_transparent_opt, TO_HOUSES)); |
344 } |
350 } |
345 } |
351 } |
346 } |
352 } |
347 |
353 |
348 void DrawNewHouseTile(TileInfo *ti, HouseID house_id) |
354 void DrawNewHouseTile(TileInfo *ti, HouseID house_id) |
371 { |
377 { |
372 const HouseSpec *hs = GetHouseSpecs(GetHouseType(tile)); |
378 const HouseSpec *hs = GetHouseSpecs(GetHouseType(tile)); |
373 byte animation_speed = hs->animation_speed; |
379 byte animation_speed = hs->animation_speed; |
374 bool frame_set_by_callback = false; |
380 bool frame_set_by_callback = false; |
375 |
381 |
376 if (HASBIT(hs->callback_mask, CBM_ANIMATION_SPEED)) { |
382 if (HASBIT(hs->callback_mask, CBM_HOUSE_ANIMATION_SPEED)) { |
377 uint16 callback_res = GetHouseCallback(CBID_HOUSE_ANIMATION_SPEED, 0, 0, GetHouseType(tile), GetTownByTile(tile), tile); |
383 uint16 callback_res = GetHouseCallback(CBID_HOUSE_ANIMATION_SPEED, 0, 0, GetHouseType(tile), GetTownByTile(tile), tile); |
378 if (callback_res != CALLBACK_FAILED) animation_speed = clamp(callback_res & 0xFF, 2, 16); |
384 if (callback_res != CALLBACK_FAILED) animation_speed = clamp(callback_res & 0xFF, 2, 16); |
379 } |
385 } |
380 |
386 |
381 /* An animation speed of 2 means the animation frame changes 4 ticks, and |
387 /* An animation speed of 2 means the animation frame changes 4 ticks, and |
385 if (_tick_counter % (1 << animation_speed) != 0) return; |
391 if (_tick_counter % (1 << animation_speed) != 0) return; |
386 |
392 |
387 byte frame = GetHouseAnimationFrame(tile); |
393 byte frame = GetHouseAnimationFrame(tile); |
388 byte num_frames = GB(hs->animation_frames, 0, 7); |
394 byte num_frames = GB(hs->animation_frames, 0, 7); |
389 |
395 |
390 if (HASBIT(hs->callback_mask, CBM_ANIMATION_NEXT_FRAME)) { |
396 if (HASBIT(hs->callback_mask, CBM_HOUSE_ANIMATION_NEXT_FRAME)) { |
391 uint32 param = (hs->extra_flags & CALLBACK_1A_RANDOM_BITS) ? Random() : 0; |
397 uint32 param = (hs->extra_flags & CALLBACK_1A_RANDOM_BITS) ? Random() : 0; |
392 uint16 callback_res = GetHouseCallback(CBID_HOUSE_ANIMATION_NEXT_FRAME, param, 0, GetHouseType(tile), GetTownByTile(tile), tile); |
398 uint16 callback_res = GetHouseCallback(CBID_HOUSE_ANIMATION_NEXT_FRAME, param, 0, GetHouseType(tile), GetTownByTile(tile), tile); |
393 |
399 |
394 if (callback_res != CALLBACK_FAILED) { |
400 if (callback_res != CALLBACK_FAILED) { |
395 frame_set_by_callback = true; |
401 frame_set_by_callback = true; |
464 |
470 |
465 static void AnimationControl(TileIndex tile, uint16 random_bits) |
471 static void AnimationControl(TileIndex tile, uint16 random_bits) |
466 { |
472 { |
467 const HouseSpec *hs = GetHouseSpecs(GetHouseType(tile)); |
473 const HouseSpec *hs = GetHouseSpecs(GetHouseType(tile)); |
468 |
474 |
469 if (HASBIT(hs->callback_mask, CBM_ANIMATION_START_STOP)) { |
475 if (HASBIT(hs->callback_mask, CBM_HOUSE_ANIMATION_START_STOP)) { |
470 uint32 param = (hs->extra_flags & SYNCHRONISED_CALLBACK_1B) ? (GB(Random(), 0, 16) | random_bits << 16) : Random(); |
476 uint32 param = (hs->extra_flags & SYNCHRONISED_CALLBACK_1B) ? (GB(Random(), 0, 16) | random_bits << 16) : Random(); |
471 uint16 callback_res = GetHouseCallback(CBID_HOUSE_ANIMATION_START_STOP, param, 0, GetHouseType(tile), GetTownByTile(tile), tile); |
477 uint16 callback_res = GetHouseCallback(CBID_HOUSE_ANIMATION_START_STOP, param, 0, GetHouseType(tile), GetTownByTile(tile), tile); |
472 |
478 |
473 if (callback_res != CALLBACK_FAILED) ChangeHouseAnimationFrame(tile, callback_res); |
479 if (callback_res != CALLBACK_FAILED) ChangeHouseAnimationFrame(tile, callback_res); |
474 } |
480 } |
487 * Process randomizing of tiles following specs. |
493 * Process randomizing of tiles following specs. |
488 * Once done, redraw the house |
494 * Once done, redraw the house |
489 * MarkTileDirtyByTile(tile); |
495 * MarkTileDirtyByTile(tile); |
490 */ |
496 */ |
491 |
497 |
492 if (HASBIT(hs->callback_mask, CBM_ANIMATION_START_STOP)) { |
498 if (HASBIT(hs->callback_mask, CBM_HOUSE_ANIMATION_START_STOP)) { |
493 /* If this house is marked as having a synchronised callback, all the |
499 /* If this house is marked as having a synchronised callback, all the |
494 * tiles will have the callback called at once, rather than when the |
500 * tiles will have the callback called at once, rather than when the |
495 * tile loop reaches them. This should only be enabled for the northern |
501 * tile loop reaches them. This should only be enabled for the northern |
496 * tile, or strange things will happen (here, and in TTDPatch). */ |
502 * tile, or strange things will happen (here, and in TTDPatch). */ |
497 if (hs->extra_flags & SYNCHRONISED_CALLBACK_1B) { |
503 if (hs->extra_flags & SYNCHRONISED_CALLBACK_1B) { |