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

Function DecrementTreeCounter

src/tree_cmd.cpp:954–963  ·  view source on GitHub ↗

* Decrement the tree tick counter. * The interval is scaled by map size to allow for the same density regardless of size. * Adjustment for map sizes below the standard 256 * 256 are handled earlier. * @return true if the counter was decremented past zero */

Source from the content-addressed store, hash-verified

952 * @return true if the counter was decremented past zero
953 */
954bool DecrementTreeCounter()
955{
956 /* Ensure _trees_tick_ctr can be decremented past zero only once for the largest map size. */
957 static_assert(2 * (MAX_MAP_SIZE_BITS - MIN_MAP_SIZE_BITS) - 4 <= std::numeric_limits<uint8_t>::digits);
958
959 /* byte underflow */
960 uint8_t old_trees_tick_ctr = _trees_tick_ctr;
961 _trees_tick_ctr -= Map::ScaleBySize(1);
962 return old_trees_tick_ctr <= _trees_tick_ctr;
963}
964
965/**
966 * Place a random tree on a random tile.

Callers 1

OnTick_TreesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected