Ticket #1693: 0007-Add-ability-to-specify-sval-in-make_object-et.-al.patch

File 0007-Add-ability-to-specify-sval-in-make_object-et.-al.patch, 7.2 KB (added by daniel.santos, 7 years ago)

I'm not so sure on this one and I may implement the raw meat as its own tval (instead of adding it to the FOOD_GOOD group)

  • src/generate.c

    From 08857416d9388ef8d377fe921dbf070da31f75fa Mon Sep 17 00:00:00 2001
    From: Daniel Santos <daniel.santos@pobox.com>
    Date: Sun, 21 Oct 2012 15:39:20 -0500
    Subject: [PATCH v2 07/11] Add ability to specify sval in make_object, et. al.
    
    This probably is not the correct way to go about my changes for meat,
    but it's a first run
    ---
     src/generate.c         |    2 +-
     src/monster/mon-make.c |    2 +-
     src/object/chest.c     |    2 +-
     src/object/obj-make.c  |   17 ++++++++++-------
     src/object/obj-util.c  |    2 +-
     src/object/object.h    |    4 ++--
     src/store.c            |    2 +-
     src/wizard.c           |    2 +-
     8 files changed, 18 insertions(+), 15 deletions(-)
    
    diff --git a/src/generate.c b/src/generate.c
    index 2626c80..3ee5d61 100644
    a b void place_object(struct cave *c, int y, int x, int level, bool good, bool great 
    535535        if (!cave_canputitem(c, y, x)) return; 
    536536 
    537537        object_wipe(&otype); 
    538         if (!make_object(c, &otype, level, good, great, &rating, tval)) return; 
     538        if (!make_object(c, &otype, level, good, great, &rating, tval, 0)) return; 
    539539 
    540540        otype.origin = origin; 
    541541        otype.origin_depth = c->depth; 
  • src/monster/mon-make.c

    diff --git a/src/monster/mon-make.c b/src/monster/mon-make.c
    index 0b4f689..8094140 100644
    a b static bool mon_create_drop(int m_idx, byte origin) 
    621621                if (gold_ok && (!item_ok || (randint0(100) < 50))) { 
    622622                        make_gold(i_ptr, level, SV_GOLD_ANY); 
    623623                } else { 
    624                         if (!make_object(cave, i_ptr, level, good, great, NULL, 0)) continue; 
     624                        if (!make_object(cave, i_ptr, level, good, great, NULL, 0, 0)) continue; 
    625625                } 
    626626 
    627627                i_ptr->origin = origin; 
  • src/object/chest.c

    diff --git a/src/object/chest.c b/src/object/chest.c
    index e10cd2f..87b1c0b 100644
    a b static void chest_death(int y, int x, s16b o_idx) 
    276276 
    277277                /* Otherwise drop an item, as long as it isn't a chest */ 
    278278                else { 
    279                         if (!make_object(cave, i_ptr, value, FALSE, FALSE, NULL, 0)) continue; 
     279                        if (!make_object(cave, i_ptr, value, FALSE, FALSE, NULL, 0, 0)) continue; 
    280280                        if (i_ptr->tval == TV_CHEST) continue; 
    281281                } 
    282282 
  • src/object/obj-make.c

    diff --git a/src/object/obj-make.c b/src/object/obj-make.c
    index b095053..2bb265c 100644
    a b void free_obj_alloc(void) 
    805805/* 
    806806 * Choose an object kind of a given tval given a dungeon level. 
    807807 */ 
    808 static object_kind *get_obj_num_by_kind(int level, bool good, int tval) 
     808static object_kind *get_obj_num_by_kind(int level, bool good, int tval, int sval) 
    809809{ 
    810810        /* This is the base index into obj_alloc for this dlev */ 
    811811        size_t ind, item; 
    812812        u32b value; 
    813813        int total = 0; 
    814814        byte *ojbects = good ? obj_alloc_great : obj_alloc; 
     815        struct object_kind *kind; 
    815816 
    816817        /* Pick an object */ 
    817818        ind = level * z_info->k_max; 
    818819 
    819820        /* Get new total */ 
    820821        for (item = 1; item < z_info->k_max; item++) { 
    821                 if (objkind_byid(item)->tval == tval) { 
     822                kind = objkind_byid(item); 
     823                if (kind->tval == tval && (!sval || kind->sval == sval)) { 
    822824                        total += ojbects[ind + item]; 
    823825                } 
    824826        } 
    static object_kind *get_obj_num_by_kind(int level, bool good, int tval) 
    829831        value = randint0(total); 
    830832         
    831833        for (item = 1; item < z_info->k_max; item++) { 
    832                 if (objkind_byid(item)->tval == tval) { 
     834                kind = objkind_byid(item); 
     835                if (kind->tval == tval && (!sval || kind->sval == sval)) { 
    833836                        if (value < ojbects[ind + item]) break; 
    834837 
    835838                        value -= ojbects[ind + item]; 
    static object_kind *get_obj_num_by_kind(int level, bool good, int tval) 
    845848 * If tval = 0, we can choose an object of any type. 
    846849 * Otherwise we can only choose one of the given tval. 
    847850 */ 
    848 object_kind *get_obj_num(int level, bool good, int tval) 
     851object_kind *get_obj_num(int level, bool good, int tval, int sval) 
    849852{ 
    850853        /* This is the base index into obj_alloc for this dlev */ 
    851854        size_t ind, item; 
    object_kind *get_obj_num(int level, bool good, int tval) 
    866869        ind = level * z_info->k_max; 
    867870         
    868871        if(tval) 
    869                 return get_obj_num_by_kind(level, good, tval); 
     872                return get_obj_num_by_kind(level, good, tval, sval); 
    870873         
    871874 
    872875        if (!good) 
    object_kind *get_obj_num(int level, bool good, int tval) 
    916919 * Returns the whether or not creation worked. 
    917920 */ 
    918921bool make_object(struct cave *c, object_type *j_ptr, int lev, bool good, 
    919         bool great, s32b *value, int tval) 
     922        bool great, s32b *value, int tval, int sval) 
    920923{ 
    921924        int base; 
    922925        object_kind *kind; 
    bool make_object(struct cave *c, object_type *j_ptr, int lev, bool good, 
    936939        base = (good ? (lev + 10) : lev); 
    937940 
    938941        /* Get the object, prep it and apply magic */ 
    939         kind = get_obj_num(base, good || great, tval); 
     942        kind = get_obj_num(base, good || great, tval, sval); 
    940943        if (!kind) return FALSE; 
    941944        object_prep(j_ptr, kind, lev, RANDOMISE); 
    942945        apply_magic(j_ptr, lev, TRUE, good, great); 
  • src/object/obj-util.c

    diff --git a/src/object/obj-util.c b/src/object/obj-util.c
    index f1dcf3f..43c285a 100644
    a b void acquirement(int y1, int x1, int level, int num, bool great) 
    22452245                object_wipe(i_ptr); 
    22462246 
    22472247                /* Make a good (or great) object (if possible) */ 
    2248                 if (!make_object(cave, i_ptr, level, TRUE, great, NULL, 0)) continue; 
     2248                if (!make_object(cave, i_ptr, level, TRUE, great, NULL, 0, 0)) continue; 
    22492249 
    22502250                i_ptr->origin = ORIGIN_ACQUIRE; 
    22512251                i_ptr->origin_depth = p_ptr->depth; 
  • src/object/object.h

    diff --git a/src/object/object.h b/src/object/object.h
    index fa4b1c2..b443c22 100644
    a b void object_info_chardump(ang_file *f, const object_type *o_ptr, int indent, int 
    612612/* obj-make.c */ 
    613613void free_obj_alloc(void); 
    614614bool init_obj_alloc(void); 
    615 object_kind *get_obj_num(int level, bool good, int tval); 
     615object_kind *get_obj_num(int level, bool good, int tval, int sval); 
    616616void object_prep(object_type *o_ptr, struct object_kind *kind, int lev, aspect rand_aspect); 
    617617s16b apply_magic(object_type *o_ptr, int lev, bool okay, bool good, bool great); 
    618 bool make_object(struct cave *c, object_type *j_ptr, int lev, bool good, bool great, s32b *value, int tval); 
     618bool make_object(struct cave *c, object_type *j_ptr, int lev, bool good, bool great, s32b *value, int tval, int sval); 
    619619void make_gold(object_type *j_ptr, int lev, int coin_type); 
    620620void copy_artifact_data(object_type *o_ptr, const artifact_type *a_ptr); 
    621621void ego_apply_magic(object_type *o_ptr, int level); 
  • src/store.c

    diff --git a/src/store.c b/src/store.c
    index d711465..6f4ee6b 100644
    a b static bool store_create_random(struct store *store) 
    13641364 
    13651365                /* Black Markets have a random object, of a given level */ 
    13661366                if (store->sidx == STORE_B_MARKET) 
    1367                         kind = get_obj_num(level, FALSE, 0); 
     1367                        kind = get_obj_num(level, FALSE, 0, 0); 
    13681368                else 
    13691369                        kind = store_get_choice(store); 
    13701370 
  • src/wizard.c

    diff --git a/src/wizard.c b/src/wizard.c
    index 5733e71..2a4feb3 100644
    a b static void wiz_statistics(object_type *o_ptr, int level) 
    881881                        object_wipe(i_ptr); 
    882882 
    883883                        /* Create an object */ 
    884                         make_object(cave, i_ptr, level, good, great, NULL, 0); 
     884                        make_object(cave, i_ptr, level, good, great, NULL, 0, 0); 
    885885 
    886886                        /* Allow multiple artifacts, because breaking the game is fine here */ 
    887887                        if (o_ptr->artifact) o_ptr->artifact->created = FALSE;