MudBytes
Pages: << prev 1 next >>
Mprog fun, loading backwards?
jurdendurden
Conjurer






Group: Members
Posts: 219
Joined: Nov 20, 2009

Go to the bottom of the page Go to the top of the page
#1 id:41539 Posted Feb 6, 2010, 11:04 am

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.


Code (c):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
 
 
/*
 * 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:

Code (c):
1
2
3
4
5
6
7
8
9
10
11
12
 
 
 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);
    }
 
 
.........................
Aragond: the Chronicles

jurdendurden
Conjurer






Group: Members
Posts: 219
Joined: Nov 20, 2009

Go to the bottom of the page Go to the top of the page
#2 id:41572 Posted Feb 6, 2010, 1:41 pm

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.
.........................
Aragond: the Chronicles

Sharmair
Conjurer






Group: Members
Posts: 230
Joined: Nov 9, 2008

Go to the bottom of the page Go to the top of the page
#3 id:41637 Posted Feb 7, 2010, 8:52 am

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.

Pages:<< prev 1 next >>
Tags
[+]

Valid XHTML 1.1! Valid CSS!