Пример #1
0
void era_init(era_arm_p arm, can_device_p can_dev, era_config_p config) {
  era_config_init_default(&arm->config, &era_config_default);
  if (config)
    era_config_set(&arm->config, config);

  era_motors_init(&arm->motors, can_dev, &arm->config.joints);
  era_security_init(&arm->security,
    config_get_int(&arm->config.arm, ERA_PARAMETER_ARM_SECURITY_FUNC),
    config_get_int(&arm->config.arm, ERA_PARAMETER_ARM_ESTOP_CHANNEL),
    config_get_int(&arm->config.arm, ERA_PARAMETER_ARM_SWITCH_CHANNEL));

  era_joint_state_t min_state, max_state, state_margin;
  era_velocity_state_t max_vel;
  era_acceleration_state_t min_accel, max_accel;
  era_geometry_init(&arm->geometry,
    config_get_float(&arm->config.arm, ERA_PARAMETER_ARM_UPPER_LENGTH),
    config_get_float(&arm->config.arm, ERA_PARAMETER_ARM_LOWER_LENGTH),
    config_get_float(&arm->config.arm, ERA_PARAMETER_ARM_TOOL_LENGTH));
  era_kinematics_limits_init(&arm->kin_limits,
    (era_joint_state_p)era_config_joint_get_rad(&arm->config, 
      ERA_PARAMETER_JOINT_MIN_POSITION, (double*)&min_state),
    (era_joint_state_p)era_config_joint_get_rad(&arm->config, 
      ERA_PARAMETER_JOINT_MAX_POSITION, (double*)&max_state),
    (era_joint_state_p)era_config_joint_get_rad(&arm->config, 
      ERA_PARAMETER_JOINT_POSITION_MARGIN, (double*)&state_margin));
  era_dynamics_limits_init(&arm->dyn_limits,
    (era_velocity_state_p)era_config_joint_get_rad(&arm->config, 
      ERA_PARAMETER_JOINT_MAX_VELOCITY, (double*)&max_vel),
    (era_acceleration_state_p)era_config_joint_get_rad(&arm->config, 
      ERA_PARAMETER_JOINT_MIN_ACCELERATION, (double*)&min_accel),
    (era_acceleration_state_p)era_config_joint_get_rad(&arm->config, 
      ERA_PARAMETER_JOINT_MAX_ACCELERATION, (double*)&max_accel));
}
Пример #2
0
Файл: ui.c Проект: jjgod/legend
int ui_init()
{
    int width, height;

    font_init();

    width = config_get_int("width");
    height = config_get_int("height");

    SDL_putenv("SDL_VIDEO_WINDOW_POS=center");

    if (SDL_Init(SDL_INIT_EVERYTHING) < 0)
    {
        fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError());
        return -1;
    }

    atexit(SDL_Quit);

    screen = SDL_SetVideoMode(width, height, 32,
                              SDL_HWSURFACE | SDL_DOUBLEBUF);
    if (screen == NULL)
    {
        fprintf(stderr, "Unable to set %dx%d video: %s\n",
                width, height, SDL_GetError());
        return -1;
    }

    scripting_init_ui();
    SDL_Flip(screen);

    return 0;
}
Пример #3
0
int can_open(can_device_p dev) {
  if (!dev->comm_dev)
    dev->comm_dev = malloc(sizeof(can_cpc_device_t));

  if (!dev->num_references) {
    dev->num_sent = 0;
    dev->num_received = 0;

    if (can_cpc_open(dev->comm_dev,
        config_get_string(&dev->config, CAN_CPC_PARAMETER_DEVICE)) ||
      can_cpc_setup(dev->comm_dev,
        config_get_int(&dev->config, CAN_CPC_PARAMETER_BITRATE),
        config_get_int(&dev->config, CAN_CPC_PARAMETER_QUANTA_PER_BIT),
        config_get_float(&dev->config, CAN_CPC_PARAMETER_SAMPLING_POINT),
        config_get_float(&dev->config, CAN_CPC_PARAMETER_TIMEOUT))) {
      free(dev->comm_dev);
      dev->comm_dev = 0;

      return CAN_ERROR_OPEN;
    }
  }
  ++dev->num_references;

  return CAN_ERROR_NONE;
}
Пример #4
0
void network_init()
{
  ENetAddress address;
  int status, port, max_clients;
  gchar *server;

  network = g_malloc(sizeof(*network));

  server = (gchar *) config_get_string("server", default_server);
  port = config_get_int("port", default_port);
  max_clients = config_get_int("max_clients", default_max_clients);

  status = enet_initialize();
  g_return_if_fail(status == 0);

  enet_address_set_host(&address, server);
  address.port = port;

  network->server = enet_host_create(&address, max_clients, 
#ifdef HAS_RECENT_ENET
                                     2, 
#endif
                                     0, 0);
  g_return_if_fail(network->server != NULL);
  g_debug("Listening on %s:%d", server, port);

  network->clients = NULL;
  g_free(server);
}
Пример #5
0
TEST_F(ConfigTest, config_remove_key_missing) {
  config_t *config = config_new(CONFIG_FILE);
  EXPECT_EQ(config_get_int(config, "DID", "productId", 999), 0x1200);
  EXPECT_TRUE(config_remove_key(config, "DID", "productId"));
  EXPECT_EQ(config_get_int(config, "DID", "productId", 999), 999);
  config_free(config);
}
Пример #6
0
static bool input_try_autoconfigure_joypad_from_conf(config_file_t *conf,
      unsigned idx, const char *name, const char *drv,
      int32_t vid, int32_t pid, bool block_osd_spam)
{
   char ident[PATH_MAX_LENGTH], ident_idx[PATH_MAX_LENGTH];
   char input_driver[PATH_MAX_LENGTH], msg[PATH_MAX_LENGTH];
   int input_vid = 0, input_pid = 0;
   bool cond_found_idx, cond_found_general,
        cond_found_vid = false, cond_found_pid = false;

   if (!conf)
      return false;

   *ident = *input_driver = '\0';

   config_get_array(conf, "input_device", ident, sizeof(ident));
   config_get_array(conf, "input_driver", input_driver, sizeof(input_driver));
   config_get_int(conf, "input_vendor_id", &input_vid);
   config_get_int(conf, "input_product_id", &input_pid);

   snprintf(ident_idx, sizeof(ident_idx), "%s_p%u", ident, idx);

#if 0
   RARCH_LOG("ident_idx: %s\n", ident_idx);
#endif

   cond_found_idx     = !strcmp(ident_idx, name);
   cond_found_general = !strcmp(ident, name) && !strcmp(drv, input_driver);
   if ((vid != 0) && (input_vid != 0))
      cond_found_vid     = (vid == input_vid);
   if ((pid != 0) && (input_pid != 0))
      cond_found_pid     = (pid == input_pid);

   /* If Vendor ID and Product ID matches, we've found our
    * entry. */
   if (cond_found_vid && cond_found_pid)
      goto found;

   /* Check for name match. */
   if (cond_found_idx)
      goto found;
   else if (cond_found_general)
      goto found;

   return false;

found:
   g_settings.input.autoconfigured[idx] = true;
   input_autoconfigure_joypad_conf(conf, g_settings.input.autoconf_binds[idx]);

   snprintf(msg, sizeof(msg), "Joypad port #%u (%s) configured.",
         idx, name);

   if (!block_osd_spam)
      rarch_main_msg_queue_push(msg, 0, 60, false);
   RARCH_LOG("%s\n", msg);

   return true;
}
Пример #7
0
static int theme_read(THEME_REC *theme, const char *path, const char *data)
{
	CONFIG_REC *config;
	THEME_READ_REC rec;
        char *str;

	config = config_open(data == NULL ? path : NULL, -1) ;
	if (config == NULL) {
		/* didn't exist or no access? */
		str = g_strdup_printf("Error reading theme file %s: %s",
				      path, g_strerror(errno));
		read_error(str);
		g_free(str);
		return FALSE;
	}

	if (data != NULL)
		config_parse_data(config, data, "internal");
        else
		config_parse(config);

	if (config_last_error(config) != NULL) {
		str = g_strdup_printf("Ignored errors in theme %s:\n%s",
				      theme->name, config_last_error(config));
		read_error(str);
                g_free(str);
	}

	theme->default_color =
		config_get_int(config, NULL, "default_color", -1);
	theme->info_eol = config_get_bool(config, NULL, "info_eol", FALSE);

	/* FIXME: remove after 0.7.99 */
	if (theme->default_color == 0 &&
	    config_get_int(config, NULL, "default_real_color", -1) != -1)
                theme->default_color = -1;
	theme_read_replaces(config, theme);

	if (data == NULL) {
		/* get the default abstracts from default theme. */
		CONFIG_REC *default_config;

		default_config = config_open(NULL, -1);
		config_parse_data(default_config, default_theme, "internal");
		theme_read_abstracts(default_config, theme);
		config_close(default_config);
	}
	theme_read_abstracts(config, theme);

	rec.theme = theme;
	rec.config = config;
	g_hash_table_foreach(default_formats,
			     (GHFunc) theme_read_modules, &rec);
	config_close(config);

        return TRUE;
}
Пример #8
0
static int input_try_autoconfigure_joypad_from_conf(config_file_t *conf,
      autoconfig_params_t *params)
{
   char ident[PATH_MAX_LENGTH]        = {0};
   char input_driver[PATH_MAX_LENGTH] = {0};
   int                      input_vid = 0;
   int                      input_pid = 0;
   int                          score = 0;

   if (!conf)
      return false;

   config_get_array(conf, "input_device", ident, sizeof(ident));
   config_get_array(conf, "input_driver", input_driver, sizeof(input_driver));
   config_get_int  (conf, "input_vendor_id", &input_vid);
   config_get_int  (conf, "input_product_id", &input_pid);

   /* Check for VID/PID */
   if (     (params->vid == input_vid)
         && (params->pid == input_pid)
         && params->vid != 0
         && params->pid != 0
         && input_vid   != 0
         && input_pid   != 0)
   {
      score += 3;
#if 0
      RARCH_LOG("Autodetect: VID/PID match score=%d\n", score);
#endif
   }

   /* Check for name match */
   if (string_is_equal(ident, params->name))
   {
      score += 2;
#if 0
      RARCH_LOG("Autodetect: exact name match score=%d\n", score);
#endif
   }
   else
   {
      if (!string_is_empty(ident) 
            && !strncmp(params->name, ident, strlen(ident)))
      {
         score += 1;
#if 0
         RARCH_LOG("Autodetect: partial name match score=%d\n", score);
#endif
      }
   }
#if 0
   RARCH_LOG("Autodetect: configuration file: %s score: %d\n",
         conf->path, score);
#endif
   return score;
}
Пример #9
0
/* Return a positive, negative or not possible result to the LDAP auth for
 * the specified user.
 */
