Changeset - r9592:cdeca10f617d
[Not reviewed]
master
0 5 0
frosch - 16 years ago 2008-06-25 18:46:05
frosch@openttd.org
(svn r13632) -Codechange: Use 'void *' for user-data of CircularTileSearch().
5 files changed with 32 insertions and 28 deletions:
0 comments (0 inline, 0 general)
src/industry_cmd.cpp
Show inline comments
 
@@ -962,10 +962,10 @@ void PlantRandomFarmField(const Industry
 
/**
 
 * 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
 

	
 
	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
 
}
 

	
src/map.cpp
Show inline comments
 
@@ -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,
 
		/* 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 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
 
				}
src/map_func.h
Show inline comments
 
@@ -383,15 +383,15 @@ static inline TileIndex TileAddByDiagDir
 
 * 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.
src/newgrf_house.cpp
Show inline comments
 
@@ -203,15 +203,16 @@ uint32 GetNearbyTileInformation(byte par
 

	
 
/** 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(TileInde
 

	
 
/** 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(TileI
 

	
 
/** 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(TileI
 
 *                  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
 
	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;
src/town_cmd.cpp
Show inline comments
 
@@ -2182,12 +2182,13 @@ static bool DoBuildStatueOfCompany(TileI
 
/**
 
 * 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 *
 
{
 
	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
 
	}
 
}
0 comments (0 inline, 0 general)