You'll also have to make sure both objects are enchanted first, or their
affects will be on the index.
Maybe you can glean something useful from my do_add code.
--Palrich.

void do_add(CHAR_DATA *ch, char *argument)
{
  int value;
  OBJ_DATA *obj;
  AFFECT_DATA pAf;
  char loc[MAX_INPUT_LENGTH];

  argument = one_argument(argument, loc);
  if (!*loc || !(obj = get_obj_carry(ch, loc, ch)))
  {
    chprintf(ch, "Unable to find %s.\n\r", loc);
    return;
  }

  argument = one_argument(argument, loc);

  if (!*loc || !*argument || !is_number(argument))
  {
    send_to_char("Syntax:  add [object] [location] [mod]\n\r", ch);
    return;
  }

  if ((value = flag_value(apply_flags, loc)) == NO_FLAG)
  {
    send_to_char("Valid affects are:\n\r", ch);
    show_help(ch, "apply");
    return;
  }
  affect_enchant(obj);
  pAf.location   =   value;
  pAf.modifier   =   atoi(argument);
  pAf.where      =   TO_OBJECT;
  pAf.type       =   0;
  pAf.duration   =   -1;
  pAf.bitvector  =   0;
  pAf.level      =   obj->level;
  affect_join_obj(obj, &pAf);

  send_to_char( "Affect added.\n\r", ch);
}

void affect_join_obj(OBJ_DATA *obj, AFFECT_DATA *paf)
{
  AFFECT_DATA *paf_old;
  AFFECT_DATA paf_new = *paf;

  for (paf_old = obj->affected; paf_old != NULL;
    paf_old = paf_old->next)
  {
    if (paf_old->where == paf_new.where
     && paf_old->location == paf_new.location)
    {
      paf_new.level = (paf_new.level += paf_old->level) / 2;
      paf_new.duration += paf_old->duration;
      paf_new.modifier += paf_old->modifier;
      affect_remove_obj(obj, paf_old);
      if (paf_new.modifier)
        affect_to_obj(obj, &paf_new);
      return;
    }
  }
  affect_to_obj(obj, &paf_new);
}


On Thu, 2004-04-15 at 12:36, Richard Lindsey wrote:
> Heh, one more thing, you may want to put a check in at the very bottom
> of that statement to say that if the total for the modifier (or
> duration) == 0, to strip that affect and reassign the ->next pointers
> appropriately
> 
> Richard Lindsey
> 
> -----Original Message-----
> From: Richard Lindsey 
> Sent: Thursday, April 15, 2004 12:32 PM
> To: Richard Lindsey; [EMAIL PROTECTED]; [email protected]
> Subject: RE: Combining Affects
> 
> One thing I just remembered is the different durations also, if you have
> some affects that are set for permanent, but some that are set for a
> certain # of hours (if you've fixed this in your mud) you'll want to
> either specify a variable to hold the total of those values also, or an
> average of them, or the highest of all of them, or whatever, and change
> the original affect in the chain's ->duration field to that value...
> 
> Richard Lindsey
> 
> -----Original Message-----
> From: Richard Lindsey 
> Sent: Thursday, April 15, 2004 12:28 PM
> To: [EMAIL PROTECTED]; [email protected]
> Subject: RE: Combining Affects
> 
> It's something you'd have to write yourself, but you can do something
> like this...
> 
> int total, apply;
> AFFECT_DATA *paf, *paf_next, *paf_next2;
> 
> for ( paf = obj->affected; paf != NULL; paf = paf->next )
> {
>    apply = paf->location;
>    total = paf->modifier;
>    for ( paf_next = paf->next; paf_next != NULL; paf_next =
> paf_next->next )
>    {
>       paf_next2 = paf_next->next;
> 
>       if ( paf_next == paf->next && paf_next->location ==
> paf->location )
>       {
>          total += paf_next->modifier;
>          paf->next = paf_next2;
>          free_affect(paf_next);
>       }
> 
>       if ( paf_next2->location == paf->location )
>       {
>          total += paf_next->modifier;
>          paf_next->next = paf_next2->next;
>          free_affect(paf_next2);
>       }
>    }
>    paf->modifier = total;
> }
> 
> I think that should work, in theory anyway, it'll cycle through the
> affect list, starting with the first, it'll record that apply number and
> check the rest of the list for duplicates... any duplicates it finds
> it'll add the modifier to total and destroy that affect, then loop on to
> (the newly assigned) next affect in the chain until it hits the end, the
> go to the 2nd element in the list and check from there on in the same
> way... feel free to point out any bugs you see in this (anyone) as I
> kind of thought it up on the fly but would like to put it into mine also
> :D
> 
> Richard Lindsey 
> 
> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
> Sent: Thursday, April 15, 2004 12:12 PM
> To: [email protected]
> Subject: Combining Affects
> 
> I want to combine the affects on 2 items.
> For example - Item 1 has an 'addaffect' of +100 hp, and Item 2 has an
> 'addaffect' of +20 hp. When 'combined' by the player, the new item will
> have
> +120 hp. Is there something in the ROM code that I am missing that does
> this,
> or I have to write one myself? If so, any help would be good.
> Thanks
> 
> 
> 
> -- 
> ROM mailing list
> [email protected]
> http://www.rom.org/cgi-bin/mailman/listinfo/rom
> 
> -- 
> ROM mailing list
> [email protected]
> http://www.rom.org/cgi-bin/mailman/listinfo/rom
> 
> -- 
> ROM mailing list
> [email protected]
> http://www.rom.org/cgi-bin/mailman/listinfo/rom


Reply via email to