Prompts the user for an ability to use, first checking the lua hook c_choose_ability
| 1637 | // Prompts the user for an ability to use, first checking the lua hook |
| 1638 | // c_choose_ability |
| 1639 | bool activate_ability() |
| 1640 | { |
| 1641 | vector<talent> talents = your_talents(); |
| 1642 | |
| 1643 | if (talents.empty()) |
| 1644 | { |
| 1645 | no_ability_msg(); |
| 1646 | crawl_state.zero_turns_taken(); |
| 1647 | return false; |
| 1648 | } |
| 1649 | |
| 1650 | int selected = -1; |
| 1651 | |
| 1652 | string luachoice; |
| 1653 | |
| 1654 | if (!clua.callfn("c_choose_ability", ">s", &luachoice)) |
| 1655 | { |
| 1656 | if (!clua.error.empty()) |
| 1657 | mprf(MSGCH_ERROR, "Lua error: %s", clua.error.c_str()); |
| 1658 | } |
| 1659 | else if (!luachoice.empty()) |
| 1660 | { |
| 1661 | bool valid = false; |
| 1662 | // Sanity check |
| 1663 | for (unsigned int i = 0; i < talents.size(); ++i) |
| 1664 | { |
| 1665 | if (talents[i].hotkey == luachoice[0]) |
| 1666 | { |
| 1667 | selected = static_cast<int>(i); |
| 1668 | valid = true; |
| 1669 | break; |
| 1670 | } |
| 1671 | } |
| 1672 | |
| 1673 | // Lua gave us garbage, defer to the user |
| 1674 | if (!valid) |
| 1675 | selected = -1; |
| 1676 | } |
| 1677 | |
| 1678 | if (Options.ability_menu && selected == -1) |
| 1679 | { |
| 1680 | selected = choose_ability_menu(talents); |
| 1681 | if (selected == -1) |
| 1682 | { |
| 1683 | canned_msg(MSG_OK); |
| 1684 | crawl_state.zero_turns_taken(); |
| 1685 | return false; |
| 1686 | } |
| 1687 | } |
| 1688 | else |
| 1689 | { |
| 1690 | while (selected < 0) |
| 1691 | { |
| 1692 | msg::streams(MSGCH_PROMPT) << "Use which ability? (? or * to list) " |
| 1693 | << endl; |
| 1694 | |
| 1695 | const int keyin = get_ch(); |
| 1696 |
no test coverage detected