<commit_before>/* ************************************************************************
*  file:  plrtoascii.c                                     Part of tbaMUD *
*  Copyright (C) 1990, 1991 - see 'license.doc' for complete information. *
*  All Rights Reserved                                                    *
************************************************************************* */

#include "conf.h"
#include "sysdep.h"

#include "structs.h"
#include "utils.h"
#include "db.h"
#include "pfdefaults.h"


// first some stock circle 3.0 defines. Change where appropriate.
#define MAX_NAME_LENGTH		20  /* Used in char_file_u *DO*NOT*CHANGE* */
#define MAX_PWD_LENGTH		10  /* Used in char_file_u *DO*NOT*CHANGE* */
#define MAX_TITLE_LENGTH	80  /* Used in char_file_u *DO*NOT*CHANGE* */
#define HOST_LENGTH		30  /* Used in char_file_u *DO*NOT*CHANGE* */
#define MAX_SKILLS		300 /* Used in char_file_u *DO*NOT*CHANGE* */
#define MAX_AFFECT		64  /* Used in char_file_u *DO*NOT*CHANGE* */

#define MAX_PWD_LENGTH        10     /**< Max PC password length */
#define PLR_DESC_LENGTH       240   /**< Max length for PC description */
#define MAX_SKILLS            300    /**< Max number of skills/spells */

#define MAX_CHORES 15

/* Char's abilities.  Used in char_file_u *DO*NOT*CHANGE* */
struct char_ability_data_plrtoascii {
    char str;
    char str_add;
    char intel;
    char wis;
    char dex;
    char con;
    char cha;
};


/* Char's points.  Used in char_file_u *DO*NOT*CHANGE* */
struct char_point_data_plrtoascii {
    sh_int mana;
    sh_int max_mana; /* Max move for PC/NPC                     */
    sh_int hit;
    sh_int max_hit; /* Max hit for PC/NPC                      */
    sh_int move;
    sh_int max_move; /* Max move for PC/NPC                     */

    sh_int armor; /* Internal -100..100, external -10..10 AC */
    int gold; /* Money carried                           */
    int bank_gold; /* Gold the char has in a bank account     */
    int exp; /* The experience of the player            */
    char hitroll; /* Any bonus or penalty to the hit roll    */
    char damroll; /* Any bonus or penalty to the damage roll */
};


/* 
 * char_special_data_saved: specials which both a PC and an NPC have in
 * common, but which must be saved to the playerfile for PC's.
 *
 * WARNING:  Do not change this structure.  Doing so will ruin the
 * playerfile.  If you want to add to the playerfile, use the spares
 * in player_special_data.
 */
struct char_special_data_saved_plrtoascii {
    int alignment; /* +-1000 for alignments                    */
    long idnum; /* player's idnum; -1 for mobiles           */
    int act[PM_ARRAY_MAX]; /* act flag for NPC's; player flag for PC's */
    int affected_by[AF_ARRAY_MAX]; /* Bitvector for spells/skills affected by */
    sh_int apply_saving_throw[5]; /* Saving throw (Bonuses)       */
};

struct player_special_data_saved_plrtoascii {
  u_char skills[MAX_SKILLS+1]; /* array of skills plus skill 0  */
  u_char skill_usage[MAX_SKILLS+1];
  u_char spare01;              /* Used to be race, moved it after purge */
  u_char spells_to_learn;      /* How many can you learn yet this level. */
  int    wimp_level;           /* Below this # of hit points, flee!    */
  u_char freeze_level;         /* Level of god who froze char, if any */
  short  invis_level;          /* level of invisibility  */
  short  load_room;            /* Which room to place char in  */
  int  pref[PR_ARRAY_MAX];     /* preference flags for PC's.  */
  u_char bad_pws;              /* number of bad password attemps   */
  char   conditions[3];        /* Drunk, full, thirsty         */
  u_char clan_id;
  u_char clan_rank;
  u_char sub_race;             /* Players sub_race */
  u_char pthief_countdown;
  u_char combat_delay;
  u_char race_modifier;
  char poofin[80];	       /* Poofin */
  char poofout[80];	       /* Poofout */
  int    pkill_countdown;
  u_char conj_countdown[4];       /* Time before character can use a conj spell */
  int    ac_remain;            /* Remainder from ac calcs in handler.c - stored in 8ths */
  int    jail_timer;           /* Flag Game jail control variable.         */
  int    quest_pts;            /* The number of quest points a player has  */
  char unused1;
  char unused2;
  char unused3;
  char mastery;                /* Mastery, currently only used for warrior weapons */
  int    olc_zone;             /* zone this immortal can use olc on.       */
  int    prayer_time;	       /* Time in ticks before can pray again */
  int    locker_num;           /* vnum of this player's locker, if any */
  int    assistant;            /* hp of divine assistant */
  u_char notell_level;
  u_char nogoss_level;
  u_char phunt_countdown;
  u_char chore_count;
  int    aggr_pref;
  int   recall;
  int    chores[MAX_CHORES];
  /*
  ** spares below for future expansion.  You can change the names from
  ** 'sparen' to something meaningful, but don't change the order.
  */
  int    arenarank;           /* Elo rating for arena kills */
  int    advance_level;
  int    specialization;
  char   cooldown[4];
  int    spares[10];
};

