Changeset 610

Show
Ignore:
Timestamp:
10/02/07 08:42:07 (1 year ago)
Author:
takkaria
Message:
  • Move all object generation code out to obj-make.c
  • Move all object function declarations to object.h
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/Makefile.src

    r595 r610  
    7979        object2.o \ 
    8080        obj-info.o \ 
     81        obj-make.o \ 
    8182        option.o \ 
    8283        randart.o \ 
  • trunk/src/angband.h

    r479 r610  
    3939#include "z-type.h" 
    4040#include "externs.h" 
    41  
     41#include "object.h" 
    4242 
    4343 
  • trunk/src/externs.h

    r603 r610  
    392392extern void update_smart_learn(int m_idx, int what); 
    393393 
    394 /* obj-info.c */ 
    395 extern void object_info_header(const object_type *o_ptr); 
    396 extern bool object_info_known(const object_type *o_ptr); 
    397 extern bool object_info_full(const object_type *o_ptr); 
    398 extern bool object_info_store(const object_type *o_ptr); 
    399  
    400 /* object1.c */ 
    401 extern void flavor_init(void); 
    402 extern void reset_visuals(bool prefs); 
    403 extern void object_kind_name(char *buf, size_t max, int k_idx, bool easy_know); 
    404 extern void object_flags(const object_type *o_ptr, u32b *f1, u32b *f2, u32b *f3); 
    405 extern void object_flags_known(const object_type *o_ptr, u32b *f1, u32b *f2, u32b *f3); 
    406 extern void object_desc(char *buf, size_t max, const object_type *o_ptr, int pref, int mode); 
    407 extern void object_desc_spoil(char *buf, size_t max, const object_type *o_ptr, int pref, int mode); 
    408 extern void identify_random_gen(const object_type *o_ptr); 
    409 extern char index_to_label(int i); 
    410 extern s16b label_to_inven(int c); 
    411 extern s16b label_to_equip(int c); 
    412 extern s16b wield_slot(const object_type *o_ptr); 
    413 extern cptr mention_use(int i); 
    414 extern cptr describe_use(int i); 
    415 extern bool item_tester_okay(const object_type *o_ptr); 
    416 extern int scan_floor(int *items, int max_size, int y, int x, int mode); 
    417 extern void display_inven(void); 
    418 extern void display_equip(void); 
    419 extern void show_inven(void); 
    420 extern void show_equip(void); 
    421 extern void show_floor(const int *floor_list, int floor_num, bool gold); 
    422 extern void toggle_inven_equip(void); 
    423 extern bool verify_item(cptr prompt, int item); 
    424 extern bool get_item(int *cp, cptr pmt, cptr str, int mode); 
    425  
    426 /* object2.c */ 
    427 extern void excise_object_idx(int o_idx); 
    428 extern void delete_object_idx(int o_idx); 
    429 extern void delete_object(int y, int x); 
    430 extern void compact_objects(int size); 
    431 extern void wipe_o_list(void); 
    432 extern s16b o_pop(void); 
    433 extern object_type *get_first_object(int y, int x); 
    434 extern object_type *get_next_object(const object_type *o_ptr); 
    435 extern bool init_obj_alloc(void); 
    436 extern void free_obj_alloc(void); 
    437 extern s16b get_obj_num(int level); 
    438 extern void object_known(object_type *o_ptr); 
    439 extern void object_aware(object_type *o_ptr); 
    440 extern void object_tried(object_type *o_ptr); 
    441 extern bool is_blessed(const object_type *o_ptr); 
    442 extern s32b object_value(const object_type *o_ptr); 
    443 extern void distribute_charges(object_type *o_ptr, object_type *i_ptr, int amt); 
    444 extern void reduce_charges(object_type *o_ptr, int amt); 
    445 extern bool object_similar(const object_type *o_ptr, const object_type *j_ptr); 
    446 extern void object_absorb(object_type *o_ptr, const object_type *j_ptr); 
    447 extern s16b lookup_kind(int tval, int sval); 
    448 extern void object_wipe(object_type *o_ptr); 
    449 extern void object_copy(object_type *o_ptr, const object_type *j_ptr); 
    450 extern void object_prep(object_type *o_ptr, int k_idx); 
    451 extern void apply_magic(object_type *o_ptr, int lev, bool okay, bool good, bool great); 
    452 extern bool make_object(object_type *j_ptr, int lev, bool good, bool great); 
    453 extern bool make_gold(object_type *j_ptr, int lev); 
    454 extern s16b floor_carry(int y, int x, object_type *j_ptr); 
    455 extern void drop_near(object_type *j_ptr, int chance, int y, int x); 
    456 extern void acquirement(int y1, int x1, int level, int num, bool great); 
    457 extern void place_object(int y, int x, int level, bool good, bool great); 
    458 extern void place_gold(int y, int x, int level); 
    459 extern void place_secret_door(int y, int x); 
    460 extern void place_closed_door(int y, int x); 
    461 extern void place_random_door(int y, int x); 
    462 extern void inven_item_charges(int item); 
    463 extern void inven_item_describe(int item); 
    464 extern void inven_item_increase(int item, int num); 
    465 extern void inven_item_optimize(int item); 
    466 extern void floor_item_charges(int item); 
    467 extern void floor_item_describe(int item); 
    468 extern void floor_item_increase(int item, int num); 
    469 extern void floor_item_optimize(int item); 
    470 extern bool inven_stack_okay(const object_type *o_ptr); 
    471 extern bool inven_carry_okay(const object_type *o_ptr); 
    472 extern s16b inven_carry(object_type *o_ptr); 
    473 extern s16b inven_takeoff(int item, int amt); 
    474 extern void inven_drop(int item, int amt); 
    475 extern void combine_pack(void); 
    476 extern void reorder_pack(void); 
    477  
    478394/* pathfind.c */ 
    479395extern bool findpath(int y, int x); 
     
    696612 
    697613/* xtra1.c */ 
    698 extern void cnv_stat(int val, char *out_val, size_t len); 
    699 extern s16b modify_stat_value(int value, int amount); 
    700 extern int calc_blows(const object_type *o_ptr); 
    701 extern void display_player_compact(void); 
    702 extern void notice_stuff(void); 
    703 extern void update_stuff(void); 
    704 extern void redraw_stuff(void); 
    705 extern void window_stuff(void); 
    706 extern void handle_stuff(void); 
    707 extern void init_display(void); 
     614s16b modify_stat_value(int value, int amount); 
     615int calc_blows(const object_type *o_ptr); 
     616void notice_stuff(void); 
     617void update_stuff(void); 
     618void redraw_stuff(void); 
     619void handle_stuff(void); 
    708620 
    709621/* xtra2.c */ 
    710 extern bool set_timed(int idx, int v); 
    711 extern bool inc_timed(int idx, int v); 
    712 extern bool dec_timed(int idx, int v); 
    713 extern bool clear_timed(int idx); 
    714 extern bool set_food(int v); 
    715 extern void check_experience(void); 
    716 extern void gain_exp(s32b amount); 
    717 extern void lose_exp(s32b amount); 
    718 extern void monster_death(int m_idx); 
    719 extern bool mon_take_hit(int m_idx, int dam, bool *fear, cptr note); 
    720 extern bool modify_panel(term *t, int wy, int wx); 
    721 extern bool adjust_panel(int y, int x); 
    722 extern bool change_panel(int dir); 
    723 extern void verify_panel(void); 
    724 extern void ang_sort_aux(void *u, void *v, int p, int q); 
    725 extern void ang_sort(void *u, void *v, int n); 
    726 extern int motion_dir(int y1, int x1, int y2, int x2); 
    727 extern int target_dir(char ch); 
    728 extern bool target_able(int m_idx); 
    729 extern bool target_okay(void); 
    730 extern void target_set_monster(int m_idx); 
    731 extern void target_set_location(int y, int x); 
    732 extern bool target_set_interactive(int mode); 
    733 extern bool get_aim_dir(int *dp); 
    734 extern bool get_rep_dir(int *dp); 
    735 extern bool confuse_dir(int *dp); 
    736  
    737  
    738 /* 
    739  * Hack -- conditional externs 
    740  */ 
    741  
     622bool set_timed(int idx, int v); 
     623bool inc_timed(int idx, int v); 
     624bool dec_timed(int idx, int v); 
     625bool clear_timed(int idx); 
     626bool set_food(int v); 
     627void check_experience(void); 
     628void gain_exp(s32b amount); 
     629void lose_exp(s32b amount); 
     630void monster_death(int m_idx); 
     631bool mon_take_hit(int m_idx, int dam, bool *fear, cptr note); 
     632bool modify_panel(term *t, int wy, int wx); 
     633bool adjust_panel(int y, int x); 
     634bool change_panel(int dir); 
     635void verify_panel(void); 
     636void ang_sort_aux(void *u, void *v, int p, int q); 
     637void ang_sort(void *u, void *v, int n); 
     638int motion_dir(int y1, int x1, int y2, int x2); 
     639int target_dir(char ch); 
     640bool target_able(int m_idx); 
     641bool target_okay(void); 
     642void target_set_monster(int m_idx); 
     643void target_set_location(int y, int x); 
     644bool target_set_interactive(int mode); 
     645bool get_aim_dir(int *dp); 
     646bool get_rep_dir(int *dp); 
     647bool confuse_dir(int *dp); 
     648 
     649/* xtra3.c */ 
     650void cnv_stat(int val, char *out_val, size_t out_len); 
     651void toggle_inven_equip(void); 
     652void subwindows_set_flags(u32b *new_flags, size_t n_subwindows); 
     653void init_display(void); 
     654 
     655/* wiz-spoil.c */ 
     656bool make_fake_artifact(object_type *o_ptr, byte name1); 
     657 
     658 
     659 
     660/* borg.h */ 
    742661#ifdef ALLOW_BORG 
    743 /* borg.h */ 
    744662extern void do_cmd_borg(void); 
    745663#endif /* ALLOW_BORG */ 
    746664 
    747 bool make_fake_artifact(object_type *o_ptr, byte name1); 
    748  
    749665/* Testing Hacks XXX */ 
    750666extern bool new_save; 
  • trunk/src/object2.c

    r594 r610  
    575575 
    576576 
    577  
    578  
    579 static u32b obj_total[MAX_DEPTH]; 
    580 static byte *obj_alloc; 
    581  
    582 /* Don't worry about probabilities for anything past dlev100 */ 
    583 #define MAX_O_DEPTH             100 
    584  
    585 /* 
    586  * Free object allocation info. 
    587  */ 
    588 void free_obj_alloc(void) 
    589 { 
    590         FREE(obj_alloc); 
    591 } 
    592  
    593  
    594 /* 
    595  * Using k_info[], init rarity data for the entire dungeon. 
    596  */ 
    597 bool init_obj_alloc(void) 
    598 { 
    599         int k_max = z_info->k_max; 
    600         int item, lev; 
    601  
    602  
    603         /* Free obj_allocs if allocated */ 
    604         FREE(obj_alloc); 
    605  
    606         /* Allocate and wipe */ 
    607         obj_alloc = C_ZNEW((MAX_O_DEPTH + 1) * k_max, byte); 
    608  
    609         /* Wipe the totals */ 
    610         C_WIPE(obj_total, MAX_O_DEPTH + 1, u32b); 
    611  
    612  
    613         /* Init allocation data */ 
    614         for (item = 1; item < k_max; item++) 
    615         { 
    616                 object_kind *k_ptr = &k_info[item]; 
    617  
    618                 int min = k_ptr->alloc_min; 
    619                 int max = k_ptr->alloc_max; 
    620  
    621                 /* If an item doesn't have a rarity, move on */ 
    622                 if (!k_ptr->alloc_prob) continue; 
    623  
    624                 /* Go through all the dungeon levels */ 
    625                 for (lev = 0; lev <= MAX_O_DEPTH; lev++) 
    626                 { 
    627                         int rarity = k_ptr->alloc_prob; 
    628  
    629                         /* Give out-of-depth items a tiny chance at being made */ 
    630                         if ((lev < min) || (lev > max)) rarity = 0; 
    631  
    632                         /* Save the probability */ 
    633                         obj_total[lev] += rarity; 
    634                         obj_alloc[(lev * k_max) + item] = rarity; 
    635                 } 
    636         } 
    637  
    638         return TRUE; 
    639 } 
    640  
    641  
    642  
    643  
    644 /* 
    645  * Choose an object kind given a dungeon level to choose it for. 
    646  */ 
    647 s16b get_obj_num(int level) 
    648 { 
    649         /* This is the base index into obj_alloc for this dlev */ 
    650         size_t ind, item; 
    651         u32b value; 
    652  
    653         /* Occasional level boost */ 
    654         if ((level > 0) && !rand_int(GREAT_OBJ)) 
    655         {  
    656                 /* What a bizarre calculation */  
    657                 level = 1 + (level * MAX_O_DEPTH / randint(MAX_O_DEPTH));  
    658         } 
    659  
    660         /* Paranoia */ 
    661         level = MIN(level, MAX_O_DEPTH); 
    662         level = MAX(level, 0); 
    663  
    664         /* Pick an object */ 
    665         ind = level * z_info->k_max; 
    666         value = rand_int(obj_total[level]); 
    667         for (item = 1; item < z_info->k_max; item++) 
    668         { 
    669                 /* Found it */ 
    670                 if (value < obj_alloc[ind + item]) break; 
    671  
    672                 /* Decrement */ 
    673                 value -= obj_alloc[ind + item]; 
    674         } 
    675  
    676  
    677         /* Return the item index */ 
    678         return item; 
    679 } 
    680  
    681  
    682  
    683  
    684  
    685  
    686  
    687  
    688577/* 
    689578 * Known is true when the "attributes" of an object are "known". 
     
    716605        o_ptr->ident |= (IDENT_KNOWN); 
    717606} 
    718  
    719  
    720  
    721607 
    722608 
     
    14541340 
    14551341/* 
    1456  * Help determine an "enchantment bonus" for an object. 
    1457  * 
    1458  * To avoid floating point but still provide a smooth distribution of bonuses, 
    1459  * we simply round the results of division in such a way as to "average" the 
    1460  * correct floating point value. 
    1461  * 
    1462  * This function has been changed.  It uses "Rand_normal()" to choose values 
    1463  * from a normal distribution, whose mean moves from zero towards the max as 
    1464  * the level increases, and whose standard deviation is equal to 1/4 of the 
    1465  * max, and whose values are forced to lie between zero and the max, inclusive. 
    1466  * 
    1467  * Since the "level" rarely passes 100 before Morgoth is dead, it is very 
    1468  * rare to get the "full" enchantment on an object, even a deep levels. 
    1469  * 
    1470  * It is always possible (albeit unlikely) to get the "full" enchantment. 
    1471  * 
    1472  * A sample distribution of values from "m_bonus(10, N)" is shown below: 
    1473  * 
    1474  *   N       0     1     2     3     4     5     6     7     8     9    10 
    1475  * ---    ----  ----  ----  ----  ----  ----  ----  ----  ----  ----  ---- 
    1476  *   0   66.37 13.01  9.73  5.47  2.89  1.31  0.72  0.26  0.12  0.09  0.03 
    1477  *   8   46.85 24.66 12.13  8.13  4.20  2.30  1.05  0.36  0.19  0.08  0.05 
    1478  *  16   30.12 27.62 18.52 10.52  6.34  3.52  1.95  0.90  0.31  0.15  0.05 
    1479  *  24   22.44 15.62 30.14 12.92  8.55  5.30  2.39  1.63  0.62  0.28  0.11 
    1480  *  32   16.23 11.43 23.01 22.31 11.19  7.18  4.46  2.13  1.20  0.45  0.41 
    1481  *  40   10.76  8.91 12.80 29.51 16.00  9.69  5.90  3.43  1.47  0.88  0.65 
    1482  *  48    7.28  6.81 10.51 18.27 27.57 11.76  7.85  4.99  2.80  1.22  0.94 
    1483  *  56    4.41  4.73  8.52 11.96 24.94 19.78 11.06  7.18  3.68  1.96  1.78 
    1484  *  64    2.81  3.07  5.65  9.17 13.01 31.57 13.70  9.30  6.04  3.04  2.64 
    1485  *  72    1.87  1.99  3.68  7.15 10.56 20.24 25.78 12.17  7.52  4.42  4.62 
    1486  *  80    1.02  1.23  2.78  4.75  8.37 12.04 27.61 18.07 10.28  6.52  7.33 
    1487  *  88    0.70  0.57  1.56  3.12  6.34 10.06 15.76 30.46 12.58  8.47 10.38 
    1488  *  96    0.27  0.60  1.25  2.28  4.30  7.60 10.77 22.52 22.51 11.37 16.53 
    1489  * 104    0.22  0.42  0.77  1.36  2.62  5.33  8.93 13.05 29.54 15.23 22.53 
    1490  * 112    0.15  0.20  0.56  0.87  2.00  3.83  6.86 10.06 17.89 27.31 30.27 
    1491  * 120    0.03  0.11  0.31  0.46  1.31  2.48  4.60  7.78 11.67 25.53 45.72 
    1492  * 128    0.02  0.01  0.13  0.33  0.83  1.41  3.24  6.17  9.57 14.22 64.07 
    1493  */ 
    1494 static s16b m_bonus(int max, int level) 
    1495 { 
    1496         int bonus, stand, extra, value; 
    1497  
    1498  
    1499         /* Paranoia -- enforce maximal "level" */ 
    1500         if (level > MAX_DEPTH - 1) level = MAX_DEPTH - 1; 
    1501  
    1502  
    1503         /* The "bonus" moves towards the max */ 
    1504         bonus = ((max * level) / MAX_DEPTH); 
    1505  
    1506         /* Hack -- determine fraction of error */ 
    1507         extra = ((max * level) % MAX_DEPTH); 
    1508  
    1509         /* Hack -- simulate floating point computations */ 
    1510         if (rand_int(MAX_DEPTH) < extra) bonus++; 
    1511  
    1512  
    1513         /* The "stand" is equal to one quarter of the max */ 
    1514         stand = (max / 4); 
    1515  
    1516         /* Hack -- determine fraction of error */ 
    1517         extra = (max % 4); 
    1518  
    1519         /* Hack -- simulate floating point computations */ 
    1520         if (rand_int(4) < extra) stand++; 
    1521  
    1522  
    1523         /* Choose an "interesting" value */ 
    1524         value = Rand_normal(bonus, stand); 
    1525  
    1526         /* Enforce the minimum value */ 
    1527         if (value < 0) return (0); 
    1528  
    1529         /* Enforce the maximum value */ 
    1530         if (value > max) return (max); 
    1531  
    1532         /* Result */ 
    1533         return (value); 
    1534 } 
    1535  
    1536  
    1537  
    1538  
    1539 /* 
    1540  * Cheat -- describe a created object for the user 
    1541  */ 
    1542 static void object_mention(const object_type *o_ptr) 
    1543 { 
    1544         char o_name[80]; 
    1545  
    1546         /* Describe */ 
    1547         object_desc_spoil(o_name, sizeof(o_name), o_ptr, FALSE, 0); 
    1548  
    1549         /* Artifact */ 
    1550         if (artifact_p(o_ptr)) 
    1551         { 
    1552                 /* Silly message */ 
    1553                 msg_format("Artifact (%s)", o_name); 
    1554         } 
    1555  
    1556         /* Ego-item */ 
    1557         else if (ego_item_p(o_ptr)) 
    1558         { 
    1559                 /* Silly message */ 
    1560                 msg_format("Ego-item (%s)", o_name); 
    1561         } 
    1562  
    1563         /* Normal item */ 
    1564         else 
    1565         { 
    1566                 /* Silly message */ 
    1567                 msg_format("Object (%s)", o_name); 
    1568         } 
    1569 } 
    1570  
    1571  
    1572 /* 
    1573  * Attempt to change an object into an ego-item -MWK- 
    1574  * Better only called by apply_magic(). 
    1575  * The return value says if we picked a cursed item (if allowed) and is 
    1576  * passed on to a_m_aux1/2(). 
    1577  * If no legal ego item is found, this routine returns 0, resulting in 
    1578  * an unenchanted item. 
    1579  */ 
    1580 static int make_ego_item(object_type *o_ptr, int level, bool only_good) 
    1581 { 
    1582         int i, j; 
    1583  
    1584         int e_idx; 
    1585  
    1586         long value, total; 
    1587  
    1588         ego_item_type *e_ptr; 
    1589  
    1590         alloc_entry *table = alloc_ego_table; 
    1591  
    1592  
    1593         /* Fail if object already is ego or artifact */ 
    1594         if (o_ptr->name1) return (FALSE); 
    1595         if (o_ptr->name2) return (FALSE); 
    1596  
    1597         /* Boost level (like with object base types) */ 
    1598         if (level > 0) 
    1599         { 
    1600                 /* Occasional "boost" */ 
    1601                 if (rand_int(GREAT_EGO) == 0) 
    1602                 { 
    1603                         /* The bizarre calculation again */ 
    1604                         level = 1 + (level * MAX_DEPTH / randint(MAX_DEPTH)); 
    1605                 } 
    1606         } 
    1607  
    1608         /* Reset total */ 
    1609         total = 0L; 
    1610  
    1611         /* Process probabilities */ 
    1612         for (i = 0; i < alloc_ego_size; i++) 
    1613         { 
    1614                 /* Default */ 
    1615                 table[i].prob3 = 0; 
    1616  
    1617                 /* Objects are sorted by depth */ 
    1618                 if (table[i].level > level) continue; 
    1619  
    1620                 /* Get the index */ 
    1621                 e_idx = table[i].index; 
    1622  
    1623                 /* Get the actual kind */ 
    1624                 e_ptr = &e_info[e_idx]; 
    1625  
    1626                 /* If we force good/great, don't create cursed */ 
    1627                 if (only_good && (e_ptr->flags3 & TR3_LIGHT_CURSE)) continue; 
    1628  
    1629                 /* Test if this is a legal ego-item type for this object */ 
    1630                 for (j = 0; j < EGO_TVALS_MAX; j++) 
    1631                 { 
    1632                         /* Require identical base type */ 
    1633                         if (o_ptr->tval == e_ptr->tval[j]) 
    1634                         { 
    1635                                 /* Require sval in bounds, lower */ 
    1636                                 if (o_ptr->sval >= e_ptr->min_sval[j]) 
    1637                                 { 
    1638                                         /* Require sval in bounds, upper */ 
    1639                                         if (o_ptr->sval <= e_ptr->max_sval[j]) 
    1640                                         { 
    1641                                                 /* Accept */ 
    1642                                                 table[i].prob3 = table[i].prob2; 
    1643                                         } 
    1644                                 } 
    1645                         } 
    1646                 } 
    1647  
    1648                 /* Total */ 
    1649                 total += table[i].prob3; 
    1650         } 
    1651  
    1652         /* No legal ego-items -- create a normal unenchanted one */ 
    1653         if (total == 0) return (0); 
    1654  
    1655  
    1656         /* Pick an ego-item */ 
    1657         value = rand_int(total); 
    1658  
    1659         /* Find the object */ 
    1660         for (i = 0; i < alloc_ego_size; i++) 
    1661         { 
    1662                 /* Found the entry */ 
    1663                 if (value < table[i].prob3) break; 
    1664  
    1665                 /* Decrement */ 
    1666                 value = value - table[i].prob3; 
    1667         } 
    1668  
    1669         /* We have one */ 
    1670         e_idx = (byte)table[i].index; 
    1671         o_ptr->name2 = e_idx; 
    1672  
    1673         return ((e_info[e_idx].flags3 & TR3_LIGHT_CURSE) ? -2 : 2); 
    1674 } 
    1675  
    1676  
    1677 /* 
    1678  * Mega-Hack -- Attempt to create one of the "Special Objects". 
    1679  * 
    1680  * We are only called from "make_object()", and we assume that 
    1681  * "apply_magic()" is called immediately after we return. 
    1682  * 
    1683  * Note -- see "make_artifact()" and "apply_magic()". 
    1684  * 
    1685  * We *prefer* to create the special artifacts in order, but this is 
    1686  * normally outweighed by the "rarity" rolls for those artifacts.  The 
    1687  * only major effect of this logic is that the Phial (with rarity one) 
    1688  * is always the first special artifact created. 
    1689  */ 
    1690 static bool make_artifact_special(object_type *o_ptr, int level) 
    1691 { 
    1692         int i; 
    1693  
    1694         int k_idx; 
    1695  
    1696  
    1697         /* No artifacts, do nothing */ 
    1698         if (adult_no_artifacts) return (FALSE); 
    1699  
    1700         /* No artifacts in the town */ 
    1701         if (!p_ptr->depth) return (FALSE); 
    1702  
    1703         /* Check the special artifacts */ 
    1704         for (i = 0; i < ART_MIN_NORMAL; ++i) 
    1705         { 
    1706                 artifact_type *a_ptr = &a_info[i]; 
    1707  
    1708                 /* Skip "empty" artifacts */ 
    1709                 if (!a_ptr->name) continue; 
    1710  
    1711                 /* Cannot make an artifact twice */ 
    1712                 if (a_ptr->cur_num) continue; 
    1713  
    1714                 /* Enforce minimum "depth" (loosely) */ 
    1715                 if (a_ptr->level > p_ptr->depth) 
    1716                 { 
    1717                         /* Get the "out-of-depth factor" */ 
    1718                         int d = (a_ptr->level - p_ptr->depth) * 2; 
    1719  
    1720                         /* Roll for out-of-depth creation */ 
    1721                         if (rand_int(d) != 0) continue; 
    1722                 } 
    1723  
    1724                 /* Artifact "rarity roll" */ 
    1725                 if (rand_int(a_ptr->rarity) != 0) continue; 
    1726  
    1727                 /* Find the base object */ 
    1728                 k_idx = lookup_kind(a_ptr->tval, a_ptr->sval); 
    1729  
    1730                 /* Enforce minimum "object" level (loosely) */ 
    1731                 if (k_info[k_idx].level > level) 
    1732                 { 
    1733                         /* Get the "out-of-depth factor" */ 
    1734                         int d = (k_info[k_idx].level - level) * 5; 
    1735  
    1736                         /* Roll for out-of-depth creation */ 
    1737                         if (rand_int(d) != 0) continue; 
    1738                 } 
    1739  
    1740                 /* Assign the template */ 
    1741                 object_prep(o_ptr, k_idx); 
    1742  
    1743                 /* Mark the item as an artifact */ 
    1744                 o_ptr->name1 = i; 
    1745  
    1746                 /* Success */ 
    1747                 return (TRUE); 
    1748         } 
    1749  
    1750         /* Failure */ 
    1751         return (FALSE); 
    1752 } 
    1753  
    1754  
    1755 /* 
    1756  * Attempt to change an object into an artifact 
    1757  * 
    1758  * This routine should only be called by "apply_magic()" 
    1759  * 
    1760  * Note -- see "make_artifact_special()" and "apply_magic()" 
    1761  */ 
    1762 static bool make_artifact(object_type *o_ptr) 
    1763 { 
    1764         int i; 
    1765  
    1766  
    1767         /* No artifacts, do nothing */ 
    1768         if (adult_no_artifacts) return (FALSE); 
    1769  
    1770         /* No artifacts in the town */ 
    1771         if (!p_ptr->depth) return (FALSE); 
    1772  
    1773         /* Paranoia -- no "plural" artifacts */ 
    1774         if (o_ptr->number != 1) return (FALSE); 
    1775  
    1776         /* Check the artifact list (skip the "specials") */ 
    1777         for (i = ART_MIN_NORMAL; i < z_info->a_max; i++) 
    1778         { 
    1779                 artifact_type *a_ptr = &a_info[i]; 
    1780  
    1781                 /* Skip "empty" items */ 
    1782                 if (!a_ptr->name) continue; 
    1783  
    1784                 /* Cannot make an artifact twice */ 
    1785                 if (a_ptr->cur_num) continue; 
    1786  
    1787                 /* Must have the correct fields */ 
    1788                 if (a_ptr->tval != o_ptr->tval) continue; 
    1789                 if (a_ptr->sval != o_ptr->sval) continue; 
    1790  
    1791                 /* XXX XXX Enforce minimum "depth" (loosely) */ 
    1792                 if (a_ptr->level > p_ptr->depth) 
    1793                 { 
    1794                         /* Get the "out-of-depth factor" */ 
    1795                         int d = (a_ptr->level - p_ptr->depth) * 2; 
    1796  
    1797                         /* Roll for out-of-depth creation */ 
    1798                         if (rand_int(d) != 0) continue; 
    1799                 } 
    1800  
    1801                 /* We must make the "rarity roll" */ 
    1802                 if (rand_int(a_ptr->rarity) != 0) continue; 
    1803  
    1804                 /* Mark the item as an artifact */ 
    1805                 o_ptr->name1 = i; 
    1806  
    1807                 /* Success */ 
    1808                 return (TRUE); 
    1809         } 
    1810  
    1811         /* Failure */ 
    1812         return (FALSE); 
    1813 } 
    1814  
    1815  
    1816  
    1817  
    1818 /* 
    1819  * Apply magic to an item known to be a "weapon" 
    1820  * 
    1821  * Hack -- note special base damage dice boosting 
    1822  * Hack -- note special processing for weapon/digger 
    1823  * Hack -- note special rating boost for dragon scale mail 
    1824  */ 
    1825 static void a_m_aux_1(object_type *o_ptr, int level, int power) 
    1826 { 
    1827         int tohit1 = randint(5) + m_bonus(5, level); 
    1828         int todam1 = randint(5) + m_bonus(5, level); 
    1829  
    1830         int tohit2 = m_bonus(10, level); 
    1831         int todam2 = m_bonus(10, level); 
    1832  
    1833  
    1834         /* Good */ 
    1835         if (power > 0) 
    1836         { 
    1837                 /* Enchant */ 
    1838                 o_ptr->to_h += tohit1; 
    1839                 o_ptr->to_d += todam1; 
    1840  
    1841                 /* Very good */ 
    1842                 if (power > 1) 
    1843                 { 
    1844                         /* Enchant again */ 
    1845                         o_ptr->to_h += tohit2; 
    1846                         o_ptr->to_d += todam2; 
    1847                 } 
    1848         } 
    1849  
    1850         /* Cursed */ 
    1851         else if (power < 0) 
    1852         { 
    1853                 /* Penalize */ 
    1854                 o_ptr->to_h -= tohit1; 
    1855                 o_ptr->to_d -= todam1; 
    1856  
    1857                 /* Very cursed */ 
    1858                 if (power < -1) 
    1859                 { 
    1860                         /* Penalize again */ 
    1861                         o_ptr->to_h -= tohit2; 
    1862                         o_ptr->to_d -= todam2; 
    1863                 } 
    1864  
    1865                 /* Cursed (if "bad") */ 
    1866                 if (o_ptr->to_h + o_ptr->to_d < 0) 
    1867                         o_ptr->flags3 |= TR3_LIGHT_CURSE; 
    1868         } 
    1869  
    1870  
    1871         /* Analyze type */ 
    1872         switch (o_ptr->tval) 
    1873         { 
    1874                 case TV_DIGGING: 
    1875                 { 
    1876                         /* Very bad */ 
    1877                         if (power < -1) 
    1878                         { 
    1879                                 /* Hack -- Horrible digging bonus */ 
    1880                                 o_ptr->pval = 0 - (5 + randint(5)); 
    1881                         } 
    1882  
    1883                         /* Bad */ 
    1884                         else if (power < 0) 
    1885                         { 
    1886                                 /* Hack -- Reverse digging bonus */ 
    1887                                 o_ptr->pval = 0 - (o_ptr->pval); 
    1888                         } 
    1889  
    1890                         break; 
    1891                 } 
    1892  
    1893  
    1894                 case TV_HAFTED: 
    1895                 case TV_POLEARM: 
    1896                 case TV_SWORD: 
    1897                 { 
    1898                         /* Very Good */ 
    1899                         if (power > 1) 
    1900                         { 
    1901                                 /* Hack -- Super-charge the damage dice */ 
    1902                                 while ((o_ptr->dd * o_ptr->ds > 0) && 
    1903                                        (rand_int(10L * o_ptr->dd * o_ptr->ds) == 0)) 
    1904                                 { 
    1905                                         o_ptr->dd++; 
    1906                                 } 
    1907  
    1908                                 /* Hack -- Lower the damage dice */ 
    1909                                 if (o_ptr->dd > 9) o_ptr->dd = 9; 
    1910                         } 
    1911  
    1912                         break; 
    1913                 } 
    1914  
    1915  
    1916                 case TV_BOLT: 
    1917                 case TV_ARROW: 
    1918                 case TV_SHOT: 
    1919                 { 
    1920                         /* Very good */ 
    1921                         if (power > 1) 
    1922                         { 
    1923                                 /* Hack -- super-charge the damage dice */ 
    1924                                 while ((o_ptr->dd * o_ptr->ds > 0) && 
    1925                                        (rand_int(10L * o_ptr->dd * o_ptr->ds) == 0)) 
    1926                                 { 
    1927                                         o_ptr->dd++; 
    1928                                 } 
    1929  
    1930                                 /* Hack -- restrict the damage dice */ 
    1931                                 if (o_ptr->dd > 9) o_ptr->dd = 9; 
    1932                         } 
    1933  
    1934                         break; 
    1935                 } 
    1936         } 
    1937 } 
    1938  
    1939  
    1940 /* 
    1941  * Apply magic to an item known to be "armor" 
    1942  * 
    1943  * Hack -- note special processing for crown/helm 
    1944  * Hack -- note special processing for robe of permanence 
    1945  */ 
    1946 static void a_m_aux_2(object_type *o_ptr, int level, int power) 
    1947 { 
    1948         int toac1 = randint(5) + m_bonus(5, level); 
    1949  
    1950         int toac2 = m_bonus(10, level); 
    1951  
    1952  
    1953         /* Good */ 
    1954         if (power > 0) 
    1955         { 
    1956                 /* Enchant */ 
    1957                 o_ptr->to_a += toac1; 
    1958  
    1959                 /* Very good */ 
    1960                 if (power > 1) 
    1961                 { 
    1962                         /* Enchant again */ 
    1963                         o_ptr->to_a += toac2; 
    1964                 } 
    1965         } 
    1966  
    1967         /* Cursed */ 
    1968         else if (power < 0) 
    1969         { 
    1970                 /* Penalize */ 
    1971                 o_ptr->to_a -= toac1; 
    1972  
    1973                 /* Very cursed */ 
    1974                 if (power < -1) 
    1975                 { 
    1976                         /* Penalize again */ 
    1977                         o_ptr->to_a -= toac2; 
    1978                 } 
    1979  
    1980                 /* Cursed (if "bad") */ 
    1981                 if (o_ptr->to_a < 0) 
    1982                     o_ptr->flags3 |= TR3_LIGHT_CURSE; 
    1983         } 
    1984  
    1985  
    1986         /* Analyze type */ 
    1987         switch (o_ptr->tval) 
    1988         { 
    1989                 case TV_DRAG_ARMOR: 
    1990                 { 
    1991                         /* Rating boost */ 
    1992                         rating += 30; 
    1993  
    1994                         /* Mention the item */ 
    1995                         if (cheat_peek) object_mention(o_ptr); 
    1996  
    1997                         break; 
    1998                 } 
    1999         } 
    2000 } 
    2001  
    2002  
    2003  
    2004 /* 
    2005  * Apply magic to an item known to be a "ring" or "amulet" 
    2006  * 
    2007  * Hack -- note special rating boost for ring of speed 
    2008  * Hack -- note special rating boost for certain amulets 
    2009  * Hack -- note special "pval boost" code for ring of speed 
    2010  * Hack -- note that some items must be cursed (or blessed) 
    2011  */ 
    2012 static void a_m_aux_3(object_type *o_ptr, int level, int power) 
    2013 { 
    2014         /* Apply magic (good or bad) according to type */ 
    2015         switch (o_ptr->tval) 
    2016         { 
    2017                 case TV_RING: 
    2018                 { 
    2019                         /* Analyze */ 
    2020                         switch (o_ptr->sval) 
    2021                         { 
    2022                                 /* Strength, Constitution, Dexterity, Intelligence */ 
    2023                                 case SV_RING_STR: 
    2024                                 case SV_RING_CON: 
    2025                                 case SV_RING_DEX: 
    2026                                 case SV_RING_INT: 
    2027                                 { 
    2028                                         /* Stat bonus */ 
    2029                                         o_ptr->pval = 1 + m_bonus(5, level); 
    2030  
    2031                                         /* Cursed */ 
    2032                                         if (power < 0) 
    2033                                         { 
    2034                                                 /* Broken */ 
    2035                                                 o_ptr->ident |= (IDENT_BROKEN); 
    2036  
    2037                                                 /* Cursed */ 
    2038                                                 o_ptr->flags3 |= TR3_LIGHT_CURSE; 
    2039  
    2040                                                 /* Reverse pval */ 
    2041                                                 o_ptr->pval = 0 - (o_ptr->pval); 
    2042                                         } 
    2043  
    2044                                         break; 
    2045                                 } 
    2046  
    2047                                 /* Ring of Speed! */ 
    2048                                 case SV_RING_SPEED: 
    2049                                 { 
    2050                                         /* Base speed (1 to 10) */ 
    2051                                         o_ptr->pval = randint(5) + m_bonus(5, level); 
    2052  
    2053                                         /* Super-charge the ring */ 
    2054                                         while (rand_int(100) < 50) o_ptr->pval++; 
    2055  
    2056                                         /* Cursed Ring */ 
    2057                                         if (power < 0) 
    2058                                         { 
    2059                                                 /* Broken */ 
    2060                                                 o_ptr->ident |= (IDENT_BROKEN); 
    2061  
    2062                                                 /* Cursed */ 
    2063                                                 o_ptr->flags3 |= TR3_LIGHT_CURSE; 
    2064  
    2065                                                 /* Reverse pval */ 
    2066                                                 o_ptr->pval = 0 - (o_ptr->pval); 
    2067  
    2068                                                 break; 
    2069                                         } 
    2070                                         else 
    2071                                         { 
    2072                                                 /* Rating boost */ 
    2073                                                 rating += 25; 
    2074                                         } 
    2075  
    2076                                         /* Mention the item */ 
    2077                                         if (cheat_peek) object_mention(o_ptr); 
    2078  
    2079                                         break; 
    2080                                 } 
    2081  
    2082                                 /* Searching */ 
    2083                                 case SV_RING_SEARCHING: 
    2084                                 { 
    2085                                         /* Bonus to searching */ 
    2086                                         o_ptr->pval = 1 + m_bonus(5, level); 
    2087  
    2088