Exemple #1
0
/*
 * Initialize money info
 */
static void init_money_svals(void)
{
	int *money_svals;
	int i;

	/* Count the money types and make a list */
	num_money_types = tval_sval_count("gold");
	money_type = mem_zalloc(num_money_types * sizeof(struct money));
	money_svals = mem_zalloc(num_money_types * sizeof(struct money));
	tval_sval_list("gold", money_svals, num_money_types);

	/* List the money types */
	for (i = 0; i < num_money_types; i++) {
		struct object_kind *kind = lookup_kind(TV_GOLD, money_svals[i]);
		money_type[i].name = string_make(kind->name);
		money_type[i].type = money_svals[i];
	}

	mem_free(money_svals);
}
Exemple #2
0
static void init_obj_make(void) {
	int i, item, lev;
	int k_max = z_info->k_max;
	struct alloc_entry *table;
	struct ego_item *ego;
	s16b *num;
	s16b *aux;
	int *money_svals;

	/*** Initialize object allocation info ***/

	/* Allocate and wipe */
	obj_alloc = mem_zalloc((z_info->max_obj_depth + 1) * k_max * sizeof(byte));
	obj_alloc_great = mem_zalloc((z_info->max_obj_depth + 1) * k_max * sizeof(byte));
	obj_total = mem_zalloc((z_info->max_obj_depth + 1) * sizeof(u32b));
	obj_total_great = mem_zalloc((z_info->max_obj_depth + 1) * sizeof(u32b));

	/* Init allocation data */
	for (item = 1; item < k_max; item++) {
		const struct object_kind *kind = &k_info[item];

		int min = kind->alloc_min;
		int max = kind->alloc_max;

		/* If an item doesn't have a rarity, move on */
		if (!kind->alloc_prob) continue;

		/* Go through all the dungeon levels */
		for (lev = 0; lev <= z_info->max_obj_depth; lev++) {
			int rarity = kind->alloc_prob;

			/* Save the probability in the standard table */
			if ((lev < min) || (lev > max)) rarity = 0;
			obj_total[lev] += rarity;
			obj_alloc[(lev * k_max) + item] = rarity;

			/* Save the probability in the "great" table if relevant */
			if (!kind_is_good(kind)) rarity = 0;
			obj_total_great[lev] += rarity;
			obj_alloc_great[(lev * k_max) + item] = rarity;
		}
	}

	/*** Initialize ego-item allocation info ***/

	num = mem_zalloc((z_info->max_obj_depth + 1) * sizeof(s16b));
	aux = mem_zalloc((z_info->max_obj_depth + 1) * sizeof(s16b));

	/* Scan the ego items */
	for (i = 1; i < z_info->e_max; i++) {
		/* Get the i'th ego item */
		ego = &e_info[i];

		/* Legal items */
		if (ego->rarity) {
			/* Count the entries */
			alloc_ego_size++;

			/* Group by level */
			num[ego->level]++;
		}
	}

	/* Collect the level indexes */
	for (i = 1; i < z_info->max_obj_depth; i++)
		num[i] += num[i - 1];

	/* Allocate the alloc_ego_table */
	alloc_ego_table = mem_zalloc(alloc_ego_size * sizeof(alloc_entry));

	/* Get the table entry */
	table = alloc_ego_table;

	/* Scan the ego-items */
	for (i = 1; i < z_info->e_max; i++) {
		/* Get the i'th ego item */
		ego = &e_info[i];

		/* Count valid pairs */
		if (ego->rarity) {
			int p, x, y, z;

			/* Extract the base level */
			x = ego->level;

			/* Extract the base probability */
			p = (100 / ego->rarity);

			/* Skip entries preceding our locale */
			y = (x > 0) ? num[x - 1] : 0;

			/* Skip previous entries at this locale */
			z = y + aux[x];

			/* Load the entry */
			table[z].index = i;
			table[z].level = x;
			table[z].prob1 = p;
			table[z].prob2 = p;
			table[z].prob3 = p;

			/* Another entry complete for this locale */
			aux[x]++;
		}
	}
	mem_free(aux);
	mem_free(num);

	/*** Initialize money info ***/

	/* Count the money types and make a list */
	num_money_types = tval_sval_count("gold");
	money_type = mem_zalloc(num_money_types * sizeof(struct money));
	money_svals = mem_zalloc(num_money_types * sizeof(struct money));
	tval_sval_list("gold", money_svals, num_money_types);

	/* List the money types */
	for (i = 0; i < num_money_types; i++) {
		struct object_kind *kind = lookup_kind(TV_GOLD, money_svals[i]);
		money_type[i].name = string_make(kind->name);
		money_type[i].type = money_svals[i];
	}
	mem_free(money_svals);
}