Use std::vector for extra station name strings
This commit is contained in:
@@ -154,11 +154,8 @@ void CheckExternalFiles()
|
|||||||
|
|
||||||
void InitGRFGlobalVars()
|
void InitGRFGlobalVars()
|
||||||
{
|
{
|
||||||
extern uint _extra_station_names_used;
|
extern void ClearExtraStationNames();
|
||||||
_extra_station_names_used = 0;
|
ClearExtraStationNames();
|
||||||
|
|
||||||
extern uint8_t _extra_station_names_probability;
|
|
||||||
_extra_station_names_probability = 0;
|
|
||||||
|
|
||||||
extern bool _allow_rocks_desert;
|
extern bool _allow_rocks_desert;
|
||||||
_allow_rocks_desert = false;
|
_allow_rocks_desert = false;
|
||||||
|
@@ -2925,11 +2925,11 @@ static ChangeInfoResult GlobalVarChangeInfo(uint gvid, int numinfo, int prop, co
|
|||||||
if (MappedPropertyLengthMismatch(buf, 4, mapping_entry)) break;
|
if (MappedPropertyLengthMismatch(buf, 4, mapping_entry)) break;
|
||||||
uint16_t str = buf->ReadWord();
|
uint16_t str = buf->ReadWord();
|
||||||
uint16_t flags = buf->ReadWord();
|
uint16_t flags = buf->ReadWord();
|
||||||
if (_extra_station_names_used < MAX_EXTRA_STATION_NAMES) {
|
if (_extra_station_names.size() < MAX_EXTRA_STATION_NAMES) {
|
||||||
ExtraStationNameInfo &info = _extra_station_names[_extra_station_names_used];
|
size_t idx = _extra_station_names.size();
|
||||||
AddStringForMapping(str, &info.str);
|
ExtraStationNameInfo &info = _extra_station_names.emplace_back();
|
||||||
|
AddStringForMapping(str, idx, [](StringID str, size_t idx) { _extra_station_names[idx].str = str; });
|
||||||
info.flags = flags;
|
info.flags = flags;
|
||||||
_extra_station_names_used++;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@@ -39,8 +39,7 @@
|
|||||||
StationPool _station_pool("Station");
|
StationPool _station_pool("Station");
|
||||||
INSTANTIATE_POOL_METHODS(Station)
|
INSTANTIATE_POOL_METHODS(Station)
|
||||||
|
|
||||||
std::array<ExtraStationNameInfo, MAX_EXTRA_STATION_NAMES> _extra_station_names;
|
std::vector<ExtraStationNameInfo> _extra_station_names;
|
||||||
uint _extra_station_names_used;
|
|
||||||
uint8_t _extra_station_names_probability;
|
uint8_t _extra_station_names_probability;
|
||||||
|
|
||||||
const StationCargoList _empty_cargo_list{};
|
const StationCargoList _empty_cargo_list{};
|
||||||
@@ -769,3 +768,11 @@ bool StationCompare::operator() (const Station *lhs, const Station *rhs) const
|
|||||||
{
|
{
|
||||||
return lhs->index < rhs->index;
|
return lhs->index < rhs->index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ClearExtraStationNames()
|
||||||
|
{
|
||||||
|
_extra_station_names.clear();
|
||||||
|
_extra_station_names.shrink_to_fit();
|
||||||
|
|
||||||
|
_extra_station_names_probability = 0;
|
||||||
|
}
|
||||||
|
@@ -50,8 +50,7 @@ struct ExtraStationNameInfo {
|
|||||||
uint16_t flags;
|
uint16_t flags;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern std::array<ExtraStationNameInfo, MAX_EXTRA_STATION_NAMES> _extra_station_names;
|
extern std::vector<ExtraStationNameInfo> _extra_station_names;
|
||||||
extern uint _extra_station_names_used;
|
|
||||||
extern uint8_t _extra_station_names_probability;
|
extern uint8_t _extra_station_names_probability;
|
||||||
|
|
||||||
class FlowStatMap;
|
class FlowStatMap;
|
||||||
|
@@ -319,13 +319,13 @@ static StringID GenerateStationName(Station *st, TileIndex tile, StationNaming n
|
|||||||
return STR_SV_STNAME;
|
return STR_SV_STNAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool use_extra_names = _extra_station_names_used > 0;
|
bool use_extra_names = !_extra_station_names.empty();
|
||||||
auto check_extra_names = [&]() -> bool {
|
auto check_extra_names = [&]() -> bool {
|
||||||
if (use_extra_names) {
|
if (use_extra_names) {
|
||||||
use_extra_names = false;
|
use_extra_names = false;
|
||||||
const bool near_water = CountMapSquareAround(tile, CMSAWater) >= 5;
|
const bool near_water = CountMapSquareAround(tile, CMSAWater) >= 5;
|
||||||
std::vector<uint16_t> candidates;
|
std::vector<uint16_t> candidates;
|
||||||
for (uint i = 0; i < _extra_station_names_used; i++) {
|
for (size_t i = 0; i < _extra_station_names.size(); i++) {
|
||||||
const ExtraStationNameInfo &info = _extra_station_names[i];
|
const ExtraStationNameInfo &info = _extra_station_names[i];
|
||||||
if (extra_names[i]) continue;
|
if (extra_names[i]) continue;
|
||||||
if (!HasBit(info.flags, name_class)) continue;
|
if (!HasBit(info.flags, name_class)) continue;
|
||||||
@@ -333,7 +333,7 @@ static StringID GenerateStationName(Station *st, TileIndex tile, StationNaming n
|
|||||||
if (HasBit(info.flags, ESNIF_NOT_CENTRAL) && is_central) continue;
|
if (HasBit(info.flags, ESNIF_NOT_CENTRAL) && is_central) continue;
|
||||||
if (HasBit(info.flags, ESNIF_NEAR_WATER) && !near_water) continue;
|
if (HasBit(info.flags, ESNIF_NEAR_WATER) && !near_water) continue;
|
||||||
if (HasBit(info.flags, ESNIF_NOT_NEAR_WATER) && near_water) continue;
|
if (HasBit(info.flags, ESNIF_NOT_NEAR_WATER) && near_water) continue;
|
||||||
candidates.push_back(i);
|
candidates.push_back(static_cast<uint16_t>(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!candidates.empty()) {
|
if (!candidates.empty()) {
|
||||||
|
@@ -1957,7 +1957,7 @@ static void FormatString(StringBuilder builder, const char *str_arg, StringParam
|
|||||||
string_id = indsp->station_name;
|
string_id = indsp->station_name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (st->extra_name_index != UINT16_MAX && st->extra_name_index < _extra_station_names_used) {
|
if (st->extra_name_index != UINT16_MAX && st->extra_name_index < _extra_station_names.size()) {
|
||||||
string_id = _extra_station_names[st->extra_name_index].str;
|
string_id = _extra_station_names[st->extra_name_index].str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user