/** * Function performing a search around a center tile and going outward, thus in circle. * Although it really is a square search... * Every tile will be tested by means of the callback function proc, * which will determine if yes or no the given tile meets criteria of search. * @param tile to start the search from. Upon completion, it will return the tile matching the search * @param size: number of tiles per side of the desired search area * @param proc: callback testing function pointer. * @param user_data to be passed to the callback function. Depends on the implementation * @return result of the search * @pre proc != NULL * @pre size > 0 */ bool CircularTileSearch(TileIndex *tile, uint size, TestTileOnSearchProc proc, void *user_data) { assert(proc != NULL); assert(size > 0); if (size % 2 == 1) { /* If the length of the side is uneven, the center has to be checked * separately, as the pattern of uneven sides requires to go around the center */ if (proc(*tile, user_data)) return true; /* If tile test is not successful, get one tile up, * ready for a test in first circle around center tile */ *tile = TILE_ADD(*tile, TileOffsByDir(DIR_N)); return CircularTileSearch(tile, size / 2, 1, 1, proc, user_data); } else { return CircularTileSearch(tile, size / 2, 0, 0, proc, user_data); } }
static uint32 GetRailContinuationInfo(TileIndex tile) { /* Tile offsets and exit dirs for X axis */ static const Direction x_dir[8] = { DIR_SW, DIR_NE, DIR_SE, DIR_NW, DIR_S, DIR_E, DIR_W, DIR_N }; static const DiagDirection x_exits[8] = { DIAGDIR_SW, DIAGDIR_NE, DIAGDIR_SE, DIAGDIR_NW, DIAGDIR_SW, DIAGDIR_NE, DIAGDIR_SW, DIAGDIR_NE }; /* Tile offsets and exit dirs for Y axis */ static const Direction y_dir[8] = { DIR_SE, DIR_NW, DIR_SW, DIR_NE, DIR_S, DIR_W, DIR_E, DIR_N }; static const DiagDirection y_exits[8] = { DIAGDIR_SE, DIAGDIR_NW, DIAGDIR_SW, DIAGDIR_NE, DIAGDIR_SE, DIAGDIR_NW, DIAGDIR_SE, DIAGDIR_NW }; Axis axis = GetRailStationAxis(tile); /* Choose appropriate lookup table to use */ const Direction *dir = axis == AXIS_X ? x_dir : y_dir; const DiagDirection *diagdir = axis == AXIS_X ? x_exits : y_exits; uint32 res = 0; uint i; for (i = 0; i < lengthof(x_dir); i++, dir++, diagdir++) { TileIndex neighbour_tile = tile + TileOffsByDir(*dir); TrackBits trackbits = TrackStatusToTrackBits(GetTileTrackStatus(neighbour_tile, TRANSPORT_RAIL, 0)); if (trackbits != TRACK_BIT_NONE) { /* If there is any track on the tile, set the bit in the second byte */ SetBit(res, i + 8); /* With tunnels and bridges the tile has tracks, but they are not necessarily connected * with the next tile because the ramp is not going in the right direction. */ if (IsTileType(neighbour_tile, MP_TUNNELBRIDGE) && GetTunnelBridgeDirection(neighbour_tile) != *diagdir) { continue; } /* If any track reaches our exit direction, set the bit in the lower byte */ if (trackbits & DiagdirReachesTracks(*diagdir)) SetBit(res, i); } } return res; }
/** * Marks the tiles around a tile as dirty, if they are canals or rivers. * * @param tile The center of the tile where all other tiles are marked as dirty * @ingroup dirty */ static void MarkCanalsAndRiversAroundDirty(TileIndex tile) { for (Direction dir = DIR_BEGIN; dir < DIR_END; dir++) { MarkTileDirtyIfCanalOrRiver(tile + TileOffsByDir(dir)); } }
static void TileLoop_Trees(TileIndex tile) { if (GetTreeGround(tile) == TREE_GROUND_SHORE) { TileLoop_Water(tile); } else { switch (_settings_game.game_creation.landscape) { case LT_TROPIC: TileLoopTreesDesert(tile); break; case LT_ARCTIC: TileLoopTreesAlps(tile); break; } } TileLoopClearHelper(tile); uint treeCounter = GetTreeCounter(tile); /* Handle growth of grass (under trees/on MP_TREES tiles) at every 8th processings, like it's done for grass on MP_CLEAR tiles. */ if ((treeCounter & 7) == 7 && GetTreeGround(tile) == TREE_GROUND_GRASS) { uint density = GetTreeDensity(tile); if (density < 3) { SetTreeGroundDensity(tile, TREE_GROUND_GRASS, density + 1); MarkTileDirtyByTile(tile); } } if (GetTreeCounter(tile) < 15) { AddTreeCounter(tile, 1); return; } SetTreeCounter(tile, 0); switch (GetTreeGrowth(tile)) { case 3: // regular sized tree if (_settings_game.game_creation.landscape == LT_TROPIC && GetTreeType(tile) != TREE_CACTUS && GetTropicZone(tile) == TROPICZONE_DESERT) { AddTreeGrowth(tile, 1); } else { switch (GB(Random(), 0, 3)) { case 0: // start destructing AddTreeGrowth(tile, 1); break; case 1: // add a tree if (GetTreeCount(tile) < 4) { AddTreeCount(tile, 1); SetTreeGrowth(tile, 0); break; } /* FALL THROUGH */ case 2: { // add a neighbouring tree /* Don't plant extra trees if that's not allowed. */ if ((_settings_game.game_creation.landscape == LT_TROPIC && GetTropicZone(tile) == TROPICZONE_RAINFOREST) ? _settings_game.construction.extra_tree_placement == ETP_NONE : _settings_game.construction.extra_tree_placement != ETP_ALL) { break; } TreeType treetype = GetTreeType(tile); tile += TileOffsByDir((Direction)(Random() & 7)); /* Cacti don't spread */ if (!CanPlantTreesOnTile(tile, false)) return; /* Don't plant trees, if ground was freshly cleared */ if (IsTileType(tile, MP_CLEAR) && GetClearGround(tile) == CLEAR_GRASS && GetClearDensity(tile) != 3) return; PlantTreesOnTile(tile, treetype, 0, 0); break; } default: return; } } break; case 6: // final stage of tree destruction if (GetTreeCount(tile) > 1) { /* more than one tree, delete it */ AddTreeCount(tile, -1); SetTreeGrowth(tile, 3); } else { /* just one tree, change type into MP_CLEAR */ switch (GetTreeGround(tile)) { case TREE_GROUND_SHORE: MakeShore(tile); break; case TREE_GROUND_GRASS: MakeClear(tile, CLEAR_GRASS, GetTreeDensity(tile)); break; case TREE_GROUND_ROUGH: MakeClear(tile, CLEAR_ROUGH, 3); break; case TREE_GROUND_ROUGH_SNOW: { uint density = GetTreeDensity(tile); MakeClear(tile, CLEAR_ROUGH, 3); MakeSnow(tile, density); break; } default: // snow or desert if (_settings_game.game_creation.landscape == LT_TROPIC) { MakeClear(tile, CLEAR_DESERT, GetTreeDensity(tile)); } else { uint density = GetTreeDensity(tile); MakeClear(tile, CLEAR_GRASS, 3); MakeSnow(tile, density); } break; } } break; default: AddTreeGrowth(tile, 1); break; } MarkTileDirtyByTile(tile); }