]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - phantasia/convert.c
1 /* $NetBSD: convert.c,v 1.2 1995/03/24 03:58:34 cgd Exp $ */
4 * Convert Phantasia 3.3.1 and 3.3.1+ characs file format to 3.3.2
11 struct oldplayer Oldplayer
; /* old format structure */
12 struct player Newplayer
; /* new format structure */
14 char Oldpfile
[] = DEST
/characs
"; /* old format file */
15 char Newpfile[] = DEST/newcharacs"; /* new format file */
17 /************************************************************************
19 / FUNCTION NAME: main()
21 / FUNCTION: convert old Phantasia player file to new format
23 / AUTHOR: C. Robertson, 9/1/85 E. A. Estes, 3/12/86
29 / MODULES CALLED: time(), exit(), fread(), fopen(), srandom(), floor(),
30 / random(), strcmp(), fwrite(), strcpy(), fclose(), fprintf()
32 / GLOBAL INPUTS: _iob[], Oldplayer, Newplayer
34 / GLOBAL OUTPUTS: Oldplayer, Newplayer
37 / Read in old player structures and write out to new file in
39 / Old player file is unmodified.
40 / New file is "DEST/newcharacs".
41 / #define PHANTPLUS to convert from 3.3.1+.
43 /************************************************************************/
47 FILE *oldcharac
, *newcharac
; /* to open old and new files */
49 if ((oldcharac
= fopen(Oldpfile
, "r")) == NULL
)
51 fprintf(stderr
, "Cannot open original character file!\n");
55 if ((newcharac
= fopen(Newpfile
, "w")) == NULL
)
57 fprintf(stderr
, "Cannot create new character file!\n");
61 srandom((unsigned) time((long *) NULL
)); /* prime random numbers */
63 while (fread((char *) &Oldplayer
, sizeof(struct oldplayer
), 1, oldcharac
) == 1)
64 /* read and convert old structures into new */
66 Newplayer
.p_experience
= Oldplayer
.o_experience
;
67 Newplayer
.p_level
= (double) Oldplayer
.o_level
;
68 Newplayer
.p_strength
= Oldplayer
.o_strength
;
69 Newplayer
.p_sword
= Oldplayer
.o_sword
;
70 Newplayer
.p_might
= 0.0; /* game will calculate */
71 Newplayer
.p_energy
= Oldplayer
.o_energy
;
72 Newplayer
.p_maxenergy
= Oldplayer
.o_maxenergy
;
73 Newplayer
.p_shield
= Oldplayer
.o_shield
;
74 Newplayer
.p_quickness
= (double) Oldplayer
.o_quickness
;
75 Newplayer
.p_quksilver
= (double) Oldplayer
.o_quksilver
;
76 Newplayer
.p_speed
= 0.0; /* game will calculate */
77 Newplayer
.p_magiclvl
= Oldplayer
.o_magiclvl
;
78 Newplayer
.p_mana
= Oldplayer
.o_mana
;
79 Newplayer
.p_brains
= Oldplayer
.o_brains
;
80 Newplayer
.p_poison
= Oldplayer
.o_poison
;
81 Newplayer
.p_gold
= Oldplayer
.o_gold
;
82 Newplayer
.p_gems
= Oldplayer
.o_gems
;
83 Newplayer
.p_sin
= Oldplayer
.o_sin
;
84 Newplayer
.p_x
= Oldplayer
.o_x
;
85 Newplayer
.p_y
= Oldplayer
.o_y
;
86 Newplayer
.p_1scratch
= Oldplayer
.o_1scratch
;
87 Newplayer
.p_2scratch
= Oldplayer
.o_2scratch
;
89 Newplayer
.p_ring
.ring_type
= Oldplayer
.o_ring
.ring_type
;
90 Newplayer
.p_ring
.ring_duration
= Oldplayer
.o_ring
.ring_duration
;
91 Newplayer
.p_ring
.ring_inuse
= FALSE
;
93 Newplayer
.p_age
= (long) Oldplayer
.o_degenerated
* N_AGE
;
95 Newplayer
.p_degenerated
= Oldplayer
.o_degenerated
+ 1;
97 /* convert character type into character type and special type */
99 if (Oldplayer
.o_type
< 0)
100 /* player with crown */
101 Oldplayer
.o_type
= -Oldplayer
.o_type
;
103 if (Oldplayer
.o_type
== 99)
106 Newplayer
.p_specialtype
= SC_VALAR
;
107 Newplayer
.p_type
= (short) ROLL(C_MAGIC
, C_EXPER
- C_MAGIC
+ 1);
108 Newplayer
.p_lives
= Oldplayer
.o_ring
.ring_duration
;
110 else if (Oldplayer
.o_type
== 90)
113 Newplayer
.p_specialtype
= SC_EXVALAR
;
114 Newplayer
.p_type
= (short) ROLL(C_MAGIC
, C_EXPER
- C_MAGIC
+ 1);
115 Newplayer
.p_lives
= 0;
117 else if (Oldplayer
.o_type
> 20)
118 /* council of wise */
120 Newplayer
.p_specialtype
= SC_COUNCIL
;
121 Newplayer
.p_type
= Oldplayer
.o_type
- 20;
122 Newplayer
.p_lives
= Oldplayer
.o_ring
.ring_duration
;
124 else if (Oldplayer
.o_type
> 10)
127 Newplayer
.p_specialtype
= SC_KING
;
128 Newplayer
.p_type
= Oldplayer
.o_type
- 10;
129 Newplayer
.p_lives
= 0;
134 Newplayer
.p_specialtype
= SC_NONE
;
135 Newplayer
.p_type
= Oldplayer
.o_type
;
136 Newplayer
.p_lives
= 0;
139 Newplayer
.p_lives
= 0;
140 Newplayer
.p_crowns
= Oldplayer
.o_crowns
;
141 Newplayer
.p_charms
= Oldplayer
.o_charms
;
142 Newplayer
.p_amulets
= Oldplayer
.o_amulets
;
143 Newplayer
.p_holywater
= Oldplayer
.o_holywater
;
144 Newplayer
.p_lastused
= Oldplayer
.o_lastused
;
146 /* convert status and name into status */
148 Newplayer
.p_status
= Oldplayer
.o_status
+ S_OFF
;
149 if (strcmp(Oldplayer
.m_name
, "<null>") == 0)
151 Newplayer
.p_status
= S_NOTUSED
;
152 if (Oldplayer
.o_quickness
< 0)
155 Newplayer
.p_quickness
= (double) Oldplayer
.o_tampered
;
156 Oldplayer
.o_tampered
= T_OFF
;
157 Newplayer
.p_status
= S_HUNGUP
;
160 Newplayer
.p_tampered
= Oldplayer
.o_tampered
+ T_OFF
;
161 Newplayer
.p_istat
= I_OFF
;
163 Newplayer
.p_palantir
= Oldplayer
.o_palantir
;
164 Newplayer
.p_blessing
= Oldplayer
.o_blessing
;
165 Newplayer
.p_virgin
= Oldplayer
.o_virgin
;
166 Newplayer
.p_blindness
= Oldplayer
.o_blindness
;
168 strcpy(Newplayer
.p_name
, Oldplayer
.o_name
);
169 strcpy(Newplayer
.p_password
, Oldplayer
.o_password
);
170 strcpy(Newplayer
.p_login
, Oldplayer
.o_login
);
172 /* write new structure */
173 fwrite((char *) &Newplayer
, sizeof(Newplayer
), 1, newcharac
);
176 fclose(oldcharac
); /* close files */
182 /************************************************************************
184 / FUNCTION NAME: drandom()
186 / FUNCTION: return a random number between 0.0 < 1.0
188 / AUTHOR: E. A. Estes, 2/7/86
192 / RETURN VALUE: random number
194 / MODULES CALLED: random()
196 / GLOBAL INPUTS: none
198 / GLOBAL OUTPUTS: none
201 / Return a random number.
203 /************************************************************************/
208 if (sizeof(int) != 2)
209 return((double) (random() & 0x7fff) / 32768.0);
211 return((double) random() / 32768.0);