
Pages:<< prev 1 next >>


Off the Edge of the Map

GroupAdministrators
Posts1,199
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:
Change to:
Locate:
Change to:
magic.c, spell_affectchar
Locate:
Change to:
magic.c, spell_affect
Locate:
Change to:
Locate:
Change to:
magic.c, spell_attack
Locate:
Change to:
Locate:
Change to:
magic.c, spell_area_attack
Locate:
Change to:
skills.c, do_slookup
Locate:
Change to:
skills.c, do_sset
Locate:
Change to:
Locate:
Change to:
tables.c, fwrite_skill
Locate:
Change to:
tables.c, fread_skill
Locate:
Change to:
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.
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 >>