Changeset - r14157:8722b3bbfc4d
[Not reviewed]
master
0 5 0
rubidium - 15 years ago 2010-01-04 18:12:10
rubidium@openttd.org
(svn r18715) -Codechange: make StationFinder a subclass of TileArea
5 files changed with 7 insertions and 12 deletions:
0 comments (0 inline, 0 general)
src/industry_cmd.cpp
Show inline comments
 
@@ -506,13 +506,13 @@ static CommandCost ClearTile_Industry(Ti
 
static void TransportIndustryGoods(TileIndex tile)
 
{
 
	Industry *i = Industry::GetByTile(tile);
 
	const IndustrySpec *indspec = GetIndustrySpec(i->type);
 
	bool moved_cargo = false;
 

	
 
	StationFinder stations(i->xy, i->width, i->height);
 
	StationFinder stations(TileArea(i->xy, i->width, i->height));
 

	
 
	for (uint j = 0; j < lengthof(i->produced_cargo_waiting); j++) {
 
		uint cw = min(i->produced_cargo_waiting[j], 255);
 
		if (cw > indspec->minimal_cargo && i->produced_cargo[j] != CT_INVALID) {
 
			i->produced_cargo_waiting[j] -= cw;
 

	
src/station_cmd.cpp
Show inline comments
 
@@ -3032,13 +3032,13 @@ void FindStationsAroundTiles(TileIndex t
 
 * Run a tile loop to find stations around a tile, on demand. Cache the result for further requests
 
 * @return pointer to a StationList containing all stations found
 
 */
 
const StationList *StationFinder::GetStations()
 
{
 
	if (this->tile != INVALID_TILE) {
 
		FindStationsAroundTiles(this->tile, this->x_extent, this->y_extent, &this->stations);
 
		FindStationsAroundTiles(this->tile, this->w, this->h, &this->stations);
 
		this->tile = INVALID_TILE;
 
	}
 
	return &this->stations;
 
}
 

	
 
uint MoveGoodsToStation(CargoID type, uint amount, SourceType source_type, SourceID source_id, const StationList *all_stations)
src/station_type.h
Show inline comments
 
@@ -96,23 +96,18 @@ enum {
 
typedef SmallVector<Station *, 2> StationList;
 

	
 
/**
 
 * Structure contains cached list of stations nearby. The list
 
 * is created upon first call to GetStations()
 
 */
 
class StationFinder {
 
class StationFinder : TileArea {
 
	StationList stations; ///< List of stations nearby
 
	TileIndex tile;       ///< Northern tile of producer, INVALID_TILE when # stations is valid
 
	int x_extent;         ///< Width of producer
 
	int y_extent;         ///< Height of producer
 
public:
 
	/**
 
	 * Constructs StationFinder
 
	 * @param t northern tile
 
	 * @param dx width of producer
 
	 * @param dy height of producer
 
	 * @param area the area to search from
 
	 */
 
	StationFinder(TileIndex t, int dx, int dy) : tile(t), x_extent(dx), y_extent(dy) {}
 
	StationFinder(const TileArea &area) : TileArea(area) {}
 
	const StationList *GetStations();
 
};
 

	
 
#endif /* STATION_TYPE_H */
src/town_cmd.cpp
Show inline comments
 
@@ -462,13 +462,13 @@ static void TileLoop_Town(TileIndex tile
 
		AddAnimatedTile(tile);
 
	}
 

	
 
	Town *t = Town::GetByTile(tile);
 
	uint32 r = Random();
 

	
 
	StationFinder stations(tile, 1, 1);
 
	StationFinder stations(TileArea(tile, 1, 1));
 

	
 
	if (HasBit(hs->callback_mask, CBM_HOUSE_PRODUCE_CARGO)) {
 
		for (uint i = 0; i < 256; i++) {
 
			uint16 callback = GetHouseCallback(CBID_HOUSE_PRODUCE_CARGO, i, r, house_id, t, tile);
 

	
 
			if (callback == CALLBACK_FAILED || callback == CALLBACK_HOUSEPRODCARGO_END) break;
src/unmovable_cmd.cpp
Show inline comments
 
@@ -340,13 +340,13 @@ static void TileLoop_Unmovable(TileIndex
 
	 * between 4 tiles it occupies! */
 

	
 
	/* HQ level (depends on company performance) in the range 1..5. */
 
	uint level = GetCompanyHQSize(tile) + 1;
 
	assert(level < 6);
 

	
 
	StationFinder stations(tile, 2, 2);
 
	StationFinder stations(TileArea(tile, 2, 2));
 

	
 
	uint r = Random();
 
	/* Top town buildings generate 250, so the top HQ type makes 256. */
 
	if (GB(r, 0, 8) < (256 / 4 / (6 - level))) {
 
		uint amt = GB(r, 0, 8) / 8 / 4 + 1;
 
		if (_economy.fluct <= 0) amt = (amt + 1) >> 1;
0 comments (0 inline, 0 general)