static int ldap_auth(const char *const user, const char *const pswd) {
	static time_t last;
	static char *prev_user;
	LDAP *ld;
	int ldap_ver, r;
	char f[256];
	ConfigHandleType *c = config_load(amazon_ldap_config_dd);

	/* Don't repeat query too often if the user name hasn't changed */
	if (last && prev_user &&
			time(NULL) < (last + config_get_int(c, AMAZON_LDAP_CACHET)) &&
			strcmp(prev_user, user) == 0) {
		config_free(c);
		last = time(NULL);
		return 1;
	}
	if (prev_user != NULL)   { free(prev_user);	prev_user = NULL;   }
	last = 0;

	if ((ld = ldap_init(config_get_string(c, AMAZON_LDAP_HOST),
			config_get_int(c, AMAZON_LDAP_PORT))) == NULL) {
		syslog(LOG_ERR, "unable to initialise LDAP");
		config_free(c);
		return 0;
	}
	if (ldap_set_option(ld, LDAP_OPT_REFERRALS, LDAP_OPT_OFF) != LDAP_SUCCESS) {
		syslog(LOG_ERR, "unable to set LDAP referrals off");
		config_free(c);
		ldap_unbind(ld);
		return 0;
	}
	ldap_ver = config_get_int(c, AMAZON_LDAP_VERSION);
	if (ldap_ver > 0 && ldap_set_option(ld, LDAP_OPT_PROTOCOL_VERSION, &ldap_ver) != LDAP_SUCCESS) {
		syslog(LOG_ERR, "unable to set LDAP version %d", ldap_ver);
		config_free(c);
		ldap_unbind(ld);
		return 0;
	}
	snprintf(f, sizeof f, config_get_string(c, AMAZON_LDAP_BIND_DN), user);
	r = ldap_simple_bind_s(ld, f, pswd);
	if (r != LDAP_SUCCESS) {
		syslog(LOG_ERR, "unable to connect to LDAP (%s)", ldap_err2string(r));
		config_free(c);
		ldap_unbind(ld);
		return (r==LDAP_INVALID_CREDENTIALS)?-1:0;
	}
	config_free(c);
	ldap_unbind(ld);
	/* Caching timing details for next time through */
	prev_user = strdup(user);
	last = time(NULL);
	return 1;
}
Пример #10
0
static int input_autoconfigure_joypad_try_from_conf(config_file_t *conf,
      autoconfig_params_t *params)
{
   char ident[256];
   char input_driver[32];
   int tmp_int                = 0;
   int              input_vid = 0;
   int              input_pid = 0;
   int                  score = 0;

   ident[0] = input_driver[0] = '\0';

   config_get_array(conf, "input_device", ident, sizeof(ident));
   config_get_array(conf, "input_driver", input_driver, sizeof(input_driver));

   if (config_get_int  (conf, "input_vendor_id", &tmp_int))
      input_vid = tmp_int;

   if (config_get_int  (conf, "input_product_id", &tmp_int))
      input_pid = tmp_int;

   if (params->vid == BLISSBOX_VID)
      input_pid = BLISSBOX_PID;

   /* Check for VID/PID */
   if (     (params->vid == input_vid)
         && (params->pid == input_pid)
         && (params->vid != 0)
         && (params->pid != 0)
         && (params->vid != BLISSBOX_VID)
         && (params->pid != BLISSBOX_PID))
      score += 3;

   /* Check for name match */
   if (!string_is_empty(params->name)
         && !string_is_empty(ident)
         && string_is_equal(ident, params->name))
      score += 2;
#if 0
   else
   {
      if (string_is_empty(params->name))
         RARCH_LOG("[Autoconf]: failed match because params->name was empty\n");
      else if (string_is_empty(ident))
         RARCH_LOG("[Autoconf]: failed match because ident was empty\n");
      else
         RARCH_LOG("[Autoconf]: failed match because ident '%s' != param->name '%s'\n",
               ident, params->name);
   }
#endif

   return score;
}
Пример #11
0
// Parses the specified Device ID configuration file and registers the
// Device ID records with SDP.
void bte_load_did_conf(const char *p_path) {
    assert(p_path != NULL);

    config_t *config = config_new(p_path);
    if (!config) {
        LOG_ERROR(LOG_TAG, "%s unable to load DID config '%s'.", __func__, p_path);
        return;
    }

    for (int i = 1; i <= BTA_DI_NUM_MAX; ++i) {
        char section_name[16] = { 0 };
        snprintf(section_name, sizeof(section_name), "DID%d", i);

        if (!config_has_section(config, section_name)) {
            LOG_DEBUG(LOG_TAG, "%s no section named %s.", __func__, section_name);
            break;
        }

        tBTA_DI_RECORD record;
        record.vendor = config_get_int(config, section_name, "vendorId", LMP_COMPID_BROADCOM);
        record.vendor_id_source = config_get_int(config, section_name, "vendorIdSource", DI_VENDOR_ID_SOURCE_BTSIG);
        record.product = config_get_int(config, section_name, "productId", 0);
        record.version = config_get_int(config, section_name, "version", 0);
        record.primary_record = config_get_bool(config, section_name, "primaryRecord", false);
        strlcpy(record.client_executable_url, config_get_string(config, section_name, "clientExecutableURL", ""), sizeof(record.client_executable_url));
        strlcpy(record.service_description, config_get_string(config, section_name, "serviceDescription", ""), sizeof(record.service_description));
        strlcpy(record.documentation_url, config_get_string(config, section_name, "documentationURL", ""), sizeof(record.documentation_url));

        if (record.vendor_id_source != DI_VENDOR_ID_SOURCE_BTSIG &&
            record.vendor_id_source != DI_VENDOR_ID_SOURCE_USBIF) {
            LOG_ERROR(LOG_TAG, "%s invalid vendor id source %d; ignoring DID record %d.", __func__, record.vendor_id_source, i);
            continue;
        }

        LOG_DEBUG(LOG_TAG, "Device ID record %d : %s", i, (record.primary_record ? "primary" : "not primary"));
        LOG_DEBUG(LOG_TAG, "  vendorId            = %04x", record.vendor);
        LOG_DEBUG(LOG_TAG, "  vendorIdSource      = %04x", record.vendor_id_source);
        LOG_DEBUG(LOG_TAG, "  product             = %04x", record.product);
        LOG_DEBUG(LOG_TAG, "  version             = %04x", record.version);
        LOG_DEBUG(LOG_TAG, "  clientExecutableURL = %s", record.client_executable_url);
        LOG_DEBUG(LOG_TAG, "  serviceDescription  = %s", record.service_description);
        LOG_DEBUG(LOG_TAG, "  documentationURL    = %s", record.documentation_url);

        uint32_t record_handle;
        tBTA_STATUS status = BTA_DmSetLocalDiRecord(&record, &record_handle);
        if (status != BTA_SUCCESS) {
            LOG_ERROR(LOG_TAG, "%s unable to set device ID record %d: error %d.", __func__, i, status);
        }
    }

    config_free(config);
}
Пример #12
0
void config_get(char *file_path, config *conf)
{
    /***********************************************/
	/** Initialization of configuration variables **/
	/***********************************************/
    
    int i=0, j=0;
    
    conf->server_port=36000;
    strcpy(conf->server_address,"localhost");
    
    
    for (i=0; i<HASH_TYPE_COUNT; i++)
        for (j=0; j<2; j++)
            conf->idp[i][j]=0;
    
	/************************/
	/** Read existing file **/
	/************************/
    
    conf->nb_core = config_get_int(file_path, "NB_CORE");
    config_get_string(file_path, "SERVER_ADDRESS", conf->server_address);
    conf->server_port = config_get_int(file_path, "SERVER_PORT");
    conf->idp[HASH_TYPE_MD5][IDP_TYPE_CPU] = config_get_int(file_path, "IDP_MD5_CPU");
    conf->idp[HASH_TYPE_MD5][IDP_TYPE_GPU] = config_get_int(file_path, "IDP_MD5_GPU");

	/************************/
	/** Confirm parameters **/
	/************************/

	printf("\nCore(s) available : %d\n", get_core_count());
    conf->nb_core = ui_input_int("Number of core to use", conf->nb_core, 1, get_core_count());
    ui_input_string("Server address", conf->server_address, conf->server_address);
    conf->server_port = ui_input_int("Server port", conf->server_port, 1, 65535);

	/*******************************/
	/** Write preferences in file **/
	/*******************************/
    
    remove(file_path);
	
	config_set_int(file_path,"NB_CORE", conf->nb_core);
	config_set_string(file_path, "SERVER_ADDRESS", conf->server_address);

	config_set_int(file_path,"SERVER_PORT", conf->server_port);
    config_set_int(file_path, "IDP_MD5_CPU", conf->idp[HASH_TYPE_MD5][IDP_TYPE_CPU]);
    config_set_int(file_path, "IDP_MD5_GPU", conf->idp[HASH_TYPE_MD5][IDP_TYPE_GPU]);
    
    

}
Пример #13
0
static void statistics_restore_geometry (GtkWidget *window) {
	int height, width;

	config_push_prefix ("/" CONFIG_FILE "/Statistics Window Geometry/");

	height = config_get_int ("height");
	width = config_get_int ("width");
	if (!width || !height)
		return;

	gtk_window_set_default_size (GTK_WINDOW (window), width, height);

	config_pop_prefix ();
}
Пример #14
0
void epos_init(epos_node_p node, can_device_p can_dev, config_p config) {
  if (!can_dev) {
    can_dev = malloc(sizeof(can_device_t));
    can_init(can_dev, 0);
  }

  config_init_default(&node->config, &epos_default_config);
  if (config)
    config_set(&node->config, config);

  epos_device_init(&node->dev, can_dev,
    config_get_int(&node->config, EPOS_PARAMETER_ID),
    config_get_int(&node->config, EPOS_PARAMETER_RESET));
  epos_sensor_init(&node->sensor, &node->dev,
    config_get_int(&node->config, EPOS_PARAMETER_SENSOR_TYPE),
    config_get_int(&node->config, EPOS_PARAMETER_SENSOR_POLARITY),
    config_get_int(&node->config, EPOS_PARAMETER_SENSOR_PULSES),
    config_get_int(&node->config, EPOS_PARAMETER_SENSOR_SUPERVISION));
  epos_motor_init(&node->motor, &node->dev,
    config_get_int(&node->config, EPOS_PARAMETER_MOTOR_TYPE),
    config_get_float(&node->config, EPOS_PARAMETER_MOTOR_CURRENT));
  epos_gear_init(&node->gear, &node->sensor,
    config_get_float(&node->config, EPOS_PARAMETER_GEAR_TRANSMISSION));
  epos_input_init(&node->input, &node->dev);
  epos_control_init(&node->control, &node->dev,
    config_get_int(&node->config, EPOS_PARAMETER_CONTROL_TYPE));
}
Пример #15
0
static int softfilter_get_int(void *userdata, const char *key_str, int *value, int default_value)
{
   struct softfilter_userdata *filt = (struct softfilter_userdata*)userdata;

   char key[2][256];
   snprintf(key[0], sizeof(key[0]), "%s_%s", filt->prefix[0], key_str);
   snprintf(key[1], sizeof(key[1]), "%s_%s", filt->prefix[1], key_str);

   bool got = config_get_int(filt->conf, key[0], value);
   got = got || config_get_int(filt->conf, key[1], value);

   if (!got)
      *value = default_value;
   return got;
}
Пример #16
0
void dispatch_init2(void)
{
	int io, pin;
	unsigned int cmd_port, uart_port;

	if(config_get_int("trigger.status.io", &io, -1, -1) &&
			config_get_int("trigger.status.pin", &pin, -1, -1))
	{
		trigger_alert.io = io;
		trigger_alert.pin = pin;
	}

	if(config_get_int("trigger.assoc.io", &io, -1, -1) &&
			config_get_int("trigger.assoc.pin", &pin, -1, -1))
	{
		assoc_alert.io = io;
		assoc_alert.pin = pin;
	}

	if(!config_get_uint("cmd.port", &cmd_port, -1, -1))
		cmd_port = 24;

	if(!config_get_uint("bridge.port", &uart_port, -1, -1))
		uart_port = 0;

	wifi_set_event_handler_cb(wlan_event_handler);

	command_left_to_read = 0;

	lwip_if_socket_create(&command_socket, &command_socket_receive_buffer, &command_socket_send_buffer, cmd_port,
			true, config_flags_match(flag_udp_term_empty), socket_command_callback_data_received);

	if(uart_port > 0)
	{
		lwip_if_socket_create(&uart_socket, &uart_socket_receive_buffer, &uart_socket_send_buffer, uart_port,
			true, config_flags_match(flag_udp_term_empty), socket_uart_callback_data_received);

		uart_bridge_active = true;
	}

	os_timer_setfn(&slow_timer, slow_timer_callback, (void *)0);
	os_timer_arm(&slow_timer, 100, 1); // slow system timer / 10 Hz / 100 ms

	os_timer_setfn(&fast_timer, fast_timer_callback, (void *)0);
	os_timer_arm(&fast_timer, 10, 1); // fast system timer / 100 Hz / 10 ms

	dispatch_post_command(command_task_init_displays);
}
Пример #17
0
int
GetConfigInt(char *key, int default_value)
{
	THREAD_DATA *td = get_thread_data();

	return config_get_int(key, default_value, td->config->filename);
}
Пример #18
0
static int
context_config_get_int(CONTEXT *me, const char *key, int defval)
{
	(void) me;
	
	return config_get_int(key, defval);
}
Пример #19
0
static int bind_common_onoffplus_get(OptionBinding *b) {
	int v = config_get_int(b->configentry);

	if(v > 1)
		return v;
	return !v;
}
Пример #20
0
int bt_effsize(const building_type * btype, const building * b, int bsize)
{
    int i = bsize, n = 0;
    const construction *cons = btype->construction;

    /* TECH DEBT: simplest thing that works for E3 dwarf/halfling faction rules */
    if (b && config_get_int("rules.dwarf_castles", 0)
        && strcmp(btype->_name, "castle") == 0) {
        unit *u = building_owner(b);
        if (u && u->faction->race == get_race(RC_HALFLING)) {
            i = bsize * 10 / 8;
        }
    }

    if (!cons || !cons->improvement) {
        return 0;
    }

    while (cons && cons->maxsize != -1 && i >= cons->maxsize) {
        i -= cons->maxsize;
        cons = cons->improvement;
        ++n;
    }

    return n;
}
Пример #21
0
static void rotting_herbs(void)
{
    region *r;
    int rule_rot = config_get_int("rules.economy.herbrot", HERBROTCHANCE);
    if (rule_rot == 0) return;

    for (r = regions; r; r = r->next) {
        unit *u;
        for (u = r->units; u; u = u->next) {
            const struct item_type *it_bag = it_find("magicherbbag");
            item **itmp = &u->items;
            int rot_chance = rule_rot;

            if (it_bag && *i_find(itmp, it_bag)) {
                rot_chance = (rot_chance * 2) / 5;
            }
            while (*itmp) {
                item *itm = *itmp;
                int n = itm->number;
                double k = n * rot_chance / 100.0;
                if (fval(itm->type, ITF_HERB)) {
                    double nv = normalvariate(k, k / 4);
                    int inv = (int)nv;
                    int delta = _min(n, inv);
                    if (!i_change(itmp, itm->type, -delta)) {
                        continue;
                    }
                }
                itmp = &itm->next;
            }
        }
    }
}
Пример #22
0
static void video_update_vsync(void) {
	if(global.frameskip || config_get_int(CONFIG_VSYNC) == 0) {
		SDL_GL_SetSwapInterval(0);
	} else {
		switch (config_get_int(CONFIG_VSYNC)) {
			case 2: // adaptive
				if(SDL_GL_SetSwapInterval(-1) < 0) {
			case 1: // on
					if(SDL_GL_SetSwapInterval(1) < 0) {
						log_warn("SDL_GL_SetSwapInterval() failed: %s", SDL_GetError());
					}
				}
			break;
		}
	}
}
Пример #23
0
static uint32_t get_fullscreen_flag(void) {
	if(config_get_int(CONFIG_FULLSCREEN_DESKTOP)) {
		return SDL_WINDOW_FULLSCREEN_DESKTOP;
	} else {
		return SDL_WINDOW_FULLSCREEN;
	}
}
Пример #24
0
int config_link_table(config_var_t *table, void *config_root, ...)
{
	xml_node_t *node, *root = config_root;
	va_list args;

	gconfig_level++;

	va_start(args, config_root);
	root = xml_node_vlookup(root, args, 1);
	va_end(args);

	if (!root) {
		gconfig_level--;
		return(-1);
	}

	while (table->name) {
		node = xml_node_lookup(root, 1, table->name, 0, NULL);
		node->client_data = table;
		if (table->type == CONFIG_INT) config_get_int(table->ptr, root, table->name, 0, NULL);
		else if (table->type == CONFIG_STRING) {
			char *str;
			config_get_str(&str, root, table->name, 0, NULL);
			str_redup(table->ptr, str);
		}
		table++;
	}

	gconfig_level--;
	return(0);
}
Пример #25
0
static void provide(char *conf_name, char *mvm_id_str)
{
    struct CONF *conf;
    unsigned long sz;
    int fd, mvm_id;
    void *mem;
    char x;

    conf = config_parse(conf_name);
    sz = config_get_int(conf, "size");
    sz *= 1024 * 1024;
    assert(sz);
    mvm_id = atoi(mvm_id_str);
    assert(mvm_id);

    mem = valloc(sz);
    assert(mem);

    fd = init_mvm(sz, mem, conf, mvm_id);
    printf("Providing, press [enter] to finish.\n");
    fscanf(stdin, "%c", &x);

    heca_close(fd);
    config_clean(conf);
    free(mem);
}
Пример #26
0
static int report_json(const char *filename, report_context * ctx, const char *charset)
{
    if (config_get_int("jsreport.enabled", 0) != 0) {
        FILE * F = fopen(filename, "w");
        if (F) {
            int x, y, minx = INT_MAX, maxx = INT_MIN, miny = INT_MAX, maxy = INT_MIN;
            seen_region *sr;
            region *r;
            /* traverse all regions */
            for (sr = NULL, r = ctx->first; sr == NULL && r != ctx->last; r = r->next) {
                sr = find_seen(ctx->f->seen, r);
            }
            for (; sr != NULL; sr = sr->next) {
                int tx = sr->r->x;
                int ty = sr->r->y;
                coor_to_tiled(&tx, &ty);
                if (ty < miny) miny = ty;
                else if (ty > maxy) maxy = ty;
                if (tx < minx) minx = tx;
                else if (tx > maxx) maxx = tx;
            }
            if (maxx >= minx && maxy >= miny) {
                int w = maxx - minx + 1, h = maxy - miny + 1;
                fputs("{ \"orientation\":\"hexagonal\",\"staggeraxis\":\"y\",", F);
                fprintf(F, "\"staggerindex\":\"%s\", \"height\":%d, \"width\":%d, \"layers\":[", (miny & 1) ? "odd" : "even", h, w);
                fprintf(F, "{ \"height\":%d, \"width\":%d, ", h, w);
                fputs("\"visible\":true, \"opacity\":1, \"type\":\"tilelayer\", \"name\":\"terrain\", \"x\":0, \"y\":0, \"data\":[", F);
                for (y = miny; y <= maxy; ++y) {
                    for (x = minx; x <= maxx; ++x) {
                        int data = 0;
                        int tx = x, ty = y;
                        coor_from_tiled(&tx, &ty);
                        r = findregion(tx, ty);
                        if (r) {
                            sr = find_seen(ctx->f->seen, r);
                            if (sr) {
                                terrain_t ter = oldterrain(r->terrain);
                                if (ter == NOTERRAIN) {
                                    data = 1 + r->terrain->_name[0];
                                }
                                else {
                                    data = 1 + (int)ter;
                                }
                            }
                        }
                        fprintf(F, "%d", data);
                        if (x != maxx || y != maxy) fputs(", ", F);
                    }
                }
                fputs("]}], \"tilesets\": [{\"firstgid\": 1, \"image\": \"magellan.png\", \"imageheight\": 192, \"imagewidth\": 256,"
                    "\"margin\": 0, \"name\": \"hextiles\", \"properties\": { }, \"spacing\": 0, "
                    "\"tileheight\" : 64, \"tilewidth\" : 64 }], \"tilewidth\": 64, \"tileheight\": 96}", F);
            }
            fclose(F);
            return 0;
        }
        return -1;
    }
    return 0;
}
Пример #27
0
static int produceexp_days(void) {
    static int config, rule;
    if (config_changed(&config)) {
        rule = config_get_int("study.produceexp", EXPERIENCEDAYS);
    }
    return rule;
}
Пример #28
0
int skill_limit(faction * f, skill_t sk)
{
    int m = INT_MAX;
    int al = allied_skilllimit(f, sk);
    if (al > 0) {
        if (sk != SK_ALCHEMY && sk != SK_MAGIC)
            return INT_MAX;
        if (f_get_alliance(f)) {
            int sc, fl, ac = listlen(f->alliance->members);   /* number of factions */

            assert(ac > 0);
            fl = (al + ac - 1) / ac;      /* faction limit, rounded up */
            /* the faction limit may not be achievable because it would break the alliance-limit */
            sc = al - allied_skillcount(f, sk);
            if (sc <= 0)
                return 0;
            return fl;
        }
    }
    if (sk == SK_MAGIC) {
        m = max_magicians(f);
    }
    else if (sk == SK_ALCHEMY) {
        m = config_get_int("rules.maxskills.alchemy", 3);
    }
    return m;
}
Пример #29
0
static int ShipSpeedBonus(const unit * u)
{
    const ship * sh = u->ship;
    static int config;
    static int bonus;

    if (config_changed(&config)) {
        bonus = config_get_int("movement.shipspeed.skillbonus", 0);
    }
    if (bonus > 0) {
        int skl = effskill(u, SK_SAILING, NULL);
        int minsk = (sh->type->cptskill + 1) / 2;
        return (skl - minsk) / bonus;
    }
    else if (sh->type->flags & SFL_SPEEDY) {
        int base = 3;
        int speed = 0;
        int minsk = sh->type->cptskill * base;
        int skl = effskill(u, SK_SAILING, NULL);
        while (skl >= minsk) {
            ++speed;
            minsk *= base;
        }
        return speed;
    }
    return 0;
}
Пример #30
0
static int init(void)
{
	int i;

	DEBUG(1, "input_sdl: init()\n");
	for (i=0; fixed_inputs[i].type; i++)
	{
		inputs[i].type = fixed_inputs[i].type;
		inputs[i].id = fixed_inputs[i].id;
		strncpy(inputs[i].name, fixed_inputs[i].name, sizeof(inputs[i].name));
	}
	inputs[i].type = 0;
	num_inputs = i;
	mouse_mode = MOUSE_POINTER;
	if (config_get_int("joystick"))
	{
		DEBUG(1, "input_sdl: initializing joystick subsystem\n");
		if (SDL_InitSubSystem(SDL_INIT_JOYSTICK))
		{
			ERROR("SDL_InitSubSystem(): %s", SDL_GetError());
			return 1;
		}
		init_joysticks();
	}

	return 0;
}