Changeset - r7233:d578434a488b
[Not reviewed]
master
0 4 0
rubidium - 17 years ago 2007-07-11 22:57:47
rubidium@openttd.org
(svn r10514) -Codechange: add support for getting the nearest industry with a given type.
4 files changed with 42 insertions and 6 deletions:
0 comments (0 inline, 0 general)
src/newgrf.cpp
Show inline comments
 
@@ -44,6 +44,7 @@
 
#include "table/build_industry.h"
 
#include "newgrf_commons.h"
 
#include "newgrf_townname.h"
 
#include "newgrf_industries.h"
 

	
 
/* TTDPatch extended GRF format codec
 
 * (c) Petr Baudis 2004 (GPL'd)
 
@@ -5228,6 +5229,15 @@ static void FinaliseIndustriesArray()
 
			}
 
		}
 
	}
 

	
 
	for (uint j = 0; j < NUM_INDUSTRYTYPES; j++) {
 
		IndustrySpec *indsp = &_industry_specs[j];
 
		if (indsp->enabled && indsp->grf_prop.grffile != NULL) {
 
			for (uint i = 0; i < 3; i++) {
 
				indsp->conflicting[i] = MapNewGRFIndustryType(indsp->conflicting[i], indsp->grf_prop.grffile->grfid);
 
			}
 
		}
 
	}
 
}
 

	
 
/** Each cargo string needs to be mapped from TTDPatch to OpenTTD string IDs.
src/newgrf_industries.cpp
Show inline comments
 
@@ -27,6 +27,14 @@
 
IndustryOverrideManager _industry_mngr(NEW_INDUSTRYOFFSET, NUM_INDUSTRYTYPES, INVALID_INDUSTRYTYPE);
 
IndustryTileOverrideManager _industile_mngr(NEW_INDUSTRYTILEOFFSET, NUM_INDUSTRYTILES, INVALID_INDUSTRYTILE);
 

	
 
IndustryType MapNewGRFIndustryType(IndustryType grf_type, uint32 grf_id)
 
{
 
	if (grf_type == IT_INVALID) return IT_INVALID;
 
	if (!HASBIT(grf_type, 7)) return GB(grf_type, 0, 6);
 

	
 
	return _industry_mngr.GetID(GB(grf_type, 0, 6), grf_id);
 
}
 

	
 
/**
 
 * Finds the distance for the closest tile with water/land given a tile
 
 * @param tile  the tile to find the distance too
 
@@ -112,6 +120,19 @@ uint32 GetIndustryIDAtOffset(TileIndex n
 
	return 0xFFFF; // tile is not an industry one or  does not belong to the current industry
 
}
 

	
 
static uint32 GetClosestIndustry(TileIndex tile, IndustryType type, const Industry *current)
 
{
 
	uint32 best_dist = MAX_UVALUE(uint32);
 
	const Industry *i;
 
	FOR_ALL_INDUSTRIES(i) {
 
		if (i->type != type || i == current) continue;
 

	
 
		best_dist = min(best_dist, DistanceManhattan(tile, i->xy));
 
	}
 

	
 
	return best_dist;
 
}
 

	
 
/** This function implements the industries variables that newGRF defines.
 
 * @param variable that is queried
 
 * @param parameter unused
 
@@ -145,8 +166,8 @@ uint32 IndustryGetVariable(const Resolve
 
		case 0x61: return 0; // Get random tile bits at offset param
 

	
 
		case 0x62: // Land info of nearby tiles
 
		case 0x63: // Animation stage of nerby tiles
 
		case 0x64: break; // Distance of nearest industry of given type
 
		case 0x63: break; // Animation stage of nerby tiles
 
		case 0x64: return GetClosestIndustry(tile, MapNewGRFIndustryType(parameter, indspec->grf_prop.grffile->grfid), industry); // Distance of nearest industry of given type
 
		/* Get town zone and Manhattan distance of closest town */
 
 		case 0x65: return GetTownRadiusGroup(industry->town, tile) << 16 | min(DistanceManhattan(tile, industry->town->xy), 0xFFFF);
 
		/* Get square of Euclidian distance of closes town */
 
@@ -275,8 +296,8 @@ uint32 IndustryLocationGetVariable(const
 
	}
 

	
 
	switch (variable) {
 
		case 0x62: // Land info of nearby tiles
 
		case 0x64: break; // Distance of nearest industry of given type
 
		case 0x62: break;// Land info of nearby tiles
 
		case 0x64: return GetClosestIndustry(tile, MapNewGRFIndustryType(parameter, object->u.industry_location.spec->grf_prop.grffile->grfid), NULL); // Distance of nearest industry of given type
 

	
 
		/* Location where to build the industry */
 
		case 0x80: return tile;
 
@@ -309,7 +330,7 @@ uint32 IndustryLocationGetVariable(const
 
		case 0x8D: return min(DistanceSquare(ClosestTownFromTile(tile, (uint)-1)->xy, tile), 65535);
 
	}
 

	
 
	DEBUG(grf, 1, "Unhandled industry property 0x%X", variable);
 
	DEBUG(grf, 1, "Unhandled location industry property 0x%X", variable);
 

	
 
	*available = false;
 
	return (uint32)-1;
src/newgrf_industries.h
Show inline comments
 
@@ -15,6 +15,8 @@ uint32 GetIndustryIDAtOffset(TileIndex n
 
void IndustryProductionCallback(Industry *ind, int reason);
 
bool CheckIfCallBackAllowsCreation(TileIndex tile, IndustryType type, uint itspec_index);
 

	
 
IndustryType MapNewGRFIndustryType(IndustryType grf_type, uint32 grf_id);
 

	
 
/* in newgrf_industrytiles.cpp*/
 
uint32 IndustryTileGetRandomBits(const ResolverObject *object);
 
uint32 IndustryTileGetTriggers(const ResolverObject *object);
src/newgrf_industrytiles.cpp
Show inline comments
 
@@ -99,7 +99,10 @@ static uint32 IndustryTileGetVariable(co
 
		case 0x62 : return GetIndustryIDAtOffset(GetNearbyTile(parameter, tile), tile, inds);
 
	}
 

	
 
	return 0;
 
	DEBUG(grf, 1, "Unhandled industry tile property 0x%X", variable);
 

	
 
	*available = false;
 
	return (uint32)-1;
 
}
 

	
 
static const SpriteGroup *IndustryTileResolveReal(const ResolverObject *object, const SpriteGroup *group)
0 comments (0 inline, 0 general)