mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-12 18:40:29 +00:00
Codechange: Convert IndustryVector to a std::set.
This commit is contained in:
parent
ed6084523d
commit
94b40fd530
@ -151,9 +151,9 @@ void AddCargoDelivery(CargoID cargo_type, CompanyID company, uint32 amount, Sour
|
|||||||
if (iter != _cargo_deliveries.end()) iter->second += amount;
|
if (iter != _cargo_deliveries.end()) iter->second += amount;
|
||||||
|
|
||||||
/* Industry delivery. */
|
/* Industry delivery. */
|
||||||
for (const Industry * const *ip = st->industries_near.Begin(); ip != st->industries_near.End(); ip++) {
|
for (Industry *ind : st->industries_near) {
|
||||||
if ((*ip)->index != dest) continue;
|
if (ind->index != dest) continue;
|
||||||
CargoMonitorID num = EncodeCargoIndustryMonitor(company, cargo_type, (*ip)->index);
|
CargoMonitorID num = EncodeCargoIndustryMonitor(company, cargo_type, ind->index);
|
||||||
CargoMonitorMap::iterator iter = _cargo_deliveries.find(num);
|
CargoMonitorMap::iterator iter = _cargo_deliveries.find(num);
|
||||||
if (iter != _cargo_deliveries.end()) iter->second += amount;
|
if (iter != _cargo_deliveries.end()) iter->second += amount;
|
||||||
}
|
}
|
||||||
|
@ -1044,8 +1044,9 @@ static uint DeliverGoodsToIndustry(const Station *st, CargoID cargo_type, uint n
|
|||||||
|
|
||||||
uint accepted = 0;
|
uint accepted = 0;
|
||||||
|
|
||||||
for (uint i = 0; i < st->industries_near.Length() && num_pieces != 0; i++) {
|
for (Industry *ind : st->industries_near) {
|
||||||
Industry *ind = st->industries_near[i];
|
if (num_pieces == 0) break;
|
||||||
|
|
||||||
if (ind->index == source) continue;
|
if (ind->index == source) continue;
|
||||||
|
|
||||||
if (!_settings_game.station.serve_neutral_industries) {
|
if (!_settings_game.station.serve_neutral_industries) {
|
||||||
|
@ -521,7 +521,7 @@ static bool TransportIndustryGoods(TileIndex tile)
|
|||||||
|
|
||||||
if (i->neutral_station != NULL && !_settings_game.station.serve_neutral_industries) {
|
if (i->neutral_station != NULL && !_settings_game.station.serve_neutral_industries) {
|
||||||
/* Industry has a neutral station. Use it and ignore any other nearby stations. */
|
/* Industry has a neutral station. Use it and ignore any other nearby stations. */
|
||||||
*neutral.Append() = i->neutral_station;
|
neutral.insert(i->neutral_station);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (uint j = 0; j < lengthof(i->produced_cargo_waiting); j++) {
|
for (uint j = 0; j < lengthof(i->produced_cargo_waiting); j++) {
|
||||||
@ -534,7 +534,7 @@ static bool TransportIndustryGoods(TileIndex tile)
|
|||||||
|
|
||||||
i->this_month_production[j] += cw;
|
i->this_month_production[j] += cw;
|
||||||
|
|
||||||
uint am = MoveGoodsToStation(i->produced_cargo[j], cw, ST_INDUSTRY, i->index, neutral.Length() != 0 ? &neutral : stations.GetStations());
|
uint am = MoveGoodsToStation(i->produced_cargo[j], cw, ST_INDUSTRY, i->index, neutral.size() != 0 ? &neutral : stations.GetStations());
|
||||||
i->this_month_transported[j] += am;
|
i->this_month_transported[j] += am;
|
||||||
|
|
||||||
moved_cargo |= (am != 0);
|
moved_cargo |= (am != 0);
|
||||||
@ -2907,3 +2907,8 @@ extern const TileTypeProcs _tile_type_industry_procs = {
|
|||||||
GetFoundation_Industry, // get_foundation_proc
|
GetFoundation_Industry, // get_foundation_proc
|
||||||
TerraformTile_Industry, // terraform_tile_proc
|
TerraformTile_Industry, // terraform_tile_proc
|
||||||
};
|
};
|
||||||
|
|
||||||
|
bool IndustryCompare::operator() (const Industry *lhs, const Industry *rhs) const
|
||||||
|
{
|
||||||
|
return lhs->index < rhs->index;
|
||||||
|
}
|
||||||
|
@ -308,7 +308,7 @@ Rect Station::GetCatchmentRect() const
|
|||||||
/** Rect and pointer to IndustryVector */
|
/** Rect and pointer to IndustryVector */
|
||||||
struct RectAndIndustryVector {
|
struct RectAndIndustryVector {
|
||||||
Rect rect; ///< The rectangle to search the industries in.
|
Rect rect; ///< The rectangle to search the industries in.
|
||||||
IndustryVector *industries_near; ///< The nearby industries.
|
IndustryList *industries_near; ///< The nearby industries.
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -328,7 +328,7 @@ static bool FindIndustryToDeliver(TileIndex ind_tile, void *user_data)
|
|||||||
Industry *ind = Industry::GetByTile(ind_tile);
|
Industry *ind = Industry::GetByTile(ind_tile);
|
||||||
|
|
||||||
/* Don't check further if this industry is already in the list */
|
/* Don't check further if this industry is already in the list */
|
||||||
if (riv->industries_near->Contains(ind)) return false;
|
if (riv->industries_near->find(ind) != riv->industries_near->end()) return false;
|
||||||
|
|
||||||
/* Only process tiles in the station acceptance rectangle */
|
/* Only process tiles in the station acceptance rectangle */
|
||||||
int x = TileX(ind_tile);
|
int x = TileX(ind_tile);
|
||||||
@ -342,7 +342,7 @@ static bool FindIndustryToDeliver(TileIndex ind_tile, void *user_data)
|
|||||||
}
|
}
|
||||||
if (cargo_index >= lengthof(ind->accepts_cargo)) return false;
|
if (cargo_index >= lengthof(ind->accepts_cargo)) return false;
|
||||||
|
|
||||||
*riv->industries_near->Append() = ind;
|
riv->industries_near->insert(ind);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -353,12 +353,12 @@ static bool FindIndustryToDeliver(TileIndex ind_tile, void *user_data)
|
|||||||
*/
|
*/
|
||||||
void Station::RecomputeIndustriesNear()
|
void Station::RecomputeIndustriesNear()
|
||||||
{
|
{
|
||||||
this->industries_near.Clear();
|
this->industries_near.clear();
|
||||||
if (this->rect.IsEmpty()) return;
|
if (this->rect.IsEmpty()) return;
|
||||||
|
|
||||||
if (!_settings_game.station.serve_neutral_industries && this->industry != NULL) {
|
if (!_settings_game.station.serve_neutral_industries && this->industry != NULL) {
|
||||||
/* Station is associated with an industry, so we only need to deliver to that industry. */
|
/* Station is associated with an industry, so we only need to deliver to that industry. */
|
||||||
*this->industries_near.Append() = this->industry;
|
this->industries_near.insert(this->industry);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
#include "linkgraph/linkgraph_type.h"
|
#include "linkgraph/linkgraph_type.h"
|
||||||
#include "newgrf_storage.h"
|
#include "newgrf_storage.h"
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <set>
|
||||||
|
|
||||||
typedef Pool<BaseStation, StationID, 32, 64000> StationPool;
|
typedef Pool<BaseStation, StationID, 32, 64000> StationPool;
|
||||||
extern StationPool _station_pool;
|
extern StationPool _station_pool;
|
||||||
@ -440,7 +441,11 @@ private:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef SmallVector<Industry *, 2> IndustryVector;
|
struct IndustryCompare {
|
||||||
|
bool operator() (const Industry *lhs, const Industry *rhs) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef std::set<Industry *, IndustryCompare> IndustryList;
|
||||||
|
|
||||||
/** Station data structure */
|
/** Station data structure */
|
||||||
struct Station FINAL : SpecializedStation<Station, false> {
|
struct Station FINAL : SpecializedStation<Station, false> {
|
||||||
@ -472,7 +477,7 @@ public:
|
|||||||
GoodsEntry goods[NUM_CARGO]; ///< Goods at this station
|
GoodsEntry goods[NUM_CARGO]; ///< Goods at this station
|
||||||
CargoTypes always_accepted; ///< Bitmask of always accepted cargo types (by houses, HQs, industry tiles when industry doesn't accept cargo)
|
CargoTypes always_accepted; ///< Bitmask of always accepted cargo types (by houses, HQs, industry tiles when industry doesn't accept cargo)
|
||||||
|
|
||||||
IndustryVector industries_near; ///< Cached list of industries near the station that can accept cargo, @see DeliverGoodsToIndustry()
|
IndustryList industries_near; ///< Cached list of industries near the station that can accept cargo, @see DeliverGoodsToIndustry()
|
||||||
Industry *industry; ///< NOSAVE: Associated industry for neutral stations. (Rebuilt on load from Industry->st)
|
Industry *industry; ///< NOSAVE: Associated industry for neutral stations. (Rebuilt on load from Industry->st)
|
||||||
|
|
||||||
Station(TileIndex tile = INVALID_TILE);
|
Station(TileIndex tile = INVALID_TILE);
|
||||||
|
@ -596,9 +596,9 @@ bool CheckSubsidised(CargoID cargo_type, CompanyID company, SourceType src_type,
|
|||||||
if (s->cargo_type == cargo_type && s->src_type == src_type && s->src == src && (!s->IsAwarded() || s->awarded == company)) {
|
if (s->cargo_type == cargo_type && s->src_type == src_type && s->src == src && (!s->IsAwarded() || s->awarded == company)) {
|
||||||
switch (s->dst_type) {
|
switch (s->dst_type) {
|
||||||
case ST_INDUSTRY:
|
case ST_INDUSTRY:
|
||||||
for (const Industry * const *ip = st->industries_near.Begin(); ip != st->industries_near.End(); ip++) {
|
for (Industry *ind : st->industries_near) {
|
||||||
if (s->dst == (*ip)->index) {
|
if (s->dst == ind->index) {
|
||||||
assert((*ip)->part_of_subsidy & POS_DST);
|
assert(ind->part_of_subsidy & POS_DST);
|
||||||
subsidised = true;
|
subsidised = true;
|
||||||
if (!s->IsAwarded()) s->AwardTo(company);
|
if (!s->IsAwarded()) s->AwardTo(company);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user