From 0833b843a38b997a7c4dbda1fd8ac9fdc915bdba Mon Sep 17 00:00:00 2001 From: Thefeli73 Date: Sun, 4 Oct 2020 17:54:41 +0200 Subject: [PATCH] check if structures are available before building --- main.py | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/main.py b/main.py index 70d74e9..0ab3454 100644 --- a/main.py +++ b/main.py @@ -287,22 +287,27 @@ def build(structure): for i in range(len(availableTiles)): if isinstance(availableTiles[i], tuple): game_layer.place_foundation(availableTiles[i], structure) - for j in range(len(state.residences)): - building = state.residences[j] - coords_to_check = (building.X, building.Y) - if coords_to_check == availableTiles[i]: - availableTiles[i] = building - building_under_construction = (building.X, building.Y, j) - rounds_between_energy = len(state.residences)+5 - return True - for j in range(len(state.utilities)): - building = state.utilities[j] - coords_to_check = (building.X, building.Y) - if coords_to_check == availableTiles[i]: - availableTiles[i] = building - building_under_construction = (building.X, building.Y, j) - rounds_between_energy = len(state.residences)+5 - return True + for building in state.available_residence_buildings: + if structure in building.building_name: + for j in range(len(state.residences)): + building = state.residences[j] + coords_to_check = (building.X, building.Y) + if coords_to_check == availableTiles[i]: + availableTiles[i] = building + building_under_construction = (building.X, building.Y, j) + rounds_between_energy = len(state.residences)+2 + return True + for building in state.available_utility_buildings: + if structure in building.building_name: + for j in range(len(state.utilities)): + building = state.utilities[j] + coords_to_check = (building.X, building.Y) + if coords_to_check == availableTiles[i]: + availableTiles[i] = building + building_under_construction = (building.X, building.Y, j) + rounds_between_energy = len(state.residences)+2 + return True + return False if __name__ == "__main__":