Esempio n. 1
0
void gray_mage_cast_spell(void)
{
    _slot_info_ptr slot_ptr;

    /* Blind is OK!!! */

    if (p_ptr->confused)
    {
        msg_print("You are too confused!");
        return;
    }

    slot_ptr = _choose("Cast", _ALLOW_EXCHANGE | _SHOW_INFO);
    if (slot_ptr)
    {
        magic_type *spell_ptr = _get_spell_info(slot_ptr->realm, slot_ptr->spell);
        int         cost = calculate_cost(spell_ptr->smana);
        int         fail = calculate_fail_rate(spell_ptr->slevel, spell_ptr->sfail, p_ptr->stat_ind[A_INT]);

        if (spell_ptr->slevel > p_ptr->lev) /* Experience Drain? */
        {
            msg_format("You need to be level %d to use that spell.", spell_ptr->slevel);
            return;
        }

        if (cost > p_ptr->csp)
        {
            msg_print("You do not have enough mana to cast this spell.");
            return;
        }

        p_ptr->csp -= cost;
        energy_use = 100;

        if (randint0(100) < fail)
        {
            if (flush_failure) flush();

            cmsg_format(TERM_VIOLET, "You failed to cast %s!", do_spell(slot_ptr->realm, slot_ptr->spell, SPELL_NAME));
            if (demigod_is_(DEMIGOD_ATHENA))
                p_ptr->csp += cost/2;
            spell_stats_on_fail_old(slot_ptr->realm, slot_ptr->spell);
            sound(SOUND_FAIL);
            do_spell(slot_ptr->realm, slot_ptr->spell, SPELL_FAIL);
        }
        else
        {
            if (!do_spell(slot_ptr->realm, slot_ptr->spell, SPELL_CAST))
            {  /* Canceled */
                p_ptr->csp += cost;
                energy_use = 0;
                return;
            }
            sound(SOUND_ZAP);
            spell_stats_on_cast_old(slot_ptr->realm, slot_ptr->spell);
        }
    }
    p_ptr->redraw |= PR_MANA;
    p_ptr->window |= PW_SPELL;
}
Esempio n. 2
0
void _choose(int start, int* pickedOut, int length, int index, int maxcount)
{   
	if(index==maxcount){
            _dump (pickedOut, start, maxcount);

		return;
      }
      if(!length)
		return; NULL;
      pickedOut[index] = store[start];
      pickedOut[index+1] = start+1;
      
	_choose(start+1, pickedOut, length-1, index+2, maxcount);
      _choose(start+1, pickedOut, length-1, index, maxcount);


}
static PyObject* choose(PyObject* self, PyObject* args)
{
  double v,w;
 
  if (!PyArg_ParseTuple(args, "dd", &v, &w))
    return NULL;
 
  return Py_BuildValue("d", _choose(v,w));
}
Esempio n. 4
0
static int _choose_mimic_form(void)
{
    int             r_idx = -1;
    int             i;
    _choice_array_t choices = {{{0}}};

    /* List Known Forms */
    for (i = 0; i < _MAX_FORMS; i++)
    {
        if (_forms[i])
        {
            int        j = choices.size++;
            _choice_t *choice = &choices.choices[j];

            choice->r_idx = _forms[i];
            choice->slot = i;
            choice->type = _TYPE_KNOWN;
            choice->key = I2A(j);
        }
    }

    /* List Visible Forms */
    for (i = 1; i < m_max; i++)
    {
        monster_type *m_ptr = &m_list[i];

        if (!m_ptr->r_idx) continue;
        if (!m_ptr->ml) continue;
        if (!projectable(py, px, m_ptr->fy, m_ptr->fx)) continue;
        if (!r_info[m_ptr->r_idx].body.life) continue; /* Form not implemented yet ... */

        _add_visible_form(&choices, m_ptr->r_idx);
    }

    /* Assign menu keys at the end due to insertion sort */
    for (i = 0; i < choices.size; i++)
    {
        _choice_t *choice = &choices.choices[i];
        
        if (choice->type == _TYPE_VISIBLE)
            choice->key = I2A(i);
    }

    if (choices.size)
    {
        choices.mode = _CHOOSE_MODE_MIMIC;
        if (_choose(&choices))
            r_idx = choices.choices[choices.current].r_idx;
        do_cmd_redraw();
    }
    else
        msg_print("You see nothing to mimic.");
    return r_idx;
}
Esempio n. 5
0
/**********************************************************************
 * Public
 **********************************************************************/
