empiremud/cnf/
empiremud/doc/
empiremud/lib/boards/
empiremud/lib/etc/
empiremud/lib/misc/
empiremud/lib/plralias/F-J/
empiremud/lib/plralias/K-O/
empiremud/lib/plralias/P-T/
empiremud/lib/plralias/U-Z/
empiremud/lib/plrobjs/
empiremud/lib/plrobjs/F-J/
empiremud/lib/plrobjs/K-O/
empiremud/lib/plrobjs/P-T/
empiremud/lib/plrobjs/U-Z/
empiremud/lib/world/
empiremud/lib/world/mob/
empiremud/lib/world/obj/
empiremud/log/
/*
   Author: Paul Clarke
   Usage:  EmpireMUD pfile painlessly (ugh)

   This player converter converts the playerfile easily.  Do NOT
   use without knowing EXACTLY what you're doing.
   
   Credits: This is a cheap mock-up of play2to3.c which is included in
            CircleMUD 3.0 pbl 11, written by Edward Almasy, almasy@axis.com.
            It has been tossed around rigorously, if you are going to use
            it, heed the warning above.
 */

#include <stdio.h>
#include <time.h>
#include <sys/types.h>

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

#include "../structs.h"
#include "../utils.h"



struct OLD_player_special_data_saved {
	sh_int invis_level;			/* level of invisibility				*/
	room_vnum load_room;		/* Which room to place char in			*/
	room_vnum spare_room;		/* Used for systems which store rooms	*/
	long pref;					/* preference flags for PC's.			*/
	ubyte bad_pws;				/* number of bad password attemps		*/
	sh_int conditions[4];		/* Drunk, full, thirsty					*/
	sh_int languages;			/* Languages spoken						*/
	byte speaking;				/* Language currently speaking			*/
	int res[NUM_ITEM_MATS];		/* God resources						*/

	long loyalty;				/* The empire this player follows		*/
	byte rank;					/* Rank in the empire					*/
	long pledge;				/* Empire he's applying to				*/
	int defect_timer;			/* To prevent quick re-entry			*/

	byte hair;
	byte eyes;
	byte exp_today;
	byte days_since_bathing;
	ubyte apparent_age;

	bool hardcore;				/* Permanent death/hardcore				*/

	byte talents[NUM_ABILITIES];			/* Talent Abilities				*/
	byte skills[NUM_ABILITIES];			/* Skill Abilities				*/	
	byte knowledges[NUM_ABILITIES];	/* Knowledge Abilities			*/

	byte mort_skills[25];		/* holder space							*/

	byte imm_lev;

	ubyte morph;
	int last_direction;

	int exp_cycle;				/* Last update cycle registered			*/

	int action;
	int action_timer;
	int action_room;
	int action_vnum[2];
	int action_rotation;

	/* Vampires */
	byte clan;					/* Vampire's clan						*/
	byte generation;			/* Vampire's Generation					*/
	byte discs[NUM_DISCS];		/* Discipline ratings					*/
	byte paths[NUM_PATHS];		/* Thaumaturgy ratings					*/
	byte primary_path;			/* Which path is primary				*/

	/* Werewolves */
	byte tribe;					/* Werewolf's tribe						*/
	byte auspice;				/* Werewolf's auspice					*/
	byte breed;					/* Werewolf's breed form				*/
	byte deformity;				/* Werewolf's deformity					*/

	/* spares below for future expansion.  You can change the names from
	   'sparen' to something meaningful, but don't change the order.  */

	byte spare0;
	ubyte spare1;
	int spare2;
	int spare3;
	long spare4;
	long spare5;
	};


struct OLD_affected_type {
	sh_int type;			/* The type of spell that caused this		*/
	sh_int duration;		/* For how long its effects will last		*/
	sbyte modifier;			/* This is added to apropriate ability		*/
	byte location;			/* Tells which ability to change(APPLY_XXX)	*/
	long bitvector;			/* Tells which bits to set (AFF_XXX)		*/
	bitvector_t disc_bit;	/* Tells which bits to set (DSC_XXX)		*/

	struct affected_type *next;
	};