struct affected_type_plrtoascii {
    short type; /* The type of spell that caused this       */
    short duration; /* For how long its effects will last       */
    char modifier; /* This is added to apropriate ability      */
    u_char location; /* Tells which ability to change(APPLY_XXX) */
    u_int bitvector; /* Tells which bits to set (AFF_XXX)        */
    char level;
    char unused1;
    short unused2;
};

/* ==================== File Structure for Player ======================= */
/*             BEWARE: Changing it will ruin the playerfile		  */
struct char_file_u_plrtoascii {
   /* char_player_data */
   char	name[MAX_NAME_LENGTH+1];
   char	description[PLR_DESC_LENGTH];
   char	title[MAX_TITLE_LENGTH+1];
   char sex;
   char chclass;
   char race;
   char level;
   char lostlevels;
   char orcs;
   time_t birth;   /* Time of birth of character     */
   int	played;    /* Number of secs played in total */
   ubyte weight;
   ubyte height;
   char	pwd[MAX_PWD_LENGTH+1];    /* character's password */

   struct char_special_data_saved_plrtoascii char_specials_saved;
   struct player_special_data_saved_plrtoascii player_specials_saved;
   struct char_ability_data_plrtoascii abilities;
   struct char_point_data_plrtoascii points;
   struct affected_type_plrtoascii affected[MAX_AFFECT];

   time_t last_logon;		/* Time (in secs) of last logon */
   char host[HOST_LENGTH+1];	/* host of last logon */
};
/* ====================================================================== */

int sprintascii(char *out, bitvector_t bits);
int plr_filename(char *orig_name, char *filename);