void gray_mage_browse_spell(void)
{
    bool done = FALSE;

    screen_save();
    _browse_choice = 0;
    while (!done)
    {
        _slot_info_ptr slot = _choose("Browse", _ALLOW_EXCHANGE | _SHOW_INFO | _SHOW_STATS);
        if (!slot)
            done = TRUE;
        else
            _browse_choice = slot - _spells;
    }
    _browse_choice = -1;
    screen_load();
}
Esempio n. 6
0
int menu_choose(menu_ptr menu)
{
    int choice = -1;

    if (REPEAT_PULL(&choice))
    {
        if (choice >= 0 && choice < menu->count)
            return choice;
    }

    screen_save();

    choice = _choose(menu);
    REPEAT_PUSH(choice);

    screen_load();

    return choice;
}
Esempio n. 7
0
static int _choose_new_slot(int new_r_idx)
{
    int             slot = -1;
    int             i;
    _choice_array_t choices = {{{0}}};

    /* Display the Newly Learned Form */
    assert(new_r_idx);
    {
        _choice_t *choice = &choices.choices[choices.size++];
        choice->r_idx = new_r_idx;
        choice->slot = -1; /* paranoia ... it should not be possible to choose this choice! */
        choice->type = _TYPE_NEW;
    }

    /* List Existing Slots/Known Forms */
    for (i = 0; i < _MAX_FORMS; i++)
    {
        if (_forms[i])
        {
            int        j = choices.size++;
            _choice_t *choice = &choices.choices[j];
            choice->r_idx = _forms[i];
            choice->slot = i;
            choice->type = _TYPE_KNOWN;
            choice->key = I2A(j-1);
        }
        else
        {
            /* Simply use the first empty slot */
            return i;
        }
    }

    choices.mode = _CHOOSE_MODE_LEARN;
    if (_choose(&choices))
        slot = choices.choices[choices.current].slot;
    do_cmd_redraw();

    return slot;
}
Esempio n. 8
0
int main(int argv, char* argc[])   
{   
      int i;
	int pickedOut[2*S];//pickedOut is used for storing the slected item and its No followed

      printf ("There are items below:\n");
      for (i=0; i<S; i++){
		printf ("%d)%-4d", i+1, store[i]);
	}

	printf ("\nPlease set the volume of the bag:");
	scanf ("%d", &volume);

	for (i=1; i<=S; i++){
      	_choose(0, pickedOut, S, 0, 2*i);
	}

	if (isFound == 0) printf ("No solution is found!\n");//judge whether there is a solution
	else printf ("The End.\n");
	  
	system ("pause");
	return 0;
}
Esempio n. 9
0
	/// Gets configurations matching the specified attribute values
	Configs(const Display& display, const FinishedConfigAttribs& attribs)
	 : _display(display)
	{
		_choose(attribs);
	}
Esempio n. 10
0
void gray_mage_gain_spell(void)
{
    int item;

    if (p_ptr->blind || no_lite())
    {
        msg_print("You cannot see!");
        return;
    }

    if (p_ptr->confused)
    {
        msg_print("You are too confused!");
        return;
    }

    if (!p_ptr->new_spells)
    {
        msg_print("You cannot learn any new spells!");
        return;
    }

    item_tester_hook = _spell_book_p;
    if (get_item(&item, "Study which book?", "You have no books that you can read.", USE_INVEN))
    {
        object_type    *o_ptr = &inventory[item];
        int             spell_idx;
        _slot_info_ptr  slot_ptr;

        /* Pick a spell to learn */
        spell_idx = _choose_spell_to_gain(o_ptr);
        if (spell_idx == -1) return;

        /* Pick a slot for storage (possibly replacing an already learned spell) */
        slot_ptr = _choose("Replace", _ALLOW_EMPTY | _SHOW_INFO);
        if (!slot_ptr) return;

        if (slot_ptr->realm != REALM_NONE)
        {
            string_ptr prompt = string_alloc_format(
                "Really replace %s? <color:y>[y/N]</color>",
                do_spell(slot_ptr->realm, slot_ptr->spell, SPELL_NAME));

            if (msg_prompt(string_buffer(prompt), "ny", PROMPT_DEFAULT) == 'n')
            {
                string_free(prompt);
                return;
            }

            string_free(prompt);
        }

        /* Learn the spell: Note, we don't bother with spell_learned# and spell_order[], since
           these are hard coded for 2 spell realms. Hopefully, ticking up learned_spells is enough? */
        p_ptr->learned_spells++;
        slot_ptr->realm = tval2realm(o_ptr->tval);
        slot_ptr->spell = spell_idx;
        msg_format("You have learned the spell '%s'.", do_spell(slot_ptr->realm, slot_ptr->spell, SPELL_NAME));
        p_ptr->update |= PU_SPELLS;
        p_ptr->redraw |= PR_EFFECTS;
        energy_use = 100;
    }
}