/* get_grid_item: updates the grid_item with fresh data */ void get_grid_item(void) { int x, y; scew_attribute *a = NULL; scew_element *e = NULL; scew_element *sub_e = NULL; scew_element *r = NULL; POINT p; if (!maptree) return; p = get_mouse_pos(); x = p.x - (p.x % TILE_W); y = p.y - (p.y % TILE_H) + map_offset; r = scew_tree_root(maptree); if (mode == TILE_MODE) { e = scew_element_by_name(r, "Tiles"); } else if (mode == SPRITE_MODE) { e = scew_element_by_name(r, "Sprites"); } else return; sub_e = scew_element_next(e, sub_e); while (sub_e) { a = scew_attribute_by_name(sub_e, "x"); if (x == atoi(scew_attribute_value(a))) { a = scew_attribute_by_name(sub_e, "y"); if (y == atoi(scew_attribute_value(a))) { grid_item.x = x; grid_item.y = y; grid_item.mode = mode; a = scew_attribute_by_name(sub_e, "name"); strncpy(grid_item.name, scew_attribute_value(a), NAME_LN); if (mode == TILE_MODE) { a = scew_attribute_by_name(sub_e, "passable"); grid_item.passable = atoi(scew_attribute_value(a)); } else { grid_item.passable = -1; } break; } } sub_e = scew_element_next(e, sub_e); } }
/******************************************************************************* * Function: Element_Attribute * * This function returns a char * representing a pointer to a NULL terminated * character array, which contains the value associated with the attribute, * specified by the _attr input parameter, of the element specified by the * _element input parameter. * * Parameters: * _element: A void * representing a valid pointer to a scew_element * structure. This pointer must have been created previously by * some other function in this library. * _attr: A char * pointing to a NULL terminated character array, which * contains the name of the attribute in _element, for which to * find a value. * * Returns: * char *: Representing a pointer to a NULL terminated character array, which * contains the value of the attribute of _element, if it exists. * A NULL Pointer is returned on error. * ******************************************************************************/ DLLIMPORT char *Element_Attribute( void *_element, char *_attr ) { char *ret_val = NULL; if ( ( _element != NULL ) && ( _attr != NULL ) ) { scew_attribute *temp = scew_attribute_by_name( _element, _attr ); if ( temp != NULL ) ret_val = (char *)scew_attribute_value( temp ); }; return ret_val; }
m->reset = reset; m->is_listening_for = is_listening_for; m->has_pending_actions = has_pending_actions; m->has_pending_infections = has_pending_infections; m->to_string = to_string; m->printf = local_printf; m->fprintf = local_fprintf; m->free = local_free; /* Make sure the right XML subtree was sent. */ g_assert (strcmp (scew_element_name (params), MODEL_NAME) == 0); #if DEBUG g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "setting contact type"); #endif attr = scew_attribute_by_name (params, "contact-type"); g_assert (attr != NULL); attr_text = scew_attribute_value (attr); if (strcmp (attr_text, "direct") == 0) local_data->contact_type = NAADSM_DirectContact; else if (strcmp (attr_text, "indirect") == 0) local_data->contact_type = NAADSM_IndirectContact; else g_assert_not_reached (); local_data->contact_type_name = NAADSM_contact_type_abbrev[local_data->contact_type]; #if DEBUG g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "setting production types"); #endif local_data->production_types = herds->production_type_names; local_data->production_type =
/** * Adds a set of parameters to a contact spread model. */ void set_params (struct naadsm_model_t_ *self, PAR_parameter_t * params) { local_data_t *local_data = (local_data_t *) (self->model_data); unsigned int nzones = ZON_zone_list_length (local_data->zones); unsigned int nprod_types = local_data->production_types->len; scew_element *e, **ee; gboolean success; gboolean has_destruction_cost_params = FALSE; gboolean has_vaccination_cost_params = FALSE; gboolean has_surveillance_cost_param = FALSE; destruction_cost_data_t destruction_cost_params = {}; vaccination_cost_data_t vaccination_cost_params = {}; double surveillance_cost_param = 0; gboolean *production_type = NULL; gboolean *zone = NULL; unsigned int i, j; unsigned int noutputs; RPT_reporting_t *output; const XML_Char *variable_name; #if DEBUG g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "----- ENTER set_params (%s)", MODEL_NAME); #endif /* Make sure the right XML subtree was sent. */ g_assert (strcmp (scew_element_name (params), MODEL_NAME) == 0); #if DEBUG g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "setting production types"); #endif /* Destruction Cost Parameters */ e = scew_element_by_name (params, "appraisal"); if (e != NULL) { destruction_cost_params.appraisal = PAR_get_money (e, &success); if (success) { has_destruction_cost_params = TRUE; } else { g_warning ("%s: setting per-unit appraisal cost to 0", MODEL_NAME); destruction_cost_params.appraisal = 0; } } else { g_warning ("%s: per-unit appraisal cost missing, setting to 0", MODEL_NAME); destruction_cost_params.appraisal = 0; } e = scew_element_by_name (params, "euthanasia"); if (e != NULL) { destruction_cost_params.euthanasia = PAR_get_money (e, &success); if (success) { has_destruction_cost_params = TRUE; } else { g_warning ("%s: setting per-animal euthanasia cost to 0", MODEL_NAME); destruction_cost_params.euthanasia = 0; } } else { g_warning ("%s: per-animal euthanasia cost missing, setting to 0", MODEL_NAME); destruction_cost_params.euthanasia = 0; } e = scew_element_by_name (params, "indemnification"); if (e != NULL) { destruction_cost_params.indemnification = PAR_get_money (e, &success); if (success) { has_destruction_cost_params = TRUE; } else { g_warning ("%s: setting per-animal indemnification cost to 0", MODEL_NAME); destruction_cost_params.indemnification = 0; } } else { g_warning ("%s: per-animal indemnification cost missing, setting to 0", MODEL_NAME); destruction_cost_params.indemnification = 0; } e = scew_element_by_name (params, "carcass-disposal"); if (e != NULL) { destruction_cost_params.carcass_disposal = PAR_get_money (e, &success); if (success) { has_destruction_cost_params = TRUE; } else { g_warning ("%s: setting per-animal carcass disposal cost to 0", MODEL_NAME); destruction_cost_params.carcass_disposal = 0; } } else { g_warning ("%s: per-animal carcass disposal cost missing, setting to 0", MODEL_NAME); destruction_cost_params.carcass_disposal = 0; } e = scew_element_by_name (params, "cleaning-disinfecting"); if (e != NULL) { destruction_cost_params.cleaning_disinfecting = PAR_get_money (e, &success); if (success) { has_destruction_cost_params = TRUE; } else { g_warning ("%s: setting per-unit cleaning and disinfecting cost to 0", MODEL_NAME); destruction_cost_params.cleaning_disinfecting = 0; } } else { g_warning ("%s: per-unit cleaning and disinfecting cost missing, setting to 0", MODEL_NAME); destruction_cost_params.cleaning_disinfecting = 0; } /* Vaccination Cost Parameters */ e = scew_element_by_name (params, "vaccination-fixed"); if (e != NULL) { vaccination_cost_params.vaccination_fixed = PAR_get_money (e, &success); if (success) { has_vaccination_cost_params = TRUE; } else { g_warning ("%s: setting per-unit vaccination cost to 0", MODEL_NAME); vaccination_cost_params.vaccination_fixed = 0; } } else { g_warning ("%s: per-unit vaccination cost missing, setting to 0", MODEL_NAME); vaccination_cost_params.vaccination_fixed = 0; } e = scew_element_by_name (params, "vaccination"); if (e != NULL) { vaccination_cost_params.vaccination = PAR_get_money (e, &success); if (success) { has_vaccination_cost_params = TRUE; } else { g_warning ("%s: setting per-animal vaccination cost to 0", MODEL_NAME); vaccination_cost_params.vaccination = 0; } } else { g_warning ("%s: per-animal vaccination cost missing, setting to 0", MODEL_NAME); vaccination_cost_params.vaccination = 0; } e = scew_element_by_name (params, "baseline-vaccination-capacity"); if (e != NULL) { vaccination_cost_params.baseline_capacity = (unsigned int) PAR_get_unitless (e, &success); if (success) { has_vaccination_cost_params = TRUE; } else { g_warning ("%s: setting baseline vaccination capacity to 1,000,000", MODEL_NAME); vaccination_cost_params.baseline_capacity = 1000000; } } else { g_warning ("%s: baseline vaccination capacity missing, setting to 1,000,000", MODEL_NAME); vaccination_cost_params.baseline_capacity = 1000000; } e = scew_element_by_name (params, "additional-vaccination"); if (e != NULL) { vaccination_cost_params.extra_vaccination = PAR_get_money (e, &success); if (success) { has_vaccination_cost_params = TRUE; } else { g_warning ("%s: setting additional per-animal vaccination cost to 0", MODEL_NAME); vaccination_cost_params.extra_vaccination = 0; } } else { g_warning ("%s: additional per-animal vaccination cost missing, setting to 0", MODEL_NAME); vaccination_cost_params.extra_vaccination = 0; } /* No vaccinations have been performed yet. */ vaccination_cost_params.capacity_used = 0; /* Surveillance Cost Parameters */ e = scew_element_by_name (params, "surveillance"); if (e != NULL) { surveillance_cost_param = PAR_get_money (e, &success); if (success) { has_surveillance_cost_param = TRUE; } else { g_warning ("%s: setting per-animal zone surveillance cost to 0", MODEL_NAME); surveillance_cost_param = 0; } } else { g_warning ("%s: per-animal zone surveillance cost missing, setting to 0", MODEL_NAME); surveillance_cost_param = 0; } /* Set the reporting frequency for the output variables. */ ee = scew_element_list (params, "output", &noutputs); #if DEBUG g_debug ("%i output variables", noutputs); #endif for (i = 0; i < noutputs; i++) { e = ee[i]; variable_name = scew_element_contents (scew_element_by_name (e, "variable-name")); /* Do the outputs include a variable with this name? */ for (j = 0; j < self->outputs->len; j++) { output = (RPT_reporting_t *) g_ptr_array_index (self->outputs, j); if (strcmp (output->name, variable_name) == 0) break; } if (j == self->outputs->len) g_warning ("no output variable named \"%s\", ignoring", variable_name); else { RPT_reporting_set_frequency (output, RPT_string_to_frequency (scew_element_contents (scew_element_by_name (e, "frequency")))); #if DEBUG g_debug ("report \"%s\" %s", variable_name, RPT_frequency_name[output->frequency]); #endif } } free (ee); /* Read zone and production type attributes to determine which * entries should be filled in. */ if (scew_attribute_by_name (params, "zone") != NULL) zone = naadsm_read_zone_attribute (params, local_data->zones); else zone = NULL; production_type = naadsm_read_prodtype_attribute (params, "production-type", local_data->production_types); /* Copy the parameters into the selected zone and production types. */ for (i = 0; i < nprod_types; i++) { if (production_type[i]) { if (has_destruction_cost_params) { if (local_data->destruction_cost_params == NULL) { local_data->destruction_cost_params = g_new0 (destruction_cost_data_t *, nprod_types); g_assert (local_data->destruction_cost_params != NULL); } if (local_data->destruction_cost_params[i] == NULL) { local_data->destruction_cost_params[i] = g_new0 (destruction_cost_data_t, 1); g_assert (local_data->destruction_cost_params[i] != NULL); } memcpy (local_data->destruction_cost_params[i], &destruction_cost_params, sizeof (destruction_cost_data_t)); } if (has_vaccination_cost_params) { if (local_data->vaccination_cost_params == NULL) { local_data->vaccination_cost_params = g_new0 (vaccination_cost_data_t *, nprod_types); g_assert (local_data->vaccination_cost_params != NULL); } if (local_data->vaccination_cost_params[i] == NULL) { local_data->vaccination_cost_params[i] = g_new0 (vaccination_cost_data_t, 1); g_assert (local_data->vaccination_cost_params[i] != NULL); } memcpy (local_data->vaccination_cost_params[i], &vaccination_cost_params, sizeof (vaccination_cost_data_t)); } if (has_surveillance_cost_param) { if (zone) { for (j = 0; j < nzones; j++) { if (zone[j]) { if (local_data->surveillance_cost_param == NULL) { local_data->surveillance_cost_param = g_new0 (double *, nzones); g_assert (local_data->surveillance_cost_param != NULL); } if (local_data->surveillance_cost_param[j] == NULL) { local_data->surveillance_cost_param[j] = g_new0 (double, nprod_types); g_assert (local_data->surveillance_cost_param[j] != NULL); } local_data->surveillance_cost_param[j][i] = surveillance_cost_param; } } }
DLLIMPORT void *Attribute_By_Name( void *_element, char *_name) { return scew_attribute_by_name( (scew_element*)_element, _name ); }