void convert(char *filename)
{
  FILE *fl, *outfile, *index_file;
  struct char_file_u_plrtoascii player;
  char index_name[40], outname[40], bits[127];
  int i, j;
  struct char_special_data_saved_plrtoascii *csds;
  struct player_special_data_saved_plrtoascii *psds;
  struct char_ability_data_plrtoascii *cad;
  struct char_point_data_plrtoascii *cpd;
  struct affected_type_plrtoascii *aff;

  if (!(fl = fopen(filename, "r+"))) {
    perror("error opening playerfile");
    exit(1);
  }
  sprintf(index_name, "%s%s", LIB_PLRFILES, INDEX_FILE);
  if (!(index_file = fopen(index_name, "w"))) {
    perror("error opening index file");
    exit(1);
  }
  
  int idnum = 0;
  for (;;) {
    idnum += 1;
    j = fread(&player, sizeof(struct char_file_u_plrtoascii), 1, fl);
    if (feof(fl)) {
      fclose(fl);
      fclose(index_file);
      exit(1);
    }

    if (!plr_filename(player.name, outname))
      exit(1);
    printf("writing: %s\n", outname);

    fprintf(index_file, "%ld %s %d %s %ld\n", 
	idnum, player.name, player.level, bits,
	(long)player.last_logon);

    if (!(outfile = fopen(outname, "w"))) {
      printf("error opening output file");
      exit(1);
    }

/* char_file_u */
    if (player.name)
      fprintf(outfile, "Name: %s\n", player.name);
    if (player.pwd)
      fprintf(outfile, "Pass: %s\n", player.pwd);
    if (player.title)
      fprintf(outfile, "Titl: %s\n", player.title);
    if (player.description && *player.description)
      fprintf(outfile, "Desc:\n%s~\n", player.description);
    if (player.sex != PFDEF_SEX)
      fprintf(outfile, "Sex : %d\n", (int)player.sex); 
    if (player.chclass != PFDEF_CLASS)
//      fprintf(outfile, "Clas: %d\n", (int)player.chclass); 
      fprintf(outfile, "Clas: %d\n", 1); 
    if (player.level != PFDEF_LEVEL)
      fprintf(outfile, "Levl: %d\n", (int)player.level); 
    fprintf(outfile, "Brth: %d\n", (int)player.birth);
    fprintf(outfile, "Plyd: %d\n", (int)player.played);
    fprintf(outfile, "Last: %d\n", (int)player.last_logon);
    fprintf(outfile, "Host: %s\n", player.host);
    if (player.height != PFDEF_HEIGHT)
      fprintf(outfile, "Hite: %d\n", (int)player.height);
    if (player.weight != PFDEF_WEIGHT)
      fprintf(outfile, "Wate: %d\n", (int)player.weight);

/* char_special_data_saved */
    csds = &(player.char_specials_saved);
    if (csds->alignment != PFDEF_ALIGNMENT)
      fprintf(outfile, "Alin: %d\n", csds->alignment);
    fprintf(outfile, "Id  : %d\n", idnum);
    if (csds->act != PFDEF_PLRFLAGS)
//      fprintf(outfile, "Act : %d\n", (int)csds->act);
      fprintf(outfile, "Act : %s\n", "0 0 0 0");
    if (csds->affected_by != PFDEF_AFFFLAGS) {
      sprintascii(bits, csds->affected_by);
//      fprintf(outfile, "Aff : %s\n", bits);
      fprintf(outfile, "Aff : %s\n", "0 0 0 0");
    }
    if (csds->apply_saving_throw[0] != PFDEF_SAVETHROW)
      fprintf(outfile, "Thr1: %d\n", csds->apply_saving_throw[0]);<commit_msg>Added player class, race, subrace to our conversion utility.<commit_after>/* ************************************************************************
*  file:  plrtoascii.c                                     Part of tbaMUD *
*  Copyright (C) 1990, 1991 - see 'license.doc' for complete information. *
*  All Rights Reserved                                                    *
************************************************************************* */

#include "conf.h"
#include "sysdep.h"

#include "structs.h"
#include "utils.h"
#include "db.h"
#include "pfdefaults.h"


// first some stock circle 3.0 defines. Change where appropriate.
#define MAX_NAME_LENGTH		20  /* Used in char_file_u *DO*NOT*CHANGE* */
#define MAX_PWD_LENGTH		10  /* Used in char_file_u *DO*NOT*CHANGE* */
#define MAX_TITLE_LENGTH	80  /* Used in char_file_u *DO*NOT*CHANGE* */
#define HOST_LENGTH		30  /* Used in char_file_u *DO*NOT*CHANGE* */
#define MAX_SKILLS		300 /* Used in char_file_u *DO*NOT*CHANGE* */
#define MAX_AFFECT		64  /* Used in char_file_u *DO*NOT*CHANGE* */

#define MAX_PWD_LENGTH        10     /**< Max PC password length */
#define PLR_DESC_LENGTH       240   /**< Max length for PC description */
#define MAX_SKILLS            300    /**< Max number of skills/spells */

#define MAX_CHORES 15

/* Char's abilities.  Used in char_file_u *DO*NOT*CHANGE* */
struct char_ability_data_plrtoascii {
    char str;
    char str_add;
    char intel;
    char wis;
    char dex;
    char con;
    char cha;
};


/* Char's points.  Used in char_file_u *DO*NOT*CHANGE* */
struct char_point_data_plrtoascii {
    sh_int mana;
    sh_int max_mana; /* Max move for PC/NPC                     */
    sh_int hit;
    sh_int max_hit; /* Max hit for PC/NPC                      */
    sh_int move;
    sh_int max_move; /* Max move for PC/NPC                     */

    sh_int armor; /* Internal -100..100, external -10..10 AC */
    int gold; /* Money carried                           */
    int bank_gold; /* Gold the char has in a bank account     */
    int exp; /* The experience of the player            */
    char hitroll; /* Any bonus or penalty to the hit roll    */
    char damroll; /* Any bonus or penalty to the damage roll */
};


/* 
 * char_special_data_saved: specials which both a PC and an NPC have in
 * common, but which must be saved to the playerfile for PC's.
 *
 * WARNING:  Do not change this structure.  Doing so will ruin the
 * playerfile.  If you want to add to the playerfile, use the spares
 * in player_special_data.
 */
struct char_special_data_saved_plrtoascii {
    int alignment; /* +-1000 for alignments                    */
    long idnum; /* player's idnum; -1 for mobiles           */
    int act[PM_ARRAY_MAX]; /* act flag for NPC's; player flag for PC's */
    int affected_by[AF_ARRAY_MAX]; /* Bitvector for spells/skills affected by */
    sh_int apply_saving_throw[5]; /* Saving throw (Bonuses)       */
};

struct player_special_data_saved_plrtoascii {
  u_char skills[MAX_SKILLS+1]; /* array of skills plus skill 0  */
  u_char skill_usage[MAX_SKILLS+1];
  u_char spare01;              /* Used to be race, moved it after purge */
  u_char spells_to_learn;      /* How many can you learn yet this level. */
  int    wimp_level;           /* Below this # of hit points, flee!    */
  u_char freeze_level;         /* Level of god who froze char, if any */
  short  invis_level;          /* level of invisibility  */
  short  load_room;            /* Which room to place char in  */
  int  pref[PR_ARRAY_MAX];     /* preference flags for PC's.  */
  u_char bad_pws;              /* number of bad password attemps   */
  char   conditions[3];        /* Drunk, full, thirsty         */
  u_char clan_id;
  u_char clan_rank;
  u_char sub_race;             /* Players sub_race */
  u_char pthief_countdown;
  u_char combat_delay;
  u_char race_modifier;
  char poofin[80];	       /* Poofin */
  char poofout[80];	       /* Poofout */
  int    pkill_countdown;
  u_char conj_countdown[4];       /* Time before character can use a conj spell */
  int    ac_remain;            /* Remainder from ac calcs in handler.c - stored in 8ths */
  int    jail_timer;           /* Flag Game jail control variable.         */
  int    quest_pts;            /* The number of quest points a player has  */
  char unused1;
  char unused2;
  char unused3;
  char mastery;                /* Mastery, currently only used for warrior weapons */
  int    olc_zone;             /* zone this immortal can use olc on.       */
  int    prayer_time;	       /* Time in ticks before can pray again */
  int    locker_num;           /* vnum of this player's locker, if any */
  int    assistant;            /* hp of divine assistant */
  u_char notell_level;
  u_char nogoss_level;
  u_char phunt_countdown;
  u_char chore_count;
  int    aggr_pref;
  int   recall;
  int    chores[MAX_CHORES];
  /*
  ** spares below for future expansion.  You can change the names from
  ** 'sparen' to something meaningful, but don't change the order.
  */
  int    arenarank;           /* Elo rating for arena kills */
  int    advance_level;
  int    specialization;
  char   cooldown[4];
  int    spares[10];
};

struct affected_type_plrtoascii {
    short type; /* The type of spell that caused this       */
    short duration; /* For how long its effects will last       */
    char modifier; /* This is added to apropriate ability      */
    u_char location; /* Tells which ability to change(APPLY_XXX) */
    u_int bitvector; /* Tells which bits to set (AFF_XXX)        */
    char level;
    char unused1;
    short unused2;
};

/* ==================== File Structure for Player ======================= */
/*             BEWARE: Changing it will ruin the playerfile		  */
struct char_file_u_plrtoascii {
   /* char_player_data */
   char	name[MAX_NAME_LENGTH+1];
   char	description[PLR_DESC_LENGTH];
   char	title[MAX_TITLE_LENGTH+1];
   char sex;
   char chclass;
   char race;
   char level;
   char lostlevels;
   char orcs;
   time_t birth;   /* Time of birth of character     */
   int	played;    /* Number of secs played in total */
   ubyte weight;
   ubyte height;
   char	pwd[MAX_PWD_LENGTH+1];    /* character's password */

   struct char_special_data_saved_plrtoascii char_specials_saved;
   struct player_special_data_saved_plrtoascii player_specials_saved;
   struct char_ability_data_plrtoascii abilities;
   struct char_point_data_plrtoascii points;
   struct affected_type_plrtoascii affected[MAX_AFFECT];

   time_t last_logon;		/* Time (in secs) of last logon */
   char host[HOST_LENGTH+1];	/* host of last logon */
};
/* ====================================================================== */

int sprintascii(char *out, bitvector_t bits);
int plr_filename(char *orig_name, char *filename);

void convert(char *filename)
{
  FILE *fl, *outfile, *index_file;
  struct char_file_u_plrtoascii player;
  char index_name[40], outname[40], bits[127];
  int i, j;
  struct char_special_data_saved_plrtoascii *csds;
  struct player_special_data_saved_plrtoascii *psds;
  struct char_ability_data_plrtoascii *cad;
  struct char_point_data_plrtoascii *cpd;
  struct affected_type_plrtoascii *aff;

  if (!(fl = fopen(filename, "r+"))) {
    perror("error opening playerfile");
    exit(1);
  }
  sprintf(index_name, "%s%s", LIB_PLRFILES, INDEX_FILE);
  if (!(index_file = fopen(index_name, "w"))) {
    perror("error opening index file");
    exit(1);
  }
  
  int idnum = 0;
  for (;;) {
    idnum += 1;
    j = fread(&player, sizeof(struct char_file_u_plrtoascii), 1, fl);
    if (feof(fl)) {
      fclose(fl);
      fclose(index_file);
      exit(1);
    }

    if (!plr_filename(player.name, outname))
      exit(1);
    printf("writing: %s\n", outname);

    fprintf(index_file, "%ld %s %d %s %ld\n", 
	idnum, player.name, player.level, bits,
	(long)player.last_logon);

    if (!(outfile = fopen(outname, "w"))) {
      printf("error opening output file");
      exit(1);
    }

/* char_file_u */
    if (player.name)
      fprintf(outfile, "Name: %s\n", player.name);
    if (player.pwd)
      fprintf(outfile, "Pass: %s\n", player.pwd);
    if (player.title)
      fprintf(outfile, "Titl: %s\n", player.title);
    if (player.description && *player.description)
      fprintf(outfile, "Desc:\n%s~\n", player.description);
    if (player.sex != PFDEF_SEX)
      fprintf(outfile, "Sex : %d\n", (int)player.sex); 
    if (player.chclass != PFDEF_CLASS)
      fprintf(outfile, "Clas: %d\n", (int)player.chclass); 
    if (player.race  != PFDEF_RACE)  		
        fprintf(fl, "Race: %d\n", GET_RACE(ch));
    if (player.player_specials_saved.sub_race != PFDEF_SUBRACE)  	
        fprintf(fl, "SubR: %d\n", GET_SUBRACE(ch));
    
    if (player.level != PFDEF_LEVEL)
      fprintf(outfile, "Levl: %d\n", (int)player.level); 
    fprintf(outfile, "Brth: %d\n", (int)player.birth);
    fprintf(outfile, "Plyd: %d\n", (int)player.played);
    fprintf(outfile, "Last: %d\n", (int)player.last_logon);
    fprintf(outfile, "Host: %s\n", player.host);
    if (player.height != PFDEF_HEIGHT)
      fprintf(outfile, "Hite: %d\n", (int)player.height);
    if (player.weight != PFDEF_WEIGHT)
      fprintf(outfile, "Wate: %d\n", (int)player.weight);

/* char_special_data_saved */
    csds = &(player.char_specials_saved);
    if (csds->alignment != PFDEF_ALIGNMENT)
      fprintf(outfile, "Alin: %d\n", csds->alignment);
    fprintf(outfile, "Id  : %d\n", idnum);
    if (csds->act != PFDEF_PLRFLAGS)
//      fprintf(outfile, "Act : %d\n", (int)csds->act);
      fprintf(outfile, "Act : %s\n", "0 0 0 0");
    if (csds->affected_by != PFDEF_AFFFLAGS) {
      sprintascii(bits, csds->affected_by);
//      fprintf(outfile, "Aff : %s\n", bits);
      fprintf(outfile, "Aff : %s\n", "0 0 0 0");
    }
    if (csds->apply_saving_throw[0] != PFDEF_SAVETHROW)
      fprintf(outfile, "Thr1: %d\n", csds->apply_saving_throw[0]);
{'fraction_non_alphanumeric': 0.14325040783034257, 'fraction_numerical': 0.010144779771615008, 'mean_word_length': 2.722390891840607, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '107283', 'n_tokens_mistral': 6875, 'n_tokens_neox': 6607, 'n_words': 1817}