Login
User Name:

Password:



Register
Forgot your password?
Vote for Us!
 parse description bug
Yesterday, 10:08 pm
By Remcon
Couple bugs
Dec 12, 2017, 5:42 pm
By Remcon
Bug in disarm( )
Nov 12, 2017, 6:54 pm
By GatewaySysop
Bug in will_fall( )
Oct 23, 2017, 1:35 am
By GatewaySysop
Bug in do_zap( ), do_brandish( )
Oct 18, 2017, 1:52 pm
By GatewaySysop
LOP 1.45
Author: Remcon
Submitted by: Remcon
LOP Heroes Edition
Author: Vladaar
Submitted by: Vladaar
Heroes sound extras
Author: Vladaar
Submitted by: Vladaar
6Dragons 4.3
Author: Vladaar
Submitted by: Vladaar
Memwatch
Author: Johan Lindh
Submitted by: Vladaar
Users Online
CommonCrawl, Yahoo!

Members: 0
Guests: 7
Stats
Files
Topics
Posts
Members
Newest Member
477
3,706
19,240
608
LAntorcha
Today's Birthdays
There are no member birthdays today.
Related Links
» SmaugMuds.org » Bugfix Lists » SWR FUSS Bugfix List » [Bug] Skill affects get loade...
Forum Rules | Mark all | Recent Posts

[Bug] Skill affects get loaded backward onto skill entries.
< Newer Topic :: Older Topic >

Pages:<< prev 1 next >>
Post is unread #1 Feb 4, 2010, 10:03 pm
Go to the top of the page
Go to the bottom of the page

Kayle
Off the Edge of the Map
GroupAdministrators
Posts1,195
JoinedMar 21, 2006

Bug: Skill affects get loaded backward onto skill entries
Danger: Low - Normally not an issue. Can be a problem if relying on the affect order.
Found by: Valcados
Fixed by: Samson

---

mud.h

Locate:
/*
 * A SMAUG spell
 */
struct smaug_affect
{
   SMAUG_AFF *next;
   char *duration;
   short location;
   char *modifier;
   int bitvector; /* this is the bit number */
};


Change to:
/*
 * A SMAUG spell
 */
struct smaug_affect
{
   SMAUG_AFF *next;
   SMAUG_AFF *prev;
   char *duration;
   short location;
   char *modifier;
   int bitvector; /* this is the bit number */
};


Locate:
   char difficulty;  /* Difficulty of casting/learning */
   SMAUG_AFF *affects;  /* Spell affects, if any   */
   char *components; /* Spell components, if any   */


Change to:
   char difficulty;  /* Difficulty of casting/learning */
   SMAUG_AFF *first_affect;  /* Spell affects, if any   */
   SMAUG_AFF *last_affect;
   char *components; /* Spell components, if any   */


magic.c, spell_affectchar

Locate:
   if( SPELL_FLAG( skill, SF_RECASTABLE ) )
      affect_strip( victim, sn );
   for( saf = skill->affects; saf; saf = saf->next )


Change to:
   if( SPELL_FLAG( skill, SF_RECASTABLE ) )
      affect_strip( victim, sn );
   for( saf = skill->first_affect; saf; saf = saf->next )


magic.c, spell_affect

Locate:
   if( !skill->affects )
   {
      bug( "spell_affect has no affects sn %d", sn );
      return rNONE;
   }


Change to:
   if( !skill->first_affect )
   {
      bug( "spell_affect has no affects sn %d", sn );
      return rNONE;
   }


Locate:
      if( ( saf = skill->affects ) && !saf->next
          && saf->location == APPLY_STRIPSN && !is_affected( victim, dice_parse( ch, level, saf->modifier ) ) )
      {
         failed_casting( skill, ch, victim, NULL );
         return rSPELL_FAILED;
      }


Change to:
      if( ( saf = skill->first_affect ) && !saf->next
          && saf->location == APPLY_STRIPSN && !is_affected( victim, dice_parse( ch, level, saf->modifier ) ) )
      {
         failed_casting( skill, ch, victim, NULL );
         return rSPELL_FAILED;
      }


magic.c, spell_attack

