mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Convert StationList from SmallVector to std::set.
parent
46aca9377b
commit
ed6084523d
|
@ -2432,7 +2432,7 @@ static int WhoCanServiceIndustry(Industry *ind)
|
||||||
StationList stations;
|
StationList stations;
|
||||||
FindStationsAroundTiles(ind->location, &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;
|
const Vehicle *v;
|
||||||
int result = 0;
|
int result = 0;
|
||||||
|
@ -2468,7 +2468,7 @@ static int WhoCanServiceIndustry(Industry *ind)
|
||||||
/* Same cargo produced by industry is dropped here => not serviced by vehicle v */
|
/* Same cargo produced by industry is dropped here => not serviced by vehicle v */
|
||||||
if ((o->GetUnloadType() & OUFB_UNLOAD) && !c_accepts) break;
|
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
|
if (v->owner == _local_company) return 2; // Company services industry
|
||||||
result = 1; // Competitor services industry
|
result = 1; // Competitor services industry
|
||||||
}
|
}
|
||||||
|
|
|
@ -350,8 +350,7 @@ static uint32 GetDistanceFromNearbyHouse(uint8 parameter, TileIndex tile, HouseI
|
||||||
|
|
||||||
/* Collect acceptance stats. */
|
/* Collect acceptance stats. */
|
||||||
uint32 res = 0;
|
uint32 res = 0;
|
||||||
for (Station * const * st_iter = sl->Begin(); st_iter != sl->End(); st_iter++) {
|
for (Station *st : *sl) {
|
||||||
const Station *st = *st_iter;
|
|
||||||
if (HasBit(st->goods[cid].status, GoodsEntry::GES_EVER_ACCEPTED)) SetBit(res, 0);
|
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_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_CURRENT_MONTH)) SetBit(res, 2);
|
||||||
|
|
|
@ -134,7 +134,7 @@
|
||||||
Industry *ind = ::Industry::Get(industry_id);
|
Industry *ind = ::Industry::Get(industry_id);
|
||||||
StationList stations;
|
StationList stations;
|
||||||
::FindStationsAroundTiles(ind->location, &stations);
|
::FindStationsAroundTiles(ind->location, &stations);
|
||||||
return (int32)stations.Length();
|
return (int32)stations.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* static */ int32 ScriptIndustry::GetDistanceManhattanToTile(IndustryID industry_id, TileIndex tile)
|
/* static */ int32 ScriptIndustry::GetDistanceManhattanToTile(IndustryID industry_id, TileIndex tile)
|
||||||
|
|
|
@ -571,3 +571,8 @@ Money AirportMaintenanceCost(Owner owner)
|
||||||
/* 3 bits fraction for the maintenance cost factor. */
|
/* 3 bits fraction for the maintenance cost factor. */
|
||||||
return total_cost >> 3;
|
return total_cost >> 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool StationCompare::operator() (const Station *lhs, const Station *rhs) const
|
||||||
|
{
|
||||||
|
return lhs->index < rhs->index;
|
||||||
|
}
|
||||||
|
|
|
@ -3839,7 +3839,7 @@ void FindStationsAroundTiles(const TileArea &location, StationList *stations)
|
||||||
/* Insert the station in the set. This will fail if it has
|
/* Insert the station in the set. This will fail if it has
|
||||||
* already been added.
|
* already been added.
|
||||||
*/
|
*/
|
||||||
stations->Include(st);
|
stations->insert(st);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3867,9 +3867,7 @@ uint MoveGoodsToStation(CargoID type, uint amount, SourceType source_type, Sourc
|
||||||
uint best_rating1 = 0; // rating of st1
|
uint best_rating1 = 0; // rating of st1
|
||||||
uint best_rating2 = 0; // rating of st2
|
uint best_rating2 = 0; // rating of st2
|
||||||
|
|
||||||
for (Station * const *st_iter = all_stations->Begin(); st_iter != all_stations->End(); ++st_iter) {
|
for (Station *st : *all_stations) {
|
||||||
Station *st = *st_iter;
|
|
||||||
|
|
||||||
/* Is the station reserved exclusively for somebody else? */
|
/* 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->owner != OWNER_NONE && st->town->exclusive_counter > 0 && st->town->exclusivity != st->owner) continue;
|
||||||
|
|
||||||
|
|
|
@ -12,9 +12,9 @@
|
||||||
#ifndef STATION_TYPE_H
|
#ifndef STATION_TYPE_H
|
||||||
#define STATION_TYPE_H
|
#define STATION_TYPE_H
|
||||||
|
|
||||||
#include "core/smallvec_type.hpp"
|
|
||||||
#include "core/smallstack_type.hpp"
|
#include "core/smallstack_type.hpp"
|
||||||
#include "tilearea_type.h"
|
#include "tilearea_type.h"
|
||||||
|
#include <set>
|
||||||
|
|
||||||
typedef uint16 StationID;
|
typedef uint16 StationID;
|
||||||
typedef uint16 RoadStopID;
|
typedef uint16 RoadStopID;
|
||||||
|
@ -90,8 +90,12 @@ enum CatchmentArea {
|
||||||
|
|
||||||
static const uint MAX_LENGTH_STATION_NAME_CHARS = 32; ///< The maximum length of a station name in characters including '\0'
|
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 */
|
/** List of stations */
|
||||||
typedef SmallVector<Station *, 2> StationList;
|
typedef std::set<Station *, StationCompare> StationList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Structure contains cached list of stations nearby. The list
|
* Structure contains cached list of stations nearby. The list
|
||||||
|
|
Loading…
Reference in New Issue