Skip to content

Commit

Permalink
chore: PR comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
UberWaffe committed Sep 29, 2023
1 parent cb9a0c4 commit fef8397
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions src/building/count.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ int building_count_upgraded(building_type type)

int building_count_in_area(building_type type, int minx, int miny, int maxx, int maxy)
{
int array_size = building_count();
int last_entry_position = 0;
int* found_buildings = (int*) malloc(array_size * sizeof(int));
int grid_area = abs((maxx - minx) * (maxy - miny));
int array_size = grid_area < building_count() ? grid_area : building_count();
int *found_buildings = (int *) malloc(array_size * sizeof(int));

int total = 0;
for (int x = minx; x <= maxx; x++) {
Expand All @@ -167,15 +167,14 @@ int building_count_in_area(building_type type, int minx, int miny, int maxx, int
continue;
}

for (int i = 0; i < array_size; i ++) {
for (int i = 0; i < total; i++) {
if (found_buildings[i] == b->id) {
continue;
}
}

found_buildings[total] = b->id;
total++;
found_buildings[last_entry_position] = b->id;
last_entry_position++;
}
}
}
Expand All @@ -186,9 +185,9 @@ int building_count_in_area(building_type type, int minx, int miny, int maxx, int

int building_count_fort_type_in_area(int minx, int miny, int maxx, int maxy, figure_type type)
{
int array_size = building_count();
int last_entry_position = 0;
int* found_buildings = (int*) malloc(array_size * sizeof(int));
int grid_area = abs((maxx - minx) * (maxy - miny));
int array_size = grid_area < building_count() ? grid_area : building_count();
int *found_buildings = (int *) malloc(array_size * sizeof(int));

int total = 0;
for (int x = minx; x <= maxx; x++) {
Expand All @@ -204,15 +203,14 @@ int building_count_fort_type_in_area(int minx, int miny, int maxx, int maxy, fig
continue;
}

for (int i = 0; i < array_size; i ++) {
for (int i = 0; i < total; i++) {
if (found_buildings[i] == b->id) {
continue;
}
}

found_buildings[total] = b->id;
total++;
found_buildings[last_entry_position] = b->id;
last_entry_position++;
}
}
}
Expand Down

0 comments on commit fef8397

Please sign in to comment.