Skip to content

Commit 3428069

Browse files
fix anoying reservoir bug (#1628)
1 parent 0929b5a commit 3428069

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

src/building/construction_building.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,8 @@ int building_construction_fill_vacant_lots(grid_slice *area)
427427

428428
int building_construction_place_building(building_type type, int x, int y, int exact_coordinates)
429429
{
430+
int grid_offset = map_grid_offset(x, y);
431+
430432
int terrain_mask = TERRAIN_ALL;
431433
if (building_type_is_roadblock(type)) {
432434
terrain_mask = type == BUILDING_GATEHOUSE ? ~TERRAIN_WALL & ~TERRAIN_ROAD &
@@ -455,7 +457,7 @@ int building_construction_place_building(building_type type, int x, int y, int e
455457
int building_orientation = 0;
456458
if (type == BUILDING_GATEHOUSE || type == BUILDING_WAREHOUSE) {
457459
//check if there's a preset orientation from old building
458-
building *old_b = building_main(building_get(map_building_rubble_building_id(map_grid_offset(x, y))));
460+
building *old_b = building_main(building_get(map_building_rubble_building_id(grid_offset)));
459461
if (old_b && (old_b->type == BUILDING_GATEHOUSE ||
460462
old_b->type == BUILDING_WAREHOUSE || old_b->type == BUILDING_WAREHOUSE_SPACE)) {
461463
building_orientation = old_b->subtype.orientation;
@@ -492,7 +494,7 @@ int building_construction_place_building(building_type type, int x, int y, int e
492494
city_warning_show(WARNING_CLEAR_LAND_NEEDED, NEW_WARNING_SLOT);
493495
return 0;
494496
}
495-
if (!check_gatehouse_tiles(map_grid_offset(x, y))) { //helper to make sure all building tiles are on walls
497+
if (!check_gatehouse_tiles(grid_offset)) { //helper to make sure all building tiles are on walls
496498
city_warning_show(WARNING_CLEAR_LAND_NEEDED, NEW_WARNING_SLOT);
497499
return 0;
498500
}

src/map/routing.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,18 @@ static int map_can_place_initial_road_or_aqueduct(int grid_offset, int is_aquedu
447447
}
448448
}
449449

450+
static int aqueduct_in_reservoir(int center_offset) {
451+
for (int y = map_grid_offset_to_y(center_offset) - 1; y < map_grid_offset_to_y(center_offset) + 2; y++) {
452+
for (int x = map_grid_offset_to_x(center_offset) - 1; x < map_grid_offset_to_x(center_offset) + 2; x++) {
453+
if (map_terrain_is(map_grid_offset(x, y), TERRAIN_AQUEDUCT)) {
454+
return 1;
455+
}
456+
}
457+
}
458+
459+
return 0;
460+
}
461+
450462
int map_routing_calculate_distances_for_building(routed_building_type type, int x, int y)
451463
{
452464
int source_offset = map_grid_offset(x, y);
@@ -464,8 +476,15 @@ int map_routing_calculate_distances_for_building(routed_building_type type, int
464476
route_queue_all_from(source_offset, DIRECTIONS_NO_DIAGONALS, callback_calc_distance_build_highway, 0);
465477
return 1;
466478
}
479+
480+
if (type == ROUTED_BUILDING_DRAGGABLE_RESERVOIR) {
481+
if (!map_terrain_is(source_offset, TERRAIN_AQUEDUCT) && aqueduct_in_reservoir(source_offset)) {
482+
return 0;
483+
}
484+
}
467485

468-
if (!map_can_place_initial_road_or_aqueduct(source_offset, type != ROUTED_BUILDING_ROAD)) {
486+
if (!map_can_place_initial_road_or_aqueduct(source_offset, type != ROUTED_BUILDING_ROAD &&
487+
type != ROUTED_BUILDING_DRAGGABLE_RESERVOIR)) {
469488
return 0;
470489
}
471490
if (map_terrain_is(source_offset, TERRAIN_ROAD) &&

0 commit comments

Comments
 (0)