06 Feb, 2010, jurdendurden wrote in the 1st comment:
Votes: 0
It would appear that mprogs listed on any given mob will load in reverse during a copyover. I have checked the load_mobprog and save_mobile functions and (from what I can tell) they seem to be fine. I will post them below to see if anyone else can discern an issue with them.


/*
* Load mobprogs section
*/
void load_mobprogs (FILE * fp)
{
PROG_CODE *pMprog;

if (area_last == NULL)
{
bug ("Load_mobprogs: no #AREA seen yet.", 0);
exit (1);
}

for (;;)
{
sh_int vnum;
char letter;

letter = fread_letter (fp);
if (letter != '#')
{
bug ("Load_mobprogs: # not found.", 0);
exit (1);
}

vnum = fread_number (fp);
if (vnum == 0)
break;

fBootDb = FALSE;
if (get_prog_index (vnum, PRG_MPROG) != NULL)
{
bug ("Load_mobprogs: vnum %d duplicated.", vnum);
exit (1);
}
fBootDb = TRUE;

pMprog = alloc_perm (sizeof (*pMprog));
pMprog->vnum = vnum;
pMprog->code = fread_string (fp);
if (mprog_list == NULL)
mprog_list = pMprog;
else
{
pMprog->next = mprog_list;
mprog_list = pMprog;
}
top_mprog_index++;
}
log_f("Loaded %d mobprogs.", top_mprog_index);
return;
}

/*
* Translate mobprog vnums pointers to real code
*/
void fix_mobprogs (void)
{
MOB_INDEX_DATA *pMobIndex;
PROG_LIST *list;
PROG_CODE *prog;
int iHash;

for (iHash = 0; iHash < MAX_KEY_HASH; iHash++)
{
for (pMobIndex = mob_index_hash[iHash];
pMobIndex != NULL; pMobIndex = pMobIndex->next)
{
for (list = pMobIndex->mprogs; list != NULL; list = list->next)
{
if ((prog = get_prog_index (list->vnum, PRG_MPROG)) != NULL)
list->code = prog->code;
else
{
bug ("Fix_mobprogs: code vnum %d not found.", list->vnum);
exit (1);
}
}
}
}
}


This next part is from save_mobile, near the end:

for (pMprog = pMobIndex->mprogs; pMprog; pMprog = pMprog->next)
{
fprintf (fp, "M %s %d %s~\n",
prog_type_to_name(pMprog->trig_type), pMprog->vnum,
pMprog->trig_phrase);
}
06 Feb, 2010, jurdendurden wrote in the 2nd comment:
Votes: 0
Also I'm not getting any errors in the logfiles, or while running GDB. They just load in complete reverse, making some of the mprog logic in the game so far nonsensical.
07 Feb, 2010, Sharmair wrote in the 3rd comment:
Votes: 0
It looks like you are saving the programs in the order they are on the mob,
but then loading in that same order but tacking them on the head (start)
of the list. This puts the last loaded at the start of the list and in effect
reversing the list.
You could do a number of things:
save the programs in reverse order.
maintain a tail pointer and add the programs there.
search to the end of the list and add there.
to name a few.
0.0/3