Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision

Target

Select target project
  • bdc/cats
1 result
Select Git revision
Show changes
Showing
with 181 additions and 87 deletions
......@@ -28,6 +28,7 @@
#include "plants/juveniles.h"
#include "inline_overlays.h"
#include "inline_population.h"
#include "overlays/overlay_habitat_type_cc.h"
void
......@@ -50,22 +51,18 @@ get_carrying_capacity_all_classes(struct cats_grid **grids, cats_dt_coord row, c
cats_dt_population
get_carrying_capacity(const struct cats_grid *grid, cats_dt_coord row, cats_dt_coord col)
{
assert(grid->conf != NULL);
assert(grid != NULL && grid->conf != NULL);
const struct cats_configuration *conf = grid->conf;
// if we have an exclusion mask AND it is set the CC is 0
if (cell_excluded_by_overlay(conf, row, col)) { return 0; }
double multiplier = 1.0;
double multiplier = get_overlay_cc_multiplier(conf, row, col);
if (multiplier <= 0.0) { return 0; }
if (conf->overlays.overlay[OL_HABITAT_TYPE_CC].enabled) {
multiplier *= conf->overlays.habitat_cc->data[row][col];
if (multiplier <= 0.0) { return 0; }
}
cats_dt_rates cc;
const struct cats_vital_rate *link = &grid->param.carrying_capacity;
cc = calculate_rate(link, NAN, &grid->param, grid, row, col, NULL);
......@@ -91,7 +88,7 @@ cell_apply_carrying_capacity(struct cats_grid *grid, struct cats_thread_info *ts
if (grid->param.default_demographics) {
cats_dt_population N = get_adult_population(grid, row, col);
if (N == 0 && grid->juveniles[row][col] == NULL) return;
if (N == 0 && juveniles_exist(grid, row, col) == false) return;
if (N > 0) ts->stats[grid_id].stats[CS_POPULATED_BEFORE_CC] += 1;
cats_dt_population K_A = get_adult_carrying_capacity_from_cc(grid, K_tot);
......
......@@ -29,6 +29,8 @@
#include "data/cats_grid.h"
#include "inline_vital_rates.h"
#include "memory/cats_memory.h"
#include "inline_vital_ages.h"
#include "inline_carrying_capacity.h"
void setup_plant_juvenile_weights(struct cats_species_param *param)
......@@ -85,12 +87,12 @@ scale_down_juveniles2(struct cats_grid *grid, cats_dt_coord row, cats_dt_coord c
assert(grid != NULL && grid->juveniles != NULL);
assert(row >= 0 && row < grid->dimension.rows);
assert(col >= 0 && col < grid->dimension.cols);
assert(grid->juveniles[row] != NULL);
assert(juveniles_exist(grid, row, col));
assert(juvenile_cc > 0);
if (grid->juveniles[row][col] == NULL || weighted_juvenile_sum == 0) return;
if (juveniles_exist(grid, row, col) == false || weighted_juvenile_sum == 0) return;
if (weighted_juvenile_sum < juvenile_cc) return;
const int32_t mat_max = get_vital_age(grid, VA_AGE_OF_MATURITY_MAX); // grid->param.max_age_of_maturity;
const int32_t mat_max = get_vital_age(grid, VA_AGE_OF_MATURITY_MAX);
cats_dt_rates factor = 1.0;
for (int32_t i = 0; i < mat_max + 1; i++) {
......@@ -119,8 +121,8 @@ scale_down_juveniles2(struct cats_grid *grid, cats_dt_coord row, cats_dt_coord c
log_message(LOG_ERROR, "%s: weighted juvenile sum > juvenile CC", __func__);
log_message(LOG_RAW, "sum: %"PRId64", cc %"PRId64"\n", weighted_juvenile_sum, juvenile_cc);
log_message(LOG_RAW, "factor %f\n", (double) factor);
for (int32_t i = 0; i < mat_max + 1 - 1; i++) {
log_message(LOG_RAW, "juvenile stage %d: %d - multiplier %f\n", i,
for (int32_t i = 0; i < mat_max + 1; i++) {
log_message(LOG_RAW, "juvenile stage %d: %d - multiplier %f\n", i,
grid->juveniles[row][col][i],
(double) juvenile_cc_multiplier(&grid->param, i));
}
......@@ -135,7 +137,7 @@ void cell_apply_juvenile_cc(struct cats_grid *g, cats_dt_coord row,
cats_dt_coord col, cats_dt_population K_tot, cats_dt_population N)
{
if (g->juveniles == NULL) return;
if (g->juveniles[row][col] == NULL) return;
if (juveniles_exist(g, row, col) == false) return;
cats_dt_population K_J = K_tot - N;
......
......@@ -56,14 +56,15 @@ void adjust_juvenile_populations(struct cats_configuration *conf, struct cats_gr
//cats_dt_rates w = juvenile_cc_multiplier(&grid->param, i);
cats_dt_rates w = grid->param.juvenile_cc_weights[i];
cats_dt_rates juv_pop = (cats_dt_rates) N * multi / w;
if (juv_pop > CATS_MAX_POPULATION) {
juv_pop = CATS_MAX_POPULATION / 2.0;
}
grid->juveniles[r][c][i] = round_population_safe(juv_pop);
set_juveniles(grid, r, c, i, round_population_safe(juv_pop));
}
}
}
}
......@@ -153,7 +154,8 @@ void prune_initial_population_under_threshold(struct cats_configuration *conf, s
}
}
log_message(LOG_INFO, "Species '%s': pruned %"PRId64" of %"PRId64" initial populations (suitability < threshold), %"PRId64" remaining",
log_message(LOG_INFO,
"Species '%s': pruned %"PRId64" of %"PRId64" initial populations (suitability < threshold), %"PRId64" remaining",
grid->param.species_name, destroyed, populated, populated - destroyed);
}
......
......@@ -45,7 +45,8 @@ cats_dt_rates get_direct_rate(const struct cats_vital_rate *rate_info,
log_message(LOG_ERROR, "%s: wrong environment set type for set '%s'", __func__, set->name);
exit(EXIT_FAILURE);
}
cats_dt_rates rate = set->environments[0]->current.values[row][col] * rate_info->environment_multiplier;
cats_dt_environment value = load_input_environment_raster(&set->environments[0]->current, row, col);
cats_dt_rates rate = value * rate_info->environment_multiplier;
if (isnan(rate)) return 0.0f;
cats_dt_rates dens_multiplier = density_multiplier(density_type, N, K, rate_info->density_ts);
......
......@@ -45,13 +45,13 @@ cats_dt_rates get_glm(const struct cats_vital_rate *rate_info,
if (set->glm.type == GLM_QUADRATIC) {
for (int32_t i = 0; i < set->count; i++) {
const cats_dt_rates predictor = set->environments[i]->current.values[row][col];
const cats_dt_rates predictor = load_input_environment_raster(&set->environments[i]->current, row, col);
result += predictor * set->glm.linear[i] + predictor * predictor * set->glm.quadratic[i];
}
} else if (set->glm.type == GLM_LINEAR) {
for (int32_t i = 0; i < set->count; i++) {
const cats_dt_rates predictor = set->environments[i]->current.values[row][col];
const cats_dt_rates predictor = load_input_environment_raster(&set->environments[i]->current, row, col);
result += predictor * set->glm.linear[i];
}
} else {
......
......@@ -89,8 +89,8 @@ void csv_free(struct cats_csv **csv)
if (this->data[row] == NULL) continue;
for (int32_t col = 0; col < this->column_count; col++) {
free(this->data[row][col]);
this->data[row][col] = NULL;
free(this->data[row][col]); // clean-up, non-spatial [csv_free]
this->data[row][col] = NULL; // clean-up, non-spatial [csv_free]
}
free(this->data[row]);
......@@ -142,7 +142,7 @@ char *csv_get_value_field_name(struct cats_csv *csv, int32_t row, const char *fi
exit(EXIT_FAILURE);
}
return csv->data[row][field_idx];
return csv->data[row][field_idx]; // getter, non-spatial [csv_get_value_field_name]
}
......@@ -164,7 +164,7 @@ char *csv_get_value_field_idx(struct cats_csv *csv, int32_t row, int32_t field_i
exit(EXIT_FAILURE);
}
return csv->data[row][field_idx];
return csv->data[row][field_idx]; // getter, non-spatial [csv_get_value_field_idx]
}
......@@ -242,8 +242,7 @@ void csv_add_row(struct cats_csv *csv, char *line)
csv->data[row] = malloc_or_die_trace(fields * sizeof(char *), __func__);
for (int32_t i = 0; i < csv->column_count; i++) {
csv->data[row][i] = strdup(data->string[i]);
csv->data[row][i] = strdup(data->string[i]); // initialisation, non-spatial [csv_add_row]
}
free_string_array(&data);
......
......@@ -10,7 +10,7 @@ add_library(cats-butterflies SHARED ""
butterflies_overlays.c butterflies_overlays.h
butterflies_paths.c butterflies_paths.h
butterflies_actions_setup.c
butterflies_actions_setup.h butterflies_initial_population.c butterflies_initial_population.h butterflies_scale.c butterflies_scale.h)
butterflies_actions_setup.h butterflies_initial_population.c butterflies_initial_population.h butterflies_scale.c butterflies_scale.h inline_butterflies.h)
target_include_directories(cats-butterflies PUBLIC ".")
......
......@@ -10,6 +10,7 @@
#include "butterflies_dispersal.h"
#include "configuration/configuration.h"
#include "modules/module_header.h"
#include "inline_butterflies.h"
const int N_DIRECTIONS = 9;
/*
......@@ -19,7 +20,7 @@ const int N_DIRECTIONS = 9;
* 6 7 8
*/
const cats_dt_coord DIRECTION_OFFSETS[9][2] = {
const cats_dt_coord DIRECTION_OFFSETS[9][2] = { // initialisation, non-spatial
{+0, +0},
{+0, +1},
{-1, +1},
......@@ -38,7 +39,7 @@ static void inline single_random_walk(struct cats_thread_info *ts, struct cats_g
{
const int module_id = CATS_MODULE_ID;
const struct grid_data_butterflies *data = grid->grid_modules[module_id].module_data;
struct grid_data_butterflies *data = grid->grid_modules[module_id].module_data;
const struct conf_data_butterflies *module_conf = CATS_MODULE_DATA;
const bool debug_rw = module_conf->debug_rw;
const int64_t stat_id_deposits = module_conf->stat_ids[BF_RANDOM_WALK_DEPOSIT_COUNT];
......@@ -74,7 +75,8 @@ static void inline single_random_walk(struct cats_thread_info *ts, struct cats_g
// is the cell a valid dispersal target location?
if (!(data->info_layer[row][col] & BF_CELL_VALID_DISPERSAL_TARGET)) {
int32_t cell_info = butterflies_get_info_layer(data, row, col);
if (!(cell_info & BF_CELL_VALID_DISPERSAL_TARGET)) {
if (debug_rw) {
fprintf(module_conf->debug_rw_file, "%d,%d,%d,%d,%d,%d,%d\n", rw_num, row, col,
step + 1,
......@@ -93,8 +95,9 @@ static void inline single_random_walk(struct cats_thread_info *ts, struct cats_g
}
eggs_left -= eggs_to_deposit;
data->eggs[row][col] += (float) eggs_to_deposit;
butterflies_add_eggs(data, row, col, (float) eggs_to_deposit);
increase_custom_stat(ts->stats, stat_id_deposits, 1);
if (debug_rw) {
fprintf(module_conf->debug_rw_file, "%d,%d,%d,%d,%d,%d,%d\n", rw_num, row, col, step + 1,
module_conf->animal_dispersal_max_radius - step - 1, eggs_to_deposit, eggs_left);
......@@ -175,7 +178,8 @@ butterflies_cell_dispersal(struct cats_grid *grid, struct cats_thread_info *ts,
const cats_dt_rates source_cell_eggs = stationary_females * eggs_per_female +
wandering_females * (eggs_per_female - eggs_to_disperse_per_female);
data->eggs[row][col] += (float) ceill(source_cell_eggs);
butterflies_add_eggs(data, row, col, (float) ceill(source_cell_eggs));
if (eggs_to_disperse_per_female == 0) {
......
......@@ -5,6 +5,8 @@
#include "actions/cats_actions.h"
#include "butterflies_generations.h"
#include "inline.h"
#include "inline_butterflies.h"
// only run at the start of the year
void bf_area_generation_update(struct cats_grid *grid, struct cats_thread_info *ts)
......@@ -32,36 +34,37 @@ void bf_area_generation_update(struct cats_grid *grid, struct cats_thread_info *
for (cats_dt_coord row = start_row; row < end_row; row++) {
for (cats_dt_coord col = start_col; col < end_col; col++) {
float eggs = butterflies_get_eggs(data, row, col);
if (get_suitability(grid, row, col) < suit_ts)
{
if (data->eggs[row][col] > 0) cells_with_eggs_removed += 1;
data->eggs[row][col] = 0.0f;
data->generations[row][col] = 0.0f;
if (eggs > 0) cells_with_eggs_removed += 1;
butterflies_set_eggs(data, row, col, 0.0f);
butterflies_set_generations(data, row, col, 0.0f);
set_population_ignore_cc(grid, row, col, 0);
continue;
}
if (cell_excluded_by_overlay(conf, row, col)) {
if (data->eggs[row][col] > 0) cells_with_eggs_removed += 1;
data->eggs[row][col] = 0.0f;
data->generations[row][col] = 0.0f;
if (eggs > 0) cells_with_eggs_removed += 1;
butterflies_set_eggs(data, row, col, 0.0f);
butterflies_set_generations(data, row, col, 0.0f);
set_population_ignore_cc(grid, row, col, 0);
continue;
}
if ( ! (data->info_layer[row][col] & BF_CELL_VALID_DISPERSAL_TARGET)){
if (data->eggs[row][col] > 0) cells_with_eggs_removed += 1;
data->eggs[row][col] = 0.0f;
data->generations[row][col] = 0.0f;
int32_t cell_info = butterflies_get_info_layer(data, row, col);
if ( ! (cell_info & BF_CELL_VALID_DISPERSAL_TARGET)){
if (eggs > 0) cells_with_eggs_removed += 1;
butterflies_set_eggs(data, row, col, 0.0f);
butterflies_set_generations(data, row, col, 0.0f);
set_population_ignore_cc(grid, row, col, 0);
continue;
}
cats_dt_rates gen = calculate_rate(rate, 0, conf->param, grid, row, col, NULL);
data->generations[row][col] = (float) gen;
if (data->eggs[row][col] > 0) cells_with_eggs += 1;
butterflies_set_generations(data, row, col, (float) gen);
if (eggs > 0) cells_with_eggs += 1;
}
}
......
......@@ -14,6 +14,7 @@
#include "modules/module_header.h"
#include "actions/cats_actions.h"
#include "butterflies_initial_population.h"
#include "inline_butterflies.h"
void bf_initial_population_adjustment(struct cats_configuration *conf, struct cats_grid *grid)
......@@ -48,7 +49,7 @@ void bf_initial_population_adjustment(struct cats_configuration *conf, struct ca
start += 1;
cats_dt_rates multiplier = 1.0;
if (conf->overlays.overlay[OL_HABITAT_TYPE_CC].enabled) {
multiplier *= conf->overlays.habitat_cc->data[row][col];
multiplier *= get_overlay_habitat_cc_value(conf, row, col);];
}
cats_dt_rates suit = get_suitability(grid, row, col);
cats_dt_rates cc_raw = cc_rate->func->func(cc_rate, &grid->param, suit, 0, NAN);
......@@ -92,12 +93,14 @@ void bf_initial_population_adjustment(struct cats_configuration *conf, struct ca
for (cats_dt_coord row = 0; row < rows; row++) {
for (cats_dt_coord col = 0; col < cols; col++) {
#ifdef BF_DEBUG
if (get_adult_population(grid, row, col) || data->eggs[row][col]) {
float eggs = butterflies_get_eggs(data, row, col);
if (get_adult_population(grid, row, col) || eggs) {
printf(""
"BFDBG::%s::initial adults -> eggs::%d,%d,%d,%f\n",
__func__, row, col, get_adult_population(grid, row, col),
data->eggs[row][col]);
eggs);
}
#endif
set_population_ignore_cc(grid, row, col, 0);
......
......@@ -6,13 +6,15 @@
#include "butterflies_main.h"
#include "modules/module_header.h"
#include "inline_butterflies.h"
static inline bool bf_cell_excluded_by_generation(const struct cats_grid *grid, cats_dt_coord row, cats_dt_coord col)
{
const int module_id = CATS_MODULE_ID;
const struct grid_data_butterflies *data = grid->grid_modules[module_id].module_data;
if (data->generation_current == 0.0 || data->generation_current > (int32_t) ceilf(data->generations[row][col])) return true;
float generations = butterflies_get_generations(data, row, col);
if (data->generation_current == 0.0 || data->generation_current > (int32_t) ceilf(generations)) return true;
return false;
}
......
......@@ -7,6 +7,38 @@
#include "butterflies_main.h"
#include "inline_overlays.h"
#include "inline_population.h"
#include "inline_butterflies.h"
bool butterflies_habitat_ok(const struct cats_configuration *conf, cats_dt_coord row, cats_dt_coord col)
{
// we have no habitat layer -> all cells have suitable habitat
if (conf->overlays.overlay[OL_HABITAT_TYPE_CC].enabled == false) {
return true;
}
// habitat layer exists and the carrying capacity is > 0 -> this cell's habitat is suitable
if (get_overlay_habitat_cc_value(conf, row, col) > 0) {
return true;
}
return false;
}
bool butterflies_resources_ok(const struct cats_configuration *conf, cats_dt_coord row, cats_dt_coord col)
{
// we have no resource layer -> all cells have the resource available
if (conf->overlays.overlay[OL_RESOURCE].enabled == false) {
return true;
}
// resource layer exists and the resource is > 0 -> this cell's resource is available
if (get_overlay_resource_value(conf, row, col) > 0) {
return true;
}
return false;
}
enum action_status bf_grid_overlay_update(const struct cats_configuration *conf, struct cats_grid *grid)
......@@ -30,49 +62,43 @@ enum action_status bf_grid_overlay_update(const struct cats_configuration *conf,
for (cats_dt_coord row = 0; row < rows; row++) {
for (cats_dt_coord col = 0; col < cols; col++) {
int32_t cell_info = BF_CELL_CLEAR;
data->info_layer[row][col] = BF_CELL_CLEAR;
float eggs = butterflies_get_eggs(data, row, col);
if (cell_excluded_by_overlay(conf, row, col)) {
data->info_layer[row][col] |= BF_CELL_EXCLUDED;
if (data->eggs[row][col]) cells_eggs_removed += 1;
cell_info |= BF_CELL_EXCLUDED;
butterflies_set_info_layer(data, row, col, cell_info);
if (eggs) cells_eggs_removed += 1;
if (get_adult_population(grid, row, col)) cells_adults_removed += 1;
data->eggs[row][col] = 0;
butterflies_set_eggs(data, row, col, 0.0f);
set_population_ignore_cc(grid, row, col, 0);
cells_excluded += 1;
continue;
}
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;
cells_habitat_ok += 1;
} else if (!conf->overlays.overlay[OL_HABITAT_TYPE_CC].enabled) {
data->info_layer[row][col] |= BF_CELL_HABITAT_OK;
if (butterflies_habitat_ok(conf, row, col)) {
cell_info |= BF_CELL_HABITAT_OK;
cells_habitat_ok += 1;
}
if (conf->overlays.overlay[OL_RESOURCE].enabled &&
conf->overlays.resources->data[row][col] > 0) {
data->info_layer[row][col] |= BF_CELL_RESOURCE_AVAILABLE;
cells_resource_ok += 1;
} else if (!conf->overlays.overlay[OL_RESOURCE].enabled) {
data->info_layer[row][col] |= BF_CELL_RESOURCE_AVAILABLE;
if (butterflies_resources_ok(conf, row, col)) {
cell_info |= BF_CELL_RESOURCE_AVAILABLE;
cells_resource_ok += 1;
}
if ((data->info_layer[row][col] & BF_CELL_HABITAT_OK) &&
(data->info_layer[row][col] & BF_CELL_RESOURCE_AVAILABLE)) {
data->info_layer[row][col] |= BF_CELL_VALID_DISPERSAL_TARGET;
if ((cell_info & BF_CELL_HABITAT_OK) && (cell_info & BF_CELL_RESOURCE_AVAILABLE)) {
cell_info |= BF_CELL_VALID_DISPERSAL_TARGET;
cells_habitat_and_resource_ok += 1;
} else {
if (data->eggs[row][col]) cells_eggs_removed += 1;
if (eggs) cells_eggs_removed += 1;
if (get_adult_population(grid, row, col)) cells_adults_removed += 1;
data->eggs[row][col] = 0;
butterflies_set_eggs(data, row, col, 0.0f);
set_population_ignore_cc(grid, row, col, 0);
}
butterflies_set_info_layer(data, row, col, cell_info);
}
}
......@@ -80,7 +106,7 @@ enum action_status bf_grid_overlay_update(const struct cats_configuration *conf,
double total_eggs = 0;
for (cats_dt_coord row = 0; row < rows; row++) {
for (cats_dt_coord col = 0; col < cols; col++) {
float eggs = data->eggs[row][col];
float eggs = butterflies_get_eggs(data, row, col);
if (eggs > 0) {
cells_with_eggs += 1;
total_eggs += eggs;
......
......@@ -14,6 +14,8 @@
#include "butterflies_inline.h"
#include "inline.h"
#include "populations/population.h"
#include "inline_butterflies.h"
int64_t count_populated_cells(const struct cats_grid *grid)
{
......@@ -43,8 +45,9 @@ int64_t butterflies_prune_invalid_cells(struct cats_grid *grid)
for (cats_dt_coord row = 0; row < rows; row++) {
for (cats_dt_coord col = 0; col < cols; col++) {
int32_t cell_info = butterflies_get_info_layer(data, row, col);
if (!(cell_info & BF_CELL_VALID_DISPERSAL_TARGET)) {
if (!(data->info_layer[row][col] & BF_CELL_VALID_DISPERSAL_TARGET)) {
if(get_adult_population(grid, row, col)) {
invalid_habitat += 1;
}
......@@ -71,7 +74,7 @@ float get_fractional_generation(struct cats_grid *grid, cats_dt_coord row, cats_
float this_generation_fraction = 1.0f;
float local_generation = data->generations[row][col];
float local_generation = butterflies_get_generations(data,row,col);
int32_t global_max_generation = module_conf->generations_max;
int32_t local_max_generation = (int32_t) ceilf(local_generation);
int32_t global_current_generation = data->generation_current;
......@@ -107,10 +110,11 @@ void bf_cell_maturation(struct cats_grid *grid, struct cats_thread_info *ts, cat
const int module_id = CATS_MODULE_ID;
struct grid_data_butterflies *data = grid->grid_modules[module_id].module_data;
if (data->eggs[row][col] == 0) return;
if (data->eggs[row][col] < 0) {
log_message(LOG_ERROR, "Number of eggs < 0: row %d col %d: %f", row, col, data->eggs[row][col]);
const float all_eggs = butterflies_get_eggs(data, row, col);
if (all_eggs == 0) return;
if (all_eggs < 0) {
log_message(LOG_ERROR, "Number of eggs < 0: row %d col %d: %f", row, col, all_eggs);
exit(EXIT_FAILURE);
}
......@@ -136,21 +140,20 @@ void bf_cell_maturation(struct cats_grid *grid, struct cats_thread_info *ts, cat
//cats_dt_population max_cc = (cats_dt_population) grid->param.carrying_capacity.max_rate;
const float eggs = this_generation_fraction * data->eggs[row][col];
const float eggs = this_generation_fraction * all_eggs;
#ifdef BF_DEBUG
printf("BFDBG::%s::row %d, col %d: local gen %f gen fraction %f, eggs %f, this gen eggs %f\n",
__func__, row, col, local_generation, this_generation_fraction, data->eggs[row][col], eggs);
__func__, row, col, local_generation, this_generation_fraction, all_eggs, eggs);
#endif
if (eggs == 0) return;
if (eggs > data->eggs[row][col]) {
log_message(LOG_ERROR, "Removing more eggs than present: %d %d: %f/%f", row, col, data->eggs[row][col],
if (eggs > all_eggs) {
log_message(LOG_ERROR, "Removing more eggs than present: %d %d: %f/%f", row, col, all_eggs,
eggs);
exit_cats(EXIT_FAILURE);
}
butterflies_remove_eggs(data, row, col, eggs);
data->eggs[row][col] -= eggs;
assert(data->eggs[row][col] >= 0);
// not capped, we can have more adults than CC
......@@ -167,7 +170,7 @@ void bf_cell_maturation(struct cats_grid *grid, struct cats_thread_info *ts, cat
//printf("row %d col %d: suitability: %f, eggs: %f, reproduction rate %Lf\n", row, col, suit, eggs, reproduction_rate);
if (reproduction_rate == 0) {
data->eggs[row][col] = 0;
butterflies_set_eggs(data, row, col, 0.0f);
set_population_ignore_cc(grid, row, col, 0);
return;
}
......
#ifndef CATS_INLINE_BUTTERFLIES_H
#define CATS_INLINE_BUTTERFLIES_H
#include "butterflies_main.h"
static inline float butterflies_get_eggs(const struct grid_data_butterflies *data, cats_dt_coord row, cats_dt_coord col)
{ assert(data->eggs[row][col] >= 0); // setter [butterflies_get_eggs]
return data->eggs[row][col]; // setter [butterflies_get_eggs]
}
static inline void butterflies_set_eggs(struct grid_data_butterflies *data, cats_dt_coord row, cats_dt_coord col, float eggs)
{
assert(eggs >= 0);
data->eggs[row][col] = eggs; // setter [butterflies_set_eggs]
}
static inline void butterflies_add_eggs(struct grid_data_butterflies *data, cats_dt_coord row, cats_dt_coord col, float by)
{
assert(by >= 0);
data->eggs[row][col] += by; // setter [butterflies_add_eggs]
}
static inline void butterflies_remove_eggs(struct grid_data_butterflies *data, cats_dt_coord row, cats_dt_coord col, float by)
{
assert(by >= 0);
data->eggs[row][col] -= by; // setter [butterflies_remove_eggs]
assert(data->eggs[row][col] >= 0); // setter [butterflies_remove_eggs]
}
static inline void butterflies_set_generations(struct grid_data_butterflies *data, cats_dt_coord row, cats_dt_coord col, float generations)
{
assert(generations >= 0); // setter [butterflies_set_generations]
data->generations[row][col] = generations; // setter [butterflies_set_generations]
}
static inline float butterflies_get_generations(const struct grid_data_butterflies *data, cats_dt_coord row, cats_dt_coord col)
{
return data->generations[row][col]; // getter [butterflies_get_generations]
}
static inline void butterflies_set_info_layer(struct grid_data_butterflies *data, cats_dt_coord row, cats_dt_coord col, int32_t value)
{
data->info_layer[row][col] = value; // setter [butterflies_set_info_layer]
}
static inline int32_t butterflies_get_info_layer(const struct grid_data_butterflies *data, cats_dt_coord row, cats_dt_coord col)
{
return data->info_layer[row][col]; // getter [butterflies_get_info_layer]
}
#endif //CATS_INLINE_BUTTERFLIES_H