Locate:
            if( retcode == rNONE && skill->affects && !char_died( ch ) && !char_died( victim ) )
               retcode = spell_affectchar( sn, level, ch, victim );


Change to:
            if( retcode == rNONE && skill->first_affect && !char_died( ch ) && !char_died( victim ) )
               retcode = spell_affectchar( sn, level, ch, victim );


Locate:
   if( retcode == rNONE && skill->affects


Change to:
   if( retcode == rNONE && skill->first_affect


magic.c, spell_area_attack

Locate:
   affects = ( skill->affects ? TRUE : FALSE );


Change to:
   affects = ( skill->first_affect ? TRUE : FALSE );


skills.c, do_slookup

Locate:
      for( aff = skill->affects; aff; aff = aff->next )
      {
         if( aff == skill->affects )
            send_to_char( "\r\n", ch );


Change to:
      for( aff = skill->first_affect; aff; aff = aff->next )
      {
         if( aff == skill->first_affect )
            send_to_char( "\r\n", ch );


skills.c, do_sset

Locate:
      if( !str_cmp( arg2, "rmaffect" ) )
      {
         SMAUG_AFF *aff = skill->affects;
         SMAUG_AFF *aff_next;
         int num = atoi( argument );
         int cnt = 1;

         if( !aff )
         {
            send_to_char( "This spell has no special affects to remove.\r\n", ch );
            return;
         }
         if( num == 1 )
         {
            skill->affects = aff->next;
            DISPOSE( aff->duration );
            DISPOSE( aff->modifier );
            DISPOSE( aff );
            send_to_char( "Removed.\r\n", ch );
            return;
         }
         for( ; aff; aff = aff->next )
         {
            if( ++cnt == num && ( aff_next = aff->next ) != NULL )
            {
               aff->next = aff_next->next;
               DISPOSE( aff_next->duration );
               DISPOSE( aff_next->modifier );
               DISPOSE( aff_next );
               send_to_char( "Removed.\r\n", ch );
               return;
            }
         }
         send_to_char( "Not found.\r\n", ch );
         return;
      }


Change to:
      if( !str_cmp( arg2, "rmaffect" ) )
      {
         SMAUG_AFF *aff, *aff_next;
         int num = atoi( argument );
         int cnt = 0;

         if( !skill->first_affect )
         {
            send_to_char( "This spell has no special affects to remove.\r\n", ch );
            return;
         }
         for( aff = skill->first_affect; aff; aff = aff_next )
         {
            aff_next = aff->next;

            if( ++cnt == num )
            {
               UNLINK( aff, skill->first_affect, skill->last_affect, next, prev );
               DISPOSE( aff->duration );
               DISPOSE( aff->modifier );
               DISPOSE( aff );
               send_to_char( "Removed.\r\n", ch );
               return;
            }
         }
         send_to_char( "Not found.\r\n", ch );
         return;
      }


Locate:
         aff->bitvector = bit;
         aff->next = skill->affects;
         skill->affects = aff;
         send_to_char( "Ok.\r\n", ch );


Change to:
         aff->bitvector = bit;
         LINK( aff, skill->first_affect, skill->last_affect, next, prev );
         send_to_char( "Ok.\r\n", ch );


tables.c, fwrite_skill

Locate:
   for( aff = skill->affects; aff; aff = aff->next )


Change to:
   for( aff = skill->first_affect; aff; aff = aff->next )


tables.c, fread_skill

Locate:
               aff->next = skill->affects;
               skill->affects = aff;
               fMatch = TRUE;
               break;


Change to:
               LINK( aff, skill->first_affect, skill->last_affect, next, prev );
               fMatch = TRUE;
               break;


The entire problem here stems from how singly linked lists work. When items get added to the list ( skills load ) they get added to the front. C++ users would recognize this as a list.push_front() operation. If a skill has a long list of affects, they are effectively loaded in reverse. This is not generally much of a problem unless you are trying to do something specific which relies on exact ordering. Yes, I can hear the screams already. Why convert this to a doubly linked list just to solve a minor glitch? Besides the reliability in being able to load the list in the proper order, this also allows the list to be walked in either direction if need be. So look at this as partly bugfix, partly forward planning, and partly as consistency with other lists in the code.
       
Pages:<< prev 1 next >>