Exemple #1
0
inline static void stats_print_m(void)
{
	float level_avg = 2*p_ptr->depth + 20;

	result_add("mon-drops", format("%f", mon_drop / TRIES));
	result_add("mon-gold", format("%f", mon_gold * level_avg / TRIES));
}
Exemple #2
0
inline static void stats_print_o(void)
{
	int i;
	u64b x = 0, y = 0;

	for (i = 0; i < TRIES; i++)
		x += o_count[i];

	for (i = 0; i < TRIES; i++)
		y += gold_count[i];

	result_add("floor-objs", format("%f", (float) x / TRIES));
	result_add("floor-gold",  format("%f", (float) y / TRIES));
}
Exemple #3
0
static int list_metafile(const char *repo, struct pkg_t *pkg, struct archive *a,
                         struct result_t *result,
                         struct archive_line_reader *buf) {
  if (config.filterfunc(&config.filter, pkg->name, pkg->namelen,
                        config.icase) != 0) {
    return 0;
  }

  while (reader_getline(buf, a) == ARCHIVE_OK) {
    const size_t len = buf->line.size;
    int prefixlen = 0;
    _cleanup_free_ char *line = NULL;

    if (len == 0 || (config.binaries && !is_binary(buf->line.base, len))) {
      continue;
    }

    if (config.quiet) {
      line = strdup(buf->line.base);
      if (line == NULL) {
        fputs("error: failed to allocate memory\n", stderr);
        return 0;
      }
    } else {
      prefixlen = asprintf(&line, "%s/%s", repo, pkg->name);
      if (prefixlen < 0) {
        fputs("error: failed to allocate memory\n", stderr);
        return 0;
      }
    }
    result_add(result, line, config.quiet ? NULL : buf->line.base, prefixlen);
  }

  /* When we encounter a match with fixed string matching, we know we're done.
   * However, for other filter methods, we can't be sure that our pattern won't
   * produce further matches, so we signal our caller to continue. */
  return config.filterby == FILTER_EXACT ? -1 : 0;
}
Exemple #4
0
static int search_metafile(const char *repo, struct pkg_t *pkg,
                           struct archive *a, struct result_t *result,
                           struct archive_line_reader *buf) {
  while (reader_getline(buf, a) == ARCHIVE_OK) {
    const size_t len = buf->line.size;

    if (len == 0) {
      continue;
    }

    if (!config.directories && is_directory(buf->line.base, len)) {
      continue;
    }

    if (config.binaries && !is_binary(buf->line.base, len)) {
      continue;
    }

    if (config.filterfunc(&config.filter, buf->line.base, (int)len,
                          config.icase) == 0) {
      _cleanup_free_ char *line = NULL;
      int prefixlen = format_search_result(&line, repo, pkg);
      if (prefixlen < 0) {
        fputs("error: failed to allocate memory for result\n", stderr);
        return -1;
      }
      result_add(result, line, config.verbose ? buf->line.base : NULL,
                 config.verbose ? prefixlen : 0);

      if (!config.verbose) {
        return 0;
      }
    }
  }

  return 0;
}
Exemple #5
0
/*
 * This is the entry point for generation statistics.
 */
static void stats_collect_level(void)
{
	static bool first = TRUE;
	size_t i, x, y;

	memset(o_count, 0, sizeof(o_count));
	memset(gold_count, 0, sizeof(gold_count));

	mon_gold = 0.0;
	mon_drop = 0.0;

	results_reset();
	result_add("level", format("%d", p_ptr->depth));


	for (i = 0; i < TRIES; i++)
	{
		generate_cave();

		/* Get stats on objects */
		for (y = 1; y < DUNGEON_HGT - 1; y++)
		{
			for (x = 1; x < DUNGEON_WID - 1; x++)
			{
				const object_type *obj = get_first_object(y, x);

				if (obj) do
				{
					if (obj->tval == TV_GOLD) gold_count[i] += obj->pval;
					else o_count[i]++;
				}
				while ((obj = get_next_object(obj)));
			}
		}

		/* Get stats on monsters */
		for (y = 1; y < DUNGEON_HGT - 1; y++)
		{
			for (x = 1; x < DUNGEON_WID - 1; x++)
			{
				if (cave_m_idx[y][x])
					stats_monster(&mon_list[cave_m_idx[y][x]]);
			}
		}
	}

	stats_print_o();
	stats_print_m();

	if (first)
	{
		/* printf("level,mon-drops"); */
		results_print_csv_titles();
		first = FALSE;
	}

	/* results_print_csv_pair("level", "mon-drops"); */
	results_print_csv();

	do_cmd_redraw();
}