Пример #1
0
int get_spell_book(int Ind, int spell)
{
	player_type *p_ptr = Players[Ind];
	int i, j, index;

	/* Forget info about objects */
	for (i = 0; i < INVEN_TOTAL; i++)
	{
		object_type *o_ptr = &p_ptr->inventory[i];
		
		/* Skip non-objects */
		if (!o_ptr->k_idx) continue;

		/* Skip non-books */
		if (o_ptr->tval != p_ptr->cp_ptr->spell_book) continue;

		/* Test each spell */
		for (j = 0; j < SPELLS_PER_BOOK; j++)
		{
			index = get_spell_index(Ind, o_ptr, j);

			/* Found nice spell */
			if (index == spell) return i;
		}
	}
	return -1;
}
Пример #2
0
/* Gain a random spell from the given book (for priests) */
void do_cmd_study_book(cmd_code code, cmd_arg args[])
{
    int book = args[0].item;
    object_type *o_ptr = object_from_item_idx(book);

    int spell = -1;
    int i, k = 0;

    cptr p = ((cp_ptr->spell_book == TV_MAGIC_BOOK) ? "spell" : "prayer");

    /* Check the player can study at all atm */
    if (!player_can_study())
        return;

    /* Check that the player has access to the nominated spell book. */
    if (!item_is_available(book, obj_can_browse, (USE_INVEN | USE_FLOOR)))
    {
        msg_format("That item is not within your reach.");
        return;
    }

    /* Extract spells */
    for (i = 0; i < SPELLS_PER_BOOK; i++)
    {
        int s = get_spell_index(o_ptr, i);

        /* Skip non-OK spells */
        if (s == -1) continue;
        if (!spell_okay_to_study(s)) continue;

        /* Apply the randomizer */
        if ((++k > 1) && (randint0(k) != 0)) continue;

        /* Track it */
        spell = s;
    }

    if (spell < 0)
    {
        msg_format("You cannot learn any %ss in that book.", p);
    }
    else
    {
        spell_learn(spell);
        p_ptr->energy_use = 100;
    }
}