Merge branch 'master' into jgrpp
# Conflicts: # src/core/alloc_type.hpp # src/group_gui.cpp # src/newgrf.cpp # src/saveload/economy_sl.cpp # src/saveload/map_sl.cpp # src/station_cmd.cpp
This commit is contained in:
@@ -8534,7 +8534,7 @@ ERROR: IsEnd() is invalid as Begin() is never called
|
||||
19693 => 8
|
||||
|
||||
--TileList_IndustryProducing--
|
||||
Count(): 92
|
||||
Count(): 90
|
||||
Location ListDump:
|
||||
46919 => 1
|
||||
46918 => 1
|
||||
@@ -8626,8 +8626,6 @@ ERROR: IsEnd() is invalid as Begin() is never called
|
||||
44353 => 1
|
||||
44352 => 1
|
||||
44351 => 1
|
||||
46920 => 0
|
||||
46911 => 0
|
||||
|
||||
--TileList_StationType--
|
||||
Count(): 4
|
||||
|
@@ -32,11 +32,9 @@
|
||||
|
||||
void DrawEngineList(VehicleType type, int x, int r, int y, const GUIEngineList *eng_list, uint16 min, uint16 max, EngineID selected_id, bool show_count, GroupID selected_group);
|
||||
|
||||
static int CDECL EngineNumberSorter(const EngineID *a, const EngineID *b)
|
||||
static bool EngineNumberSorter(const EngineID &a, const EngineID &b)
|
||||
{
|
||||
int r = Engine::Get(*a)->list_position - Engine::Get(*b)->list_position;
|
||||
|
||||
return r;
|
||||
return Engine::Get(a)->list_position < Engine::Get(b)->list_position;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -34,6 +34,14 @@ public:
|
||||
this->h = 0;
|
||||
}
|
||||
|
||||
BitmapTileArea(const TileArea &ta)
|
||||
{
|
||||
this->tile = ta.tile;
|
||||
this->w = ta.w;
|
||||
this->h = ta.h;
|
||||
this->data.resize(Index(this->w, this->h));
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset and clear the BitmapTileArea.
|
||||
*/
|
||||
|
@@ -96,21 +96,21 @@ private:
|
||||
Scrollbar *vscroll;
|
||||
|
||||
/** Sort the bridges by their index */
|
||||
static int CDECL BridgeIndexSorter(const BuildBridgeData *a, const BuildBridgeData *b)
|
||||
static bool BridgeIndexSorter(const BuildBridgeData &a, const BuildBridgeData &b)
|
||||
{
|
||||
return a->index - b->index;
|
||||
return a.index < b.index;
|
||||
}
|
||||
|
||||
/** Sort the bridges by their price */
|
||||
static int CDECL BridgePriceSorter(const BuildBridgeData *a, const BuildBridgeData *b)
|
||||
static bool BridgePriceSorter(const BuildBridgeData &a, const BuildBridgeData &b)
|
||||
{
|
||||
return a->cost - b->cost;
|
||||
return a.cost < b.cost;
|
||||
}
|
||||
|
||||
/** Sort the bridges by their maximum speed */
|
||||
static int CDECL BridgeSpeedSorter(const BuildBridgeData *a, const BuildBridgeData *b)
|
||||
static bool BridgeSpeedSorter(const BuildBridgeData &a, const BuildBridgeData &b)
|
||||
{
|
||||
return a->spec->speed - b->spec->speed;
|
||||
return a.spec->speed < b.spec->speed;
|
||||
}
|
||||
|
||||
void BuildBridge(uint8 i)
|
||||
|
@@ -100,57 +100,54 @@ static CargoID _engine_sort_last_cargo_criteria[] = {CF_ANY, CF_ANY, CF_ANY, CF_
|
||||
|
||||
/**
|
||||
* Determines order of engines by engineID
|
||||
* @param *a first engine to compare
|
||||
* @param *b second engine to compare
|
||||
* @return for descending order: returns < 0 if a < b and > 0 for a > b. Vice versa for ascending order and 0 for equal
|
||||
* @param a first engine to compare
|
||||
* @param b second engine to compare
|
||||
* @return for descending order: returns true if a < b. Vice versa for ascending order
|
||||
*/
|
||||
static int CDECL EngineNumberSorter(const EngineID *a, const EngineID *b)
|
||||
static bool EngineNumberSorter(const EngineID &a, const EngineID &b)
|
||||
{
|
||||
int r = Engine::Get(*a)->list_position - Engine::Get(*b)->list_position;
|
||||
int r = Engine::Get(a)->list_position - Engine::Get(b)->list_position;
|
||||
|
||||
return _engine_sort_direction ? -r : r;
|
||||
return _engine_sort_direction ? r > 0 : r < 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines order of engines by introduction date
|
||||
* @param *a first engine to compare
|
||||
* @param *b second engine to compare
|
||||
* @return for descending order: returns < 0 if a < b and > 0 for a > b. Vice versa for ascending order and 0 for equal
|
||||
* @param a first engine to compare
|
||||
* @param b second engine to compare
|
||||
* @return for descending order: returns true if a < b. Vice versa for ascending order
|
||||
*/
|
||||
static int CDECL EngineIntroDateSorter(const EngineID *a, const EngineID *b)
|
||||
static bool EngineIntroDateSorter(const EngineID &a, const EngineID &b)
|
||||
{
|
||||
const int va = Engine::Get(*a)->intro_date;
|
||||
const int vb = Engine::Get(*b)->intro_date;
|
||||
const int va = Engine::Get(a)->intro_date;
|
||||
const int vb = Engine::Get(b)->intro_date;
|
||||
const int r = va - vb;
|
||||
|
||||
/* Use EngineID to sort instead since we want consistent sorting */
|
||||
if (r == 0) return EngineNumberSorter(a, b);
|
||||
return _engine_sort_direction ? -r : r;
|
||||
return _engine_sort_direction ? r > 0 : r < 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines order of engines by name
|
||||
* @param *a first engine to compare
|
||||
* @param *b second engine to compare
|
||||
* @return for descending order: returns < 0 if a < b and > 0 for a > b. Vice versa for ascending order and 0 for equal
|
||||
* @param a first engine to compare
|
||||
* @param b second engine to compare
|
||||
* @return for descending order: returns true if a < b. Vice versa for ascending order
|
||||
*/
|
||||
static int CDECL EngineNameSorter(const EngineID *a, const EngineID *b)
|
||||
static bool EngineNameSorter(const EngineID &a, const EngineID &b)
|
||||
{
|
||||
static EngineID last_engine[2] = { INVALID_ENGINE, INVALID_ENGINE };
|
||||
static char last_name[2][64] = { "\0", "\0" };
|
||||
|
||||
const EngineID va = *a;
|
||||
const EngineID vb = *b;
|
||||
|
||||
if (va != last_engine[0]) {
|
||||
last_engine[0] = va;
|
||||
SetDParam(0, va);
|
||||
if (a != last_engine[0]) {
|
||||
last_engine[0] = a;
|
||||
SetDParam(0, a);
|
||||
GetString(last_name[0], STR_ENGINE_NAME, lastof(last_name[0]));
|
||||
}
|
||||
|
||||
if (vb != last_engine[1]) {
|
||||
last_engine[1] = vb;
|
||||
SetDParam(0, vb);
|
||||
if (b != last_engine[1]) {
|
||||
last_engine[1] = b;
|
||||
SetDParam(0, b);
|
||||
GetString(last_name[1], STR_ENGINE_NAME, lastof(last_name[1]));
|
||||
}
|
||||
|
||||
@@ -158,121 +155,121 @@ static int CDECL EngineNameSorter(const EngineID *a, const EngineID *b)
|
||||
|
||||
/* Use EngineID to sort instead since we want consistent sorting */
|
||||
if (r == 0) return EngineNumberSorter(a, b);
|
||||
return _engine_sort_direction ? -r : r;
|
||||
return _engine_sort_direction ? r > 0 : r < 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines order of engines by reliability
|
||||
* @param *a first engine to compare
|
||||
* @param *b second engine to compare
|
||||
* @return for descending order: returns < 0 if a < b and > 0 for a > b. Vice versa for ascending order and 0 for equal
|
||||
* @param a first engine to compare
|
||||
* @param b second engine to compare
|
||||
* @return for descending order: returns true if a < b. Vice versa for ascending order
|
||||
*/
|
||||
static int CDECL EngineReliabilitySorter(const EngineID *a, const EngineID *b)
|
||||
static bool EngineReliabilitySorter(const EngineID &a, const EngineID &b)
|
||||
{
|
||||
const int va = Engine::Get(*a)->reliability;
|
||||
const int vb = Engine::Get(*b)->reliability;
|
||||
const int va = Engine::Get(a)->reliability;
|
||||
const int vb = Engine::Get(b)->reliability;
|
||||
const int r = va - vb;
|
||||
|
||||
/* Use EngineID to sort instead since we want consistent sorting */
|
||||
if (r == 0) return EngineNumberSorter(a, b);
|
||||
return _engine_sort_direction ? -r : r;
|
||||
return _engine_sort_direction ? r > 0 : r < 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines order of engines by purchase cost
|
||||
* @param *a first engine to compare
|
||||
* @param *b second engine to compare
|
||||
* @return for descending order: returns < 0 if a < b and > 0 for a > b. Vice versa for ascending order and 0 for equal
|
||||
* @param a first engine to compare
|
||||
* @param b second engine to compare
|
||||
* @return for descending order: returns true if a < b. Vice versa for ascending order
|
||||
*/
|
||||
static int CDECL EngineCostSorter(const EngineID *a, const EngineID *b)
|
||||
static bool EngineCostSorter(const EngineID &a, const EngineID &b)
|
||||
{
|
||||
Money va = Engine::Get(*a)->GetCost();
|
||||
Money vb = Engine::Get(*b)->GetCost();
|
||||
Money va = Engine::Get(a)->GetCost();
|
||||
Money vb = Engine::Get(b)->GetCost();
|
||||
int r = ClampToI32(va - vb);
|
||||
|
||||
/* Use EngineID to sort instead since we want consistent sorting */
|
||||
if (r == 0) return EngineNumberSorter(a, b);
|
||||
return _engine_sort_direction ? -r : r;
|
||||
return _engine_sort_direction ? r > 0 : r < 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines order of engines by speed
|
||||
* @param *a first engine to compare
|
||||
* @param *b second engine to compare
|
||||
* @return for descending order: returns < 0 if a < b and > 0 for a > b. Vice versa for ascending order and 0 for equal
|
||||
* @param a first engine to compare
|
||||
* @param b second engine to compare
|
||||
* @return for descending order: returns true if a < b. Vice versa for ascending order
|
||||
*/
|
||||
static int CDECL EngineSpeedSorter(const EngineID *a, const EngineID *b)
|
||||
static bool EngineSpeedSorter(const EngineID &a, const EngineID &b)
|
||||
{
|
||||
int va = Engine::Get(*a)->GetDisplayMaxSpeed();
|
||||
int vb = Engine::Get(*b)->GetDisplayMaxSpeed();
|
||||
int va = Engine::Get(a)->GetDisplayMaxSpeed();
|
||||
int vb = Engine::Get(b)->GetDisplayMaxSpeed();
|
||||
int r = va - vb;
|
||||
|
||||
/* Use EngineID to sort instead since we want consistent sorting */
|
||||
if (r == 0) return EngineNumberSorter(a, b);
|
||||
return _engine_sort_direction ? -r : r;
|
||||
return _engine_sort_direction ? r > 0 : r < 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines order of engines by power
|
||||
* @param *a first engine to compare
|
||||
* @param *b second engine to compare
|
||||
* @return for descending order: returns < 0 if a < b and > 0 for a > b. Vice versa for ascending order and 0 for equal
|
||||
* @param a first engine to compare
|
||||
* @param b second engine to compare
|
||||
* @return for descending order: returns true if a < b. Vice versa for ascending order
|
||||
*/
|
||||
static int CDECL EnginePowerSorter(const EngineID *a, const EngineID *b)
|
||||
static bool EnginePowerSorter(const EngineID &a, const EngineID &b)
|
||||
{
|
||||
int va = Engine::Get(*a)->GetPower();
|
||||
int vb = Engine::Get(*b)->GetPower();
|
||||
int va = Engine::Get(a)->GetPower();
|
||||
int vb = Engine::Get(b)->GetPower();
|
||||
int r = va - vb;
|
||||
|
||||
/* Use EngineID to sort instead since we want consistent sorting */
|
||||
if (r == 0) return EngineNumberSorter(a, b);
|
||||
return _engine_sort_direction ? -r : r;
|
||||
return _engine_sort_direction ? r > 0 : r < 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines order of engines by tractive effort
|
||||
* @param *a first engine to compare
|
||||
* @param *b second engine to compare
|
||||
* @return for descending order: returns < 0 if a < b and > 0 for a > b. Vice versa for ascending order and 0 for equal
|
||||
* @param a first engine to compare
|
||||
* @param b second engine to compare
|
||||
* @return for descending order: returns true if a < b. Vice versa for ascending order
|
||||
*/
|
||||
static int CDECL EngineTractiveEffortSorter(const EngineID *a, const EngineID *b)
|
||||
static bool EngineTractiveEffortSorter(const EngineID &a, const EngineID &b)
|
||||
{
|
||||
int va = Engine::Get(*a)->GetDisplayMaxTractiveEffort();
|
||||
int vb = Engine::Get(*b)->GetDisplayMaxTractiveEffort();
|
||||
int va = Engine::Get(a)->GetDisplayMaxTractiveEffort();
|
||||
int vb = Engine::Get(b)->GetDisplayMaxTractiveEffort();
|
||||
int r = va - vb;
|
||||
|
||||
/* Use EngineID to sort instead since we want consistent sorting */
|
||||
if (r == 0) return EngineNumberSorter(a, b);
|
||||
return _engine_sort_direction ? -r : r;
|
||||
return _engine_sort_direction ? r > 0 : r < 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines order of engines by running costs
|
||||
* @param *a first engine to compare
|
||||
* @param *b second engine to compare
|
||||
* @return for descending order: returns < 0 if a < b and > 0 for a > b. Vice versa for ascending order and 0 for equal
|
||||
* @param a first engine to compare
|
||||
* @param b second engine to compare
|
||||
* @return for descending order: returns true if a < b. Vice versa for ascending order
|
||||
*/
|
||||
static int CDECL EngineRunningCostSorter(const EngineID *a, const EngineID *b)
|
||||
static bool EngineRunningCostSorter(const EngineID &a, const EngineID &b)
|
||||
{
|
||||
Money va = Engine::Get(*a)->GetRunningCost();
|
||||
Money vb = Engine::Get(*b)->GetRunningCost();
|
||||
Money va = Engine::Get(a)->GetRunningCost();
|
||||
Money vb = Engine::Get(b)->GetRunningCost();
|
||||
int r = ClampToI32(va - vb);
|
||||
|
||||
/* Use EngineID to sort instead since we want consistent sorting */
|
||||
if (r == 0) return EngineNumberSorter(a, b);
|
||||
return _engine_sort_direction ? -r : r;
|
||||
return _engine_sort_direction ? r > 0 : r < 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines order of engines by running costs
|
||||
* @param *a first engine to compare
|
||||
* @param *b second engine to compare
|
||||
* @return for descending order: returns < 0 if a < b and > 0 for a > b. Vice versa for ascending order and 0 for equal
|
||||
* @param a first engine to compare
|
||||
* @param b second engine to compare
|
||||
* @return for descending order: returns true if a < b. Vice versa for ascending order
|
||||
*/
|
||||
static int CDECL EnginePowerVsRunningCostSorter(const EngineID *a, const EngineID *b)
|
||||
static bool EnginePowerVsRunningCostSorter(const EngineID &a, const EngineID &b)
|
||||
{
|
||||
const Engine *e_a = Engine::Get(*a);
|
||||
const Engine *e_b = Engine::Get(*b);
|
||||
const Engine *e_a = Engine::Get(a);
|
||||
const Engine *e_b = Engine::Get(b);
|
||||
|
||||
/* Here we are using a few tricks to get the right sort.
|
||||
* We want power/running cost, but since we usually got higher running cost than power and we store the result in an int,
|
||||
@@ -286,79 +283,79 @@ static int CDECL EnginePowerVsRunningCostSorter(const EngineID *a, const EngineI
|
||||
|
||||
/* Use EngineID to sort instead since we want consistent sorting */
|
||||
if (r == 0) return EngineNumberSorter(a, b);
|
||||
return _engine_sort_direction ? -r : r;
|
||||
return _engine_sort_direction ? r > 0 : r < 0;
|
||||
}
|
||||
|
||||
/* Train sorting functions */
|
||||
|
||||
/**
|
||||
* Determines order of train engines by capacity
|
||||
* @param *a first engine to compare
|
||||
* @param *b second engine to compare
|
||||
* @return for descending order: returns < 0 if a < b and > 0 for a > b. Vice versa for ascending order and 0 for equal
|
||||
* @param a first engine to compare
|
||||
* @param b second engine to compare
|
||||
* @return for descending order: returns true if a < b. Vice versa for ascending order
|
||||
*/
|
||||
static int CDECL TrainEngineCapacitySorter(const EngineID *a, const EngineID *b)
|
||||
static bool TrainEngineCapacitySorter(const EngineID &a, const EngineID &b)
|
||||
{
|
||||
const RailVehicleInfo *rvi_a = RailVehInfo(*a);
|
||||
const RailVehicleInfo *rvi_b = RailVehInfo(*b);
|
||||
const RailVehicleInfo *rvi_a = RailVehInfo(a);
|
||||
const RailVehicleInfo *rvi_b = RailVehInfo(b);
|
||||
|
||||
int va = GetTotalCapacityOfArticulatedParts(*a) * (rvi_a->railveh_type == RAILVEH_MULTIHEAD ? 2 : 1);
|
||||
int vb = GetTotalCapacityOfArticulatedParts(*b) * (rvi_b->railveh_type == RAILVEH_MULTIHEAD ? 2 : 1);
|
||||
int va = GetTotalCapacityOfArticulatedParts(a) * (rvi_a->railveh_type == RAILVEH_MULTIHEAD ? 2 : 1);
|
||||
int vb = GetTotalCapacityOfArticulatedParts(b) * (rvi_b->railveh_type == RAILVEH_MULTIHEAD ? 2 : 1);
|
||||
int r = va - vb;
|
||||
|
||||
/* Use EngineID to sort instead since we want consistent sorting */
|
||||
if (r == 0) return EngineNumberSorter(a, b);
|
||||
return _engine_sort_direction ? -r : r;
|
||||
return _engine_sort_direction ? r > 0 : r < 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines order of train engines by engine / wagon
|
||||
* @param *a first engine to compare
|
||||
* @param *b second engine to compare
|
||||
* @return for descending order: returns < 0 if a < b and > 0 for a > b. Vice versa for ascending order and 0 for equal
|
||||
* @param a first engine to compare
|
||||
* @param b second engine to compare
|
||||
* @return for descending order: returns true if a < b. Vice versa for ascending order
|
||||
*/
|
||||
static int CDECL TrainEnginesThenWagonsSorter(const EngineID *a, const EngineID *b)
|
||||
static bool TrainEnginesThenWagonsSorter(const EngineID &a, const EngineID &b)
|
||||
{
|
||||
int val_a = (RailVehInfo(*a)->railveh_type == RAILVEH_WAGON ? 1 : 0);
|
||||
int val_b = (RailVehInfo(*b)->railveh_type == RAILVEH_WAGON ? 1 : 0);
|
||||
int val_a = (RailVehInfo(a)->railveh_type == RAILVEH_WAGON ? 1 : 0);
|
||||
int val_b = (RailVehInfo(b)->railveh_type == RAILVEH_WAGON ? 1 : 0);
|
||||
int r = val_a - val_b;
|
||||
|
||||
/* Use EngineID to sort instead since we want consistent sorting */
|
||||
if (r == 0) return EngineNumberSorter(a, b);
|
||||
return _engine_sort_direction ? -r : r;
|
||||
return _engine_sort_direction ? r > 0 : r < 0;
|
||||
}
|
||||
|
||||
/* Road vehicle sorting functions */
|
||||
|
||||
/**
|
||||
* Determines order of road vehicles by capacity
|
||||
* @param *a first engine to compare
|
||||
* @param *b second engine to compare
|
||||
* @return for descending order: returns < 0 if a < b and > 0 for a > b. Vice versa for ascending order and 0 for equal
|
||||
* @param a first engine to compare
|
||||
* @param b second engine to compare
|
||||
* @return for descending order: returns true if a < b. Vice versa for ascending order
|
||||
*/
|
||||
static int CDECL RoadVehEngineCapacitySorter(const EngineID *a, const EngineID *b)
|
||||
static bool RoadVehEngineCapacitySorter(const EngineID &a, const EngineID &b)
|
||||
{
|
||||
int va = GetTotalCapacityOfArticulatedParts(*a);
|
||||
int vb = GetTotalCapacityOfArticulatedParts(*b);
|
||||
int va = GetTotalCapacityOfArticulatedParts(a);
|
||||
int vb = GetTotalCapacityOfArticulatedParts(b);
|
||||
int r = va - vb;
|
||||
|
||||
/* Use EngineID to sort instead since we want consistent sorting */
|
||||
if (r == 0) return EngineNumberSorter(a, b);
|
||||
return _engine_sort_direction ? -r : r;
|
||||
return _engine_sort_direction ? r > 0 : r < 0;
|
||||
}
|
||||
|
||||
/* Ship vehicle sorting functions */
|
||||
|
||||
/**
|
||||
* Determines order of ships by capacity
|
||||
* @param *a first engine to compare
|
||||
* @param *b second engine to compare
|
||||
* @return for descending order: returns < 0 if a < b and > 0 for a > b. Vice versa for ascending order and 0 for equal
|
||||
* @param a first engine to compare
|
||||
* @param b second engine to compare
|
||||
* @return for descending order: returns true if a < b. Vice versa for ascending order
|
||||
*/
|
||||
static int CDECL ShipEngineCapacitySorter(const EngineID *a, const EngineID *b)
|
||||
static bool ShipEngineCapacitySorter(const EngineID &a, const EngineID &b)
|
||||
{
|
||||
const Engine *e_a = Engine::Get(*a);
|
||||
const Engine *e_b = Engine::Get(*b);
|
||||
const Engine *e_a = Engine::Get(a);
|
||||
const Engine *e_b = Engine::Get(b);
|
||||
|
||||
int va = e_a->GetDisplayDefaultCapacity();
|
||||
int vb = e_b->GetDisplayDefaultCapacity();
|
||||
@@ -366,21 +363,21 @@ static int CDECL ShipEngineCapacitySorter(const EngineID *a, const EngineID *b)
|
||||
|
||||
/* Use EngineID to sort instead since we want consistent sorting */
|
||||
if (r == 0) return EngineNumberSorter(a, b);
|
||||
return _engine_sort_direction ? -r : r;
|
||||
return _engine_sort_direction ? r > 0 : r < 0;
|
||||
}
|
||||
|
||||
/* Aircraft sorting functions */
|
||||
|
||||
/**
|
||||
* Determines order of aircraft by cargo
|
||||
* @param *a first engine to compare
|
||||
* @param *b second engine to compare
|
||||
* @return for descending order: returns < 0 if a < b and > 0 for a > b. Vice versa for ascending order and 0 for equal
|
||||
* @param a first engine to compare
|
||||
* @param b second engine to compare
|
||||
* @return for descending order: returns true if a < b. Vice versa for ascending order
|
||||
*/
|
||||
static int CDECL AircraftEngineCargoSorter(const EngineID *a, const EngineID *b)
|
||||
static bool AircraftEngineCargoSorter(const EngineID &a, const EngineID &b)
|
||||
{
|
||||
const Engine *e_a = Engine::Get(*a);
|
||||
const Engine *e_b = Engine::Get(*b);
|
||||
const Engine *e_a = Engine::Get(a);
|
||||
const Engine *e_b = Engine::Get(b);
|
||||
|
||||
uint16 mail_a, mail_b;
|
||||
int va = e_a->GetDisplayDefaultCapacity(&mail_a);
|
||||
@@ -396,25 +393,25 @@ static int CDECL AircraftEngineCargoSorter(const EngineID *a, const EngineID *b)
|
||||
return EngineNumberSorter(a, b);
|
||||
}
|
||||
}
|
||||
return _engine_sort_direction ? -r : r;
|
||||
return _engine_sort_direction ? r > 0 : r < 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines order of aircraft by range.
|
||||
* @param *a first engine to compare.
|
||||
* @param *b second engine to compare.
|
||||
* @return for descending order: returns < 0 if a < b and > 0 for a > b. Vice versa for ascending order and 0 for equal.
|
||||
* @param a first engine to compare
|
||||
* @param b second engine to compare
|
||||
* @return for descending order: returns true if a < b. Vice versa for ascending order
|
||||
*/
|
||||
static int CDECL AircraftRangeSorter(const EngineID *a, const EngineID *b)
|
||||
static bool AircraftRangeSorter(const EngineID &a, const EngineID &b)
|
||||
{
|
||||
uint16 r_a = Engine::Get(*a)->GetRange();
|
||||
uint16 r_b = Engine::Get(*b)->GetRange();
|
||||
uint16 r_a = Engine::Get(a)->GetRange();
|
||||
uint16 r_b = Engine::Get(b)->GetRange();
|
||||
|
||||
int r = r_a - r_b;
|
||||
|
||||
/* Use EngineID to sort instead since we want consistent sorting */
|
||||
if (r == 0) return EngineNumberSorter(a, b);
|
||||
return _engine_sort_direction ? -r : r;
|
||||
return _engine_sort_direction ? r > 0 : r < 0;
|
||||
}
|
||||
|
||||
/** Sort functions for the vehicle sort criteria, for each vehicle type. */
|
||||
|
@@ -620,26 +620,26 @@ private:
|
||||
ShowDropDownList(this, std::move(list), sel, widget);
|
||||
}
|
||||
|
||||
static int CDECL GroupNameSorter(const Group * const *a, const Group * const *b)
|
||||
static bool GroupNameSorter(const Group * const &a, const Group * const &b)
|
||||
{
|
||||
static const Group *last_group[2] = { nullptr, nullptr };
|
||||
static char last_name[2][64] = { "", "" };
|
||||
|
||||
if (*a != last_group[0]) {
|
||||
last_group[0] = *a;
|
||||
SetDParam(0, (*a)->index);
|
||||
if (a != last_group[0]) {
|
||||
last_group[0] = a;
|
||||
SetDParam(0, a->index);
|
||||
GetString(last_name[0], STR_GROUP_NAME, lastof(last_name[0]));
|
||||
}
|
||||
|
||||
if (*b != last_group[1]) {
|
||||
last_group[1] = *b;
|
||||
SetDParam(0, (*b)->index);
|
||||
if (b != last_group[1]) {
|
||||
last_group[1] = b;
|
||||
SetDParam(0, b->index);
|
||||
GetString(last_name[1], STR_GROUP_NAME, lastof(last_name[1]));
|
||||
}
|
||||
|
||||
int r = strnatcmp(last_name[0], last_name[1]); // Sort by name (natural sorting).
|
||||
if (r == 0) return (*a)->index - (*b)->index;
|
||||
return r;
|
||||
if (r == 0) return a->index < b->index;
|
||||
return r < 0;
|
||||
}
|
||||
|
||||
void AddChildren(GUIGroupList *source, GroupID parent, int indent)
|
||||
|
@@ -14,49 +14,6 @@
|
||||
|
||||
#include "alloc_func.hpp"
|
||||
|
||||
/**
|
||||
* A small 'wrapper' for allocations that can be done on most OSes on the
|
||||
* stack, but are just too large to fit in the stack on devices with a small
|
||||
* stack such as the NDS.
|
||||
* So when it is possible a stack allocation is made, otherwise a heap
|
||||
* allocation is made and this is freed once the struct goes out of scope.
|
||||
* @param T the type to make the allocation for
|
||||
* @param length the amount of items to allocate
|
||||
*/
|
||||
template <typename T, size_t length>
|
||||
struct SmallStackSafeStackAlloc {
|
||||
/** Storing the data on the stack */
|
||||
T data[length];
|
||||
|
||||
/**
|
||||
* Gets a pointer to the data stored in this wrapper.
|
||||
* @return the pointer.
|
||||
*/
|
||||
inline operator T *()
|
||||
{
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a pointer to the data stored in this wrapper.
|
||||
* @return the pointer.
|
||||
*/
|
||||
inline T *operator -> ()
|
||||
{
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a pointer to the last data element stored in this wrapper.
|
||||
* @note needed because endof does not work properly for pointers.
|
||||
* @return the 'endof' pointer.
|
||||
*/
|
||||
inline T *EndOf()
|
||||
{
|
||||
return endof(data);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* A reusable buffer that can be used for places that temporary allocate
|
||||
* a bit of memory and do that very often, or for places where static
|
||||
@@ -160,50 +117,9 @@ public:
|
||||
inline void operator delete[](void *ptr) { free(ptr); }
|
||||
};
|
||||
|
||||
/**
|
||||
* A smart pointer class that free()'s the pointer on destruction.
|
||||
* @tparam T Storage type.
|
||||
*/
|
||||
template <typename T>
|
||||
class AutoFreePtr
|
||||
struct FreeDeleter
|
||||
{
|
||||
T *ptr = nullptr; ///< Stored pointer.
|
||||
|
||||
public:
|
||||
AutoFreePtr(T *ptr) : ptr(ptr) {}
|
||||
~AutoFreePtr() { free(this->ptr); }
|
||||
|
||||
/**
|
||||
* Take ownership of a new pointer and free the old one if needed.
|
||||
* @param ptr NEw pointer.
|
||||
*/
|
||||
inline void Assign(T *ptr)
|
||||
{
|
||||
free(this->ptr);
|
||||
this->ptr = ptr;
|
||||
}
|
||||
|
||||
/** Dereference pointer. */
|
||||
inline T *operator ->() { return this->ptr; }
|
||||
/** Dereference pointer. */
|
||||
inline const T *operator ->() const { return this->ptr; }
|
||||
|
||||
/** Cast to underlaying regular pointer. */
|
||||
inline operator T *() { return this->ptr; }
|
||||
/** Cast to underlaying regular pointer. */
|
||||
inline operator const T *() const { return this->ptr; }
|
||||
|
||||
AutoFreePtr(AutoFreePtr<T> &&other) noexcept
|
||||
{
|
||||
*this = std::move(other);
|
||||
}
|
||||
|
||||
AutoFreePtr& operator=(AutoFreePtr<T> &&other) noexcept
|
||||
{
|
||||
this->Assign(other.ptr);
|
||||
other.ptr = nullptr;
|
||||
return *this;
|
||||
}
|
||||
void operator()(const void* ptr) { free(ptr); }
|
||||
};
|
||||
|
||||
#endif /* ALLOC_TYPE_HPP */
|
||||
|
@@ -164,16 +164,6 @@ struct SmallMap : std::vector<SmallPair<T, U> > {
|
||||
n.first = key;
|
||||
return n.second;
|
||||
}
|
||||
|
||||
inline void SortByKey()
|
||||
{
|
||||
QSortT(std::vector<Pair>::data(), std::vector<Pair>::size(), KeySorter);
|
||||
}
|
||||
|
||||
static int CDECL KeySorter(const Pair *a, const Pair *b)
|
||||
{
|
||||
return a->first - b->first;
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* SMALLMAP_TYPE_HPP */
|
||||
|
@@ -325,11 +325,8 @@ void DrawVehicleEngine(int left, int right, int preferred_x, int y, EngineID eng
|
||||
*/
|
||||
void EngList_Sort(GUIEngineList *el, EngList_SortTypeFunction compare)
|
||||
{
|
||||
size_t size = el->size();
|
||||
/* out-of-bounds access at the next line for size == 0 (even with operator[] at some systems)
|
||||
* generally, do not sort if there are less than 2 items */
|
||||
if (size < 2) return;
|
||||
QSortT(el->data(), size, compare);
|
||||
if (el->size() < 2) return;
|
||||
std::sort(el->begin(), el->end(), compare);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -344,6 +341,6 @@ void EngList_SortPartial(GUIEngineList *el, EngList_SortTypeFunction compare, ui
|
||||
if (num_items < 2) return;
|
||||
assert(begin < el->size());
|
||||
assert(begin + num_items <= el->size());
|
||||
QSortT(el->data() + begin, num_items, compare);
|
||||
std::sort(el->begin() + begin, el->begin() + begin + num_items, compare);
|
||||
}
|
||||
|
||||
|
@@ -19,7 +19,7 @@
|
||||
|
||||
typedef GUIList<EngineID, CargoID> GUIEngineList;
|
||||
|
||||
typedef int CDECL EngList_SortTypeFunction(const EngineID*, const EngineID*); ///< argument type for #EngList_Sort.
|
||||
typedef bool EngList_SortTypeFunction(const EngineID&, const EngineID&); ///< argument type for #EngList_Sort.
|
||||
void EngList_Sort(GUIEngineList *el, EngList_SortTypeFunction compare);
|
||||
void EngList_SortPartial(GUIEngineList *el, EngList_SortTypeFunction compare, uint begin, uint num_items);
|
||||
|
||||
|
21
src/fios.cpp
21
src/fios.cpp
@@ -47,21 +47,20 @@ extern void GetOldSaveGameName(const char *file, char *title, const char *last);
|
||||
|
||||
/**
|
||||
* Compare two FiosItem's. Used with sort when sorting the file list.
|
||||
* @param da A pointer to the first FiosItem to compare.
|
||||
* @param db A pointer to the second FiosItem to compare.
|
||||
* @return -1, 0 or 1, depending on how the two items should be sorted.
|
||||
* @param other The FiosItem to compare to.
|
||||
* @return for ascending order: returns true if da < db. Vice versa for descending order.
|
||||
*/
|
||||
int CDECL CompareFiosItems(const FiosItem *da, const FiosItem *db)
|
||||
bool FiosItem::operator< (const FiosItem &other) const
|
||||
{
|
||||
int r = 0;
|
||||
bool r = false;
|
||||
|
||||
if ((_savegame_sort_order & SORT_BY_NAME) == 0 && da->mtime != db->mtime) {
|
||||
r = da->mtime < db->mtime ? -1 : 1;
|
||||
if ((_savegame_sort_order & SORT_BY_NAME) == 0 && (*this).mtime != other.mtime) {
|
||||
r = (*this).mtime < other.mtime;
|
||||
} else {
|
||||
r = strcasecmp(da->title, db->title);
|
||||
r = strcasecmp((*this).title, other.title) < 0;
|
||||
}
|
||||
|
||||
if (_savegame_sort_order & SORT_DESCENDING) r = -r;
|
||||
if (_savegame_sort_order & SORT_DESCENDING) r = !r;
|
||||
return r;
|
||||
}
|
||||
|
||||
@@ -380,7 +379,7 @@ static void FiosGetFileList(SaveLoadOperation fop, fios_getlist_callback_proc *c
|
||||
{
|
||||
SortingBits order = _savegame_sort_order;
|
||||
_savegame_sort_order = SORT_BY_NAME | SORT_ASCENDING;
|
||||
QSortT(file_list.files.data(), file_list.files.size(), CompareFiosItems);
|
||||
std::sort(file_list.files.begin(), file_list.files.end());
|
||||
_savegame_sort_order = order;
|
||||
}
|
||||
|
||||
@@ -395,7 +394,7 @@ static void FiosGetFileList(SaveLoadOperation fop, fios_getlist_callback_proc *c
|
||||
scanner.Scan(nullptr, subdir, true, true);
|
||||
}
|
||||
|
||||
QSortT(file_list.Get(sort_start), file_list.Length() - sort_start, CompareFiosItems);
|
||||
std::sort(file_list.files.begin() + sort_start, file_list.files.end());
|
||||
|
||||
/* Show drives */
|
||||
FiosGetDrives(file_list);
|
||||
|
@@ -109,6 +109,7 @@ struct FiosItem {
|
||||
uint64 mtime;
|
||||
char title[64];
|
||||
char name[MAX_PATH];
|
||||
bool operator< (const FiosItem &other) const;
|
||||
};
|
||||
|
||||
/** List of file information. */
|
||||
@@ -229,6 +230,4 @@ void FiosMakeSavegameName(char *buf, const char *name, const char *last);
|
||||
|
||||
FiosType FiosGetSavegameListCallback(SaveLoadOperation fop, const char *file, const char *ext, char *title, const char *last);
|
||||
|
||||
int CDECL CompareFiosItems(const FiosItem *a, const FiosItem *b);
|
||||
|
||||
#endif /* FIOS_H */
|
||||
|
@@ -260,8 +260,7 @@ static void SortSaveGameList(FileList &file_list)
|
||||
}
|
||||
}
|
||||
|
||||
size_t s_amount = file_list.Length() - sort_start - sort_end;
|
||||
QSortT(file_list.Get(sort_start), s_amount, CompareFiosItems);
|
||||
std::sort(file_list.files.begin() + sort_start, file_list.files.end() - sort_end);
|
||||
}
|
||||
|
||||
void SaveGameConfirmationCallback(Window *w, bool confirmed);
|
||||
|
@@ -1148,9 +1148,9 @@ private:
|
||||
}
|
||||
|
||||
/** Sort the company league by performance history */
|
||||
static int CDECL PerformanceSorter(const Company * const *c1, const Company * const *c2)
|
||||
static bool PerformanceSorter(const Company * const &c1, const Company * const &c2)
|
||||
{
|
||||
return (*c2)->old_economy[0].performance_history - (*c1)->old_economy[0].performance_history;
|
||||
return c2->old_economy[0].performance_history < c1->old_economy[0].performance_history;
|
||||
}
|
||||
|
||||
public:
|
||||
|
@@ -105,26 +105,26 @@ static const NWidgetPart _nested_group_widgets[] = {
|
||||
};
|
||||
|
||||
/** Sort the groups by their name */
|
||||
int CDECL GroupNameSorter(const Group * const *a, const Group * const *b)
|
||||
bool GroupNameSorter(const Group * const &a, const Group * const &b)
|
||||
{
|
||||
static const Group *last_group[2] = { nullptr, nullptr };
|
||||
static char last_name[2][64] = { "", "" };
|
||||
|
||||
if (*a != last_group[0]) {
|
||||
last_group[0] = *a;
|
||||
SetDParam(0, (*a)->index);
|
||||
if (a != last_group[0]) {
|
||||
last_group[0] = a;
|
||||
SetDParam(0, a->index);
|
||||
GetString(last_name[0], STR_GROUP_NAME, lastof(last_name[0]));
|
||||
}
|
||||
|
||||
if (*b != last_group[1]) {
|
||||
last_group[1] = *b;
|
||||
SetDParam(0, (*b)->index);
|
||||
if (b != last_group[1]) {
|
||||
last_group[1] = b;
|
||||
SetDParam(0, b->index);
|
||||
GetString(last_name[1], STR_GROUP_NAME, lastof(last_name[1]));
|
||||
}
|
||||
|
||||
int r = strnatcmp(last_name[0], last_name[1]); // Sort by name (natural sorting).
|
||||
if (r == 0) return (*a)->index - (*b)->index;
|
||||
return r;
|
||||
if (r == 0) return a->index < b->index;
|
||||
return r < 0;
|
||||
}
|
||||
|
||||
class VehicleGroupWindow : public BaseVehicleListWindow {
|
||||
|
@@ -157,8 +157,7 @@ Industry::~Industry()
|
||||
}
|
||||
|
||||
if (GetIndustrySpec(this->type)->behaviour & INDUSTRYBEH_PLANT_FIELDS) {
|
||||
TileArea ta(this->location.tile - TileDiffXY(min(TileX(this->location.tile), 21), min(TileY(this->location.tile), 21)), 42, 42);
|
||||
ta.ClampToMap();
|
||||
TileArea ta = TileArea(this->location.tile, 0, 0).Expand(21);
|
||||
|
||||
/* Remove the farmland and convert it to regular tiles over time. */
|
||||
TILE_AREA_LOOP(tile_cur, ta) {
|
||||
@@ -1541,6 +1540,8 @@ static bool CheckIfCanLevelIndustryPlatform(TileIndex tile, DoCommandFlag flags,
|
||||
/* Check that all tiles in area and surrounding are clear
|
||||
* this determines that there are no obstructing items */
|
||||
|
||||
/* TileArea::Expand is not used here as we need to abort
|
||||
* instead of clamping if the bounds cannot expanded. */
|
||||
TileArea ta(tile + TileDiffXY(-_settings_game.construction.industry_platform, -_settings_game.construction.industry_platform),
|
||||
max_x + 2 + 2 * _settings_game.construction.industry_platform, max_y + 2 + 2 * _settings_game.construction.industry_platform);
|
||||
|
||||
@@ -1601,9 +1602,7 @@ static CommandCost CheckIfFarEnoughFromConflictingIndustry(TileIndex tile, int t
|
||||
/* On a large map with many industries, it may be faster to check an area. */
|
||||
static const int dmax = 14;
|
||||
if (Industry::GetNumItems() > (size_t) (dmax * dmax * 2)) {
|
||||
const int tx = TileX(tile);
|
||||
const int ty = TileY(tile);
|
||||
TileArea tile_area = TileArea(TileXY(max(0, tx - dmax), max(0, ty - dmax)), TileXY(min(MapMaxX(), tx + dmax), min(MapMaxY(), ty + dmax)));
|
||||
TileArea tile_area = TileArea(tile, 1, 1).Expand(dmax);
|
||||
TILE_AREA_LOOP(atile, tile_area) {
|
||||
if (GetTileType(atile) == MP_INDUSTRY) {
|
||||
const Industry *i2 = Industry::GetByTile(atile);
|
||||
|
@@ -1252,52 +1252,52 @@ protected:
|
||||
}
|
||||
|
||||
/** Sort industries by name */
|
||||
static int CDECL IndustryNameSorter(const Industry * const *a, const Industry * const *b)
|
||||
static bool IndustryNameSorter(const Industry * const &a, const Industry * const &b)
|
||||
{
|
||||
static char buf_cache[96];
|
||||
static char buf[96];
|
||||
|
||||
SetDParam(0, (*a)->index);
|
||||
SetDParam(0, a->index);
|
||||
GetString(buf, STR_INDUSTRY_NAME, lastof(buf));
|
||||
|
||||
if (*b != last_industry) {
|
||||
last_industry = *b;
|
||||
SetDParam(0, (*b)->index);
|
||||
if (b != last_industry) {
|
||||
last_industry = b;
|
||||
SetDParam(0, b->index);
|
||||
GetString(buf_cache, STR_INDUSTRY_NAME, lastof(buf_cache));
|
||||
}
|
||||
|
||||
return strnatcmp(buf, buf_cache); // Sort by name (natural sorting).
|
||||
return strnatcmp(buf, buf_cache) < 0; // Sort by name (natural sorting).
|
||||
}
|
||||
|
||||
/** Sort industries by type and name */
|
||||
static int CDECL IndustryTypeSorter(const Industry * const *a, const Industry * const *b)
|
||||
static bool IndustryTypeSorter(const Industry * const &a, const Industry * const &b)
|
||||
{
|
||||
int it_a = 0;
|
||||
while (it_a != NUM_INDUSTRYTYPES && (*a)->type != _sorted_industry_types[it_a]) it_a++;
|
||||
while (it_a != NUM_INDUSTRYTYPES && a->type != _sorted_industry_types[it_a]) it_a++;
|
||||
int it_b = 0;
|
||||
while (it_b != NUM_INDUSTRYTYPES && (*b)->type != _sorted_industry_types[it_b]) it_b++;
|
||||
while (it_b != NUM_INDUSTRYTYPES && b->type != _sorted_industry_types[it_b]) it_b++;
|
||||
int r = it_a - it_b;
|
||||
return (r == 0) ? IndustryNameSorter(a, b) : r;
|
||||
return (r == 0) ? IndustryNameSorter(a, b) : r < 0;
|
||||
}
|
||||
|
||||
/** Sort industries by production and name */
|
||||
static int CDECL IndustryProductionSorter(const Industry * const *a, const Industry * const *b)
|
||||
static bool IndustryProductionSorter(const Industry * const &a, const Industry * const &b)
|
||||
{
|
||||
uint prod_a = 0, prod_b = 0;
|
||||
for (uint i = 0; i < lengthof((*a)->produced_cargo); i++) {
|
||||
if ((*a)->produced_cargo[i] != CT_INVALID) prod_a += (*a)->last_month_production[i];
|
||||
if ((*b)->produced_cargo[i] != CT_INVALID) prod_b += (*b)->last_month_production[i];
|
||||
for (uint i = 0; i < lengthof(a->produced_cargo); i++) {
|
||||
if (a->produced_cargo[i] != CT_INVALID) prod_a += a->last_month_production[i];
|
||||
if (b->produced_cargo[i] != CT_INVALID) prod_b += b->last_month_production[i];
|
||||
}
|
||||
int r = prod_a - prod_b;
|
||||
|
||||
return (r == 0) ? IndustryTypeSorter(a, b) : r;
|
||||
return (r == 0) ? IndustryTypeSorter(a, b) : r < 0;
|
||||
}
|
||||
|
||||
/** Sort industries by transported cargo and name */
|
||||
static int CDECL IndustryTransportedCargoSorter(const Industry * const *a, const Industry * const *b)
|
||||
static bool IndustryTransportedCargoSorter(const Industry * const &a, const Industry * const &b)
|
||||
{
|
||||
int r = GetCargoTransportedSortValue(*a) - GetCargoTransportedSortValue(*b);
|
||||
return (r == 0) ? IndustryNameSorter(a, b) : r;
|
||||
int r = GetCargoTransportedSortValue(a) - GetCargoTransportedSortValue(b);
|
||||
return (r == 0) ? IndustryNameSorter(a, b) : r < 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -3492,6 +3492,7 @@ STR_BUY_VEHICLE_ROAD_VEHICLE_BUY_VEHICLE_TOOLTIP :{BLACK}Keeft da
|
||||
STR_BUY_VEHICLE_SHIP_BUY_VEHICLE_TOOLTIP :{BLACK}Keeft dat ugewielte Schëff. Shift+Klick weist ongeféier Käschten ouni Kaf
|
||||
STR_BUY_VEHICLE_AIRCRAFT_BUY_VEHICLE_TOOLTIP :{BLACK}Keeft den ungewielte Fliger. Shift+Klick weist ongeféier Käschten ouni Kaf
|
||||
|
||||
STR_BUY_VEHICLE_TRAIN_BUY_REFIT_VEHICLE_TOOLTIP :{BLACK}Gewielten Zuch/Waggon kafen an ëmbauen. Shift+Klick weist ongeféier Käschten ouni Kaf
|
||||
STR_BUY_VEHICLE_AIRCRAFT_BUY_REFIT_VEHICLE_TOOLTIP :{BLACK}Gewielte Fliger kafen an ëmbauen. Shift+Klick weist ongeféier Käschten ouni Kaf
|
||||
|
||||
STR_BUY_VEHICLE_TRAIN_RENAME_BUTTON :{BLACK}Ëmbenennen
|
||||
|
@@ -405,28 +405,28 @@ class NetworkContentListWindow : public Window, ContentCallback {
|
||||
}
|
||||
|
||||
/** Sort content by name. */
|
||||
static int CDECL NameSorter(const ContentInfo * const *a, const ContentInfo * const *b)
|
||||
static bool NameSorter(const ContentInfo * const &a, const ContentInfo * const &b)
|
||||
{
|
||||
return strnatcmp((*a)->name, (*b)->name, true); // Sort by name (natural sorting).
|
||||
return strnatcmp(a->name, b->name, true) < 0; // Sort by name (natural sorting).
|
||||
}
|
||||
|
||||
/** Sort content by type. */
|
||||
static int CDECL TypeSorter(const ContentInfo * const *a, const ContentInfo * const *b)
|
||||
static bool TypeSorter(const ContentInfo * const &a, const ContentInfo * const &b)
|
||||
{
|
||||
int r = 0;
|
||||
if ((*a)->type != (*b)->type) {
|
||||
r = strnatcmp(content_type_strs[(*a)->type], content_type_strs[(*b)->type]);
|
||||
if (a->type != b->type) {
|
||||
r = strnatcmp(content_type_strs[a->type], content_type_strs[b->type]);
|
||||
}
|
||||
if (r == 0) r = NameSorter(a, b);
|
||||
return r;
|
||||
if (r == 0) return NameSorter(a, b);
|
||||
return r < 0;
|
||||
}
|
||||
|
||||
/** Sort content by state. */
|
||||
static int CDECL StateSorter(const ContentInfo * const *a, const ContentInfo * const *b)
|
||||
static bool StateSorter(const ContentInfo * const &a, const ContentInfo * const &b)
|
||||
{
|
||||
int r = (*a)->state - (*b)->state;
|
||||
if (r == 0) r = TypeSorter(a, b);
|
||||
return r;
|
||||
int r = a->state - b->state;
|
||||
if (r == 0) return TypeSorter(a, b);
|
||||
return r < 0;
|
||||
}
|
||||
|
||||
/** Sort the content list */
|
||||
|
@@ -279,10 +279,10 @@ protected:
|
||||
}
|
||||
|
||||
/** Sort servers by name. */
|
||||
static int CDECL NGameNameSorter(NetworkGameList * const *a, NetworkGameList * const *b)
|
||||
static bool NGameNameSorter(NetworkGameList * const &a, NetworkGameList * const &b)
|
||||
{
|
||||
int r = strnatcmp((*a)->info.server_name, (*b)->info.server_name, true); // Sort by name (natural sorting).
|
||||
return r == 0 ? (*a)->address.CompareTo((*b)->address) : r;
|
||||
int r = strnatcmp(a->info.server_name, b->info.server_name, true); // Sort by name (natural sorting).
|
||||
return r == 0 ? a->address.CompareTo(b->address) < 0: r < 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -290,60 +290,60 @@ protected:
|
||||
* server. If the two servers have the same amount, the one with the
|
||||
* higher maximum is preferred.
|
||||
*/
|
||||
static int CDECL NGameClientSorter(NetworkGameList * const *a, NetworkGameList * const *b)
|
||||
static bool NGameClientSorter(NetworkGameList * const &a, NetworkGameList * const &b)
|
||||
{
|
||||
/* Reverse as per default we are interested in most-clients first */
|
||||
int r = (*a)->info.clients_on - (*b)->info.clients_on;
|
||||
int r = a->info.clients_on - b->info.clients_on;
|
||||
|
||||
if (r == 0) r = (*a)->info.clients_max - (*b)->info.clients_max;
|
||||
if (r == 0) r = NGameNameSorter(a, b);
|
||||
if (r == 0) r = a->info.clients_max - b->info.clients_max;
|
||||
if (r == 0) return NGameNameSorter(a, b);
|
||||
|
||||
return r;
|
||||
return r < 0;
|
||||
}
|
||||
|
||||
/** Sort servers by map size */
|
||||
static int CDECL NGameMapSizeSorter(NetworkGameList * const *a, NetworkGameList * const *b)
|
||||
static bool NGameMapSizeSorter(NetworkGameList * const &a, NetworkGameList * const &b)
|
||||
{
|
||||
/* Sort by the area of the map. */
|
||||
int r = ((*a)->info.map_height) * ((*a)->info.map_width) - ((*b)->info.map_height) * ((*b)->info.map_width);
|
||||
int r = (a->info.map_height) * (a->info.map_width) - (b->info.map_height) * (b->info.map_width);
|
||||
|
||||
if (r == 0) r = (*a)->info.map_width - (*b)->info.map_width;
|
||||
return (r != 0) ? r : NGameClientSorter(a, b);
|
||||
if (r == 0) r = a->info.map_width - b->info.map_width;
|
||||
return (r != 0) ? r < 0 : NGameClientSorter(a, b);
|
||||
}
|
||||
|
||||
/** Sort servers by current date */
|
||||
static int CDECL NGameDateSorter(NetworkGameList * const *a, NetworkGameList * const *b)
|
||||
static bool NGameDateSorter(NetworkGameList * const &a, NetworkGameList * const &b)
|
||||
{
|
||||
int r = (*a)->info.game_date - (*b)->info.game_date;
|
||||
return (r != 0) ? r : NGameClientSorter(a, b);
|
||||
int r = a->info.game_date - b->info.game_date;
|
||||
return (r != 0) ? r < 0 : NGameClientSorter(a, b);
|
||||
}
|
||||
|
||||
/** Sort servers by the number of days the game is running */
|
||||
static int CDECL NGameYearsSorter(NetworkGameList * const *a, NetworkGameList * const *b)
|
||||
static bool NGameYearsSorter(NetworkGameList * const &a, NetworkGameList * const &b)
|
||||
{
|
||||
int r = (*a)->info.game_date - (*a)->info.start_date - (*b)->info.game_date + (*b)->info.start_date;
|
||||
return (r != 0) ? r : NGameDateSorter(a, b);
|
||||
int r = a->info.game_date - a->info.start_date - b->info.game_date + b->info.start_date;
|
||||
return (r != 0) ? r < 0: NGameDateSorter(a, b);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort servers by joinability. If both servers are the
|
||||
* same, prefer the non-passworded server first.
|
||||
*/
|
||||
static int CDECL NGameAllowedSorter(NetworkGameList * const *a, NetworkGameList * const *b)
|
||||
static bool NGameAllowedSorter(NetworkGameList * const &a, NetworkGameList * const &b)
|
||||
{
|
||||
/* The servers we do not know anything about (the ones that did not reply) should be at the bottom) */
|
||||
int r = StrEmpty((*a)->info.server_revision) - StrEmpty((*b)->info.server_revision);
|
||||
int r = StrEmpty(a->info.server_revision) - StrEmpty(b->info.server_revision);
|
||||
|
||||
/* Reverse default as we are interested in version-compatible clients first */
|
||||
if (r == 0) r = (*b)->info.version_compatible - (*a)->info.version_compatible;
|
||||
if (r == 0) r = b->info.version_compatible - a->info.version_compatible;
|
||||
/* The version-compatible ones are then sorted with NewGRF compatible first, incompatible last */
|
||||
if (r == 0) r = (*b)->info.compatible - (*a)->info.compatible;
|
||||
if (r == 0) r = b->info.compatible - a->info.compatible;
|
||||
/* Passworded servers should be below unpassworded servers */
|
||||
if (r == 0) r = (*a)->info.use_password - (*b)->info.use_password;
|
||||
if (r == 0) r = a->info.use_password - b->info.use_password;
|
||||
/* Finally sort on the number of clients of the server */
|
||||
if (r == 0) r = -NGameClientSorter(a, b);
|
||||
if (r == 0) return NGameClientSorter(a, b);
|
||||
|
||||
return r;
|
||||
return r < 0;
|
||||
}
|
||||
|
||||
/** Sort the server list */
|
||||
|
@@ -9523,10 +9523,10 @@ static void DecodeSpecialSprite(byte *buf, uint num, GrfLoadingStage stage)
|
||||
/* 0x0E */ { nullptr, SafeGRFInhibit, nullptr, GRFInhibit, GRFInhibit, GRFInhibit, },
|
||||
/* 0x0F */ { nullptr, GRFUnsafe, nullptr, FeatureTownName, nullptr, nullptr, },
|
||||
/* 0x10 */ { nullptr, nullptr, DefineGotoLabel, nullptr, nullptr, nullptr, },
|
||||
/* 0x11 */ { SkipAct11,GRFUnsafe, SkipAct11, GRFSound, SkipAct11, GRFSound, },
|
||||
/* 0x11 */ { SkipAct11, GRFUnsafe, SkipAct11, GRFSound, SkipAct11, GRFSound, },
|
||||
/* 0x12 */ { SkipAct12, SkipAct12, SkipAct12, SkipAct12, SkipAct12, LoadFontGlyph, },
|
||||
/* 0x13 */ { nullptr, nullptr, nullptr, nullptr, nullptr, TranslateGRFStrings, },
|
||||
/* 0x14 */ { StaticGRFInfo, nullptr, nullptr, Act14FeatureTest, nullptr, nullptr, },
|
||||
/* 0x14 */ { StaticGRFInfo, nullptr, nullptr, Act14FeatureTest,nullptr, nullptr, },
|
||||
};
|
||||
|
||||
GRFLocation location(_cur.grfconfig->ident.grfid, _cur.nfo_line);
|
||||
|
@@ -226,7 +226,7 @@ struct GRFFile : ZeroedMemoryAllocator {
|
||||
|
||||
GRFFilePropertyRemapSet action0_property_remaps[GSF_END];
|
||||
Action5TypeRemapSet action5_type_remaps;
|
||||
std::vector<AutoFreePtr<const char>> remap_unknown_property_names;
|
||||
std::vector<std::unique_ptr<const char, FreeDeleter>> remap_unknown_property_names;
|
||||
|
||||
uint32 param[0x80];
|
||||
uint param_end; ///< one more than the highest set parameter
|
||||
@@ -277,7 +277,7 @@ struct GRFLoadedFeatures {
|
||||
uint64 used_liveries; ///< Bitmask of #LiveryScheme used by the defined engines.
|
||||
bool has_newhouses; ///< Set if there are any newhouses loaded.
|
||||
bool has_newindustries; ///< Set if there are any newindustries loaded.
|
||||
ShoreReplacement shore; ///< It which way shore sprites were replaced.
|
||||
ShoreReplacement shore; ///< In which way shore sprites were replaced.
|
||||
};
|
||||
|
||||
/**
|
||||
|
@@ -1211,19 +1211,19 @@ void AlterVehicleListOrder(EngineID engine, uint target)
|
||||
* @param b right side
|
||||
* @return comparison result
|
||||
*/
|
||||
static int CDECL EnginePreSort(const EngineID *a, const EngineID *b)
|
||||
static bool EnginePreSort(const EngineID &a, const EngineID &b)
|
||||
{
|
||||
const EngineIDMapping &id_a = _engine_mngr.at(*a);
|
||||
const EngineIDMapping &id_b = _engine_mngr.at(*b);
|
||||
const EngineIDMapping &id_a = _engine_mngr.at(a);
|
||||
const EngineIDMapping &id_b = _engine_mngr.at(b);
|
||||
|
||||
/* 1. Sort by engine type */
|
||||
if (id_a.type != id_b.type) return (int)id_a.type - (int)id_b.type;
|
||||
if (id_a.type != id_b.type) return (int)id_a.type < (int)id_b.type;
|
||||
|
||||
/* 2. Sort by scope-GRFID */
|
||||
if (id_a.grfid != id_b.grfid) return id_a.grfid < id_b.grfid ? -1 : 1;
|
||||
if (id_a.grfid != id_b.grfid) return id_a.grfid < id_b.grfid;
|
||||
|
||||
/* 3. Sort by local ID */
|
||||
return (int)id_a.internal_id - (int)id_b.internal_id;
|
||||
return (int)id_a.internal_id < (int)id_b.internal_id;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1237,7 +1237,7 @@ void CommitVehicleListOrderChanges()
|
||||
FOR_ALL_ENGINES(e) {
|
||||
ordering.push_back(e->index);
|
||||
}
|
||||
QSortT(ordering.data(), ordering.size(), EnginePreSort);
|
||||
std::sort(ordering.begin(), ordering.end(), EnginePreSort);
|
||||
|
||||
/* Apply Insertion-Sort operations */
|
||||
for (const ListOrderChange &it : _list_order_changes) {
|
||||
|
@@ -1429,15 +1429,15 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
|
||||
|
||||
private:
|
||||
/** Sort grfs by name. */
|
||||
static int CDECL NameSorter(const GRFConfig * const *a, const GRFConfig * const *b)
|
||||
static bool NameSorter(const GRFConfig * const &a, const GRFConfig * const &b)
|
||||
{
|
||||
int i = strnatcmp((*a)->GetName(), (*b)->GetName(), true); // Sort by name (natural sorting).
|
||||
if (i != 0) return i;
|
||||
int i = strnatcmp(a->GetName(), b->GetName(), true); // Sort by name (natural sorting).
|
||||
if (i != 0) return i < 0;
|
||||
|
||||
i = (*a)->version - (*b)->version;
|
||||
if (i != 0) return i;
|
||||
i = a->version - b->version;
|
||||
if (i != 0) return i < 0;
|
||||
|
||||
return memcmp((*a)->ident.md5sum, (*b)->ident.md5sum, lengthof((*b)->ident.md5sum));
|
||||
return memcmp(a->ident.md5sum, b->ident.md5sum, lengthof(b->ident.md5sum)) < 0;
|
||||
}
|
||||
|
||||
/** Filter grfs by tags/name */
|
||||
|
@@ -993,7 +993,7 @@ static Order GetOrderCmdFromTile(const Vehicle *v, TileIndex tile)
|
||||
case VEH_SHIP: facil = FACIL_DOCK; break;
|
||||
case VEH_TRAIN: facil = FACIL_TRAIN; break;
|
||||
case VEH_AIRCRAFT: facil = FACIL_AIRPORT; break;
|
||||
case VEH_ROAD: facil = RoadVehicle::From(v)->IsBus() ? FACIL_BUS_STOP : FACIL_TRUCK_STOP; break;
|
||||
case VEH_ROAD: facil = FACIL_BUS_STOP | FACIL_TRUCK_STOP; break;
|
||||
default: NOT_REACHED();
|
||||
}
|
||||
if (st->facilities & facil) {
|
||||
|
@@ -15,6 +15,7 @@
|
||||
#include "../core/endian_func.hpp"
|
||||
#include "../core/endian_type.hpp"
|
||||
#include "../fios.h"
|
||||
#include <array>
|
||||
|
||||
#include "saveload.h"
|
||||
#include "saveload_buffer.h"
|
||||
@@ -57,44 +58,44 @@ static const uint MAP_SL_BUF_SIZE = 4096;
|
||||
|
||||
static void Load_MAPT()
|
||||
{
|
||||
SmallStackSafeStackAlloc<byte, MAP_SL_BUF_SIZE> buf;
|
||||
std::array<byte, MAP_SL_BUF_SIZE> buf;
|
||||
TileIndex size = MapSize();
|
||||
|
||||
for (TileIndex i = 0; i != size;) {
|
||||
SlArray(buf, MAP_SL_BUF_SIZE, SLE_UINT8);
|
||||
SlArray(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
|
||||
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) _m[i++].type = buf[j];
|
||||
}
|
||||
}
|
||||
|
||||
static void Load_MAPH()
|
||||
{
|
||||
SmallStackSafeStackAlloc<byte, MAP_SL_BUF_SIZE> buf;
|
||||
std::array<byte, MAP_SL_BUF_SIZE> buf;
|
||||
TileIndex size = MapSize();
|
||||
|
||||
for (TileIndex i = 0; i != size;) {
|
||||
SlArray(buf, MAP_SL_BUF_SIZE, SLE_UINT8);
|
||||
SlArray(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
|
||||
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) _m[i++].height = buf[j];
|
||||
}
|
||||
}
|
||||
|
||||
static void Load_MAP1()
|
||||
{
|
||||
SmallStackSafeStackAlloc<byte, MAP_SL_BUF_SIZE> buf;
|
||||
std::array<byte, MAP_SL_BUF_SIZE> buf;
|
||||
TileIndex size = MapSize();
|
||||
|
||||
for (TileIndex i = 0; i != size;) {
|
||||
SlArray(buf, MAP_SL_BUF_SIZE, SLE_UINT8);
|
||||
SlArray(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
|
||||
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) _m[i++].m1 = buf[j];
|
||||
}
|
||||
}
|
||||
|
||||
static void Load_MAP2()
|
||||
{
|
||||
SmallStackSafeStackAlloc<uint16, MAP_SL_BUF_SIZE> buf;
|
||||
std::array<uint16, MAP_SL_BUF_SIZE> buf;
|
||||
TileIndex size = MapSize();
|
||||
|
||||
for (TileIndex i = 0; i != size;) {
|
||||
SlArray(buf, MAP_SL_BUF_SIZE,
|
||||
SlArray(buf.data(), MAP_SL_BUF_SIZE,
|
||||
/* In those versions the m2 was 8 bits */
|
||||
IsSavegameVersionBefore(SLV_5) ? SLE_FILE_U8 | SLE_VAR_U16 : SLE_UINT16
|
||||
);
|
||||
@@ -104,46 +105,46 @@ static void Load_MAP2()
|
||||
|
||||
static void Load_MAP3()
|
||||
{
|
||||
SmallStackSafeStackAlloc<byte, MAP_SL_BUF_SIZE> buf;
|
||||
std::array<byte, MAP_SL_BUF_SIZE> buf;
|
||||
TileIndex size = MapSize();
|
||||
|
||||
for (TileIndex i = 0; i != size;) {
|
||||
SlArray(buf, MAP_SL_BUF_SIZE, SLE_UINT8);
|
||||
SlArray(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
|
||||
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) _m[i++].m3 = buf[j];
|
||||
}
|
||||
}
|
||||
|
||||
static void Load_MAP4()
|
||||
{
|
||||
SmallStackSafeStackAlloc<byte, MAP_SL_BUF_SIZE> buf;
|
||||
std::array<byte, MAP_SL_BUF_SIZE> buf;
|
||||
TileIndex size = MapSize();
|
||||
|
||||
for (TileIndex i = 0; i != size;) {
|
||||
SlArray(buf, MAP_SL_BUF_SIZE, SLE_UINT8);
|
||||
SlArray(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
|
||||
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) _m[i++].m4 = buf[j];
|
||||
}
|
||||
}
|
||||
|
||||
static void Load_MAP5()
|
||||
{
|
||||
SmallStackSafeStackAlloc<byte, MAP_SL_BUF_SIZE> buf;
|
||||
std::array<byte, MAP_SL_BUF_SIZE> buf;
|
||||
TileIndex size = MapSize();
|
||||
|
||||
for (TileIndex i = 0; i != size;) {
|
||||
SlArray(buf, MAP_SL_BUF_SIZE, SLE_UINT8);
|
||||
SlArray(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
|
||||
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) _m[i++].m5 = buf[j];
|
||||
}
|
||||
}
|
||||
|
||||
static void Load_MAP6()
|
||||
{
|
||||
SmallStackSafeStackAlloc<byte, MAP_SL_BUF_SIZE> buf;
|
||||
std::array<byte, MAP_SL_BUF_SIZE> buf;
|
||||
TileIndex size = MapSize();
|
||||
|
||||
if (IsSavegameVersionBefore(SLV_42)) {
|
||||
for (TileIndex i = 0; i != size;) {
|
||||
/* 1024, otherwise we overflow on 64x64 maps! */
|
||||
SlArray(buf, 1024, SLE_UINT8);
|
||||
SlArray(buf.data(), 1024, SLE_UINT8);
|
||||
for (uint j = 0; j != 1024; j++) {
|
||||
_me[i++].m6 = GB(buf[j], 0, 2);
|
||||
_me[i++].m6 = GB(buf[j], 2, 2);
|
||||
@@ -153,7 +154,7 @@ static void Load_MAP6()
|
||||
}
|
||||
} else {
|
||||
for (TileIndex i = 0; i != size;) {
|
||||
SlArray(buf, MAP_SL_BUF_SIZE, SLE_UINT8);
|
||||
SlArray(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
|
||||
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) _me[i++].m6 = buf[j];
|
||||
}
|
||||
}
|
||||
@@ -161,22 +162,22 @@ static void Load_MAP6()
|
||||
|
||||
static void Load_MAP7()
|
||||
{
|
||||
SmallStackSafeStackAlloc<byte, MAP_SL_BUF_SIZE> buf;
|
||||
std::array<byte, MAP_SL_BUF_SIZE> buf;
|
||||
TileIndex size = MapSize();
|
||||
|
||||
for (TileIndex i = 0; i != size;) {
|
||||
SlArray(buf, MAP_SL_BUF_SIZE, SLE_UINT8);
|
||||
SlArray(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
|
||||
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) _me[i++].m7 = buf[j];
|
||||
}
|
||||
}
|
||||
|
||||
static void Load_MAP8()
|
||||
{
|
||||
SmallStackSafeStackAlloc<uint16, MAP_SL_BUF_SIZE> buf;
|
||||
std::array<uint16, MAP_SL_BUF_SIZE> buf;
|
||||
TileIndex size = MapSize();
|
||||
|
||||
for (TileIndex i = 0; i != size;) {
|
||||
SlArray(buf, MAP_SL_BUF_SIZE, SLE_UINT16);
|
||||
SlArray(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT16);
|
||||
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) _me[i++].m8 = buf[j];
|
||||
}
|
||||
}
|
||||
|
@@ -31,6 +31,7 @@
|
||||
#include "../core/smallvec_type.hpp"
|
||||
#include "saveload_internal.h"
|
||||
#include "oldloader.h"
|
||||
#include <array>
|
||||
|
||||
#include "table/strings.h"
|
||||
#include "../table/engines.h"
|
||||
@@ -1753,8 +1754,8 @@ bool LoadTTDMain(LoadgameState *ls)
|
||||
_read_ttdpatch_flags = false;
|
||||
|
||||
/* Load the biggest chunk */
|
||||
SmallStackSafeStackAlloc<byte, OLD_MAP_SIZE * 2> map3;
|
||||
_old_map3 = map3.data;
|
||||
std::array<byte, OLD_MAP_SIZE * 2> map3;
|
||||
_old_map3 = map3.data();
|
||||
_old_vehicle_names = nullptr;
|
||||
try {
|
||||
if (!LoadChunk(ls, nullptr, main_chunk)) {
|
||||
@@ -1796,10 +1797,10 @@ bool LoadTTOMain(LoadgameState *ls)
|
||||
|
||||
_read_ttdpatch_flags = false;
|
||||
|
||||
SmallStackSafeStackAlloc<byte, 103 * sizeof(Engine)> engines; // we don't want to call Engine constructor here
|
||||
_old_engines = (Engine *)engines.data;
|
||||
SmallStackSafeStackAlloc<StringID, 800> vehnames;
|
||||
_old_vehicle_names = vehnames.data;
|
||||
std::array<byte, 103 * sizeof(Engine)> engines; // we don't want to call Engine constructor here
|
||||
_old_engines = (Engine *)engines.data();
|
||||
std::array<StringID, 800> vehnames;
|
||||
_old_vehicle_names = vehnames.data();
|
||||
|
||||
/* Load the biggest chunk */
|
||||
if (!LoadChunk(ls, nullptr, main_chunk)) {
|
||||
|
@@ -49,6 +49,32 @@ void ScriptTileList::RemoveTile(TileIndex tile)
|
||||
this->RemoveItem(tile);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to get list of tiles that will cover an industry's production or acceptance.
|
||||
* @param i Industry in question
|
||||
* @param radius Catchment radius to test
|
||||
* @param bta BitmapTileArea to fill
|
||||
*/
|
||||
static void FillIndustryCatchment(const Industry *i, int radius, BitmapTileArea &bta)
|
||||
{
|
||||
TILE_AREA_LOOP(cur_tile, i->location) {
|
||||
if (!::IsTileType(cur_tile, MP_INDUSTRY) || ::GetIndustryIndex(cur_tile) != i->index) continue;
|
||||
|
||||
int tx = TileX(cur_tile);
|
||||
int ty = TileY(cur_tile);
|
||||
for (int y = -radius; y <= radius; y++) {
|
||||
if (ty + y < 0 || ty + y > (int)MapMaxY()) continue;
|
||||
for (int x = -radius; x <= radius; x++) {
|
||||
if (tx + x < 0 || tx + x > (int)MapMaxX()) continue;
|
||||
TileIndex tile = TileXY(tx + x, ty + y);
|
||||
if (!IsValidTile(tile)) continue;
|
||||
if (::IsTileType(tile, MP_INDUSTRY) && ::GetIndustryIndex(tile) == i->index) continue;
|
||||
bta.SetTile(tile);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ScriptTileList_IndustryAccepting::ScriptTileList_IndustryAccepting(IndustryID industry_id, int radius)
|
||||
{
|
||||
if (!ScriptIndustry::IsValidIndustry(industry_id) || radius <= 0) return;
|
||||
@@ -66,12 +92,11 @@ ScriptTileList_IndustryAccepting::ScriptTileList_IndustryAccepting(IndustryID in
|
||||
|
||||
if (!_settings_game.station.modified_catchment) radius = CA_UNMODIFIED + _settings_game.station.catchment_increase;
|
||||
|
||||
TileArea ta(i->location.tile - ::TileDiffXY(radius, radius), i->location.w + radius * 2, i->location.h + radius * 2);
|
||||
TILE_AREA_LOOP(cur_tile, ta) {
|
||||
if (!::IsValidTile(cur_tile)) continue;
|
||||
/* Exclude all tiles that belong to this industry */
|
||||
if (::IsTileType(cur_tile, MP_INDUSTRY) && ::GetIndustryIndex(cur_tile) == industry_id) continue;
|
||||
BitmapTileArea bta(TileArea(i->location).Expand(radius));
|
||||
FillIndustryCatchment(i, radius, bta);
|
||||
|
||||
BitmapTileIterator it(bta);
|
||||
for (TileIndex cur_tile = it; cur_tile != INVALID_TILE; cur_tile = ++it) {
|
||||
/* Only add the tile if it accepts the cargo (sometimes just 1 tile of an
|
||||
* industry triggers the acceptance). */
|
||||
CargoArray acceptance = ::GetAcceptanceAroundTiles(cur_tile, 1, 1, radius);
|
||||
@@ -102,12 +127,11 @@ ScriptTileList_IndustryProducing::ScriptTileList_IndustryProducing(IndustryID in
|
||||
|
||||
if (!_settings_game.station.modified_catchment) radius = CA_UNMODIFIED + _settings_game.station.catchment_increase;
|
||||
|
||||
TileArea ta(i->location.tile - ::TileDiffXY(radius, radius), i->location.w + radius * 2, i->location.h + radius * 2);
|
||||
TILE_AREA_LOOP(cur_tile, ta) {
|
||||
if (!::IsValidTile(cur_tile)) continue;
|
||||
/* Exclude all tiles that belong to this industry */
|
||||
if (::IsTileType(cur_tile, MP_INDUSTRY) && ::GetIndustryIndex(cur_tile) == industry_id) continue;
|
||||
BitmapTileArea bta(TileArea(i->location).Expand(radius));
|
||||
FillIndustryCatchment(i, radius, bta);
|
||||
|
||||
BitmapTileIterator it(bta);
|
||||
for (TileIndex cur_tile = it; cur_tile != INVALID_TILE; cur_tile = ++it) {
|
||||
this->AddTile(cur_tile);
|
||||
}
|
||||
}
|
||||
|
@@ -72,21 +72,21 @@ struct SignList {
|
||||
}
|
||||
|
||||
/** Sort signs by their name */
|
||||
static int CDECL SignNameSorter(const Sign * const *a, const Sign * const *b)
|
||||
static bool SignNameSorter(const Sign * const &a, const Sign * const &b)
|
||||
{
|
||||
/* Signs are very very rarely using the default text, but there can also be
|
||||
* a lot of them. Therefore a worthwhile performance gain can be made by
|
||||
* directly comparing Sign::name instead of going through the string
|
||||
* system for each comparison. */
|
||||
const char *a_name = (*a)->name;
|
||||
const char *b_name = (*b)->name;
|
||||
const char *a_name = a->name;
|
||||
const char *b_name = b->name;
|
||||
|
||||
if (a_name == nullptr) a_name = SignList::default_name;
|
||||
if (b_name == nullptr) b_name = SignList::default_name;
|
||||
|
||||
int r = strnatcmp(a_name, b_name); // Sort by name (natural sorting).
|
||||
|
||||
return r != 0 ? r : ((*a)->index - (*b)->index);
|
||||
return r != 0 ? r < 0 : (a->index < b->index);
|
||||
}
|
||||
|
||||
void SortSignsList()
|
||||
|
@@ -49,7 +49,7 @@ struct Filtering {
|
||||
template <typename T, typename F = const char*>
|
||||
class GUIList : public std::vector<T> {
|
||||
public:
|
||||
typedef int CDECL SortFunction(const T*, const T*); ///< Signature of sort function.
|
||||
typedef bool SortFunction(const T&, const T&); ///< Signature of sort function.
|
||||
typedef bool CDECL FilterFunction(const T*, F); ///< Signature of filter function.
|
||||
|
||||
protected:
|
||||
@@ -270,11 +270,11 @@ public:
|
||||
if (this->flags & VL_FIRST_SORT) {
|
||||
CLRBITS(this->flags, VL_FIRST_SORT);
|
||||
|
||||
QSortT(std::vector<T>::data(), std::vector<T>::size(), compare, desc);
|
||||
std::sort(std::vector<T>::begin(), std::vector<T>::end(), [&](const T &a, const T &b) { return desc ? compare(b, a) : compare(a, b); });
|
||||
return true;
|
||||
}
|
||||
|
||||
GSortT(std::vector<T>::data(), std::vector<T>::size(), compare, desc);
|
||||
std::sort(std::vector<T>::begin(), std::vector<T>::end(), [&](const T &a, const T &b) { return desc ? compare(b, a) : compare(a, b); });
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@@ -69,8 +69,8 @@ static bool WarnCorruptSprite(uint file_slot, size_t file_pos, int line)
|
||||
*/
|
||||
bool DecodeSingleSprite(SpriteLoader::Sprite *sprite, uint file_slot, size_t file_pos, SpriteType sprite_type, int64 num, byte type, ZoomLevel zoom_lvl, byte colour_fmt, byte container_format)
|
||||
{
|
||||
AutoFreePtr<byte> dest_orig(MallocT<byte>(num));
|
||||
byte *dest = dest_orig;
|
||||
std::unique_ptr<byte[]> dest_orig(new byte[num]);
|
||||
byte *dest = dest_orig.get();
|
||||
const int64 dest_size = num;
|
||||
|
||||
/* Read the file, which has some kind of compression */
|
||||
@@ -89,7 +89,7 @@ bool DecodeSingleSprite(SpriteLoader::Sprite *sprite, uint file_slot, size_t fil
|
||||
} else {
|
||||
/* Copy bytes from earlier in the sprite */
|
||||
const uint data_offset = ((code & 7) << 8) | FioReadByte();
|
||||
if (dest - data_offset < dest_orig) return WarnCorruptSprite(file_slot, file_pos, __LINE__);
|
||||
if (dest - data_offset < dest_orig.get()) return WarnCorruptSprite(file_slot, file_pos, __LINE__);
|
||||
int size = -(code >> 3);
|
||||
num -= size;
|
||||
if (num < 0) return WarnCorruptSprite(file_slot, file_pos, __LINE__);
|
||||
@@ -123,10 +123,10 @@ bool DecodeSingleSprite(SpriteLoader::Sprite *sprite, uint file_slot, size_t fil
|
||||
}
|
||||
|
||||
/* Go to that row */
|
||||
dest = dest_orig + offset;
|
||||
dest = dest_orig.get() + offset;
|
||||
|
||||
do {
|
||||
if (dest + (container_format >= 2 && sprite->width > 256 ? 4 : 2) > dest_orig + dest_size) {
|
||||
if (dest + (container_format >= 2 && sprite->width > 256 ? 4 : 2) > dest_orig.get() + dest_size) {
|
||||
return WarnCorruptSprite(file_slot, file_pos, __LINE__);
|
||||
}
|
||||
|
||||
@@ -152,7 +152,7 @@ bool DecodeSingleSprite(SpriteLoader::Sprite *sprite, uint file_slot, size_t fil
|
||||
|
||||
data = &sprite->data[y * sprite->width + skip];
|
||||
|
||||
if (skip + length > sprite->width || dest + length * bpp > dest_orig + dest_size) {
|
||||
if (skip + length > sprite->width || dest + length * bpp > dest_orig.get() + dest_size) {
|
||||
return WarnCorruptSprite(file_slot, file_pos, __LINE__);
|
||||
}
|
||||
|
||||
@@ -188,7 +188,7 @@ bool DecodeSingleSprite(SpriteLoader::Sprite *sprite, uint file_slot, size_t fil
|
||||
warning_level = 6;
|
||||
}
|
||||
|
||||
dest = dest_orig;
|
||||
dest = dest_orig.get();
|
||||
|
||||
for (int i = 0; i < sprite->width * sprite->height; i++) {
|
||||
byte *pixel = &dest[i * bpp];
|
||||
|
@@ -472,7 +472,7 @@ void Station::RecomputeCatchment()
|
||||
if (r == CA_NONE) continue;
|
||||
|
||||
/* This tile sub-loop doesn't need to test any tiles, they are simply added to the catchment set. */
|
||||
TileArea ta2(TileXY(max<int>(TileX(tile) - r, 0), max<int>(TileY(tile) - r, 0)), TileXY(min<int>(TileX(tile) + r, MapMaxX()), min<int>(TileY(tile) + r, MapMaxY())));
|
||||
TileArea ta2 = TileArea(tile, 1, 1).Expand(r);
|
||||
TILE_AREA_LOOP(tile2, ta2) this->catchment_tiles.SetTile(tile2);
|
||||
}
|
||||
|
||||
|
@@ -103,9 +103,7 @@ bool IsHangar(TileIndex t)
|
||||
template <class T>
|
||||
CommandCost GetStationAround(TileArea ta, StationID closest_station, CompanyID company, T **st)
|
||||
{
|
||||
ta.tile -= TileDiffXY(1, 1);
|
||||
ta.w += 2;
|
||||
ta.h += 2;
|
||||
ta.Expand(1);
|
||||
|
||||
/* check around to see if there are any stations there owned by the company */
|
||||
TILE_AREA_LOOP(tile_cur, ta) {
|
||||
@@ -498,24 +496,8 @@ CargoArray GetProductionAroundTiles(TileIndex tile, int w, int h, int rad)
|
||||
{
|
||||
CargoArray produced;
|
||||
|
||||
int x = TileX(tile);
|
||||
int y = TileY(tile);
|
||||
|
||||
/* expand the region by rad tiles on each side
|
||||
* while making sure that we remain inside the board. */
|
||||
int x2 = min(x + w + rad, MapSizeX());
|
||||
int x1 = max(x - rad, 0);
|
||||
|
||||
int y2 = min(y + h + rad, MapSizeY());
|
||||
int y1 = max(y - rad, 0);
|
||||
|
||||
assert(x1 < x2);
|
||||
assert(y1 < y2);
|
||||
assert(w > 0);
|
||||
assert(h > 0);
|
||||
|
||||
btree::btree_set<IndustryID> industries;
|
||||
TileArea ta(TileXY(x1, y1), TileXY(x2 - 1, y2 - 1));
|
||||
TileArea ta = TileArea(tile, w, h).Expand(rad);
|
||||
|
||||
/* Loop over all tiles to get the produced cargo of
|
||||
* everything except industries */
|
||||
@@ -555,31 +537,14 @@ CargoArray GetAcceptanceAroundTiles(TileIndex tile, int w, int h, int rad, Cargo
|
||||
CargoArray acceptance;
|
||||
if (always_accepted != nullptr) *always_accepted = 0;
|
||||
|
||||
int x = TileX(tile);
|
||||
int y = TileY(tile);
|
||||
|
||||
/* expand the region by rad tiles on each side
|
||||
* while making sure that we remain inside the board. */
|
||||
int x2 = min(x + w + rad, MapSizeX());
|
||||
int y2 = min(y + h + rad, MapSizeY());
|
||||
int x1 = max(x - rad, 0);
|
||||
int y1 = max(y - rad, 0);
|
||||
|
||||
assert(x1 < x2);
|
||||
assert(y1 < y2);
|
||||
assert(w > 0);
|
||||
assert(h > 0);
|
||||
|
||||
for (int yc = y1; yc != y2; yc++) {
|
||||
for (int xc = x1; xc != x2; xc++) {
|
||||
TileIndex tile = TileXY(xc, yc);
|
||||
TileArea ta = TileArea(tile, w, h).Expand(rad);
|
||||
|
||||
TILE_AREA_LOOP(tile, ta) {
|
||||
/* Ignore industry if it has a neutral station. */
|
||||
if (!_settings_game.station.serve_neutral_industries && IsTileType(tile, MP_INDUSTRY) && Industry::GetByTile(tile)->neutral_station != nullptr) continue;
|
||||
|
||||
AddAcceptedCargo(tile, acceptance, always_accepted);
|
||||
}
|
||||
}
|
||||
|
||||
return acceptance;
|
||||
}
|
||||
@@ -4083,8 +4048,6 @@ void FindStationsAroundTiles(const TileArea &location, StationList * const stati
|
||||
}
|
||||
|
||||
/* Not using, or don't have a nearby stations list, so we need to scan. */
|
||||
uint x = TileX(location.tile);
|
||||
uint y = TileY(location.tile);
|
||||
|
||||
btree::btree_set<StationID> seen_stations;
|
||||
|
||||
@@ -4092,7 +4055,7 @@ void FindStationsAroundTiles(const TileArea &location, StationList * const stati
|
||||
* to find the possible nearby stations. */
|
||||
uint max_c = _settings_game.station.modified_catchment ? MAX_CATCHMENT : CA_UNMODIFIED;
|
||||
max_c += _settings_game.station.catchment_increase;
|
||||
TileArea ta(TileXY(max<int>(0, x - max_c), max<int>(0, y - max_c)), TileXY(min<int>(MapMaxX(), x + location.w + max_c), min<int>(MapMaxY(), y + location.h + max_c)));
|
||||
TileArea ta = TileArea(location).Expand(max_c);
|
||||
TILE_AREA_LOOP(tile, ta) {
|
||||
if (IsTileType(tile, MP_STATION)) seen_stations.insert(GetStationIndex(tile));
|
||||
}
|
||||
|
@@ -211,85 +211,85 @@ protected:
|
||||
}
|
||||
|
||||
/** Sort stations by their name */
|
||||
static int CDECL StationNameSorter(const Station * const *a, const Station * const *b)
|
||||
static bool StationNameSorter(const Station * const &a, const Station * const &b)
|
||||
{
|
||||
static char buf_cache[64];
|
||||
char buf[64];
|
||||
|
||||
SetDParam(0, (*a)->index);
|
||||
SetDParam(0, a->index);
|
||||
GetString(buf, STR_STATION_NAME, lastof(buf));
|
||||
|
||||
if (*b != last_station) {
|
||||
last_station = *b;
|
||||
SetDParam(0, (*b)->index);
|
||||
if (b != last_station) {
|
||||
last_station = b;
|
||||
SetDParam(0, b->index);
|
||||
GetString(buf_cache, STR_STATION_NAME, lastof(buf_cache));
|
||||
}
|
||||
|
||||
int r = strnatcmp(buf, buf_cache); // Sort by name (natural sorting).
|
||||
if (r == 0) return (*a)->index - (*b)->index;
|
||||
return r;
|
||||
if (r == 0) return a->index < b->index;
|
||||
return r < 0;
|
||||
}
|
||||
|
||||
/** Sort stations by their type */
|
||||
static int CDECL StationTypeSorter(const Station * const *a, const Station * const *b)
|
||||
static bool StationTypeSorter(const Station * const &a, const Station * const &b)
|
||||
{
|
||||
return (*a)->facilities - (*b)->facilities;
|
||||
return a->facilities < b->facilities;
|
||||
}
|
||||
|
||||
/** Sort stations by their waiting cargo */
|
||||
static int CDECL StationWaitingTotalSorter(const Station * const *a, const Station * const *b)
|
||||
static bool StationWaitingTotalSorter(const Station * const &a, const Station * const &b)
|
||||
{
|
||||
int diff = 0;
|
||||
|
||||
CargoID j;
|
||||
FOR_EACH_SET_CARGO_ID(j, cargo_filter) {
|
||||
diff += (*a)->goods[j].cargo.TotalCount() - (*b)->goods[j].cargo.TotalCount();
|
||||
diff += a->goods[j].cargo.TotalCount() - b->goods[j].cargo.TotalCount();
|
||||
}
|
||||
|
||||
return diff;
|
||||
return diff < 0;
|
||||
}
|
||||
|
||||
/** Sort stations by their available waiting cargo */
|
||||
static int CDECL StationWaitingAvailableSorter(const Station * const *a, const Station * const *b)
|
||||
static bool StationWaitingAvailableSorter(const Station * const &a, const Station * const &b)
|
||||
{
|
||||
int diff = 0;
|
||||
|
||||
CargoID j;
|
||||
FOR_EACH_SET_CARGO_ID(j, cargo_filter) {
|
||||
diff += (*a)->goods[j].cargo.AvailableCount() - (*b)->goods[j].cargo.AvailableCount();
|
||||
diff += a->goods[j].cargo.AvailableCount() - b->goods[j].cargo.AvailableCount();
|
||||
}
|
||||
|
||||
return diff;
|
||||
return diff < 0;
|
||||
}
|
||||
|
||||
/** Sort stations by their rating */
|
||||
static int CDECL StationRatingMaxSorter(const Station * const *a, const Station * const *b)
|
||||
static bool StationRatingMaxSorter(const Station * const &a, const Station * const &b)
|
||||
{
|
||||
byte maxr1 = 0;
|
||||
byte maxr2 = 0;
|
||||
|
||||
CargoID j;
|
||||
FOR_EACH_SET_CARGO_ID(j, cargo_filter) {
|
||||
if ((*a)->goods[j].HasRating()) maxr1 = max(maxr1, (*a)->goods[j].rating);
|
||||
if ((*b)->goods[j].HasRating()) maxr2 = max(maxr2, (*b)->goods[j].rating);
|
||||
if (a->goods[j].HasRating()) maxr1 = max(maxr1, a->goods[j].rating);
|
||||
if (b->goods[j].HasRating()) maxr2 = max(maxr2, b->goods[j].rating);
|
||||
}
|
||||
|
||||
return maxr1 - maxr2;
|
||||
return maxr1 < maxr2;
|
||||
}
|
||||
|
||||
/** Sort stations by their rating */
|
||||
static int CDECL StationRatingMinSorter(const Station * const *a, const Station * const *b)
|
||||
static bool StationRatingMinSorter(const Station * const &a, const Station * const &b)
|
||||
{
|
||||
byte minr1 = 255;
|
||||
byte minr2 = 255;
|
||||
|
||||
for (CargoID j = 0; j < NUM_CARGO; j++) {
|
||||
if (!HasBit(cargo_filter, j)) continue;
|
||||
if ((*a)->goods[j].HasRating()) minr1 = min(minr1, (*a)->goods[j].rating);
|
||||
if ((*b)->goods[j].HasRating()) minr2 = min(minr2, (*b)->goods[j].rating);
|
||||
if (a->goods[j].HasRating()) minr1 = min(minr1, a->goods[j].rating);
|
||||
if (b->goods[j].HasRating()) minr2 = min(minr2, b->goods[j].rating);
|
||||
}
|
||||
|
||||
return -(minr1 - minr2);
|
||||
return minr1 > minr2;
|
||||
}
|
||||
|
||||
/** Sort the stations list */
|
||||
|
@@ -69,9 +69,9 @@ protected:
|
||||
}
|
||||
|
||||
/** Sort story pages by order value. */
|
||||
static int CDECL PageOrderSorter(const StoryPage * const *a, const StoryPage * const *b)
|
||||
static bool PageOrderSorter(const StoryPage * const &a, const StoryPage * const &b)
|
||||
{
|
||||
return (*a)->sort_value - (*b)->sort_value;
|
||||
return a->sort_value < b->sort_value;
|
||||
}
|
||||
|
||||
/** (Re)Build story page element list. */
|
||||
@@ -98,9 +98,9 @@ protected:
|
||||
}
|
||||
|
||||
/** Sort story page elements by order value. */
|
||||
static int CDECL PageElementOrderSorter(const StoryPageElement * const *a, const StoryPageElement * const *b)
|
||||
static bool PageElementOrderSorter(const StoryPageElement * const &a, const StoryPageElement * const &b)
|
||||
{
|
||||
return (*a)->sort_value - (*b)->sort_value;
|
||||
return a->sort_value < b->sort_value;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@@ -1995,7 +1995,7 @@ static const char * const _name_romanian_real[] = {
|
||||
"Motru",
|
||||
"N\xC4\x83s\xC4\x83ud",
|
||||
"N\xC4\x83vodari",
|
||||
"Odobe\xC8x99ti",
|
||||
"Odobe\xC8\x99ti",
|
||||
"Olteni\xC8\x9B""a",
|
||||
"One\xC8\x99ti",
|
||||
"Oradea",
|
||||
|
@@ -559,29 +559,6 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
/** Sort the groups by their name */
|
||||
static int CDECL GroupNameSorter(const Group * const *a, const Group * const *b)
|
||||
{
|
||||
static const Group *last_group[2] = { nullptr, nullptr };
|
||||
static char last_name[2][64] = { "", "" };
|
||||
|
||||
if (*a != last_group[0]) {
|
||||
last_group[0] = *a;
|
||||
SetDParam(0, (*a)->index);
|
||||
GetString(last_name[0], STR_GROUP_NAME, lastof(last_name[0]));
|
||||
}
|
||||
|
||||
if (*b != last_group[1]) {
|
||||
last_group[1] = *b;
|
||||
SetDParam(0, (*b)->index);
|
||||
GetString(last_name[1], STR_GROUP_NAME, lastof(last_name[1]));
|
||||
}
|
||||
|
||||
int r = strnatcmp(last_name[0], last_name[1]); // Sort by name (natural sorting).
|
||||
if (r == 0) return (*a)->index - (*b)->index;
|
||||
return r;
|
||||
}
|
||||
|
||||
void BuildGroupList(Owner owner)
|
||||
{
|
||||
if (!this->groups.NeedRebuild()) return;
|
||||
@@ -599,6 +576,7 @@ public:
|
||||
}
|
||||
|
||||
list.ForceResort();
|
||||
extern bool GroupNameSorter(const Group * const &a, const Group * const &b);
|
||||
list.Sort(&GroupNameSorter);
|
||||
|
||||
AddParents(&list, INVALID_GROUP, 0);
|
||||
|
@@ -117,6 +117,27 @@ bool OrthogonalTileArea::Contains(TileIndex tile) const
|
||||
return IsInsideBS(tile_x, left, this->w) && IsInsideBS(tile_y, top, this->h);
|
||||
}
|
||||
|
||||
/**
|
||||
* Expand a tile area by rad tiles in each direction, keeping within map bounds.
|
||||
* @param rad Number of tiles to expand
|
||||
* @return The OrthogonalTileArea.
|
||||
*/
|
||||
OrthogonalTileArea &OrthogonalTileArea::Expand(int rad)
|
||||
{
|
||||
int x = TileX(this->tile);
|
||||
int y = TileY(this->tile);
|
||||
|
||||
int sx = max(x - rad, 0);
|
||||
int sy = max(y - rad, 0);
|
||||
int ex = min(x + this->w + rad, MapSizeX());
|
||||
int ey = min(y + this->h + rad, MapSizeY());
|
||||
|
||||
this->tile = TileXY(sx, sy);
|
||||
this->w = ex - sx;
|
||||
this->h = ey - sy;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clamp the tile area to map borders.
|
||||
*/
|
||||
|
@@ -50,6 +50,8 @@ struct OrthogonalTileArea {
|
||||
|
||||
bool Contains(TileIndex tile) const;
|
||||
|
||||
OrthogonalTileArea &Expand(int rad);
|
||||
|
||||
void ClampToMap();
|
||||
|
||||
/**
|
||||
|
@@ -342,15 +342,12 @@ CommandCost CmdSetVehicleOnTime(TileIndex tile, DoCommandFlag flags, uint32 p1,
|
||||
* Order vehicles based on their timetable. The vehicles will be sorted in order
|
||||
* they would reach the first station.
|
||||
*
|
||||
* @param ap First Vehicle pointer.
|
||||
* @param bp Second Vehicle pointer.
|
||||
* @param a First Vehicle pointer.
|
||||
* @param b Second Vehicle pointer.
|
||||
* @return Comparison value.
|
||||
*/
|
||||
static int CDECL VehicleTimetableSorter(Vehicle * const *ap, Vehicle * const *bp)
|
||||
static bool VehicleTimetableSorter(Vehicle * const &a, Vehicle * const &b)
|
||||
{
|
||||
const Vehicle *a = *ap;
|
||||
const Vehicle *b = *bp;
|
||||
|
||||
VehicleOrderID a_order = a->cur_real_order_index;
|
||||
VehicleOrderID b_order = b->cur_real_order_index;
|
||||
int j = (int)b_order - (int)a_order;
|
||||
@@ -368,15 +365,15 @@ static int CDECL VehicleTimetableSorter(Vehicle * const *ap, Vehicle * const *bp
|
||||
|
||||
/* First check the order index that accounted for loading, then just the raw one. */
|
||||
int i = (int)b_order - (int)a_order;
|
||||
if (i != 0) return i;
|
||||
if (j != 0) return j;
|
||||
if (i != 0) return i < 0;
|
||||
if (j != 0) return j < 0;
|
||||
|
||||
/* Look at the time we spent in this order; the higher, the closer to its destination. */
|
||||
i = b->current_order_time - a->current_order_time;
|
||||
if (i != 0) return i;
|
||||
if (i != 0) return i < 0;
|
||||
|
||||
/* If all else is equal, use some unique index to sort it the same way. */
|
||||
return b->unitnumber - a->unitnumber;
|
||||
return b->unitnumber < a->unitnumber;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -421,7 +418,7 @@ CommandCost CmdSetTimetableStart(TileIndex tile, DoCommandFlag flags, uint32 p1,
|
||||
int num_vehs = (uint)vehs.size();
|
||||
|
||||
if (num_vehs >= 2) {
|
||||
QSortT(vehs.data(), vehs.size(), &VehicleTimetableSorter);
|
||||
std::sort(vehs.begin(), vehs.end(), &VehicleTimetableSorter);
|
||||
}
|
||||
|
||||
int idx = vehs.begin() - std::find(vehs.begin(), vehs.end(), v);
|
||||
|
@@ -674,54 +674,55 @@ private:
|
||||
}
|
||||
|
||||
/** Sort by town name */
|
||||
static int CDECL TownNameSorter(const Town * const *a, const Town * const *b)
|
||||
static bool TownNameSorter(const Town * const &a, const Town * const &b)
|
||||
{
|
||||
static char buf_cache[64];
|
||||
const Town *ta = *a;
|
||||
const Town *tb = *b;
|
||||
char buf[64];
|
||||
|
||||
SetDParam(0, ta->index);
|
||||
SetDParam(0, a->index);
|
||||
GetString(buf, STR_TOWN_NAME, lastof(buf));
|
||||
|
||||
/* If 'b' is the same town as in the last round, use the cached value
|
||||
* We do this to speed stuff up ('b' is called with the same value a lot of
|
||||
* times after each other) */
|
||||
if (tb != last_town) {
|
||||
last_town = tb;
|
||||
SetDParam(0, tb->index);
|
||||
if (b != last_town) {
|
||||
last_town = b;
|
||||
SetDParam(0, b->index);
|
||||
GetString(buf_cache, STR_TOWN_NAME, lastof(buf_cache));
|
||||
}
|
||||
|
||||
return strnatcmp(buf, buf_cache); // Sort by name (natural sorting).
|
||||
return strnatcmp(buf, buf_cache) < 0; // Sort by name (natural sorting).
|
||||
}
|
||||
|
||||
/** Sort by population (default descending, as big towns are of the most interest). */
|
||||
static int CDECL TownPopulationSorter(const Town * const *a, const Town * const *b)
|
||||
static bool TownPopulationSorter(const Town * const &a, const Town * const &b)
|
||||
{
|
||||
uint32 a_population = (*a)->cache.population;
|
||||
uint32 b_population = (*b)->cache.population;
|
||||
uint32 a_population = a->cache.population;
|
||||
uint32 b_population = b->cache.population;
|
||||
if (a_population == b_population) return TownDirectoryWindow::TownNameSorter(a, b);
|
||||
return (a_population < b_population) ? -1 : 1;
|
||||
return a_population < b_population;
|
||||
}
|
||||
|
||||
/** Sort by town rating */
|
||||
static int CDECL TownRatingSorter(const Town * const *a, const Town * const *b)
|
||||
static bool TownRatingSorter(const Town * const &a, const Town * const &b)
|
||||
{
|
||||
int before = TownDirectoryWindow::last_sorting.order ? 1 : -1; // Value to get 'a' before 'b'.
|
||||
bool before = !TownDirectoryWindow::last_sorting.order; // Value to get 'a' before 'b'.
|
||||
|
||||
/* Towns without rating are always after towns with rating. */
|
||||
if (HasBit((*a)->have_ratings, _local_company)) {
|
||||
if (HasBit((*b)->have_ratings, _local_company)) {
|
||||
int16 a_rating = (*a)->ratings[_local_company];
|
||||
int16 b_rating = (*b)->ratings[_local_company];
|
||||
if (HasBit(a->have_ratings, _local_company)) {
|
||||
if (HasBit(b->have_ratings, _local_company)) {
|
||||
int16 a_rating = a->ratings[_local_company];
|
||||
int16 b_rating = b->ratings[_local_company];
|
||||
if (a_rating == b_rating) return TownDirectoryWindow::TownNameSorter(a, b);
|
||||
return (a_rating < b_rating) ? -1 : 1;
|
||||
return a_rating < b_rating;
|
||||
}
|
||||
return before;
|
||||
}
|
||||
if (HasBit((*b)->have_ratings, _local_company)) return -before;
|
||||
return -before * TownDirectoryWindow::TownNameSorter(a, b); // Sort unrated towns always on ascending town name.
|
||||
if (HasBit(b->have_ratings, _local_company)) return !before;
|
||||
|
||||
/* Sort unrated towns always on ascending town name. */
|
||||
if (before) return TownDirectoryWindow::TownNameSorter(a, b);
|
||||
return !TownDirectoryWindow::TownNameSorter(a, b);
|
||||
}
|
||||
|
||||
public:
|
||||
|
@@ -474,7 +474,7 @@ static const TraceRestrictDropDownListSet *GetSortedCargoTypeDropDownListSet()
|
||||
static DropDownList GetGroupDropDownList(Owner owner, GroupID group_id, int &selected)
|
||||
{
|
||||
typedef GUIList<const Group*> GUIGroupList;
|
||||
extern int CDECL GroupNameSorter(const Group * const *a, const Group * const *b);
|
||||
extern bool GroupNameSorter(const Group * const &a, const Group * const &b);
|
||||
|
||||
GUIGroupList list;
|
||||
|
||||
@@ -506,11 +506,11 @@ static DropDownList GetGroupDropDownList(Owner owner, GroupID group_id, int &sel
|
||||
}
|
||||
|
||||
/** Sort slots by their name */
|
||||
static int CDECL SlotNameSorter(const TraceRestrictSlot * const *a, const TraceRestrictSlot * const *b)
|
||||
static bool CDECL SlotNameSorter(const TraceRestrictSlot * const &a, const TraceRestrictSlot * const &b)
|
||||
{
|
||||
int r = strnatcmp((*a)->name.c_str(), (*b)->name.c_str()); // Sort by name (natural sorting).
|
||||
if (r == 0) return (*a)->index - (*b)->index;
|
||||
return r;
|
||||
int r = strnatcmp(a->name.c_str(), b->name.c_str()); // Sort by name (natural sorting).
|
||||
if (r == 0) return a->index < b->index;
|
||||
return r < 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -384,7 +384,7 @@ void BaseVehicleListWindow::SortVehicleList()
|
||||
void DepotSortList(VehicleList *list)
|
||||
{
|
||||
if (list->size() < 2) return;
|
||||
QSortT(list->data(), list->size(), &VehicleNumberSorter);
|
||||
std::sort(list->begin(), list->end(), &VehicleNumberSorter);
|
||||
}
|
||||
|
||||
/** draw the vehicle profit button in the vehicle list window. */
|
||||
@@ -1338,69 +1338,69 @@ StringID GetCargoSubtypeText(const Vehicle *v)
|
||||
}
|
||||
|
||||
/** Sort vehicles by their number */
|
||||
static int CDECL VehicleNumberSorter(const Vehicle * const *a, const Vehicle * const *b)
|
||||
static bool VehicleNumberSorter(const Vehicle * const &a, const Vehicle * const &b)
|
||||
{
|
||||
return (*a)->unitnumber - (*b)->unitnumber;
|
||||
return a->unitnumber < b->unitnumber;
|
||||
}
|
||||
|
||||
/** Sort vehicles by their name */
|
||||
static int CDECL VehicleNameSorter(const Vehicle * const *a, const Vehicle * const *b)
|
||||
static bool VehicleNameSorter(const Vehicle * const &a, const Vehicle * const &b)
|
||||
{
|
||||
static char last_name[2][64];
|
||||
|
||||
if (*a != _last_vehicle[0]) {
|
||||
_last_vehicle[0] = *a;
|
||||
SetDParam(0, (*a)->index);
|
||||
if (a != _last_vehicle[0]) {
|
||||
_last_vehicle[0] = a;
|
||||
SetDParam(0, a->index);
|
||||
GetString(last_name[0], STR_VEHICLE_NAME, lastof(last_name[0]));
|
||||
}
|
||||
|
||||
if (*b != _last_vehicle[1]) {
|
||||
_last_vehicle[1] = *b;
|
||||
SetDParam(0, (*b)->index);
|
||||
if (b != _last_vehicle[1]) {
|
||||
_last_vehicle[1] = b;
|
||||
SetDParam(0, b->index);
|
||||
GetString(last_name[1], STR_VEHICLE_NAME, lastof(last_name[1]));
|
||||
}
|
||||
|
||||
int r = strnatcmp(last_name[0], last_name[1]); // Sort by name (natural sorting).
|
||||
return (r != 0) ? r : VehicleNumberSorter(a, b);
|
||||
return (r != 0) ? r < 0: VehicleNumberSorter(a, b);
|
||||
}
|
||||
|
||||
/** Sort vehicles by their age */
|
||||
static int CDECL VehicleAgeSorter(const Vehicle * const *a, const Vehicle * const *b)
|
||||
static bool VehicleAgeSorter(const Vehicle * const &a, const Vehicle * const &b)
|
||||
{
|
||||
int r = (*a)->age - (*b)->age;
|
||||
return (r != 0) ? r : VehicleNumberSorter(a, b);
|
||||
int r = a->age - b->age;
|
||||
return (r != 0) ? r < 0 : VehicleNumberSorter(a, b);
|
||||
}
|
||||
|
||||
/** Sort vehicles by this year profit */
|
||||
static int CDECL VehicleProfitThisYearSorter(const Vehicle * const *a, const Vehicle * const *b)
|
||||
static bool VehicleProfitThisYearSorter(const Vehicle * const &a, const Vehicle * const &b)
|
||||
{
|
||||
int r = ClampToI32((*a)->GetDisplayProfitThisYear() - (*b)->GetDisplayProfitThisYear());
|
||||
return (r != 0) ? r : VehicleNumberSorter(a, b);
|
||||
int r = ClampToI32(a->GetDisplayProfitThisYear() - b->GetDisplayProfitThisYear());
|
||||
return (r != 0) ? r < 0 : VehicleNumberSorter(a, b);
|
||||
}
|
||||
|
||||
/** Sort vehicles by last year profit */
|
||||
static int CDECL VehicleProfitLastYearSorter(const Vehicle * const *a, const Vehicle * const *b)
|
||||
static bool VehicleProfitLastYearSorter(const Vehicle * const &a, const Vehicle * const &b)
|
||||
{
|
||||
int r = ClampToI32((*a)->GetDisplayProfitLastYear() - (*b)->GetDisplayProfitLastYear());
|
||||
return (r != 0) ? r : VehicleNumberSorter(a, b);
|
||||
int r = ClampToI32(a->GetDisplayProfitLastYear() - b->GetDisplayProfitLastYear());
|
||||
return (r != 0) ? r < 0 : VehicleNumberSorter(a, b);
|
||||
}
|
||||
|
||||
/** Sort vehicles by lifetime profit */
|
||||
static int CDECL VehicleProfitLifetimeSorter(const Vehicle * const *a, const Vehicle * const *b)
|
||||
static bool VehicleProfitLifetimeSorter(const Vehicle * const &a, const Vehicle * const &b)
|
||||
{
|
||||
int r = ClampToI32((*a)->GetDisplayProfitLifetime() - (*b)->GetDisplayProfitLifetime());
|
||||
return (r != 0) ? r : VehicleNumberSorter(a, b);
|
||||
int r = ClampToI32(a->GetDisplayProfitLifetime() - b->GetDisplayProfitLifetime());
|
||||
return (r != 0) ? r < 0 : VehicleNumberSorter(a, b);
|
||||
}
|
||||
|
||||
/** Sort vehicles by their cargo */
|
||||
static int CDECL VehicleCargoSorter(const Vehicle * const *a, const Vehicle * const *b)
|
||||
static bool VehicleCargoSorter(const Vehicle * const &a, const Vehicle * const &b)
|
||||
{
|
||||
const Vehicle *v;
|
||||
CargoArray diff;
|
||||
|
||||
/* Append the cargo of the connected waggons */
|
||||
for (v = *a; v != nullptr; v = v->Next()) diff[v->cargo_type] += v->cargo_cap;
|
||||
for (v = *b; v != nullptr; v = v->Next()) diff[v->cargo_type] -= v->cargo_cap;
|
||||
for (v = a; v != nullptr; v = v->Next()) diff[v->cargo_type] += v->cargo_cap;
|
||||
for (v = b; v != nullptr; v = v->Next()) diff[v->cargo_type] -= v->cargo_cap;
|
||||
|
||||
int r = 0;
|
||||
for (CargoID i = 0; i < NUM_CARGO; i++) {
|
||||
@@ -1408,69 +1408,69 @@ static int CDECL VehicleCargoSorter(const Vehicle * const *a, const Vehicle * co
|
||||
if (r != 0) break;
|
||||
}
|
||||
|
||||
return (r != 0) ? r : VehicleNumberSorter(a, b);
|
||||
return (r != 0) ? r < 0 : VehicleNumberSorter(a, b);
|
||||
}
|
||||
|
||||
/** Sort vehicles by their reliability */
|
||||
static int CDECL VehicleReliabilitySorter(const Vehicle * const *a, const Vehicle * const *b)
|
||||
static bool VehicleReliabilitySorter(const Vehicle * const &a, const Vehicle * const &b)
|
||||
{
|
||||
int r = (*a)->reliability - (*b)->reliability;
|
||||
return (r != 0) ? r : VehicleNumberSorter(a, b);
|
||||
int r = a->reliability - b->reliability;
|
||||
return (r != 0) ? r < 0 : VehicleNumberSorter(a, b);
|
||||
}
|
||||
|
||||
/** Sort vehicles by their max speed */
|
||||
static int CDECL VehicleMaxSpeedSorter(const Vehicle * const *a, const Vehicle * const *b)
|
||||
static bool VehicleMaxSpeedSorter(const Vehicle * const &a, const Vehicle * const &b)
|
||||
{
|
||||
int r = (*a)->vcache.cached_max_speed - (*b)->vcache.cached_max_speed;
|
||||
return (r != 0) ? r : VehicleNumberSorter(a, b);
|
||||
int r = a->vcache.cached_max_speed - b->vcache.cached_max_speed;
|
||||
return (r != 0) ? r < 0 : VehicleNumberSorter(a, b);
|
||||
}
|
||||
|
||||
/** Sort vehicles by model */
|
||||
static int CDECL VehicleModelSorter(const Vehicle * const *a, const Vehicle * const *b)
|
||||
static bool VehicleModelSorter(const Vehicle * const &a, const Vehicle * const &b)
|
||||
{
|
||||
int r = (*a)->engine_type - (*b)->engine_type;
|
||||
return (r != 0) ? r : VehicleNumberSorter(a, b);
|
||||
int r = a->engine_type - b->engine_type;
|
||||
return (r != 0) ? r < 0 : VehicleNumberSorter(a, b);
|
||||
}
|
||||
|
||||
/** Sort vehicles by their value */
|
||||
static int CDECL VehicleValueSorter(const Vehicle * const *a, const Vehicle * const *b)
|
||||
static bool VehicleValueSorter(const Vehicle * const &a, const Vehicle * const &b)
|
||||
{
|
||||
const Vehicle *u;
|
||||
Money diff = 0;
|
||||
|
||||
for (u = *a; u != nullptr; u = u->Next()) diff += u->value;
|
||||
for (u = *b; u != nullptr; u = u->Next()) diff -= u->value;
|
||||
for (u = a; u != nullptr; u = u->Next()) diff += u->value;
|
||||
for (u = b; u != nullptr; u = u->Next()) diff -= u->value;
|
||||
|
||||
int r = ClampToI32(diff);
|
||||
return (r != 0) ? r : VehicleNumberSorter(a, b);
|
||||
return (r != 0) ? r < 0 : VehicleNumberSorter(a, b);
|
||||
}
|
||||
|
||||
/** Sort vehicles by their length */
|
||||
static int CDECL VehicleLengthSorter(const Vehicle * const *a, const Vehicle * const *b)
|
||||
static bool VehicleLengthSorter(const Vehicle * const &a, const Vehicle * const &b)
|
||||
{
|
||||
int r = (*a)->GetGroundVehicleCache()->cached_total_length - (*b)->GetGroundVehicleCache()->cached_total_length;
|
||||
return (r != 0) ? r : VehicleNumberSorter(a, b);
|
||||
int r = a->GetGroundVehicleCache()->cached_total_length - b->GetGroundVehicleCache()->cached_total_length;
|
||||
return (r != 0) ? r < 0 : VehicleNumberSorter(a, b);
|
||||
}
|
||||
|
||||
/** Sort vehicles by the time they can still live */
|
||||
static int CDECL VehicleTimeToLiveSorter(const Vehicle * const *a, const Vehicle * const *b)
|
||||
static bool VehicleTimeToLiveSorter(const Vehicle * const &a, const Vehicle * const &b)
|
||||
{
|
||||
int r = ClampToI32(((*a)->max_age - (*a)->age) - ((*b)->max_age - (*b)->age));
|
||||
return (r != 0) ? r : VehicleNumberSorter(a, b);
|
||||
int r = ClampToI32((a->max_age - a->age) - (b->max_age - b->age));
|
||||
return (r != 0) ? r < 0 : VehicleNumberSorter(a, b);
|
||||
}
|
||||
|
||||
/** Sort vehicles by the timetable delay */
|
||||
static int CDECL VehicleTimetableDelaySorter(const Vehicle * const *a, const Vehicle * const *b)
|
||||
static bool VehicleTimetableDelaySorter(const Vehicle * const &a, const Vehicle * const &b)
|
||||
{
|
||||
int r = (*a)->lateness_counter - (*b)->lateness_counter;
|
||||
return (r != 0) ? r : VehicleNumberSorter(a, b);
|
||||
int r = a->lateness_counter - b->lateness_counter;
|
||||
return (r != 0) ? r < 0 : VehicleNumberSorter(a, b);
|
||||
}
|
||||
|
||||
/** Sort vehicles by the average order occupancy */
|
||||
static int CDECL VehicleAverageOrderOccupancySorter(const Vehicle * const *a, const Vehicle * const *b)
|
||||
static bool VehicleAverageOrderOccupancySorter(const Vehicle * const &a, const Vehicle * const &b)
|
||||
{
|
||||
int r = (*a)->GetOrderOccupancyAverage() - (*b)->GetOrderOccupancyAverage();
|
||||
return (r != 0) ? r : VehicleNumberSorter(a, b);
|
||||
int r = a->GetOrderOccupancyAverage() - b->GetOrderOccupancyAverage();
|
||||
return (r != 0) ? r < 0 : VehicleNumberSorter(a, b);
|
||||
}
|
||||
|
||||
void InitializeGUI()
|
||||
|
@@ -213,7 +213,7 @@ CommandCost CmdBuildRailWaypoint(TileIndex start_tile, DoCommandFlag flags, uint
|
||||
}
|
||||
|
||||
Waypoint *wp = nullptr;
|
||||
TileArea new_location(TileArea(start_tile, width, height));
|
||||
TileArea new_location(start_tile, width, height);
|
||||
CommandCost ret = FindJoiningWaypoint(est, station_to_join, adjacent, new_location, &wp);
|
||||
if (ret.Failed()) return ret;
|
||||
|
||||
|
@@ -157,10 +157,10 @@ void WindowDesc::LoadFromConfig()
|
||||
/**
|
||||
* Sort WindowDesc by ini_key.
|
||||
*/
|
||||
static int CDECL DescSorter(WindowDesc * const *a, WindowDesc * const *b)
|
||||
static bool DescSorter(WindowDesc* const &a, WindowDesc* const &b)
|
||||
{
|
||||
if ((*a)->ini_key != nullptr && (*b)->ini_key != nullptr) return strcmp((*a)->ini_key, (*b)->ini_key);
|
||||
return ((*b)->ini_key != nullptr ? 1 : 0) - ((*a)->ini_key != nullptr ? 1 : 0);
|
||||
if (a->ini_key != nullptr && b->ini_key != nullptr) return strcmp(a->ini_key, b->ini_key) < 0;
|
||||
return a->ini_key != nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -169,7 +169,7 @@ static int CDECL DescSorter(WindowDesc * const *a, WindowDesc * const *b)
|
||||
void WindowDesc::SaveToConfig()
|
||||
{
|
||||
/* Sort the stuff to get a nice ini file on first write */
|
||||
QSortT(_window_descs->data(), _window_descs->size(), DescSorter);
|
||||
std::sort(_window_descs->begin(), _window_descs->end(), DescSorter);
|
||||
|
||||
IniFile *ini = new IniFile();
|
||||
ini->LoadFromDisk(_windows_file, NO_DIRECTORY);
|
||||
|
Reference in New Issue
Block a user