diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/industry_cmd.cpp | 6 | ||||
-rw-r--r-- | src/map.cpp | 8 | ||||
-rw-r--r-- | src/map_func.h | 6 | ||||
-rw-r--r-- | src/newgrf_house.cpp | 31 | ||||
-rw-r--r-- | src/town_cmd.cpp | 9 |
5 files changed, 32 insertions, 28 deletions
diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp index 1338fe9c9..67b2790e6 100644 --- a/src/industry_cmd.cpp +++ b/src/industry_cmd.cpp @@ -962,10 +962,10 @@ void PlantRandomFarmField(const Industry *i) /** * Search callback function for ChopLumberMillTrees * @param tile to test - * @param data that is passed by the caller. In this case, nothing + * @param user_data that is passed by the caller. In this case, nothing * @return the result of the test */ -static bool SearchLumberMillTrees(TileIndex tile, uint32 data) +static bool SearchLumberMillTrees(TileIndex tile, void *user_data) { if (IsTileType(tile, MP_TREES) && GetTreeGrowth(tile) > 2) { ///< 3 and up means all fully grown trees PlayerID old_player = _current_player; @@ -994,7 +994,7 @@ static void ChopLumberMillTrees(Industry *i) if (!IsIndustryCompleted(tile)) return; ///< Can't proceed if not completed - if (CircularTileSearch(&tile, 40, SearchLumberMillTrees, 0)) ///< 40x40 tiles to search + if (CircularTileSearch(&tile, 40, SearchLumberMillTrees, NULL)) ///< 40x40 tiles to search i->produced_cargo_waiting[0] = min(0xffff, i->produced_cargo_waiting[0] + 45); ///< Found a tree, add according value to waiting cargo } diff --git a/src/map.cpp b/src/map.cpp index 640864c0a..12f7a0266 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -261,12 +261,12 @@ uint DistanceFromEdge(TileIndex tile) * @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 data to be passed to the callback function. Depends on the implementation + * @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, uint32 data) +bool CircularTileSearch(TileIndex *tile, uint size, TestTileOnSearchProc proc, void *user_data) { uint n, x, y; DiagDirection dir; @@ -281,7 +281,7 @@ bool CircularTileSearch(TileIndex *tile, uint size, TestTileOnSearchProc proc, u /* 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 */ n = 2; - if (proc(TileXY(x, y), data)) { + if (proc(TileXY(x, y), user_data)) { *tile = TileXY(x, y); return true; } @@ -304,7 +304,7 @@ bool CircularTileSearch(TileIndex *tile, uint size, TestTileOnSearchProc proc, u uint j; for (j = n; j != 0; j--) { if (x <= MapMaxX() && y <= MapMaxY() && ///< Is the tile within the map? - proc(TileXY(x, y), data)) { ///< Is the callback successful? + proc(TileXY(x, y), user_data)) { ///< Is the callback successful? *tile = TileXY(x, y); return true; ///< then stop the search } diff --git a/src/map_func.h b/src/map_func.h index a4b3991da..ff539b8af 100644 --- a/src/map_func.h +++ b/src/map_func.h @@ -383,15 +383,15 @@ static inline TileIndex TileAddByDiagDir(TileIndex tile, DiagDirection dir) * A callback function type for searching tiles. * * @param tile The tile to test - * @param data additional data for the callback function to use + * @param user_data additional data for the callback function to use * @return A boolean value, depend on the definition of the function. */ -typedef bool TestTileOnSearchProc(TileIndex tile, uint32 data); +typedef bool TestTileOnSearchProc(TileIndex tile, void *user_data); /** * Searches for some cirumstances of a tile around a given tile with a helper function. */ -bool CircularTileSearch(TileIndex *tile, uint size, TestTileOnSearchProc proc, uint32 data); +bool CircularTileSearch(TileIndex *tile, uint size, TestTileOnSearchProc proc, void *user_data); /** * Get a random tile out of a given seed. diff --git a/src/newgrf_house.cpp b/src/newgrf_house.cpp index 7055722ee..033b0f393 100644 --- a/src/newgrf_house.cpp +++ b/src/newgrf_house.cpp @@ -203,15 +203,16 @@ uint32 GetNearbyTileInformation(byte parameter, TileIndex tile) /** Callback function to search a house by its HouseID * @param tile TileIndex to be examined - * @param data house id, in order to get the specs + * @param user_data house id, in order to get the specs * @return true or false, if found or not */ -static bool SearchNearbyHouseID(TileIndex tile, uint32 data) +static bool SearchNearbyHouseID(TileIndex tile, void *user_data) { if (IsTileType(tile, MP_HOUSE)) { const HouseSpec *hs = GetHouseSpecs(GetHouseType(tile)); // tile been examined if (hs->grffile != NULL) { // must be one from a grf file - const HouseSpec *test_hs = GetHouseSpecs((HouseID)GB(data, 0, 16)); + HouseID *test_house = (HouseID *)user_data; + const HouseSpec *test_hs = GetHouseSpecs(*test_house); return hs->local_id == test_hs->local_id && // same local id as the one requested hs->grffile->grfid == test_hs->grffile->grfid; // from the same grf } @@ -221,15 +222,16 @@ static bool SearchNearbyHouseID(TileIndex tile, uint32 data) /** Callback function to search a house by its classID * @param tile TileIndex to be examined - * @param data house id, in order to get the specs + * @param user_data house id, in order to get the specs * @return true or false, if found or not */ -static bool SearchNearbyHouseClass(TileIndex tile, uint32 data) +static bool SearchNearbyHouseClass(TileIndex tile, void *user_data) { if (IsTileType(tile, MP_HOUSE)) { const HouseSpec *hs = GetHouseSpecs(GetHouseType(tile)); // tile been examined if (hs->grffile != NULL) { // must be one from a grf file - const HouseSpec *test_hs = GetHouseSpecs((HouseID)GB(data, 0, 16)); + HouseID *test_house = (HouseID *)user_data; + const HouseSpec *test_hs = GetHouseSpecs(*test_house); return hs->class_id == test_hs->class_id && // same classid as the one requested hs->grffile->grfid == test_hs->grffile->grfid; // from the same grf } @@ -239,15 +241,16 @@ static bool SearchNearbyHouseClass(TileIndex tile, uint32 data) /** Callback function to search a house by its grfID * @param tile TileIndex to be examined - * @param data house id, in order to get the specs + * @param user_data house id, in order to get the specs * @return true or false, if found or not */ -static bool SearchNearbyHouseGRFID(TileIndex tile, uint32 data) +static bool SearchNearbyHouseGRFID(TileIndex tile, void *user_data) { if (IsTileType(tile, MP_HOUSE)) { const HouseSpec *hs = GetHouseSpecs(GetHouseType(tile)); // tile been examined if (hs->grffile != NULL) { // must be one from a grf file - const HouseSpec *test_hs = GetHouseSpecs((HouseID)GB(data, 0, 16)); + HouseID *test_house = (HouseID *)user_data; + const HouseSpec *test_hs = GetHouseSpecs(*test_house); return hs->grffile->grfid == test_hs->grffile->grfid; // from the same grf } } @@ -260,10 +263,10 @@ static bool SearchNearbyHouseGRFID(TileIndex tile, uint32 data) * bits 0..6 radius of the search * bits 7..8 search type i.e.: 0 = houseID/ 1 = classID/ 2 = grfID * @param tile TileIndex from which to start the search - * @param data the HouseID that is associated to the house work who started the callback - * @result the Manhattan distance from the center tile, if any, and 0 if failure - */ -static uint32 GetDistanceFromNearbyHouse(uint8 parameter, TileIndex tile, uint32 data) + * @param house the HouseID that is associated to the house, the callback is called for + * @return the Manhattan distance from the center tile, if any, and 0 if failure + */ +static uint32 GetDistanceFromNearbyHouse(uint8 parameter, TileIndex tile, HouseID house) { static TestTileOnSearchProc * const search_procs[3] = { SearchNearbyHouseID, @@ -277,7 +280,7 @@ static uint32 GetDistanceFromNearbyHouse(uint8 parameter, TileIndex tile, uint32 if (searchradius < 1) return 0; // do not use a too low radius /* Use a pointer for the tile to start the search. Will be required for calculating the distance*/ - if (CircularTileSearch(&found_tile, 2 * searchradius + 1, search_procs[searchtype], data)) { + if (CircularTileSearch(&found_tile, 2 * searchradius + 1, search_procs[searchtype], &house)) { return DistanceManhattan(found_tile, tile); } return 0; diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp index 2b79adfc8..49bf49121 100644 --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -2182,12 +2182,13 @@ static bool DoBuildStatueOfCompany(TileIndex tile, TownID town_id) /** * Search callback function for TownActionBuildStatue * @param tile on which to perform the search - * @param town_id The town_id for which we want a statue + * @param user_data The town_id for which we want a statue * @return the result of the test */ -static bool SearchTileForStatue(TileIndex tile, uint32 town_id) +static bool SearchTileForStatue(TileIndex tile, void *user_data) { - return DoBuildStatueOfCompany(tile, town_id); + TownID *town_id = (TownID *)user_data; + return DoBuildStatueOfCompany(tile, *town_id); } /** @@ -2199,7 +2200,7 @@ static void TownActionBuildStatue(Town *t) { TileIndex tile = t->xy; - if (CircularTileSearch(&tile, 9, SearchTileForStatue, t->index)) { + if (CircularTileSearch(&tile, 9, SearchTileForStatue, &t->index)) { SetBit(t->statues, _current_player); // Once found and built, "inform" the Town } } |