Saving pets with spells affecting them

Posted by Darwin on Sun 17 Feb 2008 02:09 AM — 2 posts, 12,694 views.

USA #0
[Smaug 1.4a, Linux (Ubuntu 7.10)]
I've added the following code into fwrite_mobile in save.c in an attempt to save pets with spells affecting them and allowing them to be loaded back in the same state.
  for ( paf = mob->first_affect; paf; paf = paf->next )
    {
	if ( paf->type >= 0 && (skill=get_skilltype(paf->type)) == NULL )
	    continue;

	if ( paf->type >= 0 && paf->type < TYPE_PERSONAL )
	  fprintf( fp, "AffectData   '%s' %3d %3d %3d %s\n",
	    skill->name,
	    paf->duration,
	    paf->modifier,
	    paf->location,
	    print_bitvector(&paf->bitvector)
	    );
	else
	  fprintf( fp, "Affect       %3d %3d %3d %3d %s\n",
	    paf->type,
	    paf->duration,
	    paf->modifier,
	    paf->location,
	    print_bitvector(&paf->bitvector)
	    );
    }

And I've added the following code to fread_mobile also in save.c
    case 'A':
	    if ( !strcmp( word, "Affect" ) || !strcmp( word, "AffectData" ) )
	    {
		AFFECT_DATA *paf;

		CREATE( paf, AFFECT_DATA, 1 );
		if ( !strcmp( word, "Affect" ) )
		{
		    paf->type	= fread_number( fp );
		}
		else
		{
		    int sn;
		    char *sname = fread_word(fp);

		    if ( (sn=skill_lookup(sname)) < 0 )
		    {
			if ( (sn=herb_lookup(sname)) < 0 )
			    bug( "Fread_mobile: unknown skill.", 0 );
			else
			    sn += TYPE_HERB;
		    }
		    paf->type = sn;
		}

		paf->duration	= fread_number( fp );
		paf->modifier	= fread_number( fp );
		paf->location	= fread_number( fp );
		if ( paf->location == APPLY_WEAPONSPELL
		||   paf->location == APPLY_WEARSPELL
		||   paf->location == APPLY_REMOVESPELL
		||   paf->location == APPLY_STRIPSN
		||   paf->location == APPLY_RECURRINGSPELL )
		  paf->modifier	= slot_lookup( paf->modifier );
		paf->bitvector	= fread_bitvector( fp );
        paf->caster     = mob->short_descr;
		LINK(paf, mob->first_affect, mob->last_affect, next, prev );
		fMatch = TRUE;
		break;
	    }

This does have the desired effect of saving the data to file, reading it back and applying it to the mob, however, the mob does not act as if it is affected by the spells. For instance, when I cast any of the shields (fire/ice/shockshield) on a pet, save and quit, when I log back in the pet (with mstat) will show that it has the affect on it, but it does not show on the actual mob when seeing it in the room, nor does it affect anything while it is fighting.

Is there something I'm missing?
USA #1
Arg. Nevermind. I had forgotten to save the affected_by data. After adding that, everything saved and loaded as desired.