Changeset 452

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

* Fix off-by-one in 'level' bounds check in get_obj_num(): MAX_O_DEPTH is now the largest legal object level, not one greater. Allowed object levels are now in [0, MAX_O_DEPTH]. Also, get_obj_num() now calculates the creation index *after* bounds-checking the level, not before. This fixes #324.

* Return code (removed in [410]) that sometimes chooses to allow out-of-depth object kinds. This may be responsible for the scarcity of high-powered objects and artifacts ad modest depths since that change.

Files:

Legend:

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

    r449 r452  
    614614 
    615615        /* Allocate and wipe */ 
    616         obj_alloc = C_ZNEW(MAX_O_DEPTH * k_max, byte); 
     616        obj_alloc = C_ZNEW((MAX_O_DEPTH + 1) * k_max, byte); 
    617617 
    618618        /* Wipe the totals */ 
    619         C_WIPE(obj_total, MAX_O_DEPTH, u32b); 
     619        C_WIPE(obj_total, MAX_O_DEPTH + 1, u32b); 
    620620 
    621621 
     
    632632 
    633633                /* Go through all the dungeon levels */ 
    634                 for (lev = 0; lev < MAX_O_DEPTH; lev++) 
     634                for (lev = 0; lev <= MAX_O_DEPTH; lev++) 
    635635                { 
    636636                        int rarity = k_ptr->alloc_prob; 
     
    657657{ 
    658658        /* This is the base index into obj_alloc for this dlev */ 
    659         size_t ind = level * z_info->k_max; 
    660  
    661         size_t item; 
     659        size_t ind, item; 
    662660        u32b value; 
    663661 
     662        /* Occasional level boost */ 
     663        if ((level > 0) && !rand_int(GREAT_OBJ)) 
     664        {  
     665                /* What a bizarre calculation */  
     666                level = 1 + (level * MAX_O_DEPTH / randint(MAX_O_DEPTH));  
     667        } 
    664668 
    665669        /* Paranoia */ 
     
    667671        level = MAX(level, 0); 
    668672 
    669  
    670673        /* Pick an object */ 
     674        ind = level * z_info->k_max; 
    671675        value = rand_int(obj_total[level]); 
    672676        for (item = 1; item < z_info->k_max; item++)