Changeset - r23428:4a18cf6bbfe5
[Not reviewed]
master
0 6 0
peter1138 - 5 years ago 2019-02-24 18:52:15
peter1138@openttd.org
Codechange: Convert StationList from SmallVector to std::set.
6 files changed with 17 insertions and 11 deletions:
0 comments (0 inline, 0 general)
src/industry_cmd.cpp
Show inline comments
 
@@ -2429,13 +2429,13 @@ static void CanCargoServiceIndustry(Carg
 
static int WhoCanServiceIndustry(Industry *ind)
 
{
 
	/* Find all stations within reach of the industry */
 
	StationList stations;
 
	FindStationsAroundTiles(ind->location, &stations);
 

	
 
	if (stations.Length() == 0) return 0; // No stations found at all => nobody services
 
	if (stations.size() == 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;
 
@@ -2465,13 +2465,13 @@ static int WhoCanServiceIndustry(Industr
 
				Station *st = Station::Get(o->GetDestination());
 
				assert(st != NULL);
 

	
 
				/* Same cargo produced by industry is dropped here => not serviced by vehicle v */
 
				if ((o->GetUnloadType() & OUFB_UNLOAD) && !c_accepts) break;
 

	
 
				if (stations.Contains(st)) {
 
				if (stations.find(st) != stations.end()) {
 
					if (v->owner == _local_company) return 2; // Company services industry
 
					result = 1; // Competitor services industry
 
				}
 
			}
 
		}
 
	}
src/newgrf_house.cpp
Show inline comments
 
@@ -347,14 +347,13 @@ static uint32 GetDistanceFromNearbyHouse
 

	
 
			StationFinder stations(TileArea(testtile, 1, 1));
 
			const StationList *sl = stations.GetStations();
 

	
 
			/* Collect acceptance stats. */
 
			uint32 res = 0;
 
			for (Station * const * st_iter = sl->Begin(); st_iter != sl->End(); st_iter++) {
 
				const Station *st = *st_iter;
 
			for (Station *st : *sl) {
 
				if (HasBit(st->goods[cid].status, GoodsEntry::GES_EVER_ACCEPTED))    SetBit(res, 0);
 
				if (HasBit(st->goods[cid].status, GoodsEntry::GES_LAST_MONTH))       SetBit(res, 1);
 
				if (HasBit(st->goods[cid].status, GoodsEntry::GES_CURRENT_MONTH))    SetBit(res, 2);
 
				if (HasBit(st->goods[cid].status, GoodsEntry::GES_ACCEPTED_BIGTICK)) SetBit(res, 3);
 
			}
 

	
src/script/api/script_industry.cpp
Show inline comments
 
@@ -131,13 +131,13 @@
 
{
 
	if (!IsValidIndustry(industry_id)) return -1;
 

	
 
	Industry *ind = ::Industry::Get(industry_id);
 
	StationList stations;
 
	::FindStationsAroundTiles(ind->location, &stations);
 
	return (int32)stations.Length();
 
	return (int32)stations.size();
 
}
 

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

	
src/station.cpp
Show inline comments
 
@@ -568,6 +568,11 @@ Money AirportMaintenanceCost(Owner owner
 
			total_cost += _price[PR_INFRASTRUCTURE_AIRPORT] * st->airport.GetSpec()->maintenance_cost;
 
		}
 
	}
 
	/* 3 bits fraction for the maintenance cost factor. */
 
	return total_cost >> 3;
 
}
 

	
 
bool StationCompare::operator() (const Station *lhs, const Station *rhs) const
 
{
 
	return lhs->index < rhs->index;
 
}
src/station_cmd.cpp
Show inline comments
 
@@ -3836,13 +3836,13 @@ void FindStationsAroundTiles(const TileA
 
				if (rad_y < -rad || rad_y >= rad + location.h) continue;
 
			}
 

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

	
 
/**
 
 * Run a tile loop to find stations around a tile, on demand. Cache the result for further requests
 
@@ -3864,15 +3864,13 @@ uint MoveGoodsToStation(CargoID type, ui
 

	
 
	Station *st1 = NULL;   // Station with best rating
 
	Station *st2 = NULL;   // Second best station
 
	uint best_rating1 = 0; // rating of st1
 
	uint best_rating2 = 0; // rating of st2
 

	
 
	for (Station * const *st_iter = all_stations->Begin(); st_iter != all_stations->End(); ++st_iter) {
 
		Station *st = *st_iter;
 

	
 
	for (Station *st : *all_stations) {
 
		/* Is the station reserved exclusively for somebody else? */
 
		if (st->owner != OWNER_NONE && st->town->exclusive_counter > 0 && st->town->exclusivity != st->owner) continue;
 

	
 
		if (st->goods[type].rating == 0) continue; // Lowest possible rating, better not to give cargo anymore
 

	
 
		if (_settings_game.order.selectgoods && !st->goods[type].HasVehicleEverTriedLoading()) continue; // Selectively servicing stations, and not this one
src/station_type.h
Show inline comments
 
@@ -9,15 +9,15 @@
 

	
 
/** @file station_type.h Types related to stations. */
 

	
 
#ifndef STATION_TYPE_H
 
#define STATION_TYPE_H
 

	
 
#include "core/smallvec_type.hpp"
 
#include "core/smallstack_type.hpp"
 
#include "tilearea_type.h"
 
#include <set>
 

	
 
typedef uint16 StationID;
 
typedef uint16 RoadStopID;
 

	
 
struct BaseStation;
 
struct Station;
 
@@ -87,14 +87,18 @@ enum CatchmentArea {
 

	
 
	MAX_CATCHMENT      = 10, ///< Maximum catchment for airports with "modified catchment" enabled
 
};
 

	
 
static const uint MAX_LENGTH_STATION_NAME_CHARS = 32; ///< The maximum length of a station name in characters including '\0'
 

	
 
struct StationCompare {
 
	bool operator() (const Station *lhs, const Station *rhs) const;
 
};
 

	
 
/** List of stations */
 
typedef SmallVector<Station *, 2> StationList;
 
typedef std::set<Station *, StationCompare> StationList;
 

	
 
/**
 
 * Structure contains cached list of stations nearby. The list
 
 * is created upon first call to GetStations()
 
 */
 
class StationFinder : TileArea {
0 comments (0 inline, 0 general)