Thread: Help me shorten this code plz.

  1. #1
    Registered User
    Join Date
    Apr 2020
    Posts
    4

    Help me shorten this code plz.

    Code:
    ch_ret tes_equipment_thief(int sn, int level, CHAR_DATA * ch, void *vo)
    {
      OBJ_DATA *weapon;
      OBJ_DATA *cuirass;
      OBJ_DATA *greaves;
      OBJ_DATA *helm;
      OBJ_DATA *gauntlets;
      OBJ_DATA *boots;
      OBJ_DATA *pauldrons;
    
    
      int random_cuirass;
      random_cuirass = number_range(1,18);
    
    
      if(get_eq_char(ch, WEAR_BODY) == NULL)
        {
        if(random_cuirass == 1)
          {cuirass = create_object(get_obj_index(OBJ_EQ_BOILED_NETCH_LEATHER_CUIRASS), 0);}
    
    
        if(random_cuirass == 2)
          {cuirass = create_object(get_obj_index(OBJ_EQ_NETCH_LEATHER_CUIRASS), 0);}
    
    
        if(random_cuirass == 3)
          {cuirass = create_object(get_obj_index(OBJ_EQ_NORDIC_BEARSKIN_CUIRASS), 0);}
    
    
        if(random_cuirass == 4)
          {cuirass = create_object(get_obj_index(OBJ_EQ_MITHRIL_CUIRASS), 0);}
    
    
        if(random_cuirass == 5)
          {cuirass = create_object(get_obj_index(OBJ_EQ_GLASS_CUIRASS), 0);}
    
    
        if(random_cuirass == 6)
          {cuirass = create_object(get_obj_index(OBJ_EQ_IMPERIAL_STUDDED_LEATHER_CUIRASS), 0);}
    
    
        if(random_cuirass == 7)
          {cuirass = create_object(get_obj_index(OBJ_EQ_CHITIN_CUIRASS), 0);}
    
    
        if(random_cuirass == 8)
          {cuirass = create_object(get_obj_index(OBJ_EQ_FUR_CUIRASS), 0);}
    
    
        if(random_cuirass == 9)
          {cuirass = create_object(get_obj_index(OBJ_EQ_LEATHER_CUIRASS), 0);}
    
    
        if(random_cuirass == 10)
          {cuirass = create_object(get_obj_index(OBJ_EQ_LEATHER_CUIRASS), 0);}
    
    
        if(random_cuirass == 11)
          {cuirass = create_object(get_obj_index(OBJ_EQ_COMMON_ROBE), 0);}
    
    
        if(random_cuirass == 12)
          {cuirass = create_object(get_obj_index(OBJ_EQ_EXPENSIVE_ROBE), 0);}
    
    
        if(random_cuirass == 13)
          {cuirass = create_object(get_obj_index(OBJ_EQ_EXTRAVAGANT_ROBE), 0);}
    
    
        if(random_cuirass == 14)
          {cuirass = create_object(get_obj_index(OBJ_EQ_EXQUISITE_ROBE), 0);}
    
    
        if(random_cuirass == 15)
          {cuirass = create_object(get_obj_index(OBJ_EQ_COMMON_SHIRT), 0);}
    
    
        if(random_cuirass == 16)
          {cuirass = create_object(get_obj_index(OBJ_EQ_EXPENSIVE_SHIRT), 0);}
    
    
        if(random_cuirass == 17)
          {cuirass = create_object(get_obj_index(OBJ_EQ_EXTRAVAGANT_SHIRT), 0);}
    
    
        if(random_cuirass == 18)
          {cuirass = create_object(get_obj_index(OBJ_EQ_EXQUISITE_SHIRT), 0);}
    
    
        obj_to_char(cuirass, ch);
        equip_char(ch, cuirass, WEAR_BODY);
        }
      
      int random_greaves;
      random_greaves = number_range(1,13);
    
    
      if(get_eq_char(ch, WEAR_LEGS) == NULL)
        {
        if(random_greaves == 1)
          {greaves = create_object(get_obj_index(OBJ_EQ_FUR_GREAVES), 0);}
    
    
        if(random_greaves == 2)
          {greaves = create_object(get_obj_index(OBJ_EQ_NETCH_LEATHER_GREAVES), 0);}
    
    
        if(random_greaves == 3)
          {greaves = create_object(get_obj_index(OBJ_EQ_CHITIN_GREAVES), 0);}
    
    
        if(random_greaves == 4)
          {greaves = create_object(get_obj_index(OBJ_EQ_GLASS_GREAVES), 0);}
    
    
        if(random_greaves == 5)
          {greaves = create_object(get_obj_index(OBJ_EQ_MITHRIL_GREAVES), 0);}
    
    
        if(random_greaves == 6)
          {greaves = create_object(get_obj_index(OBJ_EQ_LEATHER_GREAVES), 0);}
    
    
        if(random_greaves == 7)
          {greaves = create_object(get_obj_index(OBJ_EQ_COMMON_PANTS), 0);}
    
    
        if(random_greaves == 8)
          {greaves = create_object(get_obj_index(OBJ_EQ_EXPENSIVE_PANTS), 0);}
    
    
        if(random_greaves == 9)
          {greaves = create_object(get_obj_index(OBJ_EQ_EXTRAVAGANT_PANTS), 0);}
    
    
        if(random_greaves == 10)
          {greaves = create_object(get_obj_index(OBJ_EQ_EXQUISITE_PANTS), 0);}
    
    
        if(random_greaves == 11)
          {greaves = create_object(get_obj_index(OBJ_EQ_IMPERIAL_TEMPLAR_SKIRT), 0);}
    
    
        if(random_greaves == 12)
          {greaves = create_object(get_obj_index(OBJ_EQ_IMPERIAL_SKIRT), 0);}
    
    
        if(random_greaves == 13)
          {greaves = create_object(get_obj_index(OBJ_EQ_COMMON_SKIRT), 0);}
    
    
        obj_to_char(greaves, ch);
        equip_char(ch, greaves, WEAR_LEGS);
        }
    
    
      int random_helm;
      random_helm = number_range(1,14);
    
    
      if(get_eq_char(ch, WEAR_HEAD) == NULL)
        {
        if(random_helm == 1)
          {helm = create_object(get_obj_index(OBJ_EQ_CHITIN_MASK_HELM), 0);}
    
    
        if(random_helm == 2)
          {helm = create_object(get_obj_index(OBJ_EQ_CHITIN_HELM), 0);}
    
    
        if(random_helm == 3)
          {helm = create_object(get_obj_index(OBJ_EQ_MITHRIL_HELM), 0);}
    
    
        if(random_helm == 4)
          {helm = create_object(get_obj_index(OBJ_EQ_GLASS_HELM), 0);}
    
    
        if(random_helm == 5)
          {helm = create_object(get_obj_index(OBJ_EQ_NETCH_LEATHER_HELM), 0);}
    
    
        if(random_helm == 6)
          {helm = create_object(get_obj_index(OBJ_EQ_COLOVIAN_FUR_HELM), 0);}
    
    
        if(random_helm == 7)
          {helm = create_object(get_obj_index(OBJ_EQ_MORAG_TONG_HELM), 0);}
    
    
        if(random_helm == 8)
          {helm = create_object(get_obj_index(OBJ_EQ_REDORAN_WATCHMAN_HELM), 0);}
    
    
        if(random_helm == 9)
          {helm = create_object(get_obj_index(OBJ_EQ_TELVANI_CEPHALOPOD_HELM), 0);}
    
    
        if(random_helm == 10)
          {helm = create_object(get_obj_index(OBJ_EQ_TELVANI_DUST_ADEPT_HELM), 0);}
    
    
        if(random_helm == 11)
          {helm = create_object(get_obj_index(OBJ_EQ_TELVANI_MOLE_CRAB_HELM), 0);}
    
    
        if(random_helm == 12)
          {helm = create_object(get_obj_index(OBJ_EQ_BOILED_NETCH_LEATHER_HELM), 0);}
    
    
        if(random_helm == 13)
          {helm = create_object(get_obj_index(OBJ_EQ_LEATHER_HELM), 0);}
    
    
        if(random_helm == 14)
          {helm = create_object(get_obj_index(OBJ_EQ_FUR_HELM), 0);}
    
    
        obj_to_char(helm, ch);
        equip_char(ch, helm, WEAR_HEAD);
        }
      int random_gauntlets;
      random_gauntlets = number_range(1,11);
    
    
      if(get_eq_char(ch, WEAR_HANDS) == NULL)
        {
        if(random_gauntlets == 1)
          {gauntlets = create_object(get_obj_index(OBJ_EQ_LEATHER_GAUNTLETS), 0);}
    
    
        if(random_gauntlets == 2)
          {gauntlets = create_object(get_obj_index(OBJ_EQ_FUR_GAUNTLETS), 0);}
    
    
        if(random_gauntlets == 3)
          {gauntlets = create_object(get_obj_index(OBJ_EQ_MITHRIL_GAUNTLETS), 0);}
    
    
        if(random_gauntlets == 4)
          {gauntlets = create_object(get_obj_index(OBJ_EQ_GLASS_GAUNTLETS), 0);}
    
    
        if(random_gauntlets == 5)
          {gauntlets = create_object(get_obj_index(OBJ_EQ_CHITIN_GAUNTLETS), 0);}
    
    
        if(random_gauntlets == 6)
          {gauntlets = create_object(get_obj_index(OBJ_EQ_NETCH_LEATHER_GAUNTLETS), 0);}
    
    
        if(random_gauntlets == 7)
          {gauntlets = create_object(get_obj_index(OBJ_EQ_LEATHER_BRACERS), 0);}
    
    
        if(random_gauntlets == 8)
          {gauntlets = create_object(get_obj_index(OBJ_EQ_CLOTH_BRACERS), 0);}
    
    
        if(random_gauntlets == 9)
          {gauntlets = create_object(get_obj_index(OBJ_EQ_COMMON_GLOVES), 0);}
    
    
        if(random_gauntlets == 10)
          {gauntlets = create_object(get_obj_index(OBJ_EQ_EXPENSIVE_GLOVES), 0);}
    
    
        if(random_gauntlets == 11)
          {gauntlets = create_object(get_obj_index(OBJ_EQ_EXTRAVAGANT_GLOVES), 0);}
    
    
        obj_to_char(gauntlets, ch);
        equip_char(ch, gauntlets, WEAR_HANDS);
        }
      
      int random_boots;
      random_boots = number_range(1,10);
    
    
      if(get_eq_char(ch, WEAR_FEET) == NULL)
        {
        if(random_boots == 1)
          {boots = create_object(get_obj_index(OBJ_EQ_CHITIN_BOOTS), 0);}
    
    
        if(random_boots == 2)
          {boots = create_object(get_obj_index(OBJ_EQ_GLASS_BOOTS), 0);}
    
    
        if(random_boots == 3)
          {boots = create_object(get_obj_index(OBJ_EQ_MITHRIL_BOOTS), 0);}
    
    
        if(random_boots == 4)
          {boots = create_object(get_obj_index(OBJ_EQ_FUR_BOOTS), 0);}
    
    
        if(random_boots == 5)
          {boots = create_object(get_obj_index(OBJ_EQ_LEATHER_BOOTS), 0);}
    
    
        if(random_boots == 6)
          {boots = create_object(get_obj_index(OBJ_EQ_NETCH_LEATHER_BOOTS), 0);}
    
    
        if(random_boots == 7)
          {boots = create_object(get_obj_index(OBJ_EQ_COMMON_SHOES), 0);}
    
    
        if(random_boots == 8)
          {boots = create_object(get_obj_index(OBJ_EQ_EXPENSIVE_SHOES), 0);}
    
    
        if(random_boots == 9)
          {boots = create_object(get_obj_index(OBJ_EQ_EXTRAVAGANT_SHOES), 0);}
    
    
        if(random_boots == 10)
          {boots = create_object(get_obj_index(OBJ_EQ_EXQUISITE_SHOES), 0);}
    
    
        obj_to_char(boots, ch);
        equip_char(ch, boots, WEAR_FEET);
        }
    
    
      int random_pauldrons;
      random_pauldrons = number_range(1,4);
    
    
      if(get_eq_char(ch, WEAR_ARMS) == NULL)
        {
        if(random_pauldrons == 1)
          {pauldrons = create_object(get_obj_index(OBJ_EQ_CHITIN_PAULDRONS), 0);}
    
    
        if(random_pauldrons == 2)
          {pauldrons = create_object(get_obj_index(OBJ_EQ_GLASS_PAULDRONS), 0);}
    
    
        if(random_pauldrons == 3)
          {pauldrons = create_object(get_obj_index(OBJ_EQ_NETCH_LEATHER_PAULDRONS), 0);}
    
    
        if(random_pauldrons == 4)
          {pauldrons = create_object(get_obj_index(OBJ_EQ_NORD_FUR_PAULDRONS), 0);}
    
    
        obj_to_char(pauldrons, ch);
        equip_char(ch, pauldrons, WEAR_ARMS);
        }
    
    
      int random_weapon;
      random_weapon = number_range(1,42);
    
    
      if(get_eq_char(ch, WEAR_WIELD) == NULL)
        {
        if(random_weapon == 1)
          {weapon = create_object(get_obj_index(OBJ_EQ_IRON_CESTUS), 0);}
    
    
        if(random_weapon == 2)
          {weapon = create_object(get_obj_index(OBJ_EQ_STEEL_CESTUS), 0);}
    
    
        if(random_weapon == 3)
          {weapon = create_object(get_obj_index(OBJ_EQ_SILVER_CESTUS), 0);}
    
    
        if(random_weapon == 4)
          {weapon = create_object(get_obj_index(OBJ_EQ_GLASS_CESTUS), 0);}
    
    
        if(random_weapon == 5)
          {weapon = create_object(get_obj_index(OBJ_EQ_IRON_DAGGER), 0);}
    
    
        if(random_weapon == 6)
          {weapon = create_object(get_obj_index(OBJ_EQ_STEEL_DAGGER), 0);}
    
    
        if(random_weapon == 7)
          {weapon = create_object(get_obj_index(OBJ_EQ_CHITIN_DAGGER), 0);}
    
    
        if(random_weapon == 8)
          {weapon = create_object(get_obj_index(OBJ_EQ_SILVER_DAGGER), 0);}
    
    
        if(random_weapon == 9)
          {weapon = create_object(get_obj_index(OBJ_EQ_DAEDRIC_DAGGER), 0);}
    
    
        if(random_weapon == 10)
          {weapon = create_object(get_obj_index(OBJ_EQ_DWARVEN_DAGGER), 0);}
    
    
        if(random_weapon == 11)
          {weapon = create_object(get_obj_index(OBJ_EQ_ELVEN_DAGGER), 0);}
    
    
        if(random_weapon == 12)
          {weapon = create_object(get_obj_index(OBJ_EQ_GLASS_DAGGER), 0);}
    
    
        if(random_weapon == 13)
          {weapon = create_object(get_obj_index(OBJ_EQ_EBONY_DAGGER), 0);}
    
    
        if(random_weapon == 14)
          {weapon = create_object(get_obj_index(OBJ_EQ_IRON_TANTO), 0);}
    
    
        if(random_weapon == 15)
          {weapon = create_object(get_obj_index(OBJ_EQ_STEEL_TANTO), 0);}
    
    
        if(random_weapon == 16)
          {weapon = create_object(get_obj_index(OBJ_EQ_DAEDRIC_TANTO), 0);}
    
    
        if(random_weapon == 17)
          {weapon = create_object(get_obj_index(OBJ_EQ_IMPERIAL_SHORTSWORD), 0);}
    
    
        if(random_weapon == 18)
          {weapon = create_object(get_obj_index(OBJ_EQ_STEEL_SHORTSWORD), 0);}
    
    
        if(random_weapon == 19)
          {weapon = create_object(get_obj_index(OBJ_EQ_SILVER_SHORTSWORD), 0);}
    
    
        if(random_weapon == 20)
          {weapon = create_object(get_obj_index(OBJ_EQ_CHITIN_SHORTSWORD), 0);}
    
    
        if(random_weapon == 21)
          {weapon = create_object(get_obj_index(OBJ_EQ_EBONY_SHORTSWORD), 0);}
    
    
        if(random_weapon == 22)
          {weapon = create_object(get_obj_index(OBJ_EQ_DAEDRIC_SHORTSWORD), 0);}
    
    
        if(random_weapon == 23)
          {weapon = create_object(get_obj_index(OBJ_EQ_DWARVEN_SHORTSWORD), 0);}
    
    
        if(random_weapon == 24)
          {weapon = create_object(get_obj_index(OBJ_EQ_GLASS_SHORTSWORD), 0);}
    
    
        if(random_weapon == 25)
          {weapon = create_object(get_obj_index(OBJ_EQ_ELVEN_SHORTSWORD), 0);}
    
    
        if(random_weapon == 26)
          {weapon = create_object(get_obj_index(OBJ_EQ_ADAMANTIUM_SHORTSWORD), 0);}
    
    
        if(random_weapon == 27)
          {weapon = create_object(get_obj_index(OBJ_EQ_IRON_SHORTSWORD), 0);}
    
    
        if(random_weapon == 28)
          {weapon = create_object(get_obj_index(OBJ_EQ_IRON_WAKIZASHI), 0);}
    
    
        if(random_weapon == 29)
          {weapon = create_object(get_obj_index(OBJ_EQ_STEEL_WAKIZASHI), 0);}
    
    
        if(random_weapon == 30)
          {weapon = create_object(get_obj_index(OBJ_EQ_DAEDRIC_WAKIZASHI), 0);}
    
    
        if(random_weapon == 31)
          {weapon = create_object(get_obj_index(OBJ_EQ_STEEL_LONGBOW), 0);}
    
    
        if(random_weapon == 32)
          {weapon = create_object(get_obj_index(OBJ_EQ_BONEMOLD_LONGBOW), 0);}
    
    
        if(random_weapon == 33)
          {weapon = create_object(get_obj_index(OBJ_EQ_SILVER_LONGBOW), 0);}
    
    
        if(random_weapon == 34)
          {weapon = create_object(get_obj_index(OBJ_EQ_DWARVEN_LONGBOW), 0);}
    
    
        if(random_weapon == 35)
          {weapon = create_object(get_obj_index(OBJ_EQ_ELVEN_LONGBOW), 0);}
    
    
        if(random_weapon == 36)
          {weapon = create_object(get_obj_index(OBJ_EQ_GLASS_LONGBOW), 0);}
    
    
        if(random_weapon == 37)
          {weapon = create_object(get_obj_index(OBJ_EQ_EBONY_LONGBOW), 0);}
    
    
        if(random_weapon == 38)
          {weapon = create_object(get_obj_index(OBJ_EQ_IRON_LONGBOW2), 0);}
    
    
        if(random_weapon == 39)
          {weapon = create_object(get_obj_index(OBJ_EQ_DAEDRIC_LONGBOW), 0);}
    
    
        if(random_weapon == 40)
          {weapon = create_object(get_obj_index(OBJ_EQ_IRON_LONGBOW), 0);}
    
    
        if(random_weapon == 41)
          {weapon = create_object(get_obj_index(OBJ_EQ_STEEL_CROSSBOW), 0);}
    
    
        if(random_weapon == 42)
          {weapon = create_object(get_obj_index(OBJ_EQ_DWARVEN_CROSSBOW), 0);}
    
    
        obj_to_char(weapon, ch);
        equip_char(ch, weapon, WEAR_WIELD);
        }
    
    
      return rNONE;
    }

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    27,850
    Chuck the various constants into a few (static) arrays. Then instead of huge if-else chains, you just select the constant by accessing the relevant array by index, after which you can call gey_obj_index and create_object using the constant.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    733
    Without seeing more details about the program, I would use "weapon" as an index to an array of whatever "OBJ_EQ_DWARVEN_CROSSBOW" and other similar constants represents. You then could then reduce the 42 statements to one.

    The same with the other "OBJ_DATA" pointers.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    38,114
    Every time you use ctrl-c / ctrl-v, you need to stop coding and start thinking.

    Specifically, you need to think about how you generalise the thing you just copied.

    Code:
    #include <cstddef>
    #define ASIZE(x)  (sizeof(x)/sizeof(*x))
    ch_ret tes_equipment_thief(int sn, int level, CHAR_DATA * ch, void *vo)
    {
      const int apparel[] = {
        WEAR_BODY,
        WEAR_LEGS,
        WEAR_HEAD,
        WEAR_HANDS,
        WEAR_FEET,
        WEAR_ARMS,
        WEAR_WIELD,
      };
      const int body[] = {
        OBJ_EQ_BOILED_NETCH_LEATHER_CUIRASS,
        OBJ_EQ_NETCH_LEATHER_CUIRASS,
        OBJ_EQ_NORDIC_BEARSKIN_CUIRASS,
        OBJ_EQ_MITHRIL_CUIRASS,
        OBJ_EQ_GLASS_CUIRASS,
        OBJ_EQ_IMPERIAL_STUDDED_LEATHER_CUIRASS,
        OBJ_EQ_CHITIN_CUIRASS,
        OBJ_EQ_FUR_CUIRASS,
        OBJ_EQ_LEATHER_CUIRASS,
        OBJ_EQ_LEATHER_CUIRASS,
        OBJ_EQ_COMMON_ROBE,
        OBJ_EQ_EXPENSIVE_ROBE,
        OBJ_EQ_EXTRAVAGANT_ROBE,
        OBJ_EQ_EXQUISITE_ROBE,
        OBJ_EQ_COMMON_SHIRT,
        OBJ_EQ_EXPENSIVE_SHIRT,
        OBJ_EQ_EXTRAVAGANT_SHIRT,
        OBJ_EQ_EXQUISITE_SHIRT,
      };
      const int legs[] = {
        OBJ_EQ_FUR_GREAVES,
        OBJ_EQ_NETCH_LEATHER_GREAVES,
        OBJ_EQ_CHITIN_GREAVES,
        OBJ_EQ_GLASS_GREAVES,
        OBJ_EQ_MITHRIL_GREAVES,
        OBJ_EQ_LEATHER_GREAVES,
        OBJ_EQ_COMMON_PANTS,
        OBJ_EQ_EXPENSIVE_PANTS,
        OBJ_EQ_EXTRAVAGANT_PANTS,
        OBJ_EQ_EXQUISITE_PANTS,
        OBJ_EQ_IMPERIAL_TEMPLAR_SKIRT,
        OBJ_EQ_IMPERIAL_SKIRT,
        OBJ_EQ_COMMON_SKIRT,
      };
      const int head[] = {
        OBJ_EQ_CHITIN_MASK_HELM,
        OBJ_EQ_CHITIN_HELM,
        OBJ_EQ_MITHRIL_HELM,
        OBJ_EQ_GLASS_HELM,
        OBJ_EQ_NETCH_LEATHER_HELM,
        OBJ_EQ_COLOVIAN_FUR_HELM,
        OBJ_EQ_MORAG_TONG_HELM,
        OBJ_EQ_REDORAN_WATCHMAN_HELM,
        OBJ_EQ_TELVANI_CEPHALOPOD_HELM,
        OBJ_EQ_TELVANI_DUST_ADEPT_HELM,
        OBJ_EQ_TELVANI_MOLE_CRAB_HELM,
        OBJ_EQ_BOILED_NETCH_LEATHER_HELM,
        OBJ_EQ_LEATHER_HELM,
        OBJ_EQ_FUR_HELM,
      };
      const int hands[] = {
        OBJ_EQ_LEATHER_GAUNTLETS,
        OBJ_EQ_FUR_GAUNTLETS,
        OBJ_EQ_MITHRIL_GAUNTLETS,
        OBJ_EQ_GLASS_GAUNTLETS,
        OBJ_EQ_CHITIN_GAUNTLETS,
        OBJ_EQ_NETCH_LEATHER_GAUNTLETS,
        OBJ_EQ_LEATHER_BRACERS,
        OBJ_EQ_CLOTH_BRACERS,
        OBJ_EQ_COMMON_GLOVES,
        OBJ_EQ_EXPENSIVE_GLOVES,
        OBJ_EQ_EXTRAVAGANT_GLOVES,
      };
      const int feet[] = {
        OBJ_EQ_CHITIN_BOOTS,
        OBJ_EQ_GLASS_BOOTS,
        OBJ_EQ_MITHRIL_BOOTS,
        OBJ_EQ_FUR_BOOTS,
        OBJ_EQ_LEATHER_BOOTS,
        OBJ_EQ_NETCH_LEATHER_BOOTS,
        OBJ_EQ_COMMON_SHOES,
        OBJ_EQ_EXPENSIVE_SHOES,
        OBJ_EQ_EXTRAVAGANT_SHOES,
        OBJ_EQ_EXQUISITE_SHOES,
      };
      const int arms[] = {
        OBJ_EQ_CHITIN_PAULDRONS,
        OBJ_EQ_GLASS_PAULDRONS,
        OBJ_EQ_NETCH_LEATHER_PAULDRONS,
        OBJ_EQ_NORD_FUR_PAULDRONS,
      };
      const int weild[] = {
        OBJ_EQ_IRON_CESTUS,
        OBJ_EQ_STEEL_CESTUS,
        OBJ_EQ_SILVER_CESTUS,
        OBJ_EQ_GLASS_CESTUS,
        OBJ_EQ_IRON_DAGGER,
        OBJ_EQ_STEEL_DAGGER,
        OBJ_EQ_CHITIN_DAGGER,
        OBJ_EQ_SILVER_DAGGER,
        OBJ_EQ_DAEDRIC_DAGGER,
        OBJ_EQ_DWARVEN_DAGGER,
        OBJ_EQ_ELVEN_DAGGER,
        OBJ_EQ_GLASS_DAGGER,
        OBJ_EQ_EBONY_DAGGER,
        OBJ_EQ_IRON_TANTO,
        OBJ_EQ_STEEL_TANTO,
        OBJ_EQ_DAEDRIC_TANTO,
        OBJ_EQ_IMPERIAL_SHORTSWORD,
        OBJ_EQ_STEEL_SHORTSWORD,
        OBJ_EQ_SILVER_SHORTSWORD,
        OBJ_EQ_CHITIN_SHORTSWORD,
        OBJ_EQ_EBONY_SHORTSWORD,
        OBJ_EQ_DAEDRIC_SHORTSWORD,
        OBJ_EQ_DWARVEN_SHORTSWORD,
        OBJ_EQ_GLASS_SHORTSWORD,
        OBJ_EQ_ELVEN_SHORTSWORD,
        OBJ_EQ_ADAMANTIUM_SHORTSWORD,
        OBJ_EQ_IRON_SHORTSWORD,
        OBJ_EQ_IRON_WAKIZASHI,
        OBJ_EQ_STEEL_WAKIZASHI,
        OBJ_EQ_DAEDRIC_WAKIZASHI,
        OBJ_EQ_STEEL_LONGBOW,
        OBJ_EQ_BONEMOLD_LONGBOW,
        OBJ_EQ_SILVER_LONGBOW,
        OBJ_EQ_DWARVEN_LONGBOW,
        OBJ_EQ_ELVEN_LONGBOW,
        OBJ_EQ_GLASS_LONGBOW,
        OBJ_EQ_EBONY_LONGBOW,
        OBJ_EQ_IRON_LONGBOW2,
        OBJ_EQ_DAEDRIC_LONGBOW,
        OBJ_EQ_IRON_LONGBOW,
        OBJ_EQ_STEEL_CROSSBOW,
        OBJ_EQ_DWARVEN_CROSSBOW,
      };
      const struct {
        size_t     num_items;
        const int *items;
      } objects[] = {
        { ASIZE(body),  body },
        { ASIZE(legs),  legs },
        { ASIZE(head),  head },
        { ASIZE(hands), hands },
        { ASIZE(feet),  feet },
        { ASIZE(arms) , arms },
        { ASIZE(weild), weild },
      };
      for( size_t i = 0 ; i < ASIZE(apparel) ; i++ ) {
        if( get_eq_char(ch, apparel[i]) == NULL ) {
          size_t r = number_range(0,objects[i].num_items);
          OBJ_DATA *obj = create_object(get_obj_index(objects[i].items[r]), 0);
          obj_to_char(obj, ch);
          equip_char(ch, obj, apparel[i]);
        }
      }
      return rNONE;
    }
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. HOw can I shorten my code?
    By kdushyant297 in forum C Programming
    Replies: 1
    Last Post: 09-15-2017, 10:40 AM
  2. Making a function to shorten my code?
    By evilcubed in forum C Programming
    Replies: 8
    Last Post: 12-08-2012, 11:46 AM
  3. help to shorten my code.
    By hugoguan in forum C Programming
    Replies: 7
    Last Post: 12-01-2010, 02:19 AM
  4. Need to simplify/shorten this code. Help.
    By Lonck in forum C++ Programming
    Replies: 5
    Last Post: 11-08-2007, 04:23 AM
  5. shorten the string
    By beon in forum C Programming
    Replies: 28
    Last Post: 11-14-2006, 12:56 AM

Tags for this Thread