diff options
author | Bardur Arantsson <bardur@scientician.net> | 2015-12-11 08:09:30 +0100 |
---|---|---|
committer | Bardur Arantsson <bardur@scientician.net> | 2015-12-11 08:09:30 +0100 |
commit | 33e7dc3baa6b375efb6d8989ffe3c50511291228 (patch) | |
tree | 16c72b093ab53f33be5386a842450da8cdf117cf /src/cmd7.cc | |
parent | cc50d2db6418690470ead3faf71e0818eff1b8e4 (diff) |
Remove Alchemist class and associated skills/code
Alchemy has always been ridiculously broken and there's been a huge
amount of horrible code to support it. Sorry to any fans of
Alchemy, but it's got to go.
Diffstat (limited to 'src/cmd7.cc')
-rw-r--r-- | src/cmd7.cc | 3081 |
1 files changed, 0 insertions, 3081 deletions
diff --git a/src/cmd7.cc b/src/cmd7.cc index 4338cb52..ef314efc 100644 --- a/src/cmd7.cc +++ b/src/cmd7.cc @@ -8,8 +8,6 @@ #include "cmd7.hpp" -#include "alchemist_recipe.hpp" -#include "artifact_select_flag.hpp" #include "cave.hpp" #include "cave_type.hpp" #include "cmd1.hpp" @@ -1199,3085 +1197,6 @@ void do_cmd_beastmaster(void) /* - * Set of variables and functions to create an artifact - */ - - -/* LOG2 is a constant (compile-time) method of converting a single - * set bit into a number. Works well, but for variable (runtime) - * expressions, use a loop instead.. much smaller code*/ -#define LOG2(x) ( (x) & 0xFFFF? BLOG16(x) : BLOG16((x)>>16) + 16 ) -#define BLOG16(x) ( (x) & 0xFF ? BLOG8(x) : BLOG8 ((x)>>8 ) + 8 ) -#define BLOG8(x) ( (x) & 0xF ? BLOG4(x) : BLOG4 ((x)>>4 ) + 4 ) -#define BLOG4(x) ( (x) & 0x3 ? BLOG2(x) : BLOG2 ((x)>>2 ) + 2 ) -#define BLOG2(x) ( (x) & 0x1 ? 0 : 1 ) - -int flags_select[32*5]; -int activation_select; - -/* - Display a group of flags from a_select flags, and return - the number of flags displayed (even invisible ones) - */ -int show_flags(byte group, int pval) -{ - int i, x, color = TERM_WHITE; - int items = 0; - - char ttt[80]; - - Term_clear(); - - group++; /* Adjust - no zero group */ - - for ( i = 0 ; a_select_flags[i].group ; i++) - { - if (a_select_flags[i].group != group) - continue; - - if (a_select_flags[i].xp == 0) - break; - else - { - sprintf(ttt, "%c) %s", - (items < 26) ? I2A(items) : ('0' + items - 26), - a_select_flags[i].desc); - if ( wizard ) - { - sprintf(ttt, "%c) %s (exp " FMTu32b ")", - (items < 26) ? I2A(items) : ('0' + items - 26), - a_select_flags[i].desc, - a_select_flags[i].xp); - } - - /* Note: Somebody is VERY clever, and it wasn't me. Text printed as - * TERM_DARK is actually printed as TERM_BLUE *SPACES* to prevent the - * player from using a 'cut-and-paste' enabled terminal to see - * what he shouldn't. Thus, simply setting the color to TERM_DARK - * will entirely prevent the unspoiled player from knowing that it's - * even possible. */ - - switch (flags_select[i]) - { - case 1: - color = TERM_YELLOW; - break; /* Flag was set by the player (just now)*/ - case 0: - color = TERM_WHITE; - break; /* This flag can be set, player is 'aware' of it*/ - case - 1: - color = TERM_L_GREEN; - break; /* Flag is already set*/ - case - 2: - color = TERM_DARK; - break; /* Invisible option */ - case - 3: - color = TERM_RED; - break; /* Flag is set, but player isn't 'aware' of it */ - case - 4: - color = TERM_L_DARK; - break; /* Flag is not set, player is 'aware', but it's beyond thier skill */ - default: - color = TERM_DARK; - break; /* Just in Case*/ - } - } - - if (wizard && color == TERM_DARK) - { - color = TERM_BLUE; - } - - if (items < 16) x = 5; - else x = 45; - c_prt(color, ttt, ((items < 16) ? items : items - 16) + 5, x); - items++; - - } - return items; -} - -void show_levels(void) -{ - Term_clear(); - c_prt(TERM_WHITE, "[a] Stats, sustains, luck, speed, vision, etc. ", 3, 10); - c_prt(TERM_WHITE, "[b] Misc. (Auras, light, see invis, etc) ", 4, 10); - c_prt(TERM_WHITE, "[c] Weapon Branding ", 5, 10); - c_prt(TERM_WHITE, "[d] Resistances and Immunities ", 6, 10); - c_prt(TERM_WHITE, "[e] ESP and Curses ", 7, 10); - c_prt(TERM_WHITE, "[f] Activation ", 8, 10); - c_prt(TERM_DARK , "[g] Abilities Gained ", 9, 10); - c_prt(TERM_WHITE, "[h] Display Required Essences and items ", 10, 10); - c_prt(TERM_WHITE, "[i] Done! Finalize and commit changes. ", 11, 10); - /*No need to return anything - if the valid selections change, it'll be a code level change.*/ -} - -s32b get_flags_exp(int pval, int oldpval) -{ - int i; - s32b exp = 0; - - for (i = 0 ; a_select_flags[i].group ; i++ ) - { - if (a_select_flags[i].xp == 0) - break; - else - { - if ( a_select_flags[i].group <= 5 && flags_select[i] ) - { - s32b xp = a_select_flags[i].xp; - int factor = 1, oldfactor = 0; - - /* don't even look at flags which the user can't set - * because they also can't change the pval when a pval- - * dependant flag is set, flags which they can't set - * cannot effect the exp in any way, whether their set or not - */ - if ( flags_select[i] < -1 ) - continue; - if ( flags_select[i] == -1 ) - oldfactor = 1; - - if (a_select_flags[i].pval) - { - /* (1/4)x^2 + x - * I wanted something smaller than x^2 or x^x - * this is because although a ring of speed +10 is - * more than 10 times better than a ring of speed +1, - * I don't think it's 100 times better. More like 30. - * this function yields: - * 1=1 * 2=3 * 3=5 * 4=8 * 5=11 * 6=15 * 7=21 - * 8=24 * 9=29 * 10=35 * 11=41 * 12=48 * 13=55 - * 14=63 * 15=71 * 20=120 * 25=181 * 30=255 - * which I think is acceptable. - * briefly, to get a +30 speed ring, it would be: - * 255*50000 or over 12 million experience - * points. For reference, a level 50 human requires - * 5 million xp. I'm sure it's doable, but it'd be - * *HARD* - * a speed+10 artifact would require 1.75 million. - * much more doable, but not too easily. - */ - factor = (pval * pval / 4 + pval); - if ( flags_select[i] == -1 ) - { - oldfactor = oldpval * oldpval / 4 + oldpval; - } - } - exp += xp * factor - xp * oldfactor; - } - if ( a_select_flags[i].group == 88 && a_select_flags[i].flag == -activation_select ) - { - exp += a_select_flags[i].xp; - } - } - } - - return exp; -} - -/* returns the 'real quantity' of items needed to empower - * a particular flag to a particular pval. - * Note that this routine returns zero for any flag that - * doesn't require some sort of action. - */ -int calc_rqty(int i, int pval, int oldpval) -{ - /* return 0 if flag is greater than size of flags_select && ! activation */ - if ( a_select_flags[i].group > 5 ) - { - if ( activation_select == a_select_flags[i].flag) - return 1; - else - return 0; - } - - /* return 0 if the flag wasn't set */ - if ( flags_select[i] < -1 || flags_select[i] == 0 ) - return 0; - - /* Return change in pval if the flag was already set */ - if ( flags_select[i] == -1 && a_select_flags[i].pval) - return pval - oldpval; - - /* Return pval if the flag will be set this time */ - else if ( a_select_flags[i].pval ) - return pval; - - /* Return 0 if the flag is unknown */ - else if ( flags_select[i] == -1 ) - return 0; - return 1; -} - -/* Handle the various items that creating artifacts requires. - * Mode = 0 to print a description, - * 1 to use up the items - * -1 to check to see if the items exist - * Note that this function is called ONLY from the - * other artifact item helper function. - */ - - -static int check_artifact_items(int pval, int oldpval, int mode) -{ - int i, j, k, row = 1 , col = 15, rqty, orqty, trqty; - bool_ good = TRUE; - int temporary = -1; - char ch; - - /* For temporary items, waive the item requirements, - * except for the corpse... */ - for ( j = 0 ; a_select_flags[j].group ; j++) - if (a_select_flags[j].flag == 4*32 && flags_select[j] == 1 ) - temporary = j; - /* Check for enough items */ - for (i = 0; a_select_flags[i].group ; i++) - { - /* For temporary items, ignore - everything except the one item - */ - if (temporary != -1 && i != temporary) - continue; - - /* Calc quantity is done per flag, because - some have a pval, some don't, some where already - set at pval=2, etc - */ - rqty = orqty = calc_rqty(i, pval, oldpval); - - /* If no item is associated with this flag, - or this flag wasn't set or didn't change */ - if ( !a_select_flags[i].rtval || !rqty) - continue; - - for ( k = 0 ; k < INVEN_WIELD ; k++ ) - { - object_type *o_ptr = &p_ptr->inventory[k]; - - /* Note here that an rsval of -1 (which is read is 0xff - for a byte..) matches anything. */ - if (o_ptr->tval == a_select_flags[i].rtval - && (o_ptr->sval == a_select_flags[i].rsval - || a_select_flags[i].rsval == (byte) - 1 ) ) - { - /* Corpse validation is COMPLICATED! - * But at least we don't have to do this twice. - */ - if ( a_select_flags[i].rtval == TV_CORPSE ) - { - bool_ itemgood = TRUE; - - /*Specified race not this one */ - if ( o_ptr->pval2 != a_select_flags[i].rpval && a_select_flags[i].rpval) - continue; - - /* Race flag (any monster who...)*/ - for ( j = 0 ; !a_select_flags[i].rpval && a_select_flags[i].rflag[j] && j < 6 && itemgood ; j++) - { - int flag = a_select_flags[i].rflag[j] / 32; - u32b mask = 1 << (a_select_flags[i].rflag[j] % 32); - - switch (flag) - { - case 0: - if ( !(r_info[o_ptr->pval2].flags1 & mask) ) itemgood = FALSE; - break; - case 1: - if ( !(r_info[o_ptr->pval2].flags2 & mask) ) itemgood = FALSE; - break; - case 2: - if ( !(r_info[o_ptr->pval2].flags3 & mask) ) itemgood = FALSE; - break; - case 3: - if ( !(r_info[o_ptr->pval2].flags4 & mask) ) itemgood = FALSE; - break; - case 4: - if ( !(r_info[o_ptr->pval2].flags5 & mask) ) itemgood = FALSE; - break; - case 5: - if ( !(r_info[o_ptr->pval2].flags6 & mask) ) itemgood = FALSE; - break; - case 6: - if ( !(r_info[o_ptr->pval2].flags7 & mask) ) itemgood = FALSE; - break; - case 7: - if ( !(r_info[o_ptr->pval2].flags8 & mask) ) itemgood = FALSE; - break; - case 8: - if ( !(r_info[o_ptr->pval2].flags9 & mask) ) itemgood = FALSE; - break; - default: - msg_print("This code should never be hit!"); - } - } - if ( ! itemgood ) - continue; - - } - /* Validate pval of good item */ - else if ( a_select_flags[i].rpval) - { - /* Must have matching signs */ - if ( (o_ptr->pval < 0) != (a_select_flags[i].rpval < 0)) - continue; - /* Must be greater than */ - if ( abs(o_ptr->pval) < abs(a_select_flags[i].rpval)) - continue; - } - - trqty = MIN(o_ptr->number, rqty); - rqty -= trqty; - - if ( mode == 1 ) - { - inc_stack_size_ex(k, -trqty, NO_OPTIMIZE, DESCRIBE); - } - }/* if p_ptr->inventory item is acceptable */ - - } /*end of looping through the p_ptr->inventory*/ - - if (rqty) - { - good = FALSE; - /* Oops, we didn't have enough of this object - when actually creating the artifact. - unset this flag - */ - if ( mode == 1 ) - { - flags_select[i] = -4; - } - /* we only return false for mode -1, - * for mode 0 we display stuff, and for - * mode 1 we want to continue destroying things - * even if the player is missing one small item, - * because there's no way to change things now. - * We may have already destroyed a unique corpse, - * or some other hard-to-find item. - */ - if ( mode == -1 ) - return FALSE; - } - - /* Display a description of the required object, if needed */ - /* Note that the tests for good items HAVE to be in a different - place, because otherwise we don't know how many the player - has, as opposed to how many they need. - */ - if ( mode == 0 ) - { - char *o_name = a_select_flags[i].item_desc; - if (orqty > 1 && a_select_flags[i].pval && a_select_flags[i].item_descp) - o_name = a_select_flags[i].item_descp; - - if ( rqty ) - { - if ( orqty > 1 ) - c_prt(TERM_RED, format(" you are missing %d of the %d %s", rqty, orqty, o_name), row++, col); - else if ( is_a_vowel(o_name[0])) - c_prt(TERM_RED, format(" you are missing an %s", o_name), row++, col); - else - c_prt(TERM_RED, format(" you are missing a %s", o_name), row++, col); - } - else - { - if ( orqty > 1 ) - c_prt(TERM_GREEN, format(" you have the %d %s", orqty, o_name), row++, col); - else if ( is_a_vowel(o_name[0])) - c_prt(TERM_GREEN, format(" you have an %s", o_name), row++, col); - else - c_prt(TERM_GREEN, format(" you have a %s", o_name), row++, col); - } - - if ( row > 21 ) - { - row = 1; - if (!good) - (void)get_com("You are missing some items:", &ch); - else - (void)get_com("You have these needed items on hand:", &ch); - } - - } - - } /* End of group associated with this a_select_flags entry */ - - if ( mode == 0 ) - { - while ( row < 22 ) - c_prt(TERM_GREEN, " ", row++, col); - if (!good) - (void)get_com("You are missing some items:", &ch); - else - (void)get_com("You have these needed items on hand:", &ch); - } - return good; -} - -/* Display a list of required essences, - * and/or use up the essences. */ -bool_ artifact_display_or_use(int pval, int oldpval, bool_ use) -{ - int essence[MAX_BATERIE_SVAL]; - int essenceh[MAX_BATERIE_SVAL]; - int al_idx, i, j, k; - bool_ enough; - - /* Temporary Items require only one item, and no essences. */ - for ( i = 0 ; a_select_flags[i].group ; i++) - if ( a_select_flags[i].flag == 32*4) - { - if ( use ) - return check_artifact_items(pval, oldpval, 1); - else - return check_artifact_items(pval, oldpval, 0); - } - - for ( i = 0 ; i < MAX_BATERIE_SVAL ; i++ ) - essence[i] = essenceh[i] = 0; - - /* Accumulate a list of required essences */ - for ( al_idx = 0; al_idx < max_al_idx ; al_idx++ ) - if ( alchemist_recipes[al_idx].tval == 0 ) - for ( i = 0 ; a_select_flags[i].group ; i++) - { - int rqty = calc_rqty(i, pval, oldpval); - - /* If the flag isn't being set, rqty will be zero */ - if ( !rqty) - continue; - - if ( alchemist_recipes[al_idx].sval == a_select_flags[i].flag ) - essence[alchemist_recipes[al_idx].sval_essence] += - alchemist_recipes[al_idx].qty * rqty; - } - - /* The essence array now contains a list of all essences - * that will be consumed in the creation of this artifact */ - - /* Check for existence of required quatities of essences. */ - for ( i = 0 ; i < INVEN_WIELD ; i++ ) - { - for ( j = 0 ; j < MAX_BATERIE_SVAL ; j++) - if ( p_ptr->inventory[i].tval == TV_BATERIE && p_ptr->inventory[i].sval == j + 1) - { - essenceh[j] += p_ptr->inventory[i].number; - } - } - - /* Check for enough essences */ - enough = TRUE; - for ( i = 0 ; i < MAX_BATERIE_SVAL ; i++) - if ( essenceh[i] < essence[i] ) - { - enough = FALSE; - break; - } - - /* Check for items */ - if ( enough ) - enough = check_artifact_items(pval, oldpval, -1); - - - /* Display recipe list if they don't have enough, or not enough exp */ - if (!enough || !use ) - { - int row = 1 , col = 15; - bool_ good = FALSE; - char ch; - - /* display of list of required essences */ - /* Note: there are only 12 or so essences, so this list - * will ALWAYS fit on the screen */ - for ( i = 0 ; i < MAX_BATERIE_SVAL ; i++) - if ( essence[i] ) - { - int missing = -MIN(essenceh[i] - essence[i], 0); - good = TRUE; - if ( missing ) - c_prt(TERM_RED, format("%d of the required %d essences of %s", - missing, essence[i], - k_info[lookup_kind(TV_BATERIE, i + 1)].name ), - row++, col); - else - c_prt(TERM_GREEN, format("you have the needed %d essences of %s", - essence[i], - k_info[lookup_kind(TV_BATERIE, i + 1)].name ), - row++, col); - } - - if (good) - { - /* blank the bottom row */ - c_prt(TERM_WHITE, " ", row++, col); - - /* and wait for a key */ - (void)get_com("You are currently missing:", &ch); - } - - /* Display a list of needed items as well */ - check_artifact_items(pval, oldpval, 0); - - return FALSE; - } - - /* If we get to this point in the code, then the player - * has the required essences and items in their p_ptr->inventory */ - - /* If they do have enough, and they have enough exp, consume them */ - for (i = 0 ; i < MAX_BATERIE_SVAL ; i++) - for ( k = 0 ; k < INVEN_WIELD && essence[i] > 0 ; k++) - if (p_ptr->inventory[k].tval == TV_BATERIE - && p_ptr->inventory[k].sval == i + 1 - && essence[i]) - { - int num = p_ptr->inventory[k].number; - - inc_stack_size_ex(k, MAX( -essence[i], -num), NO_OPTIMIZE, DESCRIBE); - - essence[i] -= MIN(num, essence[i]); - } - - /* Destroy the items needed */ - check_artifact_items(pval, oldpval, 1); - - return TRUE; -} - - -void display_activation_info(int num) -{ - object_type forge; - int i; - - - /* find the a_select_flags number of this activation type... */ - for ( i = 0 ; a_select_flags[i].group ; i++) - if (a_select_flags[i].group == 88 && a_select_flags[i].flag == -num ) - break; - - object_wipe(&forge); - forge.xtra2 = num; - /* Print out various information about this activation... */ - /* min level, experience, required items (and essences) - full description (from activation_aux) */ - if (wizard) - c_prt(TERM_WHITE, format(" number:%d ", num), 5, 5); - else - c_prt(TERM_WHITE, " ", 5, 5); - c_prt(TERM_WHITE, format(" Level:%d ", a_select_flags[i].level), 6, 5); - c_prt(TERM_WHITE, format(" Exp :%d ", a_select_flags[i].xp), 7, 5); - c_prt(TERM_WHITE, format(" Item :%s ", a_select_flags[i].item_desc), 8, 5); - c_prt(TERM_WHITE, " ", 9, 5); - c_prt(TERM_WHITE, format(" %s ", activation_aux(&forge, 0, 0)), 9, 5); - c_prt(TERM_WHITE, " ", 10, 5); - inkey(); -} - -void select_an_activation(void) -{ - int i, lev, wid, hgt, begin = 0, sel = 0; - u32b max; - cptr act_list[150]; /* currently, ~127 hardcoded activations */ - int act_ref[150]; - char c; - /* How do we want to do this? */ - /* Ideally, we let them select from a list, which includes all the activations that they've ecountered in any form. - Problems with this idea include mainly the lack of any (current) place to store which activations they've seen, and - that they'll not get credit for any seen before we start tracking it. - - So - list is everything. If they select one which they're to low-level for - or if the explicitly request it, we'll display info about this item. - We'll also get our descriptions from the activation_aux(ACT_CONSTANT) - function, because they are more complete, and include even lua-scripted ones. - msg_print("Since the code to actually let you select one isn't here"); - msg_print("You will automatically get the activation 'Dawn'"); - activation_select = ACT_DAWN; - */ - - /* Build a list of available activations at the player's level */ - lev = get_skill(SKILL_ALCHEMY); - for ( i = max = 0 ; max < (sizeof(act_list) / sizeof(cptr)) && a_select_flags[i].group ; i++) - if (a_select_flags[i].group == 88 && a_select_flags[i].level <= lev ) - { - act_ref[max] = -a_select_flags[i].flag; /* Activation number */ - act_list[max++] = a_select_flags[i].desc; /* Description */ - } - - /* Select from that list, using the util.c function display_list to display the scrolled list */ - /* Note: I think that there is only one other place that uses this function. Should be more! */ - while (1) - { - Term_clear(); - Term_get_size(&wid, &hgt); - - c_prt(TERM_WHITE, "Enter to select, ? for more information, 2 and 8 to scroll ", 0, 0); - display_list(1, 0, hgt - 2, wid - 2, "Select an Activation", act_list, max, begin, sel, TERM_L_GREEN); - - c = inkey(); - - if (c == ESCAPE) break; - else if (c == '8') - { - sel--; - if (sel < 0) - { - sel = max - 1; - begin = max - hgt; - if (begin < 0) begin = 0; - } - if (sel < begin) begin = sel; - } - else if (c == '2') - { - sel++; - if (sel >= (s32b)max) - { - sel = 0; - begin = 0; - } - if (sel >= begin + hgt - 1) begin++; - } - else if (c == '?') - { - display_activation_info(act_ref[sel]); - } - else if (c == '\r') - { - display_activation_info(act_ref[sel]); - activation_select = act_ref[sel]; - return; - } - } - activation_select = 0; -} - - -/* Consume 'num' magic essences and return true. - * If there aren't enough essences, return false */ - -bool_ magic_essence(int num) -{ - int i; - int j = 0; - - for (i = 0; i < INVEN_WIELD; i++) - { - object_type *o_ptr = &p_ptr->inventory[i]; - - /* Count the magic essences */ - if (o_ptr->k_idx && (o_ptr->tval == TV_BATERIE) && (o_ptr->sval == SV_BATERIE_MAGIC)) j += o_ptr->number; - } - - /* Abort if not enough essences. */ - if (j < num) return FALSE; - - /* Consume them */ - i = 0; - j = num; - while (i < INVEN_WIELD) - { - object_type *o_ptr = &p_ptr->inventory[i]; - - if (o_ptr->k_idx && (o_ptr->tval == TV_BATERIE) && (o_ptr->sval == SV_BATERIE_MAGIC)) - { - /* This can lead to invalid object pointer for objects - * that come after the magic essences. Therefore, every - * artifactable object should come before the essences. - */ - j -= o_ptr->number; - inc_stack_size(i, -num); - num = j; - if (num <= 0) break; - /* Stay on this slot; do not increment i. */ - } - else - { - /* Move on to the next slot. */ - i++; - } - } - - /* Sanity check. */ - if (num > 0) - { - msg_format("ERROR: Couldn't destroy %d essences!", num); - return FALSE; - } - - return TRUE; -} - - -void do_cmd_create_artifact(object_type *q_ptr) -{ - int max, i = 0, j, cur_set = 0, abord = FALSE, done = FALSE; - int skill; - s32b exp = 0; - - char out_val[160]; - char choice = 0; - bool_ lockpval = FALSE; - int pval; - int oldpval; - energy_use = 100; - - pval = q_ptr->pval; - oldpval = pval; - skill = get_skill(SKILL_ALCHEMY); - - if ( !pval ) - pval = 1; - /* No activation added on this round */ - activation_select = 0; - - /* Save the current flags */ - for (i = 0 ; a_select_flags[i].group ; i++) - { - if ( a_select_flags[i].flag < 0 || a_select_flags[i].group > 5) - continue; - - flags_select[i] = 0; - - switch (a_select_flags[i].flag / 32) - { - case 0: - if (q_ptr->art_flags1 & 1 << (a_select_flags[i].flag % 32)) flags_select[i] = -1; - break; - case 1: - if (q_ptr->art_flags2 & 1 << (a_select_flags[i].flag % 32)) flags_select[i] = -1; - break; - case 2: - if (q_ptr->art_flags3 & 1 << (a_select_flags[i].flag % 32)) flags_select[i] = -1; - break; - case 3: - if (q_ptr->art_flags4 & 1 << (a_select_flags[i].flag % 32)) flags_select[i] = -1; - break; - case 4: - if (q_ptr->art_flags5 & 1 << (a_select_flags[i].flag % 32)) flags_select[i] = -1; - break; - case 5: - if (q_ptr->art_esp & 1 << (a_select_flags[i].flag % 32)) flags_select[i] = -1; - break; - default: - /*This will not be hit, inspite of activations, because of the <= 5 above...*/ - break; - } - /* - this would learn about ALL flags.... - if(wizard) - alchemist_known_artifacts[a_select_flags[i].flag/32] = 0xffffffffL; - */ - - /* Set various flags if they haven't *ID*'d an artifact with this flag set.*/ - if ( !(alchemist_known_artifacts[a_select_flags[i].flag / 32] & (1 << (a_select_flags[i].flag % 32)) )) - { - /* If this item has an ability that depends on pval which the player - * cannot set, don't allow them to change the pval either. */ - if ( a_select_flags[i].pval && flags_select[i]) - lockpval = TRUE; - - /* Set the color and set-ablitity of this flag */ - if ( flags_select[i] ) - flags_select[i] = -3; - else - flags_select[i] = -2; - continue; - } - else if ( skill < a_select_flags[i].level ) - { - /* If the alchemist has not passed the skill level for this flag, - Set this flag as unsettable. - */ - if ( flags_select[i]) - lockpval = TRUE; - else - flags_select[i] = -4; - } - } - - /* Save the screen */ - character_icky = TRUE; - Term_save(); - Term_clear(); - - - /* Everlasting love ... ... nevermind :) */ - while ( !done && !abord) - { - c_prt((q_ptr->exp - exp > 0) ? TERM_L_GREEN : TERM_L_RED, format("Experience left: %ld", q_ptr->exp - exp), 2, 0); - - /* Display the menu, but don't display it if we just - * displayed a message (it erases the screen, creating a blink message */ - if ( cur_set < 6 || cur_set == 7 ) - show_levels(); - - c_prt((q_ptr->exp - exp > 0) ? TERM_L_GREEN : TERM_L_RED, format("Experience left: %ld", q_ptr->exp - exp), 2, 0); - - prt("Enter to accept, Escape to abort", 1, 0); - - abord = !get_com("Play around with which group of powers?[a-g]", &choice); - - if ( choice == ESCAPE) - abord = TRUE; - - if ( abord ) - continue; /*or break, same diff */ - - if ( isalpha(choice)) - { - if (isupper(choice)) - choice = tolower(choice); - cur_set = A2I(choice); - } - else - { - bell(); - continue; - } - - if ( cur_set == 5 ) - { - if (q_ptr->xtra2 && !activation_select - && !get_check("This item already activates! Choose a different activation?")) continue; - select_an_activation(); - exp = get_flags_exp(pval, oldpval); - continue; - } - if ( cur_set == 6 ) - { - msg_print("This option is not available"); - continue; - } - if ( cur_set == 7 ) - { - artifact_display_or_use(pval, oldpval, FALSE); - continue; - } - if ( cur_set == 8 ) - { - if (q_ptr->exp - exp < 0) - msg_print("Not enough experience for the flags you've selected."); - else - done = TRUE; - continue; - } - - if (cur_set < 0 || cur_set > 4 ) - { - bell(); - continue; - } - - - while (!done && !abord) - { - /* Chose the flags */ - exp = 0; - max = show_flags(cur_set, pval); - exp = get_flags_exp(pval, oldpval); - c_prt((q_ptr->exp - exp > 0) ? TERM_L_GREEN : TERM_L_RED, format("Experience left: %ld", q_ptr->exp - exp), 2, 0); - - /* Build a prompt (accept all flags) */ - if (max <= 26) - { - /* Build a prompt (accept all flags) */ - strnfmt(out_val, 78, "(Flags %c-%c, I,D to change power level) Add/Remove which flag? ", - I2A(0), I2A(max - 1)); - } - else - { - strnfmt(out_val, 78, "(Flags %c-%c, I,D to change power level) Add/Remove which flag? ", - I2A(0), '0' + max - 27); - } - c_prt(TERM_L_BLUE, format("Power(I/D to increase/decrease): %d", pval), 3, 0); - - /* Get a spell from the user */ - while (!(done = !get_com(out_val, &choice))) - { - if (choice == 'I') - { - if ( lockpval ) - { - msg_print("You cannot do that - you don't know how!"); - continue; - } - if (q_ptr->exp - exp < 0) - { - msg_print("Not enough experience. Decrease power or deselect flags."); - continue; - } - pval++; - break; - } - else if (choice == 'D') - { - if ( lockpval ) - { - msg_print("You cannot do that - you don't know how!"); - continue; - } - pval--; - if (pval < oldpval) pval = oldpval; - break; - } - else if (choice == '\r' || choice == ESCAPE || choice == ' ') - { - done = TRUE; - break; - } - else if (isalpha(choice)) - { - /* Lowercase */ - if (isupper(choice)) choice = tolower(choice); - - /* Extract request */ - i = (islower(choice) ? A2I(choice) : -1); - } - else - { - i = D2I(choice) + 26; - - /* Illegal */ - if (i < 26) i = -1; - } - - /* Totally Illegal */ - if ((i < 0) || (i >= max)) - { - bell(); - continue; - } - else - { - /*Find the i'th flag in group cur_set...*/ - for ( j = 0 ; a_select_flags[j].group ; j++) - if (a_select_flags[j].group == cur_set + 1) - if (!i--) break; - - if ( flags_select[j] == -4 ) - { - msg_format("You need at least %d skill in alchemy.", - a_select_flags[j].level); - continue; - } - if ( flags_select[j] != 0 && flags_select[j] != 1) - { - bell(); - continue; - } - if (flags_select[j]) flags_select[j] = 0; - else if (!flags_select[j]) - { - if (q_ptr->exp - exp < 0) - { - msg_print("Not enough experience. Decrease power or deselect flags."); - continue; - } - flags_select[j] = 1; - } - break; - } - } - }/*sub-screen select and redraw loop*/ - done = FALSE; - Term_clear(); - }/* main screen (flag select screen) select and redraw loop*/ - - /* Abort if not enough experience, or no flags added */ - if ( q_ptr->exp - exp < 0 || exp == 0 ) - abord = TRUE; - - /* Display the recipe, or use up the essences. - * Note that this has to be done before the screen - * is restored. This is because it's also called from - * within the loop to display the required items. */ - if ( !abord ) - if (!artifact_display_or_use(pval, oldpval, TRUE)) - abord = TRUE; - - /* Restore the screen */ - Term_load(); - character_icky = FALSE; - - /* Return if abort, or missing ingredients */ - if ( abord ) - return; - - /* Actually create the artifact */ - q_ptr->exp -= exp; - q_ptr->art_flags4 &= ~TR4_ART_EXP; - q_ptr->pval = pval; - - /* Just to be sure */ - q_ptr->art_flags3 |= ( TR3_IGNORE_ACID | TR3_IGNORE_ELEC | - TR3_IGNORE_FIRE | TR3_IGNORE_COLD ); - - { - int now = 0, before = 0; - char dummy_name[80]; - char new_name[80]; - - /* Apply the flags */ - for (i = 0; a_select_flags[i].group ; i++) - { - if (flags_select[i] < 0) - before++; - else if ( flags_select[i] == 1) - { - now++; - switch (a_select_flags[i].flag / 32) - { - case 0: - q_ptr->art_flags1 |= 1 << (a_select_flags[i].flag % 32); - break; - case 1: - q_ptr->art_flags2 |= 1 << (a_select_flags[i].flag % 32); - break; - case 2: - q_ptr->art_flags3 |= 1 << (a_select_flags[i].flag % 32); - break; - case 3: - q_ptr->art_flags4 |= 1 << (a_select_flags[i].flag % 32); - break; - case 4: - q_ptr->art_flags5 |= 1 << (a_select_flags[i].flag % 32); - break; - case 5: - q_ptr->art_esp |= 1 << (a_select_flags[i].flag % 32); - break; - default: - msg_print("error: this code can't ever be hit!"); - } - } - } - - if ( activation_select ) - { - q_ptr->art_flags3 |= TR3_ACTIVATE; - q_ptr->xtra2 = activation_select; - } - - - /* Set the 'show modifier' flag */ - q_ptr->art_flags3 |= TR3_SHOW_MODS; - - /* For temporary items, set a timeout. - * alchemist_skill^2 for now */ - if ( q_ptr->art_flags5 & TR5_TEMPORARY ) - { - int lev = get_skill(SKILL_ALCHEMY); - q_ptr->timeout = lev * lev * 3; - } - - /* Describe the new artifact */ - object_out_desc(q_ptr, NULL, FALSE, TRUE); - - - /* Name the new artifact */ - strcpy(dummy_name, "of an Alchemist"); - if (!(get_string("What do you want to call the artifact? ", dummy_name, 80))) - strcpy(new_name, "of an Alchemist"); - else - { - if ((strncmp(dummy_name, "of ", 3) == 0) || - (strncmp(dummy_name, "Of ", 3) == 0) || - ((dummy_name[0] == '\'') && - (dummy_name[strlen(dummy_name) - 1] == '\''))) - { - strcpy(new_name, dummy_name); - } - else - { - strcpy(new_name, "called '"); - strcat(new_name, dummy_name); - strcat(new_name, "'"); - } - } - /* Identify it fully */ - object_aware(q_ptr); - object_known(q_ptr); - - /* Mark the item as fully known */ - q_ptr->ident |= (IDENT_MENTAL); - q_ptr->ident |= IDENT_STOREB; /* This will be used later on... */ - - /* Save the inscription */ - q_ptr->art_name = quark_add(new_name); - q_ptr->found = OBJ_FOUND_SELFMADE; - - done = FALSE; - while (!done && get_com("Do you want to let this item continue to gain experience?", &choice)) - { - switch (choice) - { - case 'y': - case 'Y': - if (magic_essence(get_skill(SKILL_ALCHEMY))) - q_ptr->art_flags4 |= TR4_ART_EXP; - else - msg_format("Oh, NO! You don't have enough magic essences. You needed %d.", get_skill(SKILL_ALCHEMY)); - done = TRUE; - break; - case 'n': - case 'N': - q_ptr->exp = 0; - done = TRUE; - break; - } - } - - /* Cycle through the p_ptr->inventory, and optimize everything. - * This wasn't done earlier, because if we had, then - * things in the p_ptr->inventory would shift around, and q_ptr - * wouldn't point to the right thing. BUT, at this point - * we don't need q_ptr anymore, so optimizing the p_ptr->inventory - * becomes sane. Sticky bug to figure out, let me tell you. - * Note also that this is cycling backwards - this is so - * that the same effect doesn't cause us to skip items. */ - for ( i = INVEN_WIELD - 1 ; i >= 0 ; i-- ) - inven_item_optimize(i); - } - - /* Window stuff */ - p_ptr->window |= (PW_INVEN | PW_EQUIP); -} - -/* - * Test to see if this tval/sval combo is in the alchemists' - * recipes as a createable item. Used to determine if we - * should extract from it. - */ -static bool_ alchemist_exists(int tval, int sval, int ego, int artifact) -{ - int al_idx; - - /* To prevent conflicts with recipes for ego-items. - * artifact not used, simplifies the loop below. */ - if ((tval == 1) || artifact) - return FALSE; - - /*Search for recipes with this tval/sval combo as the final result*/ - for (al_idx = 0 ; al_idx < max_al_idx ; al_idx++) - { - int rtval = alchemist_recipes[al_idx].tval; - int rsval = alchemist_recipes[al_idx].sval; - - /* Accept ego wands and staves since ego is extracted last */ - if (((!ego || tval == TV_WAND || tval == TV_STAFF) && rtval == tval && rsval == sval) || - ( ego && rtval == 1 && rsval == ego)) - { - return TRUE; - } - } - return FALSE; -} - - -/* - * Hook to determine if an object can have things extracted from it. - */ -bool item_tester_hook_extractable(object_type const *o_ptr) -{ - - /* No artifacts */ - if (artifact_p(o_ptr)) - { - return false; - } - - /* No cursed things */ - if (cursed_p(o_ptr)) - { - return false; - } - - /* If we REALLY wanted to rebalance alchemists, - * we'd test for 'fully identified this object kind' here. - */ - return ((o_ptr->tval == TV_ROD_MAIN && o_ptr->pval != 0) - || alchemist_exists(o_ptr->tval, o_ptr->sval, o_ptr->name2, o_ptr->name1)); -} - -/* - * Hook to determine if an object is empowerable (NOT rechargeable) - */ -static bool item_tester_hook_empower(object_type const *o_ptr) -{ - int sval = -1; - int lev = get_skill(SKILL_ALCHEMY); - /* after level 25, can empower ego items to create artifacts - * and double ego items. - * after level 50, can empower artifacts to create powerful artifacts - */ - - /* Never Empower a cursed item */ - if ( cursed_p(o_ptr)) - { - return false; - } - - /* Allow finalizing a self created artifact */ - if (artifact_p(o_ptr) - && (o_ptr->art_flags4 & TR4_ART_EXP) - && !(o_ptr->art_flags4 & TR4_ULTIMATE)) - return true; - - switch ( o_ptr->tval) - { - /* Empowerable objects: Traditional alchemist stuff */ - case TV_WAND: - sval = SV_WAND_NOTHING; - break; - case TV_RING: - sval = SV_RING_NOTHING; - break; - case TV_STAFF: - sval = SV_STAFF_NOTHING; - break; - case TV_BOTTLE: - sval = 1; - break; - case TV_AMULET: - sval = SV_AMULET_NOTHING; - break; - case TV_SCROLL: - sval = SV_SCROLL_NOTHING; - break; - case TV_ROD: - sval = SV_ROD_NOTHING; - break; - case TV_ROD_MAIN: - sval = -1; - break; - case TV_BOOK: - sval = -1; - break; - - /* Ego item stuff */ - /* Disallow ego dragon armour before you can create artifacts.*/ - case TV_DRAG_ARMOR: - if ( lev < 25) - return false; - /* FALL THROUGH! no break here. */ - - /* weapons */ - - case TV_DAEMON_BOOK: - case TV_SWORD: - case TV_HAFTED: - case TV_POLEARM: - case TV_AXE: - case TV_MSTAFF: - - /* misc other items */ - case TV_BOW: - case TV_BOOMERANG: - case TV_INSTRUMENT: - case TV_DIGGING: - case TV_LITE: - - /* Ammo */ - case TV_SHOT: - case TV_ARROW: - case TV_BOLT: - - /* Armor of various sorts */ - case TV_BOOTS: - case TV_GLOVES: - case TV_HELM: - case TV_CROWN: - case TV_SHIELD: - case TV_CLOAK: - case TV_SOFT_ARMOR: - case TV_HARD_ARMOR: - - /* Disallow ANY creation of ego items below level 5*/ - if ( lev < 5) - return false; - - /* empowering an ego item creates an artifact or a - * double ego item, disallow below level 25 */ - if ( lev < 25 && o_ptr->name2) - return false; - - /* Disallow double-ego and artifact unless the character has - * the artifact creation ability. */ - if (!has_ability(AB_CREATE_ART) && - (artifact_p(o_ptr) || (o_ptr->name2 && o_ptr->name2b))) - return false; - - /* Otherwise... */ - return true; - - default: - return false; - } - - /* Return to the traditional alchemist objects. - * All ego items and artifacts returning TRUE are accepted as artifactable - * at level 25. If we want double ego non wieldable items (Fireproof Staff - * of Plenty) the artifactable test in do_cmd_alchemist() must be changed, - * e.g. checking if the item is wearable. - * For now, we disallow non-wearable ego-items and artifacts here. - */ - - if ((o_ptr->name2 || artifact_p(o_ptr)) && - o_ptr->tval != TV_RING && o_ptr->tval != TV_AMULET) - return false; - - /* return true if it's a 'of nothing' item; - * does nothing for TV_ROD_MAIN and TV_BOOK - */ - return (sval == o_ptr->sval - - /* or if it's artifactable */ - || ((lev >= 50 || (lev >= 25 && !artifact_p(o_ptr))) && - (o_ptr->tval == TV_RING || o_ptr->tval == TV_AMULET)) - - /* or if it's egoable (note that normal egos start at level 5, wands and such start at 15) */ - || (!o_ptr->name2 && lev >= 15)); -} - -/* Extract a rod tip from a rod */ -static void rod_tip_extract(object_type *o_ptr) -{ - object_type *q_ptr; - object_type forge; - - /* Get local object */ - q_ptr = &forge; - - /* Paranoia, return if it's a rod of nothing */ - if (o_ptr->pval == SV_ROD_NOTHING) - return; - - /* Extract the rod tip */ - object_prep(q_ptr, lookup_kind(TV_ROD, o_ptr->pval)); - - q_ptr->number = o_ptr->number; - - object_aware(q_ptr); - object_known(q_ptr); - (void)inven_carry(q_ptr, FALSE); - - /* Remove it from the rod */ - o_ptr->pval = SV_ROD_NOTHING; - - /* Window stuff */ - p_ptr->window |= (PW_INVEN); -} - - -/* Begin & finish an art */ -static void do_cmd_toggle_artifact(object_type *o_ptr) -{ - char o_name[80]; - - if (!(o_ptr->art_flags4 & TR4_ART_EXP)) - { - bool_ okay = TRUE; - - msg_print("Creating an artifact will result into a permanent loss of 10 hp."); - if (!get_check("Are you sure you want to do that?")) return; - - if (!magic_essence(get_skill(SKILL_ALCHEMY))) - { - msg_format("You need %d magic essences.", get_skill(SKILL_ALCHEMY)); - return; - } - - /* Description */ - object_desc(o_name, o_ptr, FALSE, 0); - - if (o_ptr->number > 1) - { - msg_print("Not enough energy to enchant more than one object!"); - msg_format("%d of your %s %s destroyed!", (o_ptr->number) - 1, o_name, (o_ptr->number > 2 ? "were" : "was")); - o_ptr->number = 1; - } - okay = TRUE; - - if (!okay) return; - - /* he/she got warned */ - p_ptr->hp_mod -= 10; - - /* Ok toggle it */ - o_ptr->art_flags4 |= TR4_ART_EXP; - o_ptr->name2 = 0; - o_ptr->name2b = 0; - o_ptr->art_name = quark_add("Becoming"); - - /* Copy the object_kind flags to the artifact flags. - * Note that this is only needed so that flags set in the - * 'kind' area are visible when finalizing the artifact. - */ - { - u32b f1, f2, f3, f4, f5, esp; - - object_flags(o_ptr, &f1, &f2, &f3, &f4, &f5, &esp); - - o_ptr->art_flags1 |= f1; - o_ptr->art_flags2 |= f2; - o_ptr->art_flags3 |= f3; - o_ptr->art_flags4 |= f4; - o_ptr->art_flags5 |= f5; - o_ptr->art_esp |= esp; - } - - p_ptr->update |= (PU_HP); - p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER); - } - else - { - do_cmd_create_artifact(o_ptr); - } -} - -/* - * Test to see if they have all the ingredients to create an item. - * (doesn't count base item) - * creates 'tocreate' items (may be -1, but no more than that!) - * if tocreate=0, will return true if the player has enough - * in their p_ptr->inventory to empower that item. - */ -static bool_ alchemist_items_check(int tval, int sval, int ego, int tocreate, bool_ message) -{ - int al_idx, j; - bool_ exists = FALSE; - - - for ( al_idx = 0 ; al_idx < max_al_idx ; al_idx++ ) - if ((ego && alchemist_recipes[al_idx].sval == ego - && alchemist_recipes[al_idx].tval == 1 ) - || (!ego && alchemist_recipes[al_idx].sval == sval - && alchemist_recipes[al_idx].tval == tval)) - { - exists = TRUE; - /* Create the essences */ - if (tocreate > 0) - { - object_type forge; - object_type *o_ptr = &forge; - - object_wipe(o_ptr); - object_prep(o_ptr, lookup_kind(TV_BATERIE, alchemist_recipes[al_idx].sval_essence)); - o_ptr->number = alchemist_recipes[al_idx].qty * tocreate; - /* Don't bother with apply_magic */ - - /* Randomly decrease the number of essences created */ - if ( randint(3) == 1 - && randint(52) > get_skill(SKILL_ALCHEMY)) - o_ptr->number /= randint(2) + 1; - if ( o_ptr->number == 0) - continue; - object_aware(o_ptr); - object_known(o_ptr); - if (inven_carry_okay(o_ptr)) - { - int i; - inven_carry(o_ptr, FALSE); - for (i = 0; i < INVEN_WIELD ; i++) - if (p_ptr->inventory[i].tval == o_ptr->tval && p_ptr->inventory[i].sval == o_ptr->sval) - { - if ( message ) - inven_item_describe(i); - break; - } - - } - else - drop_near(o_ptr, 0, p_ptr->py, p_ptr->px); - - o_ptr->ident |= IDENT_STOREB; - } - else if ( tocreate < -1) - { - /*It's not valid to create more than one - * thing at a time, so if it's less than -1, - * it must be time to display a recipe - */ - msg_format("%d essences of %d", - alchemist_recipes[al_idx].qty, - al_idx); - } - else /* Destroy the essences (tocreate == -1) - * or check for existence(tocreate == 0)*/ - { - int rqty = alchemist_recipes[al_idx].qty; - for (j = 0; j < INVEN_WIELD; j++) - { - object_type *o_ptr = &p_ptr->inventory[j]; - if (o_ptr->k_idx - && (o_ptr->tval == TV_BATERIE ) - && (o_ptr->sval == alchemist_recipes[al_idx].sval_essence ) - && (o_ptr->number >= rqty )) - { - /* At this point, the item is required, destroy it. */ - if ( tocreate ) - { - inc_stack_size_ex(j, 0 - rqty, OPTIMIZE, message ? DESCRIBE : NO_DESCRIBE); - } - - /* When we find enough of the item, break out of the - * 'search through the p_ptr->inventory' loop */ - break; - } - } - if ( j == INVEN_WIELD) - /* This ingredient was not found, cannot do recipe */ - return FALSE; - }/*destroying items, or just checking for existence */ - } - return exists; -} - -/* This function lists all the ingredients - * needed to create something. - */ -static void alchemist_display_recipe(int tval, int sval, int ego) -{ - int al_idx; - int row = 1, col = 15; - char o_name[80]; - char ch; - object_type *o_ptr, forge; - - /* Display the ingredients for a recipe */ - for ( al_idx = 0 ; al_idx < max_al_idx ; al_idx++ ) - if ((ego && alchemist_recipes[al_idx].sval == ego - && alchemist_recipes[al_idx].tval == 1 ) - || (!ego && alchemist_recipes[al_idx].sval == sval - && alchemist_recipes[al_idx].tval == tval)) - { - int qty = alchemist_recipes[al_idx].qty; - c_prt(TERM_GREEN, - format(" %d essence%s %s ", qty, - qty > 1 ? "s" : "", - k_info[lookup_kind(TV_BATERIE, alchemist_recipes[al_idx].sval_essence)].name), - row++, col); - } - - c_prt(TERM_WHITE, " ", row++, col); - - if (!ego) - { - /* Find the name of that object */ - o_ptr = &forge; - object_prep(o_ptr, lookup_kind(tval, sval)); - o_ptr->name2 = ego; - apply_magic(o_ptr, get_skill(SKILL_ALCHEMY) * 2, FALSE, FALSE, FALSE, boost::make_optional(0)); - object_aware(o_ptr); - object_known(o_ptr); - /* the 0 mode means only the text, leaving off any numbers */ - object_desc(o_name, o_ptr, FALSE, 0); - } - else - { - /* Display the ego item name */ - strcpy(o_name, e_info[ego].name); - } - - /* Display a short message about it, and wait for a key. */ - (void)get_com(format("ingredients needed to create a %s", o_name), &ch); - -} - -/* - The select array is a simple array of 'use this char to select item x' - It has 88 items (three columns of 20 each) - selectitem is initilized with the reverse mappings: - selectitem[selectchar[x]] == x is always true. - */ -char selectchar[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*():;,.<=>[]{}/=?+'~"; -byte selectitem[256]; - -void strip_and_print(const char *str, int color, int num) -{ - int row = 2 + (num % 20), col = 40 * (num / 20); - int ch, max_len = 0; - char buf[80]; - char *string; - - if (num > 60) - { - msg_print("Attempting to display too many items!"); - return; - } - ch = selectchar[num]; - if (selectitem[ch] != num) - { - int i; - for ( i = 0 ; i < 256 ; i++) - selectitem[i] = 0xff; - for ( i = 0 ; selectchar[i] ; i++) - selectitem[(byte)selectchar[i]] = i; - } - - /* Skip past leading characters */ - while ((*str == ' ') || (*str == '&')) str++; - - /* Copy useful chars */ - for (string = buf; *str; str++) - if (*str != '~') *string++ = *str; - - /* Terminate the new name */ - *string = '\0'; - - /* strip the name down to size - if (76-col < (signed)max_len) - max_len = 76-col; - else - max_len = 30-6;*/ - max_len = 39; - - string = buf; - if (strlen(string) > (unsigned)max_len) - string = string + (strlen(string) - max_len); - - /* Print it */ - c_prt(color, format("[%c] %s", ch, string), row, col); -} - -/* Display a list of known recipies that can be made with - * materials on hand (including the passed tval). Also - * calls the recipe_display function, if requested by the - * player or there aren't enough essences to make the - * requested object. - * - * Note: sval is ignored if !ego, tval is the only determinant - * of what recipies are available otherwise. - * - * This function needs to be able to scroll a list, because - * there are SO MANY potions. :) - */ -static int alchemist_recipe_select(int *tval, int sval, int ego, bool_ recipe) -{ - int i, mod40 = 0, num, max_num = 0; - - cptr tval_desc2 = ""; - char ch; - bool_ done = FALSE; - - int choice[60]; - int validc[60]; - - const char *string; - - - /* Save and clear the screen */ - character_icky = TRUE; - Term_save(); - Term_clear(); - - /* Base object type chosen, fill in tval */ - for ( num = 0 ; num < 40 ; num ++) - if (tvals[num].tval == *tval) - { - tval_desc2 = tvals[num].desc; - } - - while (!done) - { - Term_clear(); - if (ego) - { - /* Find matching ego items */ - for (num = 0, i = 1; (num < 40) && (i < max_e_idx) ; i++) - { - int j; - ego_item_type *e_ptr = &e_info[i]; - - /* Skip if unknown ego type */ - if ( !(alchemist_known_egos[i / 32] & (1 << (i % 32)))) - continue; - - /* search in permitted tvals/svals for allowed egos */ - for ( j = 0 ; j < 6 ; j ++ ) - if ( e_ptr->tval[j] == *tval - && sval >= e_ptr->min_sval[j] - && sval <= e_ptr->max_sval[j]) - { - int color = TERM_GREEN; - - /*Reject if not opposite end of name - prefixes only on postfix egos, - postfixes only on prefix egos. - */ - if (ego != -1 && e_ptr->before == e_info[ego].before) - continue; - - /*Color it red of the alchemist doesn't have the essences to create it*/ - if (!alchemist_items_check(*tval, 0, i, 0, TRUE)) - color = TERM_RED; - - /* add this ego to the list*/ - strip_and_print(e_info[i].name, color, num); - validc[num] = color; - choice[num++] = i; - break; - } - } - } - else - { - char skipped = 0; - num = 0; - if (mod40 != 0) - { - strip_and_print("--MORE--", TERM_WHITE, num); - validc[num] = TERM_WHITE; - choice[num++] = -1; - } - - for (i = 1; (num < 39) && (i < max_k_idx); i++) - { - object_kind *k_ptr = &k_info[i]; - - /* Analyze matching items */ - if (k_ptr->tval == *tval || (k_ptr->tval == TV_POTION2 && *tval == TV_POTION)) - { - char color = TERM_GREEN; - /* Hack -- Skip instant artifacts */ - if (k_ptr->flags3 & (TR3_INSTA_ART)) continue; - - /*Don't display recipes that the alchemist doesn't know about*/ - if (!k_ptr->know && !wizard) continue; - - /*Skip recipes that are somehow known, but don't exist*/ - if (!alchemist_exists(k_ptr->tval, k_ptr->sval, 0, 0)) - continue; - - /* Skip the first 39 if they hit 'more' */ - if (skipped++ < mod40*39) - continue; - - /* Color 'unable to create' items different */ - if (!alchemist_items_check(k_ptr->tval, k_ptr->sval, 0, 0, TRUE)) - color = TERM_RED; - - /* Acquire the "name" of object "i" */ - /* and print it in it's place */ - strip_and_print(k_ptr->name, color, num); - - /* Remember the object index */ - validc[num] = color; - choice[num++] = i; - } - } - if (num == 39) - { - strip_and_print("--MORE--", TERM_WHITE, num); - validc[num] = TERM_WHITE; - choice[num++] = -1; - } - } - - /* We need to know the maximal possible remembered object_index */ - max_num = num; - string = "What Kind of %s? (* to see recipe) [%c-%c,*]"; - num = 0xff; - - /* Pretend they're all undoable if we where called to display recipes */ - if (recipe) - { - for ( num = 0 ; num < max_num ; num++) - if (validc[num] != TERM_WHITE) validc[num] = TERM_RED; - string = "show which %s recipe? [%c-%c]"; - } - - while (num == 0xff || num >= max_num) - { - ch = selectchar[max_num - 1]; - /* Choose! */ - if ( max_num == 0 || !get_com(format(string, tval_desc2, selectchar[0], ch), &ch)) - { - break; - } - - /* Extra breaks for recipe */ - if (recipe && (ch == '\r' || ch == ' ' || ch == ESCAPE )) - break; - - /* Analyze choice */ - num = selectitem[(byte)ch]; - - /* Pretend that we don't have enough essences for anything */ - if (ch == '*' ) - { - for ( num = 0 ; num < max_num ; num++) - if (validc[num] != TERM_WHITE) validc[num] = TERM_RED; - string = "Show which %s recipe? [%c-%c]"; - } - } - if ( num == 0xff || max_num == 0 || num >= max_num) - break; - - if ( validc[num] == TERM_WHITE ) - { - if (num == 0) - mod40--; - else - mod40++; - if ( mod40 < 0) - mod40 = 0; - continue; - } - - /* If we don't have enough essences, or user asked for recipes */ - if ( validc[num] != TERM_GREEN ) - { - /* Display the recipe */ - if (ego) - alchemist_display_recipe(*tval, sval, choice[num]); - else - alchemist_display_recipe(k_info[choice[num]].tval, k_info[choice[num]].sval, 0); - } - else - done = TRUE; - - }/*while(!done)*/ - - /* Restore screen contents */ - Term_load(); - character_icky = FALSE; - - /* User abort, or no choices */ - if (max_num == 0 || num == 0xff || num >= max_num) - { - if (max_num == 0) - msg_print("You don't know of anything you can make using that."); - return ( -1); - } - if ( validc[num] != TERM_GREEN ) - return ( -1); - - /* And return successful */ - if ( ego ) - return choice[num]; - - /* Set the tval, should be the same unless they selected a potion2 */ - if (*tval != k_info[choice[num]].tval && *tval != TV_POTION) - msg_print("Coding error: tval != TV_POTION"); - *tval = k_info[choice[num]].tval; - return ( k_info[choice[num]].sval ); -} - -/* Display a list of recipes that need a particular essence. - * Note that we display a list of essences first, - * so in effect, this is the alchemist's recipe book. - */ -static void alchemist_recipe_book(void) -{ - int num, max_num, i, al_idx, bat, kidx; - int choice[61], choice2[61]; - int mod40; - bool_ essence[MAX_BATERIE_SVAL + 1]; - char ch; - - /* Save and clear the screen */ - character_icky = TRUE; - Term_save(); - - while ( TRUE ) - { - Term_clear(); - - num = 0; - - /* Display bateries */ - - /* start with assumption that the alchemist knows about no recipes */ - for (i = 0; i < MAX_BATERIE_SVAL + 1 ; i++) - essence[i] = FALSE; - - /* cycle through all alchemist recipes */ - for (al_idx = 0 ; al_idx < max_al_idx ; al_idx++) - /* if we aren't already going to display this essence */ - if (!essence[alchemist_recipes[al_idx].sval_essence]) - { - - /*Note that we don't display artifact recipes here...*/ - /*This is partially because artifacts often require exotic - ingredients as well */ - - if (!alchemist_recipes[al_idx].tval) - continue; - - if (alchemist_recipes[al_idx].tval == 1) - { - if (alchemist_known_egos[alchemist_recipes[al_idx].sval / 32] - & (1 << (alchemist_recipes[al_idx].sval % 32)) ) - essence[alchemist_recipes[al_idx].sval_essence] = TRUE; - continue; - } - - kidx = lookup_kind(alchemist_recipes[al_idx].tval, alchemist_recipes[al_idx].sval); - if (alchemist_recipes[al_idx].tval != 1 && k_info[kidx].know) - essence[alchemist_recipes[al_idx].sval_essence] = TRUE; - - } - for (num = 0, i = 0; i < MAX_BATERIE_SVAL + 7 ; i++) - if (essence[i] || i > MAX_BATERIE_SVAL) - { - int kidx = lookup_kind(TV_BATERIE, i); - if (i > MAX_BATERIE_SVAL) - { - switch (i) - { - case (MAX_BATERIE_SVAL + 1): strip_and_print("Scrolls", TERM_WHITE, num); - break; - case (MAX_BATERIE_SVAL + 2): strip_and_print("Potions", TERM_WHITE, num); - break; - case (MAX_BATERIE_SVAL + 3): strip_and_print("Wands", TERM_WHITE, num); - break; - case (MAX_BATERIE_SVAL + 4): strip_and_print("Rings", TERM_WHITE, num); - break; - case (MAX_BATERIE_SVAL + 5): strip_and_print("Staves", TERM_WHITE, num); - break; - case (MAX_BATERIE_SVAL + 6): strip_and_print("Amulets", TERM_WHITE, num); - break; - default: - continue; - } - } - else - { - /* add this essence to the list*/ - strip_and_print(k_info[kidx].name, TERM_WHITE, num); - } - - choice[num++] = i; - } - max_num = num; - if ( max_num == 0) - { - /*Note that this should never actually happen, as any skill - at alchemy automatically gets you some recipes, and this - procedure shouldn't be called for players without alchemist skill - */ - msg_print("You don't know any recipes!"); - msg_print("You can't be an alchemist without recipes!"); - break; - } - - while (num == 0xff || num >= max_num) - { - ch = selectchar[max_num - 1]; - /* Choose! */ - if ( max_num == 0 || - !get_com(format("Which Type of Recipe?[a-%c]", selectchar[max_num - 1]), &ch)) - break; - - /* Analyze choice - note that the cast to byte prevents overflow*/ - num = selectitem[(byte)ch]; - - } - /* This break, and the break for no recipes above, - are the only exits from this procedure. - */ - if ( num == 0xff || num >= max_num) - break; - - /* Save the baterie index */ - bat = choice[num]; - num = 0; - - /*Display the 'type of object' recipe screen*/ - if (bat > MAX_BATERIE_SVAL) - { - int tval; - switch (bat) - { - case MAX_BATERIE_SVAL + 1: - tval = TV_SCROLL; - break; - case MAX_BATERIE_SVAL + 2: - tval = TV_POTION; - break; - case MAX_BATERIE_SVAL + 3: - tval = TV_WAND; - break; - case MAX_BATERIE_SVAL + 4: - tval = TV_RING; - break; - case MAX_BATERIE_SVAL + 5: - tval = TV_STAFF; - break; - case MAX_BATERIE_SVAL + 6: - tval = TV_AMULET; - break; - } - Term_load(); - alchemist_recipe_select(&tval, 0, FALSE, TRUE); - Term_save(); - continue; - } - mod40 = 0; - while ( TRUE ) - { - int skipped; - - Term_clear(); - num = 0; - - if (mod40) - { - strip_and_print("--MORE--", TERM_WHITE, num); - choice[num] = -2; - choice2[num++] = 0; - } - - /* Display all items made with this essence */ - for ( al_idx = 0 , skipped = 0 ; al_idx < max_al_idx ; al_idx++) - if ( alchemist_recipes[al_idx].sval_essence == bat) - { - int sval = alchemist_recipes[al_idx].sval; - int tval = alchemist_recipes[al_idx].tval; - char names[200] = ""; - - if (alchemist_recipes[al_idx].tval == 1) - { - /* Ego items */ - ego_item_type *e_ptr = &e_info[sval]; - int j, k; - - if ( !(alchemist_known_egos[sval / 32] & (1 << (sval % 32)))) - continue; - - for ( j = 0 ; j < 6 && e_ptr->tval[j] ; j ++ ) - { - if ( j > 0 && e_ptr->tval[j] == e_ptr->tval[j - 1]) - continue; - for ( k = 0; tvals[k].tval; k++) - if (tvals[k].tval == e_ptr->tval[j]) - { - strcat(names, tvals[k].desc); - strcat(names, ", "); - break; - } - } - strcat(names, e_ptr->name); - } - else - { - /* Normal Items */ - int kidx = lookup_kind(tval, sval); - int k; - if ( !k_info[kidx].know ) - continue; - - for ( k = 0; tvals[k].tval; k++) - if (tvals[k].tval == tval) - { - strcat(names, tvals[k].desc); - break; - } - strcat(names, " of "); - strcat(names, k_info[kidx].name); - - } - - /*Skip the first mod40 pages of recipes*/ - if (skipped++ < mod40*38) - continue; - - /* add this object kind to the list*/ - strip_and_print(names, TERM_WHITE, num); - choice[num] = tval; - choice2[num++] = sval; - if (num > 38) - { - strip_and_print("--MORE--", TERM_WHITE, num); - choice[num] = -1; - choice2[num++] = 0; - break; - } - - }/*Loop through tidx/sidx*/ - - max_num = num; - while (num == 0xff || num >= max_num) - { - ch = selectchar[max_num - 1]; - /* Choose! */ - if ( max_num == 0 || !get_com( - format("Examine which recipe?[%c-%c]", selectchar[0], ch) - , &ch)) - { - break; - } - - /* Analyze choice */ - num = selectitem[(byte)ch]; - } - - if ( choice[num] < 0) - { - if (choice[num] < -1) - mod40--; - else - mod40++; - continue; - } - - if ( num == 0xff || num >= max_num) - break; - - /* Display the recipe */ - if (choice[num] == 1) - alchemist_display_recipe(0, 0, choice2[num]); - else - alchemist_display_recipe(choice[num], choice2[num], 0); - } - /* - break is at top of loop, after essence list - if( num < 0 || num >= max_num) - break; - */ - - }/*show recipes*/ - - /* Restore screen contents */ - Term_load(); - character_icky = FALSE; -} - -/* Set the 'known' flags for all objects with a level <= lev - * This lets the budding alchemist create basic items. - */ -void alchemist_learn_all(int lev) -{ - int i; - - if ( !get_skill(SKILL_ALCHEMY) ) - return; - - /* msg_format("You learn about level %d items",lev); */ - - for ( i = 0 ; i < max_k_idx ; i++ ) - if ( k_info[i].level <= lev ) - if (alchemist_exists(k_info[i].tval, k_info[i].sval, 0, 0)) - k_info[i].know = TRUE; -} - -void alchemist_learn_ego(int ego) -{ - int i; - - /* some Paranoia*/ - if ( !ego || ego >= max_e_idx ) - return; - - /* Get the ego items name */ - const char *name = e_info[ego].name; - while (strchr(name, ' ')) - name = strchr(name, ' ') + 1; - - /* Don't learn about egos without recipes, and - * always learn about the passed ego item. */ - if (alchemist_exists(0, 0, ego, 0)) - { - alchemist_known_egos[ego / 32] |= (1 << (ego % 32)); - } - else - { - return; - } - - /* Don't mass learn about egos that have no name. */ - if ( name[0] == 0 ) - { - return; - } - - /* Look through all ego's for matching name */ - /* Note that the original ego is marked here too */ - for ( i = 0 ; i < max_e_idx ; i++ ) - if ( strstr(e_info[i].name, name) != NULL /*Last word of name exists in this ego's name*/ - && alchemist_exists(0, 0, i, 0) /*There exists a recipe for this*/ - && !(alchemist_known_egos[i / 32] & (1 << (i % 32)) ) ) /*Not already known*/ - { - alchemist_known_egos[i / 32] |= (1 << (i % 32)); - } - - return; -} - -/* Alchemist has learned about a new item. - * Learn about not only it, but ALL egos with the - * same name. - */ -int alchemist_learn_object(object_type *o_ptr) -{ - - /* Allow alchemist to create this item, - and.. learn about it even if the player - doesn't currently have the alchemy skill - */ - k_info[o_ptr->k_idx].know = TRUE; - - /* Not Paranoia, identify_fully calls this always */ - if ( !get_skill(SKILL_ALCHEMY) ) - return FALSE; - - if ( artifact_p(o_ptr) ) - { - char o_name[80]; - u32b f1, f2, f3, f4, f5, esp; - object_flags(o_ptr, &f1, &f2, &f3, &f4, &f5, &esp); - - /* Randarts and normal artifacts both*/ - alchemist_known_artifacts[0] |= f1; - alchemist_known_artifacts[1] |= f2; - alchemist_known_artifacts[2] |= f3; - alchemist_known_artifacts[3] |= f4; - alchemist_known_artifacts[4] |= f5; - alchemist_known_artifacts[5] |= esp; - - object_desc(o_name, o_ptr, 1, 0); - msg_format("You learn all about the abilities of %s!", o_name); - } - if (o_ptr->name2) - alchemist_learn_ego(o_ptr->name2); - - if (o_ptr->name2b) - alchemist_learn_ego(o_ptr->name2b); - - return (TRUE); -} - -/* Alchemist has gained a level - set the ego flags - * for all egos <= lev/4. - */ -static void alchemist_gain_level(int lev) -{ - object_type forge; - object_type *o_ptr = &forge; - - if ( lev == 0) - { - /* Learn about potions of Detonation */ - k_info[417].know = TRUE; - } - if ( lev == 5) - { - int ego; - int egos[] = { - 7/*armor of resist fire*/ - , 18/*shield of resist fire*/ - , 74/*shocking weapon*/ - , 75/*fiery weapon*/ - , 76/*frozen weapon*/ - , 77/*Venomous weapon*/ - , 78/*Chaotic weapon*/ - , 115/*projectile of venom*/ - , 116/*projectile of Acid*/ - , 122/*projectile of flame*/ - , 123/*projectile of frost*/ - , 137/*Lite of fearlessness*/ - , 0 /*terminator*/ - }; - object_wipe(o_ptr); - /* learn about some basic ego items */ - /* Note that this is just to get you started. */ - for ( ego = 0 ; egos[ego] ; ego++) - { - o_ptr->name2 = egos[ego]; - alchemist_learn_object(o_ptr); - } - msg_print("You recall your old master teaching you about elemental item infusing."); - } - if ( lev == 10) - { - /*For 'hard rooms' Players only, learn about diggers.*/ - if (ironman_rooms) - { - msg_print("There's gotta be an easier way to get into all these vaults!"); - object_wipe(o_ptr); - o_ptr->name2 = 101; /* Ego item, 'of digging' */ - alchemist_learn_object(o_ptr); - } - } - if ( lev == 25) - { - msg_print("You recall your old master reminiscing about legendary infusings"); - msg_print("and the Philosophers' stone."); - - /* No auto-learn on artifacts - by this level, you'll have *ID*'d several */ - } - if ( lev == 25) - { - msg_print("You wonder about shocking daggers of slay evil."); - } - if ( lev == 50) - { - /* learn about Temporary item creation */ - /* Note that this is the ONLY way to learn this, - because spells which create a temporary item - also fully ID it. */ - alchemist_known_artifacts[4] |= TR5_TEMPORARY; - msg_print("It suddenly occurs to you that artifacts don't *HAVE* to be permanent..."); - } - - /* Every Four Levels, learn about items that are - * less than that. - * Note that this isn't a significant effect after the - * first few levels, as the level at which you are learning - * things here quickly drops behind the level at which you - * are finding items. - */ - if ( (lev & 0x3) != 0 ) - return; - lev = (lev >> 2) + 1; - alchemist_learn_all(lev); - -} - -/* This, in combination with some code in loadsave.c, - insures that alchemist_gain_level is called EXACTLY - once with each possible value during the characters - lifetime. - */ -void alchemist_check_level() -{ - u32b lev = get_skill(SKILL_ALCHEMY); - if ( alchemist_gained > lev ) - return; - /*Paranoia*/ - if ( !lev ) - return; - while ( alchemist_gained <= lev ) - alchemist_gain_level(alchemist_gained++); -} - -/* - * do_cmd_cast calls this function if the player's class - * is 'alchemist'. - */ -void do_cmd_alchemist(void) -{ - int item, ext = 0; - int value, basechance; - int askill; - bool_ repeat = 0; - char ch; - - object_type *o_ptr, *q_ptr; - object_type forge, forge2; - byte carry_o_ptr = FALSE; - - /* With the new skill system, we can no longer depend on - * check_exp to handle the changes and learning involved in - * gaining levels. - * So we'll have to check for it here. - */ - alchemist_check_level(); - askill = get_skill(SKILL_ALCHEMY); - - - q_ptr = &forge; - - o_ptr = &p_ptr->inventory[INVEN_HANDS]; - if ((o_ptr->tval != TV_GLOVES) || (o_ptr->sval != SV_SET_OF_LEATHER_GLOVES)) - { - msg_print("You must wear gloves in order to do alchemy."); - return; - } - - if (p_ptr->confused) - { - msg_print("You are too confused!"); - return; - } - - while (TRUE) - { - if (!get_com("[P]ower, [R]echarge or [L]eech an item, [E]xtract essences, or recipe [B]ook?", &ch)) - { - ext = 0; - break; - } - if (ch == ' ' ) - { - ext = 0; - break; - } - if (ch == 'P' || ch == 'p') - { - ext = 1; - break; - } - if (ch == 'E' || ch == 'e') - { - ext = 2; - break; - } - if (ch == 'R' || ch == 'r') - { - ext = 3; - break; - } - if (ch == 'L' || ch == 'l') - { - ext = 2; - repeat = 1; - break; - } - if (ch == 'B' || ch == 'b') - { - ext = 4; - break; - } - } - - /**********Add a power*********/ - if (ext == 1) - { - int i, qty, tval, sval = 0, ego = 0; - char o_name[200]; - - /* Get an item */ - if (!get_item(&item, - "Empower which item? ", - "You have no empowerable items.", - (USE_INVEN | USE_FLOOR), item_tester_hook_empower)) return; - - /* Get the item */ - o_ptr = get_object(item); - - /* Create an artifact from an ego or double ego item, - * from a previous artifact, or finish an artifact - */ - if ((askill >= 25) && (artifact_p(o_ptr) || o_ptr->name2) && has_ability(AB_CREATE_ART)) - { - if (get_check("Create an artifact?")) - { - do_cmd_toggle_artifact(o_ptr); - return; - } - /* Don't change artifacts or double ego items further */ - else if (artifact_p(o_ptr) || (o_ptr->name2 && o_ptr->name2b)) - return; - } - /*Ok, now we have the item, so we can now pick recipes. - Note: No recipe is known unless we have 'extracted' from - that object type. I.E. the 'know' flag (also greater identify) - is set. - */ - - /* Here we're not setting what kind of ego item it IS, - * where' just deciding that it CAN be an ego item */ - if ( o_ptr->name2 ) /* creating a DUAL ego */ - ego = TRUE; - if ( o_ptr->tval < 40 && o_ptr->tval != TV_BOTTLE) - ego = TRUE; - if ( o_ptr->tval == TV_ROD_MAIN || o_ptr->tval == TV_DAEMON_BOOK || o_ptr->tval == TV_BOOK) - ego = TRUE; - - sval = o_ptr->sval; - if (!ego) - { - switch ( o_ptr->tval) - { - case TV_WAND: - sval = SV_WAND_NOTHING; - break; - case TV_RING: - sval = SV_RING_NOTHING; - break; - case TV_STAFF: - sval = SV_STAFF_NOTHING; - break; - case TV_BOTTLE: - sval = 1; - break; - case TV_AMULET: - sval = SV_AMULET_NOTHING; - break; - case TV_SCROLL: - sval = SV_SCROLL_NOTHING; - break; - case TV_ROD: - sval = SV_ROD_NOTHING; - break; - } - } - if ( o_ptr->sval != sval ) - ego = TRUE; - - tval = o_ptr->tval; - sval = o_ptr->sval; - - /*HACK - bottles don't have the same tval as potions*/ - /*Everything else will have the same tval after empowering*/ - if (tval == TV_BOTTLE) tval = TV_POTION; - if (ego) - if (o_ptr->name2) - ego = alchemist_recipe_select(&tval, sval, o_ptr->name2, FALSE); - else - ego = alchemist_recipe_select(&tval, sval, -1, FALSE); - else - sval = alchemist_recipe_select(&tval, 0, 0, FALSE); - - if ( sval < 0 || ego < 0) - return; - - /* Check to make sure we have enough essences */ - /* theoretically this is taken care of by recipe_select*/ - /* but we'll double check just for paranoia. */ - if (!alchemist_items_check(tval, sval, ego, 0, TRUE)) - { - msg_print("You do not have enough essences."); - return; - } - - /* Take a turn */ - energy_use = 100; - - /* Use up the essences */ - (void)alchemist_items_check(tval, sval, ego, -1, TRUE); - - /* Enchant stacks of ammunition at a time */ - if ( o_ptr->tval == TV_SHOT || o_ptr->tval == TV_ARROW || o_ptr->tval == TV_BOLT ) - { - qty = 1; - while (qty < o_ptr->number && alchemist_items_check(tval, sval, ego, -1, FALSE)) - qty++; - } - else - qty = 1; - - /* Copy the object */ - q_ptr = &forge; - object_copy(q_ptr, o_ptr); - - if ( o_ptr->tval == TV_WAND) - { - /* distribute charges on wands */ - q_ptr->pval = o_ptr->pval / o_ptr->number; - o_ptr->pval -= q_ptr->pval; - } - - o_ptr = q_ptr; - o_ptr->number = qty; - carry_o_ptr = TRUE; - - /* Destroy the initial object */ - inc_stack_size(item, -qty); - - - if ( ego ) - { - int pval, pval2; - s32b pval3; - - pval = o_ptr->pval; - pval2 = o_ptr->pval2; - pval3 = o_ptr->pval3; - - if (o_ptr->name2) - o_ptr->name2b = ego; - else - o_ptr->name2 = ego; - o_ptr->pval = randint(e_info[ego].max_pval - 1) + 1; - /* dilemma - how to prevent creation of cursed items, - * without allowing the creation of artifacts? - * We can't, unless we want to finalize the ego flags ourselves. - */ - apply_magic(o_ptr, askill * 2, FALSE, FALSE, FALSE); - /* Remember what the old pval was, so that we can re-apply it. */ - if ( o_ptr->tval == TV_WAND - || o_ptr->tval == TV_RING - || o_ptr->tval == TV_AMULET - || o_ptr->tval == TV_STAFF) - { - o_ptr->pval = pval; - o_ptr->pval2 = pval2; - o_ptr->pval3 = pval3; - } - else if (o_ptr->tval == TV_ROD_MAIN) - { - o_ptr->pval = pval; - } - else if ((o_ptr->tval == TV_BOOK) && (o_ptr->sval == 255)) - { - o_ptr->pval = pval; - } - else if (o_ptr->tval == TV_SHOT - || o_ptr->tval == TV_ARROW - || o_ptr->tval == TV_BOLT) - { - o_ptr->pval2 = pval2; - } - else if (o_ptr->tval == TV_INSTRUMENT) - { - o_ptr->pval2 = pval2; - } - - /* Calculate failure rate, lev=val/2500+5 */ - value = MIN(e_info[o_ptr->name2].cost, 50000); - if (o_ptr->name2b) value += MIN(e_info[o_ptr->name2b].cost, 50000); - basechance = (value / 1000 + 5 - get_skill_scale(SKILL_ALCHEMY, 100) ) * 10; - if ( basechance < 0) basechance = 0; - if ( basechance > 100) basechance = 100; - - value = object_value_real(o_ptr); - - } - else /* not an ego item */ - { - o_ptr = &forge; - object_wipe(o_ptr); - object_prep(o_ptr, lookup_kind(tval, sval)); - apply_magic(o_ptr, askill * 2, FALSE, FALSE, FALSE, boost::make_optional(0)); - if ( o_ptr->tval == TV_WAND || o_ptr->tval == TV_STAFF) - o_ptr->pval = 0; - value = object_value_real(o_ptr); - - basechance = k_info[o_ptr->k_idx].level - askill * 2; - basechance *= 10; - - /* Can't fail more that 100% of the time... */ - if (basechance > 100) - basechance = 100; - /* Always success in creation of potion of detonations */ - if (o_ptr->tval == TV_POTION && o_ptr->sval == SV_POTION_DETONATIONS) - { - basechance /= 10; - } - } - - /* Use up gold to create items */ - /* this has the effect of making the alchemist - chronically short of funds, unless he finds the - philosopher's stone. It also means the easiest - things to make are 'bad', like a potion of - detonations... - */ - /* Problem - to restrictive. We need something - which requires less money. But at the same time, - we don't want an 'easy cash' situation. Maybe something - like '10% * level difference', meaning at skill level 5, - level one items are free? But egos are frequently level - zero! Maybe egos are forced to level 25? with a cost ceiling? - I mean, Potions and scrolls are really the problem causing the - 'easy cash' situation, it's ego items. Ego items require - relatively few essences, and the rewards are HUGE. Most powerful - potions and scrolls require rare essences. Maybe force all egos - to require a magic essence? But then you'd get lots of magic - from distilling them. Maybe consumed in the creation? then when - you got a powerful item, you could make one ego item... - But if making things doesn't take gold, what about the cash - does the Philosopher's stone do? - Time*/ - - if (basechance > 0 && value) - { - char string[80]; - string[0] = '0'; - string[1] = 0; - - msg_format("The chance of success is only %d%%!", 100-basechance); - get_string("How much gold do you want to add?", string, 50); - i = atoi(string); - /* Note: don't trust the user to enter a positive number... */ - if ( i < 0) - i = 0; - if ( i > p_ptr->au) - i = p_ptr->au; - - if (i) - { - basechance = basechance - (i * 20) / value; - msg_format("The chance of success improved to %d%%.", 100-basechance); - } - - if (randint(100) < basechance ) - /*creation failed, even with the extra gold...*/ - carry_o_ptr = FALSE; - - /* Redraw gold */ - p_ptr->au -= i; - p_ptr->redraw |= (PR_FRAME); - } - - /* Set fully identified - * After all, the player just made it... - */ - object_aware(o_ptr); - object_known(o_ptr); - o_ptr->ident |= IDENT_MENTAL; - o_ptr->found = OBJ_FOUND_SELFMADE; - - object_desc(o_name, o_ptr, FALSE, 0); - - if ( carry_o_ptr) - { - msg_format("You have successfully created %s %s", - (o_ptr->number > 1 ? "some" : (is_a_vowel(o_name[0]) ? "an" : "a")), - o_name); - - if (inven_carry_okay(o_ptr)) - inven_carry(o_ptr, FALSE); - else - { - drop_near(o_ptr, 0, p_ptr->py, p_ptr->px); - msg_format("You drop the %s", o_name); - } - carry_o_ptr = FALSE; - } - else /* don't carry, or in other words... */ - { - int level = k_info[o_ptr->k_idx].level; - if (o_ptr->name1) /* created ego item */ - level += e_info[o_ptr->name2].level; - - msg_format("Your attempt backfires! Your %s explodes!", o_name); - take_hit(damroll(3, level - askill ) , "Alchemical Explosion"); - p_ptr->redraw |= (PR_FRAME); - } - - /* Combine / Reorder the pack (later) */ - p_ptr->notice |= (PN_COMBINE | PN_REORDER); - - /* Window stuff */ - p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER); - - /* Optimize the entire p_ptr->inventory - needed because we - don't know how many essences where used, and we may - have 'used up' a wielded item as well. - */ - for ( item = 0 ; item < INVEN_TOTAL ; item++ ) - inven_item_optimize(item); - - /**********Extract a power*********/ - } - else if (ext == 2) - { - int ego; - bool_ discharge_stick = FALSE; - - /* s_ptr holds the empty items */ - object_type *s_ptr = NULL; - bool_ carry_s_ptr = FALSE; - - /* Get an item */ - if (!get_item(&item, - "Extract from which item? ", - "You have no item to extract power from.", - (USE_INVEN | USE_FLOOR), - item_tester_hook_extractable)) return; - - /* Get the item */ - o_ptr = get_object(item); - - /* This is to prevent creating magic essences by extracting - * from a recharged wand of dragon breath or something. - */ - if (( o_ptr->tval == TV_WAND || o_ptr->tval == TV_STAFF ) - && o_ptr->art_flags4 & TR4_RECHARGED) - { - msg_print("You cannot extract essences after it's been magically recharged."); - return; - } - - /* Take a turn */ - energy_use = 100; - - /* Handle Rods before the loop, since they don't stack */ - if (o_ptr->tval == TV_ROD_MAIN && o_ptr->pval != SV_ROD_NOTHING) - { - rod_tip_extract(o_ptr); - return; - } - - do - { /* Repeat (for leech command) */ - - /* Create the items. - * we don't care if they drop to the ground, - * and if no action was taken, return - */ - ego = 0; - if ( o_ptr->name2) - ego = o_ptr->name2; - - /* For ego staves and wands (not of nothing), discharge before extracting the ego */ - discharge_stick = (o_ptr->pval > 0 && - ((o_ptr->tval == TV_STAFF && o_ptr->sval != SV_STAFF_NOTHING) || - (o_ptr->tval == TV_WAND && o_ptr->sval != SV_WAND_NOTHING))); - if (discharge_stick) - ego = 0; - - if (!alchemist_items_check(o_ptr->tval, o_ptr->sval, ego, 1, TRUE)) - { - msg_print("You cannot extract anything from that item."); - return; - } - - if (o_ptr->name2b && !alchemist_items_check(o_ptr->tval, o_ptr->sval, o_ptr->name2b, 1, TRUE)) - { - /* do nothing - if the second ego can't be extracted - because there is no recipe for it, simply destroy it - */ - } - - /* Once in three times, learn how to make the item */ - /* Sorry for the complicated if! Basically, if it's an - * unknown regular item or an unknown ego item, there's - * a one in 3 chance that it'll be id'd */ - if (((!ego && !k_info[o_ptr->k_idx].know) - || (ego && !(alchemist_known_egos[ego / 32] & (1 << (ego % 32))))) - && randint(3) == 1) - { - msg_print("While destroying it, you gain insight into this item."); - /* If over level 10, the player has a chance of 'greater ID' - * on extracted items - */ - if (askill > 9) - object_out_desc(o_ptr, NULL, FALSE, TRUE); - alchemist_learn_object(o_ptr); - } - - /* Always learn what kind of thing it is */ - object_known(o_ptr); - object_aware(o_ptr); - - /* If it's a wand or staff with charges (but not of nothing), - * decrease number of charges, unstacking if needed. - * Otherwise, create the 'of nothing' item and destroy the old one. - */ - if (discharge_stick) - { - /* Unstack staves */ - if ((o_ptr->tval == TV_STAFF) && (o_ptr->number > 1)) - { - /* Create one local copy of the staff */ - q_ptr = &forge2; - object_copy(q_ptr, o_ptr); - - /* Modify quantity */ - q_ptr->number = 1; - - /* Unstack the copied staff */ - o_ptr->number--; - - /* Use the local copy of the staff */ - o_ptr = q_ptr; - carry_o_ptr = TRUE; - } - /* remove one charge */ - o_ptr->pval--; - } - else - { - /* Create the empty, plain item */ - /* If the item was already created, increase the number */ - if (carry_s_ptr) - { - s_ptr->number++; - } - else - { - /* Otherwise we must create a local copy of the empty item */ - int tval, sval; - bool_ create_item = TRUE; - - tval = o_ptr->tval; - if ( !ego && (tval == TV_POTION || tval == TV_POTION2)) - tval = TV_BOTTLE; - - sval = o_ptr->sval; - - if (!ego) - { - switch ( tval) - { - case TV_WAND: - sval = SV_WAND_NOTHING; - break; - case TV_RING: - sval = SV_RING_NOTHING; - break; - case TV_STAFF: - sval = SV_STAFF_NOTHING; - break; - case TV_BOTTLE: - sval = 1; - break; - case TV_AMULET: - sval = SV_AMULET_NOTHING; - break; - case TV_SCROLL: - sval = SV_SCROLL_NOTHING; - break; - case TV_ROD: - sval = SV_ROD_NOTHING; - break; - default: - create_item = FALSE; - } - } - - if (create_item) - { - /* Create the empty item */ - s_ptr = &forge; - object_wipe(s_ptr); - object_prep(s_ptr, lookup_kind(tval, sval)); - s_ptr->number = 1; - - /* Force creation of non ego non cursed */ - apply_magic(s_ptr, 0, FALSE, FALSE, FALSE, boost::make_optional(0)); - - /* Hack -- remove possible curse */ - if (cursed_p(s_ptr)) - { - s_ptr->art_flags3 &= ~(TR3_CURSED | TR3_HEAVY_CURSE); - s_ptr->ident &= ~(IDENT_CURSED); - } - - /* Restore pvals (e.g. charges ==0) of the item */ - if (ego && ((tval == TV_WAND) || (tval == TV_STAFF) || - (tval == TV_RING) || (tval == TV_AMULET))) - { - s_ptr->pval = o_ptr->pval; - s_ptr->pval2 = o_ptr->pval2; - s_ptr->pval3 = o_ptr->pval3; - } - /* Restore the spell stored in a random book */ - else if ((o_ptr->tval == TV_BOOK) && (o_ptr->sval == 255)) - { - s_ptr->pval = o_ptr->pval; - } - /* Restore the type of explosive ammo */ - else if (o_ptr->tval == TV_SHOT || o_ptr->tval == TV_ARROW - || o_ptr->tval == TV_BOLT) - { - s_ptr->pval2 = o_ptr->pval2; - } - /* Restore the music stored in an instrument */ - else if (o_ptr->tval == TV_INSTRUMENT) - { - s_ptr->pval2 = o_ptr->pval2; - } - - object_aware(s_ptr); - object_known(s_ptr); - s_ptr->ident |= IDENT_STOREB; - - /* The empty item will be added to the p_ptr->inventory later */ - carry_s_ptr = TRUE; - } - } - - /* Now, we can delete the original (leeched) object. - * Is o_ptr an p_ptr->inventory / floor item or a local copy? - */ - if (!carry_o_ptr) - { - /* Break the leech-loop if it was the last item */ - if (o_ptr->number == 1) - repeat = 0; - - inc_stack_size(item, -1); - } - else - { - /* Forget the local object */ - carry_o_ptr = FALSE; - - /* reset o_ptr to the original stack, - * which contains at least another item */ - o_ptr = get_object(item); - } - } - } - while ( repeat == 1); - - /* If we carry empty items, add them to the p_ptr->inventory */ - if (carry_s_ptr) - inven_carry(s_ptr, TRUE); - - /* Combine / Reorder the pack (later) */ - p_ptr->notice |= (PN_COMBINE | PN_REORDER); - - /* Window stuff */ - p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER); - - /******* Recharge an item *******/ - } - else if (ext == 3) - { - int item; - - /* Get an item */ - if (!get_item(&item, - "Recharge which item? ", - "You have no rechargable items.", - (USE_INVEN | USE_FLOOR), - item_tester_hook_recharge())) - { - return; - } - - /* Get the item */ - o_ptr = get_object(item); - - /* Make sure we have enough essences to recharge this */ - if (!alchemist_items_check(o_ptr->tval, o_ptr->sval, 0, 0, TRUE)) - { - msg_print("You don't have the essences to recharge this item."); - return; - } - - /* Take a turn */ - energy_use = 100; - - /* Destroy the essences */ - (void)alchemist_items_check(o_ptr->tval, o_ptr->sval, 0, -1, TRUE); - - if ((o_ptr->tval == TV_STAFF) && (o_ptr->number > 1)) - { - /* Unstack staves */ - /* Get local object */ - q_ptr = &forge2; - - /* Obtain a local object */ - object_copy(q_ptr, o_ptr); - - /* Modify quantity */ - q_ptr->number = 1; - - /* Unstack the used item */ - o_ptr->number--; - - o_ptr = q_ptr; - carry_o_ptr = TRUE; - } - o_ptr->pval++; - } - else if ( ext == 4) - { - alchemist_recipe_book(); - } - /* Just in case - */ - if (carry_o_ptr) - { - /* the o_ptr item was probably an unstacked staff - * Anyway, we need to add it to the p_ptr->inventory */ - if (inven_carry_okay(o_ptr)) - inven_carry(o_ptr, TRUE); - else - drop_near(o_ptr, 0, p_ptr->py, p_ptr->px); - } -} - - -/* * Command to ask favors from your god. */ void do_cmd_pray(void) |