Example #1
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;
    }
}
Example #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;
	struct spell *sp;
	int k = 0;

	const char *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("That item is not within your reach.");
		return;
	}

	/* Extract spells */
	for (sp = o_ptr->kind->spells; sp; sp = sp->next) {
		if (!spell_okay_to_study(sp->spell_index))
			continue;
		if ((++k > 1) && (randint0(k) != 0))
			continue;
		spell = sp->spell_index;
	}

	if (spell < 0)
	{
		msg("You cannot learn any %ss in that book.", p);
	}
	else
	{
		spell_learn(spell);
		p_ptr->energy_use = 100;	
	}
}
Example #3
0
/* Gain a specific spell, specified by spell number (for mages). */
void do_cmd_study_spell(cmd_code code, cmd_arg args[])
{
	int spell = args[0].choice;

	int item_list[INVEN_TOTAL + MAX_FLOOR_STACK];
	int item_num;
	int i;

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

	/* Check that the player can actually learn the nominated spell. */
	item_tester_hook = obj_can_browse;
	item_num = scan_items(item_list, N_ELEMENTS(item_list), (USE_INVEN | USE_FLOOR));

	/* Check through all available books */
	for (i = 0; i < item_num; i++)
	{
		if (spell_in_book(spell, item_list[i]))
		{
			if (spell_okay_to_study(spell))
			{
				/* Spell is in an available book, and player is capable. */
				spell_learn(spell);
				p_ptr->energy_use = 100;
			}
			else
			{
				/* Spell is present, but player incapable. */
				msg("You cannot learn that spell.");
			}

			return;
		}
	}
}