mirror of https://github.com/OpenTTD/OpenTTD
(svn r7314) -Cleanup: const, whitespace, coding style and variable usage.
parent
04f9944746
commit
f40eccae9b
|
@ -296,8 +296,7 @@ static void GenerateBuildAircraftList(Window *w)
|
||||||
if (avi->subtype == 0) continue; // if helicopter
|
if (avi->subtype == 0) continue; // if helicopter
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ALL:
|
case ALL: break;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
EngList_Add(&bv->eng_list, eid);
|
EngList_Add(&bv->eng_list, eid);
|
||||||
}
|
}
|
||||||
|
@ -311,8 +310,8 @@ static void GenerateBuildList(Window *w)
|
||||||
switch (bv->vehicle_type) {
|
switch (bv->vehicle_type) {
|
||||||
case VEH_Aircraft:
|
case VEH_Aircraft:
|
||||||
GenerateBuildAircraftList(w);
|
GenerateBuildAircraftList(w);
|
||||||
_internal_sort_order = WP(w,buildvehicle_d).descending_sort_order;
|
_internal_sort_order = bv->descending_sort_order;
|
||||||
EngList_Sort(&WP(w, buildvehicle_d).eng_list, _aircraft_sorter[WP(w,buildvehicle_d).sort_criteria]);
|
EngList_Sort(&bv->eng_list, _aircraft_sorter[bv->sort_criteria]);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default: NOT_REACHED();
|
default: NOT_REACHED();
|
||||||
|
@ -359,7 +358,7 @@ static void DrawBuildAircraftWindow(Window *w)
|
||||||
uint16 list_length = GetEngineArrayLength(w);
|
uint16 list_length = GetEngineArrayLength(w);
|
||||||
uint16 max = min(w->vscroll.pos + w->vscroll.cap, list_length);
|
uint16 max = min(w->vscroll.pos + w->vscroll.cap, list_length);
|
||||||
|
|
||||||
for(; eid < max; eid++) {
|
for (; eid < max; eid++) {
|
||||||
const EngineID engine = list[eid];
|
const EngineID engine = list[eid];
|
||||||
|
|
||||||
DrawString(x + 62, y + 7, GetCustomEngineName(engine), engine == selected_id ? 0xC : 0x10);
|
DrawString(x + 62, y + 7, GetCustomEngineName(engine), engine == selected_id ? 0xC : 0x10);
|
||||||
|
@ -382,7 +381,7 @@ static void BuildAircraftClickEvent(Window *w, WindowEvent *e)
|
||||||
|
|
||||||
switch (e->we.click.widget) {
|
switch (e->we.click.widget) {
|
||||||
case BUILD_VEHICLE_WIDGET_SORT_ASSENDING_DESCENDING:
|
case BUILD_VEHICLE_WIDGET_SORT_ASSENDING_DESCENDING:
|
||||||
bv->descending_sort_order = !bv->descending_sort_order;
|
bv->descending_sort_order ^= true;
|
||||||
_last_sort_order = bv->descending_sort_order;
|
_last_sort_order = bv->descending_sort_order;
|
||||||
GenerateBuildList(w);
|
GenerateBuildList(w);
|
||||||
SetWindowDirty(w);
|
SetWindowDirty(w);
|
||||||
|
@ -452,8 +451,7 @@ static void NewAircraftWndProc(Window *w, WindowEvent *e)
|
||||||
|
|
||||||
case WE_DROPDOWN_SELECT: /* we have selected a dropdown item in the list */
|
case WE_DROPDOWN_SELECT: /* we have selected a dropdown item in the list */
|
||||||
if (bv->sort_criteria != e->we.dropdown.index) {
|
if (bv->sort_criteria != e->we.dropdown.index) {
|
||||||
bv->sort_criteria = e->we.dropdown.index;
|
bv->sort_criteria = _last_sort_criteria = e->we.dropdown.index;
|
||||||
_last_sort_criteria = e->we.dropdown.index;
|
|
||||||
GenerateBuildList(w);
|
GenerateBuildList(w);
|
||||||
}
|
}
|
||||||
SetWindowDirty(w);
|
SetWindowDirty(w);
|
||||||
|
@ -483,20 +481,15 @@ void ShowBuildVehicleWindow(TileIndex tile, byte type)
|
||||||
w = AllocateWindowDescFront(&_build_vehicle_desc, tile);
|
w = AllocateWindowDescFront(&_build_vehicle_desc, tile);
|
||||||
if (w == NULL) return;
|
if (w == NULL) return;
|
||||||
|
|
||||||
if (tile != 0) {
|
w->caption_color = (tile != 0) ? GetTileOwner(tile) : _local_player;
|
||||||
w->caption_color = GetTileOwner(tile);
|
|
||||||
} else {
|
|
||||||
w->caption_color = _local_player;
|
|
||||||
}
|
|
||||||
|
|
||||||
w->resize.step_height = GetVehicleListHeight(type);
|
w->resize.step_height = GetVehicleListHeight(type);
|
||||||
w->vscroll.cap = 4;
|
w->vscroll.cap = 4;
|
||||||
w->widget[BUILD_VEHICLE_WIDGET_LIST].data = (w->vscroll.cap << 8) + 1;
|
w->widget[BUILD_VEHICLE_WIDGET_LIST].data = (w->vscroll.cap << 8) + 1;
|
||||||
|
|
||||||
bv = &WP(w, buildvehicle_d);
|
bv = &WP(w, buildvehicle_d);
|
||||||
EngList_Create(&bv->eng_list);
|
EngList_Create(&bv->eng_list);
|
||||||
bv->sel_engine = INVALID_ENGINE;
|
bv->sel_engine = INVALID_ENGINE;
|
||||||
bv->sort_criteria = _last_sort_criteria;
|
bv->sort_criteria = _last_sort_criteria;
|
||||||
bv->descending_sort_order = _last_sort_order;
|
bv->descending_sort_order = _last_sort_order;
|
||||||
|
|
||||||
bv->vehicle_type = type;
|
bv->vehicle_type = type;
|
||||||
|
|
76
train_gui.c
76
train_gui.c
|
@ -74,17 +74,16 @@ static int CDECL TrainEnginesThenWagonsSorter(const void *a, const void *b)
|
||||||
int val_b = ((RailVehInfo(vb)->flags & RVI_WAGON) != 0) ? 1 : 0;
|
int val_b = ((RailVehInfo(vb)->flags & RVI_WAGON) != 0) ? 1 : 0;
|
||||||
int r = val_a - val_b;
|
int r = val_a - val_b;
|
||||||
|
|
||||||
if (r == 0) {
|
/* Use EngineID to sort instead since we want consistent sorting */
|
||||||
/* Use EngineID to sort instead since we want consistent sorting */
|
if (r == 0) return TrainEngineNumberSorter(a, b);
|
||||||
return TrainEngineNumberSorter(a, b);
|
|
||||||
}
|
|
||||||
return _internal_sort_order ? -r : r;
|
return _internal_sort_order ? -r : r;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int CDECL TrainEngineCostSorter(const void *a, const void *b)
|
static int CDECL TrainEngineCostSorter(const void *a, const void *b)
|
||||||
{
|
{
|
||||||
const int va = RailVehInfo(*(const EngineID*)a)->base_cost;
|
int va = RailVehInfo(*(const EngineID*)a)->base_cost;
|
||||||
const int vb = RailVehInfo(*(const EngineID*)b)->base_cost;
|
int vb = RailVehInfo(*(const EngineID*)b)->base_cost;
|
||||||
int r = va - vb;
|
int r = va - vb;
|
||||||
|
|
||||||
return _internal_sort_order ? -r : r;
|
return _internal_sort_order ? -r : r;
|
||||||
|
@ -92,9 +91,9 @@ static int CDECL TrainEngineCostSorter(const void *a, const void *b)
|
||||||
|
|
||||||
static int CDECL TrainEngineSpeedSorter(const void *a, const void *b)
|
static int CDECL TrainEngineSpeedSorter(const void *a, const void *b)
|
||||||
{
|
{
|
||||||
const int va = RailVehInfo(*(const EngineID*)a)->max_speed;
|
int va = RailVehInfo(*(const EngineID*)a)->max_speed;
|
||||||
const int vb = RailVehInfo(*(const EngineID*)b)->max_speed;
|
int vb = RailVehInfo(*(const EngineID*)b)->max_speed;
|
||||||
const int r = va - vb;
|
int r = va - vb;
|
||||||
|
|
||||||
return _internal_sort_order ? -r : r;
|
return _internal_sort_order ? -r : r;
|
||||||
}
|
}
|
||||||
|
@ -104,18 +103,18 @@ static int CDECL TrainEnginePowerSorter(const void *a, const void *b)
|
||||||
const RailVehicleInfo *rvi_a = RailVehInfo(*(const EngineID*)a);
|
const RailVehicleInfo *rvi_a = RailVehInfo(*(const EngineID*)a);
|
||||||
const RailVehicleInfo *rvi_b = RailVehInfo(*(const EngineID*)b);
|
const RailVehicleInfo *rvi_b = RailVehInfo(*(const EngineID*)b);
|
||||||
|
|
||||||
const int va = rvi_a->power << (rvi_a->flags & RVI_MULTIHEAD ? 1 : 0);
|
int va = rvi_a->power << (rvi_a->flags & RVI_MULTIHEAD ? 1 : 0);
|
||||||
const int vb = rvi_b->power << (rvi_b->flags & RVI_MULTIHEAD ? 1 : 0);
|
int vb = rvi_b->power << (rvi_b->flags & RVI_MULTIHEAD ? 1 : 0);
|
||||||
const int r = va - vb;
|
int r = va - vb;
|
||||||
|
|
||||||
return _internal_sort_order ? -r : r;
|
return _internal_sort_order ? -r : r;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int CDECL TrainEngineIntroDateSorter(const void *a, const void *b)
|
static int CDECL TrainEngineIntroDateSorter(const void *a, const void *b)
|
||||||
{
|
{
|
||||||
const int va = GetEngine(*(const EngineID*)a)->intro_date;
|
int va = GetEngine(*(const EngineID*)a)->intro_date;
|
||||||
const int vb = GetEngine(*(const EngineID*)b)->intro_date;
|
int vb = GetEngine(*(const EngineID*)b)->intro_date;
|
||||||
const int r = va - vb;
|
int r = va - vb;
|
||||||
|
|
||||||
return _internal_sort_order ? -r : r;
|
return _internal_sort_order ? -r : r;
|
||||||
}
|
}
|
||||||
|
@ -149,9 +148,9 @@ static int CDECL TrainEngineRunningCostSorter(const void *a, const void *b)
|
||||||
const RailVehicleInfo *rvi_a = RailVehInfo(*(const EngineID*)a);
|
const RailVehicleInfo *rvi_a = RailVehInfo(*(const EngineID*)a);
|
||||||
const RailVehicleInfo *rvi_b = RailVehInfo(*(const EngineID*)b);
|
const RailVehicleInfo *rvi_b = RailVehInfo(*(const EngineID*)b);
|
||||||
|
|
||||||
const int va = rvi_a->running_cost_base * _price.running_rail[rvi_a->running_cost_class] * (rvi_a->flags & RVI_MULTIHEAD ? 2 : 1);
|
int va = rvi_a->running_cost_base * _price.running_rail[rvi_a->running_cost_class] * (rvi_a->flags & RVI_MULTIHEAD ? 2 : 1);
|
||||||
const int vb = rvi_b->running_cost_base * _price.running_rail[rvi_b->running_cost_class] * (rvi_b->flags & RVI_MULTIHEAD ? 2 : 1);
|
int vb = rvi_b->running_cost_base * _price.running_rail[rvi_b->running_cost_class] * (rvi_b->flags & RVI_MULTIHEAD ? 2 : 1);
|
||||||
const int r = va - vb;
|
int r = va - vb;
|
||||||
|
|
||||||
return _internal_sort_order ? -r : r;
|
return _internal_sort_order ? -r : r;
|
||||||
}
|
}
|
||||||
|
@ -167,18 +166,18 @@ static int CDECL TrainEnginePowerVsRunningCostSorter(const void *a, const void *
|
||||||
* Because of this, the return value have to be reversed as well and we return b - a instead of a - b.
|
* Because of this, the return value have to be reversed as well and we return b - a instead of a - b.
|
||||||
* Another thing is that both power and running costs should be doubled for multiheaded engines.
|
* Another thing is that both power and running costs should be doubled for multiheaded engines.
|
||||||
* Since it would be multipling with 2 in both numerator and denumerator, it will even themselves out and we skip checking for multiheaded. */
|
* Since it would be multipling with 2 in both numerator and denumerator, it will even themselves out and we skip checking for multiheaded. */
|
||||||
const int va = (rvi_a->running_cost_base * _price.running_rail[rvi_a->running_cost_class]) / max(1, rvi_a->power);
|
int va = (rvi_a->running_cost_base * _price.running_rail[rvi_a->running_cost_class]) / max(1, rvi_a->power);
|
||||||
const int vb = (rvi_b->running_cost_base * _price.running_rail[rvi_b->running_cost_class]) / max(1, rvi_b->power);
|
int vb = (rvi_b->running_cost_base * _price.running_rail[rvi_b->running_cost_class]) / max(1, rvi_b->power);
|
||||||
const int r = vb - va;
|
int r = vb - va;
|
||||||
|
|
||||||
return _internal_sort_order ? -r : r;
|
return _internal_sort_order ? -r : r;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int CDECL TrainEngineReliabilitySorter(const void *a, const void *b)
|
static int CDECL TrainEngineReliabilitySorter(const void *a, const void *b)
|
||||||
{
|
{
|
||||||
const int va = GetEngine(*(const EngineID*)a)->reliability;
|
int va = GetEngine(*(const EngineID*)a)->reliability;
|
||||||
const int vb = GetEngine(*(const EngineID*)b)->reliability;
|
int vb = GetEngine(*(const EngineID*)b)->reliability;
|
||||||
const int r = va - vb;
|
int r = va - vb;
|
||||||
|
|
||||||
return _internal_sort_order ? -r : r;
|
return _internal_sort_order ? -r : r;
|
||||||
}
|
}
|
||||||
|
@ -376,23 +375,24 @@ static void engine_drawing_loop(const EngineList *engines, int x, int *y, Engine
|
||||||
|
|
||||||
static void GenerateBuildList(Window *w)
|
static void GenerateBuildList(Window *w)
|
||||||
{
|
{
|
||||||
EngineID id;
|
EngineID eid;
|
||||||
int num_engines = 0;
|
int num_engines = 0;
|
||||||
int num_wagons = 0;
|
int num_wagons = 0;
|
||||||
buildvehicle_d *bv = &WP(w, buildvehicle_d);
|
buildvehicle_d *bv = &WP(w, buildvehicle_d);
|
||||||
|
|
||||||
bv->filter.railtype = w->window_number == 0 ? RAILTYPE_END : GetRailType(w->window_number);
|
bv->filter.railtype = (w->window_number == 0) ? RAILTYPE_END : GetRailType(w->window_number);
|
||||||
|
|
||||||
EngList_RemoveAll(&bv->eng_list);
|
EngList_RemoveAll(&bv->eng_list);
|
||||||
// make list of all available cars
|
|
||||||
for (id = 0; id < NUM_TRAIN_ENGINES; id++) {
|
// make a list of all available cars
|
||||||
const Engine *e = GetEngine(id);
|
for (eid = 0; eid < NUM_TRAIN_ENGINES; eid++) {
|
||||||
const RailVehicleInfo *rvi = RailVehInfo(id);
|
const Engine *e = GetEngine(eid);
|
||||||
|
const RailVehicleInfo *rvi = RailVehInfo(eid);
|
||||||
|
|
||||||
if (bv->filter.railtype != RAILTYPE_END && !HasPowerOnRail(e->railtype, bv->filter.railtype)) continue;
|
if (bv->filter.railtype != RAILTYPE_END && !HasPowerOnRail(e->railtype, bv->filter.railtype)) continue;
|
||||||
if (!IsEngineBuildable(id, VEH_Train)) continue;
|
if (!IsEngineBuildable(eid, VEH_Train)) continue;
|
||||||
|
|
||||||
EngList_Add(&bv->eng_list, id);
|
EngList_Add(&bv->eng_list, eid);
|
||||||
if ((rvi->flags & RVI_WAGON) == 0) {
|
if ((rvi->flags & RVI_WAGON) == 0) {
|
||||||
num_engines++;
|
num_engines++;
|
||||||
} else {
|
} else {
|
||||||
|
@ -405,7 +405,7 @@ static void GenerateBuildList(Window *w)
|
||||||
EngList_Sort(&bv->eng_list, TrainEnginesThenWagonsSorter);
|
EngList_Sort(&bv->eng_list, TrainEnginesThenWagonsSorter);
|
||||||
|
|
||||||
// and then sort engines
|
// and then sort engines
|
||||||
_internal_sort_order = WP(w,buildvehicle_d).descending_sort_order;
|
_internal_sort_order = bv->descending_sort_order;
|
||||||
EngList_SortPartial(&bv->eng_list, _engine_sorter[bv->sort_criteria], 0, num_engines);
|
EngList_SortPartial(&bv->eng_list, _engine_sorter[bv->sort_criteria], 0, num_engines);
|
||||||
|
|
||||||
// and finally sort wagons
|
// and finally sort wagons
|
||||||
|
@ -414,7 +414,7 @@ static void GenerateBuildList(Window *w)
|
||||||
|
|
||||||
static void DrawTrainBuildWindow(Window *w)
|
static void DrawTrainBuildWindow(Window *w)
|
||||||
{
|
{
|
||||||
buildvehicle_d *bv = &WP(w,buildvehicle_d);
|
const buildvehicle_d *bv = &WP(w, buildvehicle_d);
|
||||||
int num_engines = EngList_Count(&bv->eng_list);
|
int num_engines = EngList_Count(&bv->eng_list);
|
||||||
int x = 1;
|
int x = 1;
|
||||||
int y = 27;
|
int y = 27;
|
||||||
|
@ -461,7 +461,7 @@ static void DrawTrainBuildWindow(Window *w)
|
||||||
|
|
||||||
static void NewRailVehicleWndProc(Window *w, WindowEvent *e)
|
static void NewRailVehicleWndProc(Window *w, WindowEvent *e)
|
||||||
{
|
{
|
||||||
buildvehicle_d *bv = &WP(w,buildvehicle_d);
|
buildvehicle_d *bv = &WP(w, buildvehicle_d);
|
||||||
switch (e->event) {
|
switch (e->event) {
|
||||||
case WE_CREATE:
|
case WE_CREATE:
|
||||||
EngList_Create(&bv->eng_list);
|
EngList_Create(&bv->eng_list);
|
||||||
|
@ -486,7 +486,8 @@ static void NewRailVehicleWndProc(Window *w, WindowEvent *e)
|
||||||
case WE_CLICK: {
|
case WE_CLICK: {
|
||||||
switch (e->we.click.widget) {
|
switch (e->we.click.widget) {
|
||||||
case BUILD_TRAIN_WIDGET_SORT_ASCENDING_DESCENDING:
|
case BUILD_TRAIN_WIDGET_SORT_ASCENDING_DESCENDING:
|
||||||
_last_sort_order = bv->descending_sort_order = !bv->descending_sort_order;
|
bv->descending_sort_order ^= true;
|
||||||
|
_last_sort_order = bv->descending_sort_order;
|
||||||
GenerateBuildList(w);
|
GenerateBuildList(w);
|
||||||
SetWindowDirty(w);
|
SetWindowDirty(w);
|
||||||
break;
|
break;
|
||||||
|
@ -532,8 +533,7 @@ static void NewRailVehicleWndProc(Window *w, WindowEvent *e)
|
||||||
|
|
||||||
case WE_DROPDOWN_SELECT: /* we have selected a dropdown item in the list */
|
case WE_DROPDOWN_SELECT: /* we have selected a dropdown item in the list */
|
||||||
if (bv->sort_criteria != e->we.dropdown.index) {
|
if (bv->sort_criteria != e->we.dropdown.index) {
|
||||||
bv->sort_criteria = e->we.dropdown.index;
|
bv->sort_criteria = _last_sort_criteria = e->we.dropdown.index;
|
||||||
_last_sort_criteria = e->we.dropdown.index;
|
|
||||||
GenerateBuildList(w);
|
GenerateBuildList(w);
|
||||||
SetWindowDirty(w);
|
SetWindowDirty(w);
|
||||||
}
|
}
|
||||||
|
|
2
window.h
2
window.h
|
@ -400,7 +400,7 @@ typedef struct {
|
||||||
byte railtype;
|
byte railtype;
|
||||||
byte acc_planes; // AIRCRAFT_ONLY, ALL, HELICOPTERS_ONLY
|
byte acc_planes; // AIRCRAFT_ONLY, ALL, HELICOPTERS_ONLY
|
||||||
} filter;
|
} filter;
|
||||||
byte sel_index;
|
byte sel_index; // deprecated value, used for 'unified' ship and road
|
||||||
bool descending_sort_order;
|
bool descending_sort_order;
|
||||||
byte sort_criteria;
|
byte sort_criteria;
|
||||||
EngineID sel_engine;
|
EngineID sel_engine;
|
||||||
|
|
Loading…
Reference in New Issue