mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Fix some CodeQL alerts.
parent
ced241ed87
commit
224b2343f0
|
@ -1659,32 +1659,26 @@ CommandCost CmdConvertRail(DoCommandFlag flags, TileIndex tile, TileIndex area_s
|
||||||
|
|
||||||
switch (tt) {
|
switch (tt) {
|
||||||
case MP_RAILWAY:
|
case MP_RAILWAY:
|
||||||
switch (GetRailTileType(tile)) {
|
found_convertible_track = true;
|
||||||
case RAIL_TILE_DEPOT:
|
if (GetRailTileType(tile) == RAIL_TILE_DEPOT) {
|
||||||
if (flags & DC_EXEC) {
|
if (flags & DC_EXEC) {
|
||||||
/* notify YAPF about the track layout change */
|
/* notify YAPF about the track layout change */
|
||||||
YapfNotifyTrackLayoutChange(tile, GetRailDepotTrack(tile));
|
YapfNotifyTrackLayoutChange(tile, GetRailDepotTrack(tile));
|
||||||
|
|
||||||
if (find(affected_depots.begin(), affected_depots.end(), (tile)) == affected_depots.end()) {
|
if (find(affected_depots.begin(), affected_depots.end(), (tile)) == affected_depots.end()) {
|
||||||
affected_depots.push_back(GetDepotIndex(tile));
|
affected_depots.push_back(GetDepotIndex(tile));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
found_convertible_track = true;
|
cost.AddCost(RailConvertCost(type, totype));
|
||||||
cost.AddCost(RailConvertCost(type, totype));
|
} else { // RAIL_TILE_NORMAL, RAIL_TILE_SIGNALS
|
||||||
break;
|
if (flags & DC_EXEC) {
|
||||||
|
/* notify YAPF about the track layout change */
|
||||||
default: // RAIL_TILE_NORMAL, RAIL_TILE_SIGNALS
|
TrackBits tracks = GetTrackBits(tile);
|
||||||
if (flags & DC_EXEC) {
|
while (tracks != TRACK_BIT_NONE) {
|
||||||
/* notify YAPF about the track layout change */
|
YapfNotifyTrackLayoutChange(tile, RemoveFirstTrack(&tracks));
|
||||||
TrackBits tracks = GetTrackBits(tile);
|
|
||||||
while (tracks != TRACK_BIT_NONE) {
|
|
||||||
YapfNotifyTrackLayoutChange(tile, RemoveFirstTrack(&tracks));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
found_convertible_track = true;
|
}
|
||||||
cost.AddCost(RailConvertCost(type, totype) * CountBits(GetTrackBits(tile)));
|
cost.AddCost(RailConvertCost(type, totype) * CountBits(GetTrackBits(tile)));
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
|
@ -2270,27 +2270,21 @@ static const uint8_t _roadveh_enter_depot_dir[4] = {
|
||||||
|
|
||||||
static VehicleEnterTileStatus VehicleEnter_Road(Vehicle *v, TileIndex tile, int, int)
|
static VehicleEnterTileStatus VehicleEnter_Road(Vehicle *v, TileIndex tile, int, int)
|
||||||
{
|
{
|
||||||
switch (GetRoadTileType(tile)) {
|
if (GetRoadTileType(tile) != ROAD_TILE_DEPOT || v->type != VEH_ROAD) return VETSB_CONTINUE;
|
||||||
case ROAD_TILE_DEPOT: {
|
|
||||||
if (v->type != VEH_ROAD) break;
|
|
||||||
|
|
||||||
RoadVehicle *rv = RoadVehicle::From(v);
|
RoadVehicle *rv = RoadVehicle::From(v);
|
||||||
if (rv->frame == RVC_DEPOT_STOP_FRAME &&
|
if (rv->frame == RVC_DEPOT_STOP_FRAME &&
|
||||||
_roadveh_enter_depot_dir[GetRoadDepotDirection(tile)] == rv->state) {
|
_roadveh_enter_depot_dir[GetRoadDepotDirection(tile)] == rv->state) {
|
||||||
rv->state = RVSB_IN_DEPOT;
|
rv->state = RVSB_IN_DEPOT;
|
||||||
rv->vehstatus |= VS_HIDDEN;
|
rv->vehstatus |= VS_HIDDEN;
|
||||||
rv->direction = ReverseDir(rv->direction);
|
rv->direction = ReverseDir(rv->direction);
|
||||||
if (rv->Next() == nullptr) VehicleEnterDepot(rv->First());
|
if (rv->Next() == nullptr) VehicleEnterDepot(rv->First());
|
||||||
rv->tile = tile;
|
rv->tile = tile;
|
||||||
|
|
||||||
InvalidateWindowData(WC_VEHICLE_DEPOT, GetDepotIndex(rv->tile));
|
InvalidateWindowData(WC_VEHICLE_DEPOT, GetDepotIndex(rv->tile));
|
||||||
return VETSB_ENTERED_WORMHOLE;
|
return VETSB_ENTERED_WORMHOLE;
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
default: break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return VETSB_CONTINUE;
|
return VETSB_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -654,29 +654,30 @@ struct RoadVehFindData {
|
||||||
|
|
||||||
static Vehicle *EnumCheckRoadVehClose(Vehicle *v, void *data)
|
static Vehicle *EnumCheckRoadVehClose(Vehicle *v, void *data)
|
||||||
{
|
{
|
||||||
static const int8_t dist_x[] = { -4, -8, -4, -1, 4, 8, 4, 1 };
|
if (v->type != VEH_ROAD || v->IsInDepot()) return nullptr;
|
||||||
static const int8_t dist_y[] = { -4, -1, 4, 8, 4, 1, -4, -8 };
|
|
||||||
|
|
||||||
RoadVehFindData *rvf = (RoadVehFindData*)data;
|
RoadVehFindData *rvf = (RoadVehFindData*)data;
|
||||||
|
|
||||||
|
if (abs(v->z_pos - rvf->veh->z_pos) >= 6 ||
|
||||||
|
v->direction != rvf->dir ||
|
||||||
|
rvf->veh->First() == v->First()) return nullptr;
|
||||||
|
|
||||||
|
static const int8_t dist_x[] = { -4, -8, -4, -1, 4, 8, 4, 1 };
|
||||||
|
static const int8_t dist_y[] = { -4, -1, 4, 8, 4, 1, -4, -8 };
|
||||||
short x_diff = v->x_pos - rvf->x;
|
short x_diff = v->x_pos - rvf->x;
|
||||||
short y_diff = v->y_pos - rvf->y;
|
short y_diff = v->y_pos - rvf->y;
|
||||||
|
|
||||||
if (v->type == VEH_ROAD &&
|
/* Check if vehicle is not close. */
|
||||||
!v->IsInDepot() &&
|
if ((dist_x[v->direction] < 0 && (x_diff > 0 || x_diff <= dist_x[v->direction]))) return nullptr;
|
||||||
abs(v->z_pos - rvf->veh->z_pos) < 6 &&
|
if ((dist_x[v->direction] > 0 && (x_diff < 0 || x_diff >= dist_x[v->direction]))) return nullptr;
|
||||||
v->direction == rvf->dir &&
|
if ((dist_y[v->direction] < 0 && (y_diff > 0 || y_diff <= dist_y[v->direction]))) return nullptr;
|
||||||
rvf->veh->First() != v->First() &&
|
if ((dist_y[v->direction] > 0 && (y_diff < 0 || y_diff >= dist_y[v->direction]))) return nullptr;
|
||||||
(dist_x[v->direction] >= 0 || (x_diff > dist_x[v->direction] && x_diff <= 0)) &&
|
|
||||||
(dist_x[v->direction] <= 0 || (x_diff < dist_x[v->direction] && x_diff >= 0)) &&
|
|
||||||
(dist_y[v->direction] >= 0 || (y_diff > dist_y[v->direction] && y_diff <= 0)) &&
|
|
||||||
(dist_y[v->direction] <= 0 || (y_diff < dist_y[v->direction] && y_diff >= 0))) {
|
|
||||||
uint diff = abs(x_diff) + abs(y_diff);
|
|
||||||
|
|
||||||
if (diff < rvf->best_diff || (diff == rvf->best_diff && v->index < rvf->best->index)) {
|
uint diff = abs(x_diff) + abs(y_diff);
|
||||||
rvf->best = v;
|
|
||||||
rvf->best_diff = diff;
|
if (diff < rvf->best_diff || (diff == rvf->best_diff && v->index < rvf->best->index)) {
|
||||||
}
|
rvf->best = v;
|
||||||
|
rvf->best_diff = diff;
|
||||||
}
|
}
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
Loading…
Reference in New Issue