Changeset - r14158:56944d690621
[Not reviewed]
master
0 4 0
rubidium - 14 years ago 2010-01-04 18:16:32
rubidium@openttd.org
(svn r18716) -Codechange: pass a TileArea to FindStationsAroundTiles
4 files changed with 10 insertions and 12 deletions:
0 comments (0 inline, 0 general)
src/ai/api/ai_industry.cpp
Show inline comments
 
@@ -115,25 +115,25 @@
 
{
 
	if (!IsValidIndustry(industry_id)) return INVALID_TILE;
 

	
 
	return ::Industry::Get(industry_id)->xy;
 
}
 

	
 
/* static */ int32 AIIndustry::GetAmountOfStationsAround(IndustryID industry_id)
 
{
 
	if (!IsValidIndustry(industry_id)) return -1;
 

	
 
	Industry *ind = ::Industry::Get(industry_id);
 
	StationList stations;
 
	::FindStationsAroundTiles(ind->xy, ind->width, ind->height, &stations);
 
	::FindStationsAroundTiles(TileArea(ind->xy, ind->width, ind->height), &stations);
 
	return (int32)stations.Length();
 
}
 

	
 
/* static */ int32 AIIndustry::GetDistanceManhattanToTile(IndustryID industry_id, TileIndex tile)
 
{
 
	if (!IsValidIndustry(industry_id)) return -1;
 

	
 
	return AIMap::DistanceManhattan(tile, GetLocation(industry_id));
 
}
 

	
 
/* static */ int32 AIIndustry::GetDistanceSquareToTile(IndustryID industry_id, TileIndex tile)
 
{
src/industry_cmd.cpp
Show inline comments
 
@@ -2057,25 +2057,25 @@ static void CanCargoServiceIndustry(Carg
 
 * technical means).
 
 *
 
 * @param ind: Industry being investigated.
 
 *
 
 * @return: 0 if nobody can service the industry, 2 if the local company can
 
 * service the industry, and 1 otherwise (only competitors can service the
 
 * industry)
 
 */
 
static int WhoCanServiceIndustry(Industry *ind)
 
{
 
	/* Find all stations within reach of the industry */
 
	StationList stations;
 
	FindStationsAroundTiles(ind->xy, ind->width, ind->height, &stations);
 
	FindStationsAroundTiles(TileArea(ind->xy, ind->width, ind->height), &stations);
 

	
 
	if (stations.Length() == 0) return 0; // No stations found at all => nobody services
 

	
 
	const Vehicle *v;
 
	int result = 0;
 
	FOR_ALL_VEHICLES(v) {
 
		/* Is it worthwhile to try this vehicle? */
 
		if (v->owner != _local_company && result != 0) continue;
 

	
 
		/* Check whether it accepts the right kind of cargo */
 
		bool c_accepts = false;
 
		bool c_produces = false;
src/station_cmd.cpp
Show inline comments
 
@@ -2988,63 +2988,61 @@ CommandCost CmdRenameStation(TileIndex t
 
		st->name = reset ? NULL : strdup(text);
 

	
 
		st->UpdateVirtCoord();
 
		InvalidateWindowData(WC_STATION_LIST, st->owner, 1);
 
	}
 

	
 
	return CommandCost();
 
}
 

	
 
/**
 
 * Find all stations around a rectangular producer (industry, house, headquarter, ...)
 
 *
 
 * @param tile North tile of producer
 
 * @param w_prod X extent of producer
 
 * @param h_prod Y extent of producer
 
 * @param location The location/area of the producer
 
 * @param stations The list to store the stations in
 
 */
 
void FindStationsAroundTiles(TileIndex tile, int w_prod, int h_prod, StationList *stations)
 
void FindStationsAroundTiles(const TileArea &location, StationList *stations)
 
{
 
	/* area to search = producer plus station catchment radius */
 
	int max_rad = (_settings_game.station.modified_catchment ? MAX_CATCHMENT : CA_UNMODIFIED);
 

	
 
	for (int dy = -max_rad; dy < h_prod + max_rad; dy++) {
 
		for (int dx = -max_rad; dx < w_prod + max_rad; dx++) {
 
			TileIndex cur_tile = TileAddWrap(tile, dx, dy);
 
	for (int dy = -max_rad; dy < location.h + max_rad; dy++) {
 
		for (int dx = -max_rad; dx < location.w + max_rad; dx++) {
 
			TileIndex cur_tile = TileAddWrap(location.tile, dx, dy);
 
			if (cur_tile == INVALID_TILE || !IsTileType(cur_tile, MP_STATION)) continue;
 

	
 
			Station *st = Station::GetByTile(cur_tile);
 
			if (st == NULL) continue;
 

	
 
			if (_settings_game.station.modified_catchment) {
 
				int rad = st->GetCatchmentRadius();
 
				if (dx < -rad || dx >= rad + w_prod || dy < -rad || dy >= rad + h_prod) continue;
 
				if (dx < -rad || dx >= rad + location.w || dy < -rad || dy >= rad + location.h) continue;
 
			}
 

	
 
			/* Insert the station in the set. This will fail if it has
 
			 * already been added.
 
			 */
 
			stations->Include(st);
 
		}
 
	}
 
}
 

	
 
/**
 
 * 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->w, this->h, &this->stations);
 
		FindStationsAroundTiles(*this, &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)
 
{
 
	/* Return if nothing to do. Also the rounding below fails for 0. */
 
	if (amount == 0) return 0;
 

	
 
	Station *st1 = NULL;   // Station with best rating
 
	Station *st2 = NULL;   // Second best station
src/station_func.h
Show inline comments
 
@@ -13,25 +13,25 @@
 
#define STATION_FUNC_H
 

	
 
#include "station_type.h"
 
#include "sprite.h"
 
#include "rail_type.h"
 
#include "road_type.h"
 
#include "tile_type.h"
 
#include "cargo_type.h"
 
#include "vehicle_type.h"
 

	
 
void ModifyStationRatingAround(TileIndex tile, Owner owner, int amount, uint radius);
 

	
 
void FindStationsAroundTiles(TileIndex tile, int w_prod, int h_prod, StationList *stations);
 
void FindStationsAroundTiles(const TileArea &location, StationList *stations);
 

	
 
void ShowStationViewWindow(StationID station);
 
void UpdateAllStationVirtCoords();
 

	
 
CargoArray GetProductionAroundTiles(TileIndex tile, int w, int h, int rad);
 
CargoArray GetAcceptanceAroundTiles(TileIndex tile, int w, int h, int rad, uint32 *always_accepted = NULL);
 

	
 
void UpdateStationAcceptance(Station *st, bool show_msg);
 

	
 
const DrawTileSprites *GetStationTileLayout(StationType st, byte gfx);
 
void StationPickerDrawSprite(int x, int y, StationType st, RailType railtype, RoadType roadtype, int image);
 

	
0 comments (0 inline, 0 general)