struct OLD_char_file_u {
	char name[MAX_NAME_LENGTH+1];		/* first name						*/
	char lastname[MAX_NAME_LENGTH+1];	/* last name						*/
	char title[MAX_TITLE_LENGTH+1];		/* character's title				*/
	char prompt[121];					/* character's prompt				*/
	char poofin[81];					/* message when appearing			*/
	char poofout[81];					/* message when disappearing		*/
	char email[81];						/* e-mail for a character			*/
	byte sex;							/* sex (yes, please)				*/
	byte level;							/* character's level				*/
	time_t birth;						/* time of birth of character		*/
	int	played;							/* number of secs played in total	*/
	ubyte weight;						/* character's weight				*/
	ubyte height;						/* character's height				*/

	char	pwd[MAX_PWD_LENGTH+1];		/* character's password				*/

	struct char_special_data_saved char_specials_saved;
	struct OLD_player_special_data_saved player_specials_saved;
	struct char_ability_data abilities;
	struct char_point_data points;
	struct OLD_affected_type affected[MAX_AFFECT];

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


int main(int argc, char *argv[]) {
	struct OLD_char_file_u stOld;
	struct char_file_u stNew;
	FILE *ptOldHndl;
	FILE *ptNewHndl;
	int iIndex;

	if (argc < 3) {
		printf("usage: plrconv [old player file] [new player file]\n");
		exit(1);
		}
	ptOldHndl = fopen(argv[1], "rb");
	if (ptOldHndl == NULL) {
		printf("unable to open source file \"%s\"\n", argv[1]);
		exit(1);
		}
	ptNewHndl = fopen(argv[2], "wb");
	if (ptNewHndl == NULL) {
		printf("unable to open destination file \"%s\"\n", argv[2]);
		exit(1);
		}

	while (!feof(ptOldHndl)) {
		fread(&stOld, sizeof(struct OLD_char_file_u), 1, ptOldHndl);

		/* char_file_u */
		strcpy(stNew.name, stOld.name);
		strcpy(stNew.lastname, stOld.lastname);
		strcpy(stNew.title, stOld.title);
		strcpy(stNew.prompt, stOld.prompt);
		strcpy(stNew.poofin, stOld.poofin);
		strcpy(stNew.poofout, stOld.poofout);
		strcpy(stNew.email, stOld.email);

		stNew.sex = stOld.sex;
		stNew.level = stOld.level;
		stNew.birth = stOld.birth;
		stNew.played = stOld.played;
		stNew.weight = stOld.weight;
		stNew.height = stOld.height;

		strcpy(stNew.pwd, stOld.pwd);

		stNew.char_specials_saved = stOld.char_specials_saved;
		stNew.abilities = stOld.abilities;
		stNew.points = stOld.points;

		for (iIndex = 0; iIndex < MAX_AFFECT; iIndex++) {
			stNew.affected[iIndex].type = stOld.affected[iIndex].type;
			stNew.affected[iIndex].duration = stOld.affected[iIndex].duration;
			stNew.affected[iIndex].modifier = stOld.affected[iIndex].modifier;
			stNew.affected[iIndex].location = stOld.affected[iIndex].location;
			stNew.affected[iIndex].bitvector = stOld.affected[iIndex].bitvector;
			stNew.affected[iIndex].disc_bit = stOld.affected[iIndex].disc_bit;
			}

		stNew.last_logon = stOld.last_logon;
		strcpy(stNew.host, stOld.host);

		/* special conversion */
		if (stOld.player_specials_saved.hardcore)
			stNew.char_specials_saved.act |= PLR_HARDCORE;

		/* player_specials_saved */
		stNew.player_specials_saved.invis_level = stOld.player_specials_saved.invis_level;
		stNew.player_specials_saved.load_room = stOld.player_specials_saved.load_room;
		stNew.player_specials_saved.spare_room = stOld.player_specials_saved.spare_room;
		stNew.player_specials_saved.pref = stOld.player_specials_saved.pref;
		stNew.player_specials_saved.bad_pws = stOld.player_specials_saved.bad_pws;
		stNew.player_specials_saved.conditions[0] = stOld.player_specials_saved.conditions[0];
		stNew.player_specials_saved.conditions[1] = stOld.player_specials_saved.conditions[1];
		stNew.player_specials_saved.conditions[2] = stOld.player_specials_saved.conditions[2];
		stNew.player_specials_saved.conditions[3] = stOld.player_specials_saved.conditions[3];
		stNew.player_specials_saved.languages = stOld.player_specials_saved.languages;
		stNew.player_specials_saved.speaking = stOld.player_specials_saved.speaking;

		for (iIndex = 0; iIndex < NUM_ITEM_MATS; iIndex++)
			stNew.player_specials_saved.res[iIndex] = stOld.player_specials_saved.res[iIndex];

		stNew.player_specials_saved.loyalty = stOld.player_specials_saved.loyalty;
		stNew.player_specials_saved.rank = stOld.player_specials_saved.rank;
		stNew.player_specials_saved.pledge = stOld.player_specials_saved.pledge;
		stNew.player_specials_saved.defect_timer = stOld.player_specials_saved.defect_timer;

		stNew.player_specials_saved.hair = stOld.player_specials_saved.hair;
		stNew.player_specials_saved.eyes = stOld.player_specials_saved.eyes;
		stNew.player_specials_saved.skin = 0;
		stNew.player_specials_saved.exp_today = stOld.player_specials_saved.exp_today;
		stNew.player_specials_saved.days_since_bathing = stOld.player_specials_saved.days_since_bathing;
		stNew.player_specials_saved.apparent_age = stOld.player_specials_saved.apparent_age;

		for (iIndex = 0; iIndex < NUM_ABILITIES; iIndex++)
			stNew.player_specials_saved.talents[iIndex] = stOld.player_specials_saved.talents[iIndex];
		for (iIndex = 0; iIndex < NUM_ABILITIES; iIndex++)
			stNew.player_specials_saved.skills[iIndex] = stOld.player_specials_saved.skills[iIndex];
		for (iIndex = 0; iIndex < NUM_ABILITIES; iIndex++)
			stNew.player_specials_saved.knowledges[iIndex] = stOld.player_specials_saved.knowledges[iIndex];

		for (iIndex = 0; iIndex < 25; iIndex++)
			stNew.player_specials_saved.mort_skills[iIndex] = stOld.player_specials_saved.mort_skills[iIndex];


		stNew.player_specials_saved.imm_lev = stOld.player_specials_saved.imm_lev;
		stNew.player_specials_saved.morph = stOld.player_specials_saved.morph;
		stNew.player_specials_saved.last_direction = stOld.player_specials_saved.last_direction;
		stNew.player_specials_saved.exp_cycle = stOld.player_specials_saved.exp_cycle;

		stNew.player_specials_saved.action = stOld.player_specials_saved.action;
		stNew.player_specials_saved.action_timer = stOld.player_specials_saved.action_timer;
		stNew.player_specials_saved.action_room = stOld.player_specials_saved.action_room;
		stNew.player_specials_saved.action_vnum[0] = stOld.player_specials_saved.action_vnum[0];
		stNew.player_specials_saved.action_vnum[1] = stOld.player_specials_saved.action_vnum[1];
		stNew.player_specials_saved.action_rotation = stOld.player_specials_saved.action_rotation;

		stNew.player_specials_saved.clan = stOld.player_specials_saved.clan;
		stNew.player_specials_saved.generation = stOld.player_specials_saved.generation;
		for (iIndex = 0; iIndex < NUM_DISCS; iIndex++)
			stNew.player_specials_saved.discs[iIndex] = stOld.player_specials_saved.discs[iIndex];
		for (iIndex = 0; iIndex < NUM_PATHS; iIndex++)
			stNew.player_specials_saved.paths[iIndex] = stOld.player_specials_saved.paths[iIndex];
		stNew.player_specials_saved.primary_path = stOld.player_specials_saved.primary_path;

		stNew.player_specials_saved.tribe = stOld.player_specials_saved.tribe;
		stNew.player_specials_saved.auspice = stOld.player_specials_saved.auspice;
		stNew.player_specials_saved.breed = stOld.player_specials_saved.breed;
		stNew.player_specials_saved.deformity = stOld.player_specials_saved.deformity;

		/* done */

		if (stNew.level >= LVL_START_IMM)
			printf("*");
		else if (stNew.level >= LVL_APPROVED)
			printf("-");
		else
			printf(".");

	    fwrite(&stNew, sizeof(struct char_file_u), 1, ptNewHndl);
		}

	printf("\n");

	fclose(ptNewHndl);
	fclose(ptOldHndl);

	return 0;
	}