From 453b30e387f8d8ab1839d96b0d1f9a8fea841292 Mon Sep 17 00:00:00 2001 From: tron Date: Mon, 6 Feb 2006 09:18:04 +0000 Subject: (svn r3564) Several smaller changes: - Don't treat non-booleans as booleans - Reduce variable scope - Bracing - Use DeMorgan's law to make conditionals easier to read - if cascade -> switch - Replace some magic numbers by symbolic names - Avoid assignments within other statements --- roadveh_cmd.c | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) (limited to 'roadveh_cmd.c') diff --git a/roadveh_cmd.c b/roadveh_cmd.c index 510baa010..1b31bba22 100644 --- a/roadveh_cmd.c +++ b/roadveh_cmd.c @@ -66,13 +66,12 @@ int GetRoadVehImage(const Vehicle *v, byte direction) if (is_custom_sprite(img)) { image = GetCustomVehicleSprite(v, direction); - if (image) return image; + if (image != 0) return image; img = orig_road_vehicle_info[v->engine_type - ROAD_ENGINES_INDEX].image_index; } image = direction + _roadveh_images[img]; - if (v->cargo_count >= (v->cargo_cap >> 1)) - image += _roadveh_full_adder[img]; + if (v->cargo_count >= v->cargo_cap / 2) image += _roadveh_full_adder[img]; return image; } @@ -509,12 +508,12 @@ static void RoadVehIsCrashed(Vehicle *v) static void *EnumCheckRoadVehCrashTrain(Vehicle *v, Vehicle *u) { - if (v->type != VEH_Train || - myabs(v->z_pos - u->z_pos) > 6 || - myabs(v->x_pos - u->x_pos) > 4 || - myabs(v->y_pos - u->y_pos) > 4) - return NULL; - return v; + return + v->type == VEH_Train && + myabs(v->z_pos - u->z_pos) <= 6 && + myabs(v->x_pos - u->x_pos) <= 4 && + myabs(v->y_pos - u->y_pos) <= 4 ? + v : NULL; } static void RoadVehCrash(Vehicle *v) @@ -527,7 +526,7 @@ static void RoadVehCrash(Vehicle *v) InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); pass = 1; - if (v->cargo_type == 0) pass += v->cargo_count; + if (v->cargo_type == CT_PASSENGERS) pass += v->cargo_count; v->cargo_count = 0; SetDParam(0, pass); @@ -573,13 +572,12 @@ static void HandleBrokenRoadVeh(Vehicle *v) if (!(v->vehstatus & VS_HIDDEN)) { Vehicle *u = CreateEffectVehicleRel(v, 4, 4, 5, EV_BREAKDOWN_SMOKE); - if (u) - u->u.special.unk0 = v->breakdown_delay * 2; + if (u != NULL) u->u.special.unk0 = v->breakdown_delay * 2; } } - if (!(v->tick_counter & 1)) { - if (!--v->breakdown_delay) { + if ((v->tick_counter & 1) == 0) { + if (--v->breakdown_delay == 0) { v->breakdown_ctr = 0; InvalidateWindow(WC_VEHICLE_VIEW, v->index); } @@ -1643,7 +1641,7 @@ void OnNewDay_RoadVeh(Vehicle *v) } // best_stop now contains the best stop we found. - if (best_stop) { + if (best_stop != NULL) { int slot; // Find a free slot in this stop. We know that at least one is free. assert(best_stop->slot[0] == INVALID_SLOT || best_stop->slot[1] == INVALID_SLOT); @@ -1654,7 +1652,7 @@ void OnNewDay_RoadVeh(Vehicle *v) v->u.road.slot_age = -5; v->u.road.slotindex = slot; DEBUG(ms, 1) ("Multistop: Slot %d at 0x%x assigned to vehicle %d (0x%x)", slot, best_stop->xy, v->unitnumber, v->tile); - } else if (first_stop) { + } else if (first_stop != NULL) { //now we couldn't assign a slot for one reason or another. //so we just go towards the first station DEBUG(ms, 1) ("Multistop: No free slot found for vehicle %d, going to default station", v->unitnumber); -- cgit v1.2.3-54-g00ecf