mirror of
https://github.com/tbamud/tbamud.git
synced 2025-09-21 21:40:49 +02:00
DG script variables now save to the player file instead of their own file. The load function has been kept for backwards compatibility.
This commit is contained in:
parent
c6ada5a4d5
commit
930fe8c827
3 changed files with 78 additions and 3 deletions
|
@ -2960,6 +2960,73 @@ void save_char_vars(struct char_data *ch)
|
|||
fclose(file);
|
||||
}
|
||||
|
||||
/* load in a character's saved variables from an ASCII pfile*/
|
||||
void read_saved_vars_ascii(FILE *file, struct char_data *ch, int count)
|
||||
{
|
||||
long context;
|
||||
char input_line[1024], *temp, *p;
|
||||
char varname[READ_SIZE];
|
||||
char context_str[READ_SIZE];
|
||||
int i;
|
||||
|
||||
/*
|
||||
* If getting to the menu from inside the game, the vars aren't removed.
|
||||
* So let's not allocate them again.
|
||||
*/
|
||||
if (SCRIPT(ch))
|
||||
return;
|
||||
|
||||
/* create the space for the script structure which holds the vars */
|
||||
/* We need to do this first, because later calls to 'remote' will need */
|
||||
/* a script already assigned. */
|
||||
CREATE(SCRIPT(ch), struct script_data, 1);
|
||||
|
||||
/* walk through each line in the file parsing variables */
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
if (get_line(file, input_line)>0) {
|
||||
p = temp = strdup(input_line);
|
||||
temp = any_one_arg(temp, varname);
|
||||
temp = any_one_arg(temp, context_str);
|
||||
skip_spaces(&temp); /* temp now points to the rest of the line */
|
||||
|
||||
context = atol(context_str);
|
||||
add_var(&(SCRIPT(ch)->global_vars), varname, temp, context);
|
||||
free(p); /* plug memory hole */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* save a characters variables out to an ASCII pfile */
|
||||
void save_char_vars_ascii(FILE *file, struct char_data *ch)
|
||||
{
|
||||
struct trig_var_data *vars;
|
||||
int count = 0;
|
||||
/* immediate return if no script (and therefore no variables) structure */
|
||||
/* has been created. this will happen when the player is logging in */
|
||||
if (SCRIPT(ch) == NULL) return;
|
||||
|
||||
/* we should never be called for an NPC, but just in case... */
|
||||
if (IS_NPC(ch)) return;
|
||||
|
||||
/* make sure this char has global variables to save */
|
||||
if (ch->script->global_vars == NULL) return;
|
||||
|
||||
/* note that currently, context will always be zero. this may change */
|
||||
/* in the future */
|
||||
for (vars = ch->script->global_vars;vars;vars = vars->next)
|
||||
if (*vars->name != '-')
|
||||
count++;
|
||||
|
||||
if (count != 0) {
|
||||
fprintf(file, "Vars: %d\n", count);
|
||||
|
||||
for (vars = ch->script->global_vars;vars;vars = vars->next)
|
||||
if (*vars->name != '-') /* don't save if it begins with - */
|
||||
fprintf(file, "%s %ld %s\n", vars->name, vars->context, vars->value);
|
||||
}
|
||||
}
|
||||
|
||||
/* find_char() helpers */
|
||||
|
||||
// Must be power of 2
|
||||
|
|
|
@ -1354,6 +1354,10 @@ int enter_player_game (struct descriptor_data *d)
|
|||
/* find_char helper */
|
||||
add_to_lookup_table(GET_ID(d->character), (void *)d->character);
|
||||
|
||||
// after moving saving of variables to the player file, this should only be called
|
||||
// in case nothing was found in the pfile. If something was found, SCRIPT(ch) will
|
||||
// be set
|
||||
if (!SCRIPT(d->character))
|
||||
read_saved_vars(d->character);
|
||||
|
||||
d->character->next = character_list;
|
||||
|
|
|
@ -402,6 +402,9 @@ int load_char(const char *name, struct char_data *ch)
|
|||
else if (!strcmp(tag, "Titl")) GET_TITLE(ch) = strdup(line);
|
||||
break;
|
||||
|
||||
case 'V':
|
||||
if (!strcmp(tag, "Vars")) read_saved_vars_ascii(fl, ch, atoi(line));
|
||||
|
||||
case 'W':
|
||||
if (!strcmp(tag, "Wate")) GET_WEIGHT(ch) = atoi(line);
|
||||
else if (!strcmp(tag, "Wimp")) GET_WIMP_LEV(ch) = atoi(line);
|
||||
|
@ -527,7 +530,7 @@ void save_char(struct char_data * ch)
|
|||
tmp_aff[i].next = 0;
|
||||
}
|
||||
}
|
||||
save_char_vars(ch);
|
||||
// save_char_vars(ch);
|
||||
|
||||
/*
|
||||
* remove the affections so that the raw values are stored; otherwise the
|
||||
|
@ -643,7 +646,8 @@ void save_char(struct char_data * ch)
|
|||
fprintf(fl, "0 0 0 0 0\n");
|
||||
}
|
||||
|
||||
if (GET_ALIASES(ch)) write_aliases_ascii(fl, ch);
|
||||
write_aliases_ascii(fl, ch);
|
||||
save_char_vars_ascii(fl, ch);
|
||||
|
||||
fclose(fl);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue