summaryrefslogtreecommitdiff
path: root/roadveh_cmd.c
diff options
context:
space:
mode:
authortron <tron@openttd.org>2006-02-06 09:18:04 +0000
committertron <tron@openttd.org>2006-02-06 09:18:04 +0000
commit453b30e387f8d8ab1839d96b0d1f9a8fea841292 (patch)
tree3a4002304d8204d11c37ba706d6ffbd2e5dfac1b /roadveh_cmd.c
parent0755bbead0240f519c9d78bb88ef4629d5ab8fa5 (diff)
downloadopenttd-453b30e387f8d8ab1839d96b0d1f9a8fea841292.tar.xz
(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
Diffstat (limited to 'roadveh_cmd.c')
-rw-r--r--roadveh_cmd.c30
1 files changed, 14 insertions, 16 deletions
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);