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