Ok to try and make things more clearer, I'm going to paste my code and put where things are called.
In Mud.h
after structure types, with the rest of them, i put...
typedef struct energy_data ENERGY;
in char_data and in mob_index_data i put...
ENERGY * energy;
somewhat space below I have the structure itself...
struct energy_data
{
long capacity;
long generate;
long prepared;
long depleted;
};
in plvl.c i have these functions....
//THE TOTAL POWERLEVEL OF A CHARACTER//
long get_plvl_maxx( CHAR_DATA *ch )
{
return URANGE( PWR_MIN, (ch->energy->capacity), PWR_MAX );
}
//THE AVAILABLE POWER OF A CHARACTER//
long get_plvl_av( CHAR_DATA *ch )
{
return URANGE( 0, ch->energy->prepared, get_plvl_maxx(ch) );
}
//THE CURRENT STORED POWER OF A CHARACTER//
long get_plvl_curr( CHAR_DATA *ch )
{
return URANGE( 0, ((get_plvl_maxx(ch)) - (ch->energy->depleted)), (get_plvl_maxx(ch)) );
}
//THE CURRENT POWER UP//
long get_plvl_up( CHAR_DATA *ch )
{
return URANGE( 0, (ch->energy->generate), PWR_MAX );
}
in comm.c as a part of the prompt and fprompt i have..,
case 'P':
stat = get_plvl_maxx(ch); /*Max Power Level*/
break;
case 'p':
stat = get_plvl_curr(ch); /*Current Power Level*/
break;
case 'E':
stat = get_plvl_up(ch); /* Power Up */
break;
case 'e':
stat = get_plvl_av(ch); /* Energy */
break;
in update.c i as a part of the regenerate section, i put..
if ( get_plvl_curr(ch) < get_plvl_maxx(ch) )
ch->energy->depleted -= plvl_curr_gain(ch);
in save.c, to do the create thingy, i have...
fprintf( fp, "Power_Level %ld %ld %ld\n",
ch->energy->capacity, ch->energy->generate, ch->energy->depleted );
and
if ( !strcmp( word, "Power_Level" ) )
{
CREATE( ch->energy, ENERGY, 1 );
ch->energy->capacity = fread_number( fp );
ch->energy->generate = fread_number( fp );
ch->energy->depleted = fread_number( fp );
fMatch = TRUE;
break;
}
thats everything that the segfault involves...here is the segfault again
#0 0x080f2bde in get_plvl_maxx (ch=0x0) at plvl.c:75
75 return URANGE( PWR_MIN, (ch->energy->capacity), PWR_MAX );
(gdb) bt
#0 0x080f2bde in get_plvl_maxx (ch=0x0) at plvl.c:75
#1 0x080f2c4f in get_plvl_curr (ch=0x83a4508) at plvl.c:87
#2 0x08123f2b in char_update () at update.c:944
#3 0x08125c89 in update_handler () at update.c:2061
#4 0x08096d66 in game_loop () at comm.c:722
#5 0x08096655 in main (argc=2, argv=0xbfffeb64) at comm.c:329
#6 0x40063d06 in __libc_start_main () from /lib/libc.so.6
It does this right on the startup of the mud. Log is fine. Before i switched the system to its own structure, it used to be ch->generate, ch->capacity, and so on so forth. It worked fine then. After I switched and followed the examples given to me, it gives me that segfault. My theory is that its in the energy->portion but i do not understand how considering that I've added the CREATE ( ch->energy, ENERGY, 1 ); into the save.c file with the rest of the stats...Please help me... |