MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / AnimateTile_Town

Function AnimateTile_Town

src/town_cmd.cpp:339–382  ·  view source on GitHub ↗

* Animate a tile for a town. * Only certain houses can be animated. * The newhouses animation supersedes regular ones. * @param tile TileIndex of the house to animate. */

Source from the content-addressed store, hash-verified

337 * @param tile TileIndex of the house to animate.
338 */
339static void AnimateTile_Town(TileIndex tile)
340{
341 if (GetHouseType(tile) >= NEW_HOUSE_OFFSET) {
342 AnimateNewHouseTile(tile);
343 return;
344 }
345
346 if (TimerGameTick::counter & 3) return;
347
348 /* If the house is not one with a lift anymore, then stop this animating.
349 * Not exactly sure when this happens, but probably when a house changes.
350 * Before this was just a return...so it'd leak animated tiles..
351 * That bug seems to have been here since day 1?? */
352 if (!HouseSpec::Get(GetHouseType(tile))->building_flags.Test(BuildingFlag::IsAnimated)) {
353 DeleteAnimatedTile(tile);
354 return;
355 }
356
357 if (!LiftHasDestination(tile)) {
358 uint i;
359
360 /* Building has 6 floors, number 0 .. 6, where 1 is illegal.
361 * This is due to the fact that the first floor is, in the graphics,
362 * the height of 2 'normal' floors.
363 * Furthermore, there are 6 lift positions from floor N (incl) to floor N + 1 (excl) */
364 do {
365 i = RandomRange(7);
366 } while (i == 1 || i * 6 == GetLiftPosition(tile));
367
368 SetLiftDestination(tile, i);
369 }
370
371 int pos = GetLiftPosition(tile);
372 int dest = GetLiftDestination(tile) * 6;
373 pos += (pos < dest) ? 1 : -1;
374 SetLiftPosition(tile, pos);
375
376 if (pos == dest) {
377 HaltLift(tile);
378 DeleteAnimatedTile(tile);
379 }
380
381 MarkTileDirtyByTile(tile);
382}
383
384/**
385 * Determines if a town is close to a tile.

Callers

nothing calls this directly

Calls 12

GetHouseTypeFunction · 0.85
AnimateNewHouseTileFunction · 0.85
DeleteAnimatedTileFunction · 0.85
LiftHasDestinationFunction · 0.85
RandomRangeFunction · 0.85
GetLiftPositionFunction · 0.85
SetLiftDestinationFunction · 0.85
GetLiftDestinationFunction · 0.85
SetLiftPositionFunction · 0.85
HaltLiftFunction · 0.85
TestMethod · 0.80
MarkTileDirtyByTileFunction · 0.70

Tested by

no test coverage detected