Ok i've spent 3 days on this and every time it crashes, i fix it,
something else goes wrong. Im at a loss, I've tried everything i know to
fix this but the issue still eludes me, so please help if you can (5
bucks says its something small, tiny and i should of seen it when i
wrote it ;) but.. heres the problem..
Im redoing leveling in my mud for a classless system, similarly based on
Eve-online's system.
It works like this. there are lets say 100 skills, everyone has them.
Players choose one at a time
to train, and after X or so hours, the skill progresses to the next
level, and they get better at it.
(to nip it in the bud, yes there are flaws with idling, but sticking the
pfiles into SQL and allowing
training even when logged off, but anyways ;)
Heres the problem, in the update() i stuck in a function called
skills_update, which is supposed
to, if the players are training to decrease their time by 1. Simple no?
Well, the issue comes when
the finish the skill, and they gain a level. It ends up, from what i can
tell in GDB that the entire charater
structure becmes croupt. (Once the entire CHAR_DATA for all things was
changed to NULL, then i tried
agian and just the single player was croupt (found it out because it was
crashing on get_trust during a look, and
ch = 0x40 which is totaly not right).
I Belive the code goes wrong in the way it cycles through the players, i
tried using the who method of going through
the descriptor data (current stage) which seems to work ok. But it still
ends up crashing the mud. Whats causing me to write this now is, i just
added a flag to, if not set not train in the updae, and it began
crashing when i tried to set a skill to train. (COMM_IS_TRAINING to be
specific, i just needed a quick place to set a flag)
Anywho, heres the code..
for do_train the starting training section is..
if (!str_prefix (arg1, "start"))
{
int sn = skill_num_lookup(arg2);
if (ch->learned[sn] == 5)
{
stc("You cannot train this skill anymore,
it is already at level 5.\n\r", ch);
return;
}
sprintf(buf, "You begin Training %s\n\r",
skill_table[sn].name);
stc(buf, ch);
SET_BIT (ch->comm, COMM_IS_TRAINING);
ch->skill_training = sn;
sprintf(buf, "%s remaining\n\r",
return_time_remaining(ch->skill_experience[sn]));
stc(buf, ch);
return;
}
(Skill_num_lookup works just like skill_lookup, only uses my new
skill_table)
return_timeremaining displays how many minuites/hours is remaining on
the clock
Currently its crashing with a SIGSEGV from sprintf in this function
the Update function..
/* Update to handle skill training via time */
void skills_update (void)
{
CHAR_DATA *wch;
DESCRIPTOR_DATA *d;
for (d = descriptor_list; d != NULL; d = d->next)
{
if (d->connected != CON_PLAYING)
continue;
wch = (d->original != NULL) ? d->original :
d->character;
train_skill(wch);
}
return;
}
I tried to keep it simple
and train_skill is..
void train_skill(CHAR_DATA * ch)
{
char buf[MSL];
int temp;
if (IS_NPC(ch))
return;
if (ch->skill_training == -1)
return;
if (!IS_SET (ch->comm, COMM_IS_TRAINING))
{
return;
}
temp = ch->skill_training;
if (temp == 0)
return;
ch->skill_experience[temp]--;
if (ch->skill_experience[temp] < 0)
{
ch->learned[temp]++;
sprintf(buf, "{WYou have finished your training in
%s and is now level %d!\n\r",
skill_table[temp].name,
ch->learned[temp]);
REMOVE_BIT (ch->comm, COMM_IS_TRAINING);
stc(buf, ch);
ch->skill_training = -1;
int bob = calculate_time_tnl(ch, temp);
ch->skill_experience[temp] = bob;
}
return;
}
the bob is just a temp thing, it 'worked' for a second before i
recalculated the time
ch->learned[] holds the levels for each skill (same as stock
ch->pcdata->learned, just moved)
ch->skill_experience[] holds the experiece (time remaining) for each skill.
Yes this part of the code is ugly, but ive tried to fix it so many
times, ive tried to put everything
in its own value.
Well any help is appreciated, Im tempted to just rip the entire system
out and do something else at
this point, its really getting to me for some reason, i've never been so
frustrated over a piece of
stupid simple code.
Thanks =)
-Thri