Skip to content
Snippets Groups Projects
Commit dd7408b2 authored by Andreas Gattringer's avatar Andreas Gattringer
Browse files

butterflies: rename food layer to info layer, implement with flags

parent db7e831a
No related branches found
No related tags found
No related merge requests found
......@@ -20,7 +20,7 @@ void *butterfly_grid_init(struct cats_configuration *conf, struct cats_grid *gri
struct grid_data_butterflies *data = malloc_or_die(sizeof(struct grid_data_butterflies));
log_message(LOG_INFO, "allocating data for generations");
data->generations = new_raw_2d_array_from_dimension(grid->dimension, sizeof(float));
data->food = new_raw_2d_array_from_dimension(grid->dimension, sizeof(int32_t));
data->info_layer = new_raw_2d_array_from_dimension(grid->dimension, sizeof(int32_t));
log_message(LOG_INFO, "done allocating data for generations");
data->generation_current = 0;
//struct conf_data_butterflies *conf_data = CATS_MODULE_DATA;
......@@ -39,9 +39,9 @@ void *butterfly_grid_cleanup(struct cats_configuration *conf, struct cats_grid *
free_grid(&grid_data->generations, grid->dimension.rows);
free(grid_data->generations);
grid_data->generations = NULL;
free_grid(&grid_data->food, grid->dimension.rows);
free(grid_data->food);
grid_data->food = NULL;
free_grid(&grid_data->info_layer, grid->dimension.rows);
free(grid_data->info_layer);
grid_data->info_layer = NULL;
grid_data->generation_current = -1;
return NULL;
}
......@@ -86,8 +86,6 @@ void cats_module_init(struct cats_configuration *conf)
register_cats_grid_init_function(conf, butterfly_grid_init, butterfly_grid_cleanup);
register_load_species_param_config_func(conf, load_butterflies_species_params);
add_vital_rates(conf, data);
log_message(LOG_INFO, "Hello from %s (id: %d)\n", module_name, id);
}
......
......@@ -9,11 +9,19 @@ struct grid_data_butterflies {
float **generations;
int32_t generation_current;
float **eggs;
int32_t **food;
int32_t **info_layer;
};
enum butterfly_cell_info {
BF_CELL_CLEAR = 0,
BF_CELL_EXCLUDED = 1 << 0,
BF_CELL_HABITAT_OK = 1 << 1,
BF_CELL_RESOURCE_AVAILABLE = 1 << 2
};
#define BF_DEBUG_ROW 4319
#define BF_DEBUG_COL 10502
......
......@@ -129,7 +129,6 @@ char *get_butterfly_population_filename(struct cats_configuration *conf, struct
return filename;
}
......@@ -230,37 +229,53 @@ enum action_status action_butterfly_update_generations(struct cats_grid *grid, s
}
void reset_food_layer(const struct cats_grid *grid, struct grid_data_butterflies *data)
void reset_info_layer(const struct cats_grid *grid, struct grid_data_butterflies *data)
{
const cats_dt_coord rows = grid->dimension.rows;
const cats_dt_coord cols = grid->dimension.cols;
for (cats_dt_coord row = 0; row < rows; row++) {
for (cats_dt_coord col = 0; col < cols; col++) {
data->food[row][col] = 0;
data->info_layer[row][col] = 0;
}
}
}
enum action_status action_butterflies_update_overlays(struct cats_grid *grid, struct cats_configuration *conf)
enum action_status action_butterflies_update_overlays(struct cats_grid *grid, struct cats_configuration *conf)
{
bool run = false;
int module_id = CATS_MODULE_ID;
struct grid_data_butterflies *data = grid->grid_modules[module_id].module_data;
if (! run) {
reset_food_layer(grid, data);
if (conf->overlays.have_overlays == false) {
return ACTION_NOT_RUN;
}
if (conf->overlays.overlay[OL_EXCLUSION].enabled) {
run = true;
}
const cats_dt_coord rows = grid->dimension.rows;
const cats_dt_coord cols = grid->dimension.cols;
for (cats_dt_coord row = 0; row < rows; row++) {
for (cats_dt_coord col = 0; col < cols; col++) {
data->info_layer[row][col] = BF_CELL_CLEAR;
if (cell_excluded_by_overlay(conf, row, col)) {
data->info_layer[row][col] |= BF_CELL_EXCLUDED;
}
if (conf->overlays.overlay[OL_HABITAT_TYPE_CC].enabled &&
conf->overlays.habitat_cc->data[row][col] > 0) {
data->info_layer[row][col] |= BF_CELL_HABITAT_OK;
}
if (conf->overlays.overlay[OL_RESOURCE].enabled &&
conf->overlays.resources->data[row][col] > 0) {
data->info_layer[row][col] |= BF_CELL_RESOURCE_AVAILABLE;
}
}
}
if (!run) return ACTION_NOT_RUN;
return ACTION_RUN;
}
......@@ -323,7 +338,7 @@ void add_actions(struct cats_configuration *conf)
"transition eggs to adults");
register_action_function(conf, action_butterflies_update_overlays, "butterfly_action_overlay_update",
"updating resource layer");
"updating overlays");
register_action_function(conf, action_butterflies_dispersal, "butterfly_action_dispersal", "egg dispersal");
register_action_function(conf, action_butterflies_kill_adults, "butterfly_kill_adults", "kill adults");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment