diff options
author | tron <tron@openttd.org> | 2006-02-06 09:18:04 +0000 |
---|---|---|
committer | tron <tron@openttd.org> | 2006-02-06 09:18:04 +0000 |
commit | 453b30e387f8d8ab1839d96b0d1f9a8fea841292 (patch) | |
tree | 3a4002304d8204d11c37ba706d6ffbd2e5dfac1b /order_cmd.c | |
parent | 0755bbead0240f519c9d78bb88ef4629d5ab8fa5 (diff) | |
download | openttd-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 'order_cmd.c')
-rw-r--r-- | order_cmd.c | 28 |
1 files changed, 11 insertions, 17 deletions
diff --git a/order_cmd.c b/order_cmd.c index 5ab21ce76..07433dce7 100644 --- a/order_cmd.c +++ b/order_cmd.c @@ -366,8 +366,7 @@ int32 CmdInsertOrder(int x, int y, uint32 flags, uint32 p1, uint32 p2) } } - u = GetFirstVehicleFromSharedList(v); - while (u != NULL) { + for (u = GetFirstVehicleFromSharedList(v); u != NULL; u = u->next_shared) { /* Increase amount of orders */ u->num_orders++; @@ -386,8 +385,6 @@ int32 CmdInsertOrder(int x, int y, uint32 flags, uint32 p1, uint32 p2) } /* Update any possible open window of the vehicle */ InvalidateVehicleOrder(u); - - u = u->next_shared; } /* Make sure to rebuild the whole list */ @@ -454,8 +451,7 @@ int32 CmdDeleteOrder(int x, int y, uint32 flags, uint32 p1, uint32 p2) order->type = OT_NOTHING; order->next = NULL; - u = GetFirstVehicleFromSharedList(v); - while (u != NULL) { + for (u = GetFirstVehicleFromSharedList(v); u != NULL; u = u->next_shared) { u->num_orders--; if (sel_ord < u->cur_order_index) @@ -476,8 +472,6 @@ int32 CmdDeleteOrder(int x, int y, uint32 flags, uint32 p1, uint32 p2) /* Update any possible open window of the vehicle */ InvalidateVehicleOrder(u); - - u = u->next_shared; } RebuildVehicleLists(); @@ -579,14 +573,15 @@ int32 CmdModifyOrder(int x, int y, uint32 flags, uint32 p1, uint32 p2) /* Update the windows and full load flags, also for vehicles that share the same order list */ { - Vehicle *u = GetFirstVehicleFromSharedList(v); - while (u != NULL) { + Vehicle* u; + + for (u = GetFirstVehicleFromSharedList(v); u != NULL; u = u->next_shared) { /* toggle u->current_order "Full load" flag if it changed */ if (sel_ord == u->cur_order_index && - HASBIT(u->current_order.flags, OFB_FULL_LOAD) != HASBIT(order->flags, OFB_FULL_LOAD)) + HASBIT(u->current_order.flags, OFB_FULL_LOAD) != HASBIT(order->flags, OFB_FULL_LOAD)) { TOGGLEBIT(u->current_order.flags, OFB_FULL_LOAD); + } InvalidateVehicleOrder(u); - u = u->next_shared; } } } @@ -632,11 +627,10 @@ int32 CmdCloneOrder(int x, int y, uint32 flags, uint32 p1, uint32 p2) /* Is the vehicle already in the shared list? */ { - Vehicle *u = GetFirstVehicleFromSharedList(src); - while (u != NULL) { - if (u == dst) - return CMD_ERROR; - u = u->next_shared; + const Vehicle* u; + + for (u = GetFirstVehicleFromSharedList(src); u != NULL; u = u->next_shared) { + if (u == dst) return CMD_ERROR; } } |