[Code] Comparing Weapons

From: Garringer, Mark (MGarringer@APACMail.com)
Date: 01/30/01

Hello. Here is the background:
        I have had mobs make better use of weapons and armor they
find/acquire through their life spans. If they aren't wearing any armor, and
they can wear a piece of it in their inventory they do. If they aren't
wielding any weapon and they have on in their inventory they can, they do.
This works fine. So then I thought, what if they are wielding a dagger and
they pick up a  long sword. The long sword is better and they should switch
weapons. This works too. Kind of.

End of background. Now the problem is that if a mob has two weapons that do
the same damage they keep switching. I noticed this with a mob who had a
long sword and a battle axe. Both do 1d8 damage. I will include the suspect
part of the code as follows:

 if (IS_WIELDING(ch) && !(mob_index[GET_MOB_RNUM(ch)].func == shop_keeper) )
    max = 1;
    /* best_obj = NULL; */
    best_obj = ch->equipment[WEAR_WIELD];
    wield_obj = ch->equipment[WEAR_WIELD];
    max = (((GET_OBJ_VAL(wield_obj, 2) + 1) / 2.0) * GET_OBJ_VAL(wield_obj,
    for ( obj = ch->carrying; obj; obj = obj->next_content) {
      if (GET_OBJ_TYPE(obj) == ITEM_WEAPON) {
        if ( ((((GET_OBJ_VAL(obj,2)+1) / 2.0) * GET_OBJ_VAL(obj, 1)) > max)
&& (!invalid_align(ch, obj) && !invalid_class(ch, obj)) ) {
          if (GET_OBJ_VNUM(obj) != GET_OBJ_VNUM(best_obj)) {
            best_obj = obj;
            max = (((GET_OBJ_VAL(best_obj,2)+1)/ 2.0) *
GET_OBJ_VAL(best_obj, 1))

It seems like when it check the damage value of the obj if it is > max
should be the correct logic because even if both weapons are 1d8 this
evaluates to 4.5 > 4.5 which is not true so they should keep what the have.
Anyone have any insight? (Besides this is ugly code :)


Mark Garringer

   | FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
   | Archives: http://post.queensu.ca/listserv/wwwarch/circle.html |

This archive was generated by hypermail 2b30 : 12/03/01 PST