Bug: Hardcoded vnums using numerical value
Danger: Low - Hardcoded vnums should use a definition name instead.
Found by: Kiasyn, Remcon, Conner
Fixed by: Kiasyn, Remcon, Conner
---
mud.h
Locate:
/*
* Well known mob virtual numbers.
* Defined in #MOBILES.
*/
#define MOB_VNUM_ANIMATED_CORPSE 5
#define MOB_VNUM_POLY_WOLF 10
#define MOB_VNUM_STORMTROOPER 20
#define MOB_VNUM_IMP_GUARD 21
#define MOB_VNUM_NR_GUARD 22
#define MOB_VNUM_NR_TROOPER 23
#define MOB_VNUM_MERCINARY 24
#define MOB_VNUM_BOUNCER 25
Below that, add:
#define MOB_VNUM_SUPERMOB 3
mud_comm.c, do_mppurge
Locate:
if( IS_NPC( victim ) && victim->pIndexData->vnum == 3 )
{
progbug( "Mppurge: trying to purge supermob", ch );
return;
}
Change to:
if( IS_NPC( victim ) && victim->pIndexData->vnum == MOB_VNUM_SUPERMOB )
{
progbug( "Mppurge: trying to purge supermob", ch );
return;
}
act_wiz.c, do_bodybag
Locate:
if( obj->in_room && !str_cmp( buf2, obj->short_descr ) && ( obj->pIndexData->vnum == 11 ) )
Change to:
if( obj->in_room && obj->pIndexData->vnum == OBJ_VNUM_CORPSE_PC && !str_cmp( buf2, obj->short_descr ) )
handler.c, can_drop_obj
Locate:
if( IS_NPC( ch ) && ch->pIndexData->vnum == 3 )
return TRUE;
Change to:
if( IS_NPC( ch ) && ch->pIndexData->vnum == MOB_VNUM_SUPERMOB )
return TRUE;
mud_prog.c, init_supermob
Locate:
supermob = create_mobile( get_mob_index( 3 ) );
office = get_room_index( 3 );
char_to_room( supermob, office );
Change to:
supermob = create_mobile( get_mob_index( MOB_VNUM_SUPERMOB ) );
office = get_room_index( ROOM_VNUM_POLY );
char_to_room( supermob, office );
mud_prog.c, release_supermob
Replace the function with:
void release_supermob( )
{
char_from_room( supermob );
char_to_room( supermob, get_room_index( ROOM_VNUM_POLY ) );
}
mud_prog.c, progbug
Locate:
/*
* Check if we're dealing with supermob, which means the bug occurred
* in a room or obj prog.
*/
if( mob->pIndexData->vnum == 3 )
Change to:
/*
* Check if we're dealing with supermob, which means the bug occurred
* in a room or obj prog.
*/
if( mob->pIndexData->vnum == MOB_VNUM_SUPERMOB )
mud_prog.c, set_supermob
Locate:
if( !supermob )
supermob = create_mobile( get_mob_index( 3 ) );
Change to:
if( !supermob )
supermob = create_mobile( get_mob_index( MOB_VNUM_SUPERMOB ) );
Hard numerical vnums are not usually a huge problem. But if someone removed the areas these vnums are in and the code can no longer find them, things usually go bad in a hurry. Changing them all to definition names allows them to be reset cleanly in mud.h so that one does not need to hunt down a bunch of hard references.