diff --git a/src/vehicle.cpp b/src/vehicle.cpp --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -222,13 +222,13 @@ Vehicle *GetVehicleTunnelBridge(TileInde } -static void UpdateVehiclePosHash(Vehicle* v, int x, int y); +static void UpdateVehiclePosHash(Vehicle *v, int x, int y); void VehiclePositionChanged(Vehicle *v) { int img = v->cur_image; Point pt = RemapCoords(v->x_pos + v->x_offs, v->y_pos + v->y_offs, v->z_pos); - const Sprite* spr = GetSprite(img); + const Sprite *spr = GetSprite(img); pt.x += spr->x_offs; pt.y += spr->y_offs; @@ -462,7 +462,7 @@ static void UpdateNewVehiclePosHash(Vehi static Vehicle *_vehicle_position_hash[0x1000]; -static void UpdateVehiclePosHash(Vehicle* v, int x, int y) +static void UpdateVehiclePosHash(Vehicle *v, int x, int y) { UpdateNewVehiclePosHash(v, x == INVALID_COORD); @@ -764,13 +764,9 @@ CommandCost GetRefitCost(EngineID engine static void DoDrawVehicle(const Vehicle *v) { SpriteID image = v->cur_image; - SpriteID pal; - - if (v->vehstatus & VS_DEFPAL) { - pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v); - } else { - pal = PAL_NONE; - } + SpriteID pal = PAL_NONE; + + if (v->vehstatus & VS_DEFPAL) pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v); AddSortableSpriteToDraw(image, pal, v->x_pos + v->x_offs, v->y_pos + v->y_offs, v->x_extent, v->y_extent, v->z_extent, v->z_pos, (v->vehstatus & VS_SHADOW) != 0); @@ -1298,11 +1294,9 @@ static void BubbleTick(Vehicle *v) * multiplayer!! (that is: in ToyLand) */ uint et; - const BubbleMovement *b; v->progress++; - if ((v->progress & 3) != 0) - return; + if ((v->progress & 3) != 0) return; BeginVehicleMove(v); @@ -1323,7 +1317,7 @@ static void BubbleTick(Vehicle *v) et = v->engine_type + 1; } - b = &_bubble_movement[v->spritenum - 1][et]; + const BubbleMovement *b = &_bubble_movement[v->spritenum - 1][et]; if (b->y == 4 && b->x == 0) { EndVehicleMove(v); @@ -1394,9 +1388,7 @@ static EffectTickProc * const _effect_ti Vehicle *CreateEffectVehicle(int x, int y, int z, EffectVehicle type) { - Vehicle *v; - - v = new SpecialVehicle(); + Vehicle *v = new SpecialVehicle(); if (v != NULL) { v->subtype = type; v->x_pos = x; @@ -1437,9 +1429,7 @@ Vehicle *CheckClickOnVehicle(const ViewP Vehicle *found = NULL, *v; uint dist, best_dist = (uint)-1; - if ( (uint)(x -= vp->left) >= (uint)vp->width || - (uint)(y -= vp->top) >= (uint)vp->height) - return NULL; + if ((uint)(x -= vp->left) >= (uint)vp->width || (uint)(y -= vp->top) >= (uint)vp->height) return NULL; x = ScaleByZoom(x, vp->zoom) + vp->virtual_left; y = ScaleByZoom(y, vp->zoom) + vp->virtual_top; @@ -1450,8 +1440,8 @@ Vehicle *CheckClickOnVehicle(const ViewP y >= v->top_coord && y <= v->bottom_coord) { dist = max( - abs( ((v->left_coord + v->right_coord)>>1) - x ), - abs( ((v->top_coord + v->bottom_coord)>>1) - y ) + abs(((v->left_coord + v->right_coord) >> 1) - x), + abs(((v->top_coord + v->bottom_coord) >> 1) - y) ); if (dist < best_dist) { @@ -1494,8 +1484,6 @@ static const byte _breakdown_chance[64] void CheckVehicleBreakdown(Vehicle *v) { int rel, rel_old; - uint32 r; - int chance; /* decrease reliability */ v->reliability = rel = max((rel_old = v->reliability) - v->reliability_spd_dec, 0); @@ -1507,10 +1495,10 @@ void CheckVehicleBreakdown(Vehicle *v) return; } - r = Random(); + uint32 r = Random(); /* increase chance of failure */ - chance = v->breakdown_chance + 1; + int chance = v->breakdown_chance + 1; if (Chance16I(1,25,r)) chance += 25; v->breakdown_chance = min(255, chance); @@ -1585,7 +1573,6 @@ CommandCost CmdMassStartStopVehicle(Tile uint16 engine_list_length = 0; uint16 engine_count = 0; CommandCost return_value = CMD_ERROR; - uint i; uint stop_command; VehicleType vehicle_type = (VehicleType)GB(p2, 0, 5); bool start_stop = HasBit(p2, 5); @@ -1609,9 +1596,8 @@ CommandCost CmdMassStartStopVehicle(Tile BuildDepotVehicleList(vehicle_type, tile, &vl, &engine_list_length, &engine_count, NULL, NULL, NULL); } - for (i = 0; i < engine_count; i++) { + for (uint i = 0; i < engine_count; i++) { const Vehicle *v = vl[i]; - CommandCost ret; if (!!(v->vehstatus & VS_STOPPED) != start_stop) continue; @@ -1623,7 +1609,7 @@ CommandCost CmdMassStartStopVehicle(Tile } } - ret = DoCommand(tile, v->index, 0, flags, stop_command); + CommandCost ret = DoCommand(tile, v->index, 0, flags, stop_command); if (CmdSucceeded(ret)) { return_value = CommandCost(); @@ -1653,7 +1639,7 @@ CommandCost CmdDepotSellAllVehicles(Tile uint16 wagon_count = 0; CommandCost cost(EXPENSES_NEW_VEHICLES); - uint i, sell_command, total_number_vehicles; + uint sell_command, total_number_vehicles; VehicleType vehicle_type = (VehicleType)GB(p1, 0, 8); switch (vehicle_type) { @@ -1669,9 +1655,8 @@ CommandCost CmdDepotSellAllVehicles(Tile &wagons, &wagon_list_length, &wagon_count); total_number_vehicles = engine_count + wagon_count; - for (i = 0; i < total_number_vehicles; i++) { + for (uint i = 0; i < total_number_vehicles; i++) { const Vehicle *v; - CommandCost ret; if (i < engine_count) { v = engines[i]; @@ -1679,7 +1664,7 @@ CommandCost CmdDepotSellAllVehicles(Tile v = wagons[i - engine_count]; } - ret = DoCommand(tile, v->index, 1, flags, sell_command); + CommandCost ret = DoCommand(tile, v->index, 1, flags, sell_command); if (CmdSucceeded(ret)) cost.AddCost(ret); } @@ -1704,7 +1689,6 @@ CommandCost CmdDepotMassAutoReplace(Tile Vehicle **vl = NULL; uint16 engine_list_length = 0; uint16 engine_count = 0; - uint i; CommandCost cost = CommandCost(EXPENSES_NEW_VEHICLES); VehicleType vehicle_type = (VehicleType)GB(p1, 0, 8); bool all_or_nothing = HasBit(p2, 0); @@ -1714,11 +1698,9 @@ CommandCost CmdDepotMassAutoReplace(Tile /* Get the list of vehicles in the depot */ BuildDepotVehicleList(vehicle_type, tile, &vl, &engine_list_length, &engine_count, &vl, &engine_list_length, &engine_count); - - for (i = 0; i < engine_count; i++) { + for (uint i = 0; i < engine_count; i++) { Vehicle *v = vl[i]; bool stopped = !(v->vehstatus & VS_STOPPED); - CommandCost ret; /* Ensure that the vehicle completely in the depot */ if (!v->IsInDepot()) continue; @@ -1727,7 +1709,7 @@ CommandCost CmdDepotMassAutoReplace(Tile v->vehstatus |= VS_STOPPED; // Stop the vehicle v->leave_depot_instantly = true; } - ret = MaybeReplaceVehicle(v, !(flags & DC_EXEC), false); + CommandCost ret = MaybeReplaceVehicle(v, !(flags & DC_EXEC), false); if (CmdSucceeded(ret)) { cost.AddCost(ret); @@ -1764,18 +1746,16 @@ error: */ CommandCost CmdCloneVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) { - Vehicle *v_front, *v; - Vehicle *w_front, *w, *w_rear; - CommandCost cost, total_cost(EXPENSES_NEW_VEHICLES); + CommandCost total_cost(EXPENSES_NEW_VEHICLES); uint32 build_argument = 2; if (!IsValidVehicleID(p1)) return CMD_ERROR; - v = GetVehicle(p1); - v_front = v; - w = NULL; - w_front = NULL; - w_rear = NULL; - + + Vehicle *v = GetVehicle(p1); + Vehicle *v_front = v; + Vehicle *w = NULL; + Vehicle *w_front = NULL; + Vehicle *w_rear = NULL; /* * v_front is the front engine in the original vehicle @@ -1809,7 +1789,7 @@ CommandCost CmdCloneVehicle(TileIndex ti continue; } - cost = DoCommand(tile, v->engine_type, build_argument, flags, GetCmdBuildVeh(v)); + CommandCost cost = DoCommand(tile, v->engine_type, build_argument, flags, GetCmdBuildVeh(v)); build_argument = 3; // ensure that we only assign a number to the first engine if (CmdFailed(cost)) return cost; @@ -1870,7 +1850,7 @@ CommandCost CmdCloneVehicle(TileIndex ti assert(w != NULL); if (w->cargo_type != v->cargo_type || w->cargo_subtype != v->cargo_subtype) { - cost = DoCommand(0, w->index, v->cargo_type | (v->cargo_subtype << 8) | 1U << 16 , flags, GetCmdRefitVeh(v)); + CommandCost cost = DoCommand(0, w->index, v->cargo_type | (v->cargo_subtype << 8) | 1U << 16 , flags, GetCmdRefitVeh(v)); if (CmdSucceeded(cost)) total_cost.AddCost(cost); } @@ -2012,21 +1992,21 @@ void BuildDepotVehicleList(VehicleType t } /** -* @param sort_list list to store the list in. Either NULL or the length length_of_array tells -* @param length_of_array informs the length allocated for sort_list. This is not the same as the number of vehicles in the list. Needs to be 0 when sort_list is NULL -* @param type type of vehicle -* @param owner PlayerID of owner to generate a list for -* @param index This parameter has different meanings depending on window_type -