Changeset 449

Show
Ignore:
Timestamp:
08/05/07 19:05:44 (1 year ago)
Author:
ctate
Message:

Eliminate the object_level global. Target depth for object creation is now passed as a parameter, typically derived from the player's current depth.

Cleanup aimed broadly at #55 - unit testing as a development goal.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/cmd2.c

    r446 r449  
    11341134                        { 
    11351135                                /* Place some gold */ 
    1136                                 place_gold(y, x); 
     1136                                place_gold(y, x, p_ptr->depth); 
    11371137 
    11381138                                /* Message */ 
     
    11781178                        { 
    11791179                                /* Create a simple object */ 
    1180                                 place_object(y, x, FALSE, FALSE); 
     1180                                place_object(y, x, p_ptr->depth, FALSE, FALSE); 
    11811181 
    11821182                                /* Observe the new object */ 
  • trunk/src/defines.h

    r448 r449  
    256256 
    257257/* 
    258  * There is a 1/20 (5%) chance of inflating the requested object_level 
     258 * There is a 1/20 (5%) chance of inflating the requested object level 
    259259 * during the creation of an object (see "get_obj_num()" in "object.c"). 
    260260 * Lower values yield better objects more often. 
  • trunk/src/dungeon.c

    r399 r449  
    16341634        /* Reset the monster generation level */ 
    16351635        monster_level = p_ptr->depth; 
    1636  
    1637         /* Reset the object generation level */ 
    1638         object_level = p_ptr->depth; 
    16391636 
    16401637        /* Main loop */ 
  • trunk/src/effects.c

    r431 r449  
    821821                case EF_ACQUIRE: 
    822822                { 
    823                         acquirement(py, px, 1, TRUE); 
     823                        acquirement(py, px, p_ptr->depth, 1, TRUE); 
    824824                        *ident = TRUE; 
    825825                        return TRUE; 
     
    828828                case EF_ACQUIRE2: 
    829829                { 
    830                         acquirement(py, px, randint(2) + 1, TRUE); 
     830                        acquirement(py, px, p_ptr->depth, randint(2) + 1, TRUE); 
    831831                        *ident = TRUE; 
    832832                        return TRUE; 
  • trunk/src/externs.h

    r443 r449  
    108108extern u32b seed_town; 
    109109extern s16b num_repro; 
    110 extern s16b object_level; 
    111110extern s16b monster_level; 
    112111extern char summon_kin_type; 
     
    448447extern s16b floor_carry(int y, int x, object_type *j_ptr); 
    449448extern void drop_near(object_type *j_ptr, int chance, int y, int x); 
    450 extern void acquirement(int y1, int x1, int num, bool great); 
    451 extern void place_object(int y, int x, bool good, bool great); 
    452 extern void place_gold(int y, int x); 
     449extern void acquirement(int y1, int x1, int level, int num, bool great); 
     450extern void place_object(int y, int x, int level, bool good, bool great); 
     451extern void place_gold(int y, int x, int level); 
    453452extern void pick_trap(int y, int x); 
    454453extern void place_trap(int y, int x); 
  • trunk/src/generate.c

    r307 r449  
    12141214 * Allocates some objects (using "place" and "type") 
    12151215 */ 
    1216 static void alloc_object(int set, int typ, int num
     1216static void alloc_object(int set, int typ, int num, int depth
    12171217{ 
    12181218        int y, x, k; 
     
    12631263                        case ALLOC_TYP_GOLD: 
    12641264                        { 
    1265                                 place_gold(y, x); 
     1265                                place_gold(y, x, depth); 
    12661266                                break; 
    12671267                        } 
     
    12691269                        case ALLOC_TYP_OBJECT: 
    12701270                        { 
    1271                                 place_object(y, x, FALSE, FALSE); 
     1271                                place_object(y, x, depth, FALSE, FALSE); 
    12721272                                break; 
    12731273                        } 
     
    16201620                if (rand_int(100) < 67) 
    16211621                { 
    1622                         place_object(y, x, FALSE, FALSE); 
     1622                        place_object(y, x, depth, FALSE, FALSE); 
    16231623                } 
    16241624 
     
    16261626                else 
    16271627                { 
    1628                         place_gold(y, x); 
     1628                        place_gold(y, x, depth); 
    16291629                } 
    16301630 
     
    24332433                        generate_hole(y1b, x1a, y2b, x2a, FEAT_SECRET); 
    24342434 
    2435                         /* Place a treasure in the vault */ 
    2436                         object_level = p_ptr->depth + 2; 
    2437                         place_object(y0, x0, FALSE, FALSE); 
    2438                         object_level = p_ptr->depth; 
     2435                        /* Place a slightly out-of-depth treasure in the vault */ 
     2436                        place_object(y0, x0, p_ptr->depth + 2, FALSE, FALSE); 
    24392437 
    24402438                        /* Let's guard the treasure well */ 
     
    25712569                        spread_monsters('\0', p_ptr->depth + 2, 4, y0, x0, 2, 6); 
    25722570 
    2573                         /* Object (80%) */ 
     2571                        /* Object (80%), slightly out-of-depth value */ 
    25742572                        if (rand_int(100) < 80) 
    25752573                        { 
    2576                                 object_level = p_ptr->depth + 2; 
    2577                                 place_object(y0, x0, FALSE, FALSE); 
    2578                                 object_level = p_ptr->depth; 
     2574                                place_object(y0, x0, p_ptr->depth + 2, FALSE, FALSE); 
    25792575                        } 
    25802576 
     
    26392635 
    26402636                                /* Objects */ 
    2641                                 if (rand_int(3) == 0) place_object(y0, x0 - 2, FALSE, FALSE); 
    2642                                 if (rand_int(3) == 0) place_object(y0, x0 + 2, FALSE, FALSE); 
     2637                                if (rand_int(3) == 0) 
     2638                                        place_object(y0, x0 - 2, p_ptr->depth, FALSE, FALSE); 
     2639                                if (rand_int(3) == 0) 
     2640                                        place_object(y0, x0 + 2, p_ptr->depth, FALSE, FALSE); 
    26432641                        } 
    26442642 
     
    30273025                                        if (rand_int(100) < 75) 
    30283026                                        { 
    3029                                                 place_object(y, x, FALSE, FALSE); 
     3027                                                place_object(y, x, p_ptr->depth, FALSE, FALSE); 
    30303028                                        } 
    30313029                                        else 
     
    30883086                                        place_monster(y, x, TRUE, TRUE); 
    30893087                                        monster_level = p_ptr->depth; 
    3090                                         object_level = p_ptr->depth + 7; 
    3091                                         place_object(y, x, TRUE, FALSE); 
    3092                                         object_level = p_ptr->depth; 
     3088                                        place_object(y, x, p_ptr->depth + 7, TRUE, FALSE); 
    30933089                                        break; 
    30943090                                } 
     
    31003096                                        place_monster(y, x, TRUE, TRUE); 
    31013097                                        monster_level = p_ptr->depth; 
    3102                                         object_level = p_ptr->depth + 20; 
    3103                                         place_object(y, x, TRUE, TRUE); 
    3104                                         object_level = p_ptr->depth; 
     3098                                        place_object(y, x, p_ptr->depth + 20, TRUE, TRUE); 
    31053099                                        break; 
    31063100                                } 
     
    31173111                                        if (rand_int(100) < 50) 
    31183112                                        { 
    3119                                                 object_level = p_ptr->depth + 7; 
    3120                                                 place_object(y, x, FALSE, FALSE); 
    3121                                                 object_level = p_ptr->depth; 
     3113                                                /* Moderately out-of-depth item */ 
     3114                                                place_object(y, x, p_ptr->depth + 7, FALSE, FALSE); 
    31223115                                        } 
    31233116                                        break; 
     
    47444737 
    47454738        /* Put some rubble in corridors */ 
    4746         alloc_object(ALLOC_SET_CORR, ALLOC_TYP_RUBBLE, randint(k)); 
     4739        alloc_object(ALLOC_SET_CORR, ALLOC_TYP_RUBBLE, randint(k), p_ptr->depth); 
    47474740 
    47484741        /* Place some traps in the dungeon */ 
    4749         alloc_object(ALLOC_SET_BOTH, ALLOC_TYP_TRAP, randint(k)); 
     4742        alloc_object(ALLOC_SET_BOTH, ALLOC_TYP_TRAP, randint(k), p_ptr->depth); 
    47504743 
    47514744 
     
    48034796 
    48044797        /* Put some objects in rooms */ 
    4805         alloc_object(ALLOC_SET_ROOM, ALLOC_TYP_OBJECT, Rand_normal(DUN_AMT_ROOM, 3)); 
     4798        alloc_object(ALLOC_SET_ROOM, 
     4799                ALLOC_TYP_OBJECT, Rand_normal(DUN_AMT_ROOM, 3), 
     4800                p_ptr->depth); 
    48064801 
    48074802        /* Put some objects/gold in the dungeon */ 
    4808         alloc_object(ALLOC_SET_BOTH, ALLOC_TYP_OBJECT, Rand_normal(DUN_AMT_ITEM, 3)); 
    4809         alloc_object(ALLOC_SET_BOTH, ALLOC_TYP_GOLD, Rand_normal(DUN_AMT_GOLD, 3)); 
     4803        alloc_object(ALLOC_SET_BOTH, 
     4804                ALLOC_TYP_OBJECT, Rand_normal(DUN_AMT_ITEM, 3), 
     4805                p_ptr->depth); 
     4806        alloc_object(ALLOC_SET_BOTH, 
     4807                ALLOC_TYP_GOLD, Rand_normal(DUN_AMT_GOLD, 3), 
     4808                p_ptr->depth); 
    48104809} 
    48114810 
     
    51165115                /* Reset the monster generation level */ 
    51175116                monster_level = p_ptr->depth; 
    5118  
    5119                 /* Reset the object generation level */ 
    5120                 object_level = p_ptr->depth; 
    51215117 
    51225118                /* Nothing special here yet */ 
  • trunk/src/object2.c

    r446 r449  
    660660 
    661661        size_t item; 
    662  
    663662        u32b value; 
    664663 
     
    15841583 * an unenchanted item. 
    15851584 */ 
    1586 static int make_ego_item(object_type *o_ptr, bool only_good) 
    1587 { 
    1588         int i, j, level
     1585static int make_ego_item(object_type *o_ptr, int level, bool only_good) 
     1586{ 
     1587        int i, j
    15891588 
    15901589        int e_idx; 
     
    16001599        if (o_ptr->name1) return (FALSE); 
    16011600        if (o_ptr->name2) return (FALSE); 
    1602  
    1603         level = object_level; 
    16041601 
    16051602        /* Boost level (like with object base types) */ 
     
    16961693 * is always the first special artifact created. 
    16971694 */ 
    1698 static bool make_artifact_special(object_type *o_ptr
     1695static bool make_artifact_special(object_type *o_ptr, int level
    16991696{ 
    17001697        int i; 
     
    17371734 
    17381735                /* Enforce minimum "object" level (loosely) */ 
    1739                 if (k_info[k_idx].level > object_level) 
     1736                if (k_info[k_idx].level > level) 
    17401737                { 
    17411738                        /* Get the "out-of-depth factor" */ 
    1742                         int d = (k_info[k_idx].level - object_level) * 5; 
     1739                        int d = (k_info[k_idx].level - level) * 5; 
    17431740 
    17441741                        /* Roll for out-of-depth creation */ 
     
    26092606                                int ego_power; 
    26102607 
    2611                                 ego_power = make_ego_item(o_ptr, (bool)(good || great)); 
     2608                                ego_power = make_ego_item(o_ptr, lev, (bool)(good || great)); 
    26122609 
    26132610                                if (ego_power) power = ego_power; 
     
    26332630                                int ego_power; 
    26342631 
    2635                                 ego_power = make_ego_item(o_ptr, (bool)(good || great)); 
     2632                                ego_power = make_ego_item(o_ptr, lev, (bool)(good || great)); 
    26362633 
    26372634                                if (ego_power) power = ego_power; 
     
    26552652                        if ((power > 1) || (power < -1)) 
    26562653                        { 
    2657                                 make_ego_item(o_ptr, (bool)(good || great)); 
     2654                                make_ego_item(o_ptr, lev, (bool)(good || great)); 
    26582655                        } 
    26592656 
     
    28842881 
    28852882        /* Generate a special artifact, or a normal object */ 
    2886         if ((rand_int(prob) != 0) || !make_artifact_special(j_ptr)) 
     2883        if ((rand_int(prob) != 0) || !make_artifact_special(j_ptr, lev)) 
    28872884        { 
    28882885                int k_idx; 
     
    33103307 * Scatter some "great" objects near the player 
    33113308 */ 
    3312 void acquirement(int y1, int x1, int num, bool great) 
     3309void acquirement(int y1, int x1, int level, int num, bool great) 
    33133310{ 
    33143311        object_type *i_ptr; 
     
    33253322 
    33263323                /* Make a good (or great) object (if possible) */ 
    3327                 if (!make_object(i_ptr, object_level, TRUE, great)) continue; 
     3324                if (!make_object(i_ptr, level, TRUE, great)) continue; 
    33283325                i_ptr->origin = ORIGIN_ACQUIRE; 
    33293326                i_ptr->origin_depth = p_ptr->depth; 
     
    33383335 * Attempt to place an object (normal or good/great) at the given location. 
    33393336 */ 
    3340 void place_object(int y, int x, bool good, bool great) 
     3337void place_object(int y, int x, int level, bool good, bool great) 
    33413338{ 
    33423339        object_type *i_ptr; 
     
    33563353 
    33573354        /* Make an object (if possible) */ 
    3358         if (make_object(i_ptr, object_level, good, great)) 
     3355        if (make_object(i_ptr, level, good, great)) 
    33593356        { 
    33603357                i_ptr->origin = ORIGIN_FLOOR; 
     
    33743371 * Places a treasure (Gold or Gems) at given location 
    33753372 */ 
    3376 void place_gold(int y, int x
     3373void place_gold(int y, int x, int level
    33773374{ 
    33783375        object_type *i_ptr; 
     
    33923389 
    33933390        /* Make some gold */ 
    3394         if (make_gold(i_ptr, object_level)) 
     3391        if (make_gold(i_ptr, level)) 
    33953392        { 
    33963393                /* Give it to the floor */ 
  • trunk/src/spells1.c

    r433 r449  
    7171void teleport_away(int m_idx, int dis) 
    7272{ 
    73         int ny, nx, oy, ox, d, i, min; 
     73        int ny = 0, nx = 0, oy, ox, d, i, min; 
    7474 
    7575        bool look = TRUE; 
     
    16301630 
    16311631                                /* Place some gold */ 
    1632                                 place_gold(y, x); 
     1632                                place_gold(y, x, p_ptr->depth); 
    16331633                        } 
    16341634 
     
    16771677 
    16781678                                        /* Place gold */ 
    1679                                         place_object(y, x, FALSE, FALSE); 
     1679                                        place_object(y, x, p_ptr->depth, FALSE, FALSE); 
    16801680                                } 
    16811681                        } 
  • trunk/src/variable.c

    r410 r449  
    7373 
    7474s16b num_repro;                 /* Current reproducer count */ 
    75 s16b object_level;              /* Current object creation level */ 
    7675s16b monster_level;             /* Current monster creation level */ 
    7776 
  • trunk/src/wizard2.c

    r446 r449  
    665665 * statistics on item creation relative to the initial item. 
    666666 */ 
    667 static void wiz_statistics(object_type *o_ptr
     667static void wiz_statistics(object_type *o_ptr, int level
    668668{ 
    669669        long i, matches, better, worse, other; 
     
    762762 
    763763                        /* Create an object */ 
    764                         make_object(i_ptr, object_level, good, great); 
     764                        make_object(i_ptr, level, good, great); 
    765765 
    766766 
     
    938938                if (ch == 's' || ch == 'S') 
    939939                { 
    940                         wiz_statistics(i_ptr); 
     940                        wiz_statistics(i_ptr, p_ptr->depth); 
    941941                } 
    942942 
     
    15671567                { 
    15681568                        if (p_ptr->command_arg <= 0) p_ptr->command_arg = 1; 
    1569                         acquirement(py, px, p_ptr->command_arg, FALSE); 
     1569                        acquirement(py, px, p_ptr->depth, p_ptr->command_arg, FALSE); 
    15701570                        break; 
    15711571                } 
     
    16681668                { 
    16691669                        if (p_ptr->command_arg <= 0) p_ptr->command_arg = 1; 
    1670                         acquirement(py, px, p_ptr->command_arg, TRUE); 
     1670                        acquirement(py, px, p_ptr->depth, p_ptr->command_arg, TRUE); 
    16711671                        break; 
    16721672                } 
  • trunk/src/xtra2.c

    r443 r449  
    11571157void monster_death(int m_idx) 
    11581158{ 
    1159         int i, j, y, x
     1159        int i, j, y, x, level
    11601160 
    11611161        int dump_item = 0; 
     
    12741274        coin_type = force_coin; 
    12751275 
    1276         /* Average dungeon and monster levels */ 
    1277         object_level = (p_ptr->depth + r_ptr->level) / 2; 
     1276        /* Average monster level and current depth */ 
     1277        level = (p_ptr->depth + r_ptr->level) / 2; 
    12781278 
    12791279        /* Drop some objects */ 
     
    12901290                { 
    12911291                        /* Make some gold */ 
    1292                         if (!make_gold(i_ptr, object_level)) continue; 
     1292                        if (!make_gold(i_ptr, level)) continue; 
    12931293 
    12941294                        /* Assume seen XXX XXX XXX */ 
     
    13001300                { 
    13011301                        /* Make an object */ 
    1302                         if (!make_object(i_ptr, object_level, good, great)) continue; 
     1302                        if (!make_object(i_ptr, level, good, great)) continue; 
    13031303 
    13041304                        /* Assume seen XXX XXX XXX */ 
     
    13151315        } 
    13161316 
    1317         /* Reset the object level */ 
    1318         object_level = p_ptr->depth; 
    1319  
    13201317        /* Reset "coin" type */ 
    13211318        coin_type = 0; 
    13221319 
    1323  
    13241320        /* Take note of any dropped treasure */ 
    13251321        if (visible && (dump_item || dump_gold)) 
     
    13291325        } 
    13301326 
    1331  
    13321327        /* Update monster list window */ 
    13331328        p_ptr->window |= PW_MONLIST; 
     
    13351330        /* Only process "Quest Monsters" */ 
    13361331        if (!(r_ptr->flags1 & (RF1_QUESTOR))) return; 
    1337  
    13381332 
    13391333        /* Hack -- Mark quests as complete */