mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-11-16 00:12:51 +00:00
(svn r3608) No functional change, just make some code more comprehensible: Reduce variable scope, remove write-only variables, turn do-while-loops with multiple induction variables into canonical for-loops
This commit is contained in:
parent
1f177c6306
commit
6cde2661c5
121
vehicle_gui.c
121
vehicle_gui.c
@ -500,36 +500,39 @@ static void train_engine_drawing_loop(int *x, int *y, int *pos, int *sel, Engine
|
|||||||
|
|
||||||
static void SetupScrollStuffForReplaceWindow(Window *w)
|
static void SetupScrollStuffForReplaceWindow(Window *w)
|
||||||
{
|
{
|
||||||
RailType railtype;
|
|
||||||
EngineID selected_id[2] = { INVALID_ENGINE, INVALID_ENGINE };
|
EngineID selected_id[2] = { INVALID_ENGINE, INVALID_ENGINE };
|
||||||
int sel[2];
|
int sel[2];
|
||||||
int count = 0;
|
int count = 0;
|
||||||
int count2 = 0;
|
int count2 = 0;
|
||||||
EngineID engine_id;
|
|
||||||
const Player *p = GetPlayer(_local_player);
|
const Player *p = GetPlayer(_local_player);
|
||||||
|
EngineID i;
|
||||||
|
|
||||||
sel[0] = WP(w,replaceveh_d).sel_index[0];
|
sel[0] = WP(w,replaceveh_d).sel_index[0];
|
||||||
sel[1] = WP(w,replaceveh_d).sel_index[1];
|
sel[1] = WP(w,replaceveh_d).sel_index[1];
|
||||||
|
|
||||||
switch (WP(w,replaceveh_d).vehicletype) {
|
switch (WP(w,replaceveh_d).vehicletype) {
|
||||||
case VEH_Train: {
|
case VEH_Train: {
|
||||||
EngineID i;
|
RailType railtype = _railtype_selected_in_replace_gui;
|
||||||
railtype = _railtype_selected_in_replace_gui;
|
|
||||||
w->widget[13].color = _player_colors[_local_player]; // sets the colour of that art thing
|
w->widget[13].color = _player_colors[_local_player]; // sets the colour of that art thing
|
||||||
w->widget[16].color = _player_colors[_local_player]; // sets the colour of that art thing
|
w->widget[16].color = _player_colors[_local_player]; // sets the colour of that art thing
|
||||||
for (i = 0; i < NUM_TRAIN_ENGINES; i++) {
|
for (i = 0; i < NUM_TRAIN_ENGINES; i++) {
|
||||||
EngineID engine_id = GetRailVehAtPosition(i);
|
EngineID eid = GetRailVehAtPosition(i);
|
||||||
const Engine *e = GetEngine(engine_id);
|
const Engine* e = GetEngine(eid);
|
||||||
const EngineInfo *info = &_engine_info[engine_id];
|
const EngineInfo* info = &_engine_info[eid];
|
||||||
|
|
||||||
if (ENGINE_AVAILABLE && ((RailVehInfo(engine_id)->power && WP(w, replaceveh_d).wagon_btnstate) || (!RailVehInfo(engine_id)->power && !WP(w, replaceveh_d).wagon_btnstate)) && e->railtype == railtype) {
|
if (ENGINE_AVAILABLE && (
|
||||||
if (_player_num_engines[engine_id] > 0 || EngineHasReplacementForPlayer(p, engine_id)) {
|
(RailVehInfo(eid)->power != 0 && WP(w, replaceveh_d).wagon_btnstate) ||
|
||||||
if (sel[0] == 0) selected_id[0] = engine_id;
|
(RailVehInfo(eid)->power == 0 && !WP(w, replaceveh_d).wagon_btnstate)
|
||||||
|
) &&
|
||||||
|
e->railtype == railtype) {
|
||||||
|
if (_player_num_engines[eid] > 0 || EngineHasReplacementForPlayer(p, eid)) {
|
||||||
|
if (sel[0] == 0) selected_id[0] = eid;
|
||||||
count++;
|
count++;
|
||||||
sel[0]--;
|
sel[0]--;
|
||||||
}
|
}
|
||||||
if (HASBIT(e->player_avail, _local_player)) {
|
if (HASBIT(e->player_avail, _local_player)) {
|
||||||
if (sel[1] == 0) selected_id[1] = engine_id;
|
if (sel[1] == 0) selected_id[1] = eid;
|
||||||
count2++;
|
count2++;
|
||||||
sel[1]--;
|
sel[1]--;
|
||||||
}
|
}
|
||||||
@ -537,98 +540,84 @@ static void SetupScrollStuffForReplaceWindow(Window *w)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case VEH_Road: {
|
|
||||||
int num = NUM_ROAD_ENGINES;
|
|
||||||
const Engine* e = GetEngine(ROAD_ENGINES_INDEX);
|
|
||||||
byte cargo;
|
|
||||||
engine_id = ROAD_ENGINES_INDEX;
|
|
||||||
|
|
||||||
do {
|
case VEH_Road: {
|
||||||
if (_player_num_engines[engine_id] > 0 || EngineHasReplacementForPlayer(p, engine_id)) {
|
for (i = ROAD_ENGINES_INDEX; i < ROAD_ENGINES_INDEX + NUM_ROAD_ENGINES; i++) {
|
||||||
if (sel[0] == 0) selected_id[0] = engine_id;
|
if (_player_num_engines[i] > 0 || EngineHasReplacementForPlayer(p, i)) {
|
||||||
|
if (sel[0] == 0) selected_id[0] = i;
|
||||||
count++;
|
count++;
|
||||||
sel[0]--;
|
sel[0]--;
|
||||||
}
|
}
|
||||||
} while (++engine_id,++e,--num);
|
}
|
||||||
|
|
||||||
if (selected_id[0] != INVALID_ENGINE) { // only draw right array if we have anything in the left one
|
if (selected_id[0] != INVALID_ENGINE) { // only draw right array if we have anything in the left one
|
||||||
num = NUM_ROAD_ENGINES;
|
CargoID cargo = RoadVehInfo(selected_id[0])->cargo_type;
|
||||||
engine_id = ROAD_ENGINES_INDEX;
|
|
||||||
e = GetEngine(ROAD_ENGINES_INDEX);
|
|
||||||
cargo = RoadVehInfo(selected_id[0])->cargo_type;
|
|
||||||
|
|
||||||
do {
|
for (i = ROAD_ENGINES_INDEX; i < ROAD_ENGINES_INDEX + NUM_ROAD_ENGINES; i++) {
|
||||||
if (cargo == RoadVehInfo(engine_id)->cargo_type && HASBIT(e->player_avail, _local_player)) {
|
const Engine* e = GetEngine(i);
|
||||||
|
|
||||||
|
if (cargo == RoadVehInfo(i)->cargo_type && HASBIT(e->player_avail, _local_player)) {
|
||||||
count2++;
|
count2++;
|
||||||
if (sel[1] == 0) selected_id[1] = engine_id;
|
if (sel[1] == 0) selected_id[1] = i;
|
||||||
sel[1]--;
|
sel[1]--;
|
||||||
}
|
}
|
||||||
} while (++engine_id,++e,--num);
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case VEH_Ship: {
|
case VEH_Ship: {
|
||||||
int num = NUM_SHIP_ENGINES;
|
for (i = SHIP_ENGINES_INDEX; i < SHIP_ENGINES_INDEX + NUM_SHIP_ENGINES; i++) {
|
||||||
const Engine* e = GetEngine(SHIP_ENGINES_INDEX);
|
if (_player_num_engines[i] > 0 || EngineHasReplacementForPlayer(p, i)) {
|
||||||
byte cargo, refittable;
|
if (sel[0] == 0) selected_id[0] = i;
|
||||||
engine_id = SHIP_ENGINES_INDEX;
|
|
||||||
|
|
||||||
do {
|
|
||||||
if (_player_num_engines[engine_id] > 0 || EngineHasReplacementForPlayer(p, engine_id)) {
|
|
||||||
if (sel[0] == 0) selected_id[0] = engine_id;
|
|
||||||
count++;
|
count++;
|
||||||
sel[0]--;
|
sel[0]--;
|
||||||
}
|
}
|
||||||
} while (++engine_id,++e,--num);
|
}
|
||||||
|
|
||||||
if (selected_id[0] != INVALID_ENGINE) {
|
if (selected_id[0] != INVALID_ENGINE) {
|
||||||
num = NUM_SHIP_ENGINES;
|
byte cargo = ShipVehInfo(selected_id[0])->cargo_type;
|
||||||
e = GetEngine(SHIP_ENGINES_INDEX);
|
byte refittable = ShipVehInfo(selected_id[0])->refittable;
|
||||||
engine_id = SHIP_ENGINES_INDEX;
|
|
||||||
cargo = ShipVehInfo(selected_id[0])->cargo_type;
|
|
||||||
refittable = ShipVehInfo(selected_id[0])->refittable;
|
|
||||||
|
|
||||||
do {
|
for (i = SHIP_ENGINES_INDEX; i < SHIP_ENGINES_INDEX + NUM_SHIP_ENGINES; i++) {
|
||||||
if (HASBIT(e->player_avail, _local_player) &&
|
const Engine* e = GetEngine(i);
|
||||||
(cargo == ShipVehInfo(engine_id)->cargo_type || refittable & ShipVehInfo(engine_id)->refittable)) {
|
|
||||||
if (sel[1] == 0) selected_id[1] = engine_id;
|
if (HASBIT(e->player_avail, _local_player) && (
|
||||||
|
ShipVehInfo(i)->cargo_type == cargo ||
|
||||||
|
ShipVehInfo(i)->refittable & refittable
|
||||||
|
)) {
|
||||||
|
if (sel[1] == 0) selected_id[1] = i;
|
||||||
sel[1]--;
|
sel[1]--;
|
||||||
count2++;
|
count2++;
|
||||||
}
|
}
|
||||||
} while (++engine_id,++e,--num);
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
} //end of ship
|
}
|
||||||
|
|
||||||
case VEH_Aircraft:{
|
case VEH_Aircraft: {
|
||||||
int num = NUM_AIRCRAFT_ENGINES;
|
for (i = AIRCRAFT_ENGINES_INDEX; i < AIRCRAFT_ENGINES_INDEX + NUM_AIRCRAFT_ENGINES; i++) {
|
||||||
byte subtype;
|
if (_player_num_engines[i] > 0 || EngineHasReplacementForPlayer(p, i)) {
|
||||||
const Engine* e = GetEngine(AIRCRAFT_ENGINES_INDEX);
|
|
||||||
engine_id = AIRCRAFT_ENGINES_INDEX;
|
|
||||||
|
|
||||||
do {
|
|
||||||
if (_player_num_engines[engine_id] > 0 || EngineHasReplacementForPlayer(p, engine_id)) {
|
|
||||||
count++;
|
count++;
|
||||||
if (sel[0] == 0) selected_id[0] = engine_id;
|
if (sel[0] == 0) selected_id[0] = i;
|
||||||
sel[0]--;
|
sel[0]--;
|
||||||
}
|
}
|
||||||
} while (++engine_id,++e,--num);
|
}
|
||||||
|
|
||||||
if (selected_id[0] != INVALID_ENGINE) {
|
if (selected_id[0] != INVALID_ENGINE) {
|
||||||
num = NUM_AIRCRAFT_ENGINES;
|
byte subtype = AircraftVehInfo(selected_id[0])->subtype;
|
||||||
e = GetEngine(AIRCRAFT_ENGINES_INDEX);
|
|
||||||
subtype = AircraftVehInfo(selected_id[0])->subtype;
|
for (i = AIRCRAFT_ENGINES_INDEX; i < AIRCRAFT_ENGINES_INDEX + NUM_AIRCRAFT_ENGINES; i++) {
|
||||||
engine_id = AIRCRAFT_ENGINES_INDEX;
|
const Engine* e = GetEngine(i);
|
||||||
do {
|
|
||||||
if (HASBIT(e->player_avail, _local_player)) {
|
if (HASBIT(e->player_avail, _local_player)) {
|
||||||
if (HASBIT(subtype, 0) == HASBIT(AircraftVehInfo(engine_id)->subtype, 0)) {
|
if (HASBIT(subtype, 0) == HASBIT(AircraftVehInfo(i)->subtype, 0)) {
|
||||||
count2++;
|
count2++;
|
||||||
if (sel[1] == 0) selected_id[1] = engine_id;
|
if (sel[1] == 0) selected_id[1] = i;
|
||||||
sel[1]--;
|
sel[1]--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while (++engine_id,++e,--num);
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user