1*34601Sbostic /*
2*34601Sbostic * Convert Phantasia 3.3.1 and 3.3.1+ characs file format to 3.3.2
3*34601Sbostic *
4*34601Sbostic */
5*34601Sbostic
6*34601Sbostic #include "include.h"
7*34601Sbostic #include "oldplayer.h"
8*34601Sbostic
9*34601Sbostic struct oldplayer Oldplayer; /* old format structure */
10*34601Sbostic struct player Newplayer; /* new format structure */
11*34601Sbostic
12*34601Sbostic char Oldpfile[] = DEST/characs"; /* old format file */
13*34601Sbostic char Newpfile[] = DEST/newcharacs"; /* new format file */
14*34601Sbostic
15*34601Sbostic /************************************************************************
16*34601Sbostic /
17*34601Sbostic / FUNCTION NAME: main()
18*34601Sbostic /
19*34601Sbostic / FUNCTION: convert old Phantasia player file to new format
20*34601Sbostic /
21*34601Sbostic / AUTHOR: C. Robertson, 9/1/85 E. A. Estes, 3/12/86
22*34601Sbostic /
23*34601Sbostic / ARGUMENTS: none
24*34601Sbostic /
25*34601Sbostic / RETURN VALUE: none
26*34601Sbostic /
27*34601Sbostic / MODULES CALLED: time(), exit(), fread(), fopen(), srandom(), floor(),
28*34601Sbostic / random(), strcmp(), fwrite(), strcpy(), fclose(), fprintf()
29*34601Sbostic /
30*34601Sbostic / GLOBAL INPUTS: _iob[], Oldplayer, Newplayer
31*34601Sbostic /
32*34601Sbostic / GLOBAL OUTPUTS: Oldplayer, Newplayer
33*34601Sbostic /
34*34601Sbostic / DESCRIPTION:
35*34601Sbostic / Read in old player structures and write out to new file in
36*34601Sbostic / new format.
37*34601Sbostic / Old player file is unmodified.
38*34601Sbostic / New file is "DEST/newcharacs".
39*34601Sbostic / #define PHANTPLUS to convert from 3.3.1+.
40*34601Sbostic /
41*34601Sbostic /************************************************************************/
42*34601Sbostic
main()43*34601Sbostic main()
44*34601Sbostic {
45*34601Sbostic FILE *oldcharac, *newcharac; /* to open old and new files */
46*34601Sbostic
47*34601Sbostic if ((oldcharac = fopen(Oldpfile, "r")) == NULL)
48*34601Sbostic {
49*34601Sbostic fprintf(stderr, "Cannot open original character file!\n");
50*34601Sbostic exit(1);
51*34601Sbostic }
52*34601Sbostic
53*34601Sbostic if ((newcharac = fopen(Newpfile, "w")) == NULL)
54*34601Sbostic {
55*34601Sbostic fprintf(stderr, "Cannot create new character file!\n");
56*34601Sbostic exit(1);
57*34601Sbostic }
58*34601Sbostic
59*34601Sbostic srandom((unsigned) time((long *) NULL)); /* prime random numbers */
60*34601Sbostic
61*34601Sbostic while (fread((char *) &Oldplayer, sizeof(struct oldplayer), 1, oldcharac) == 1)
62*34601Sbostic /* read and convert old structures into new */
63*34601Sbostic {
64*34601Sbostic Newplayer.p_experience = Oldplayer.o_experience;
65*34601Sbostic Newplayer.p_level = (double) Oldplayer.o_level;
66*34601Sbostic Newplayer.p_strength = Oldplayer.o_strength;
67*34601Sbostic Newplayer.p_sword = Oldplayer.o_sword;
68*34601Sbostic Newplayer.p_might = 0.0; /* game will calculate */
69*34601Sbostic Newplayer.p_energy = Oldplayer.o_energy;
70*34601Sbostic Newplayer.p_maxenergy = Oldplayer.o_maxenergy;
71*34601Sbostic Newplayer.p_shield = Oldplayer.o_shield;
72*34601Sbostic Newplayer.p_quickness = (double) Oldplayer.o_quickness;
73*34601Sbostic Newplayer.p_quksilver = (double) Oldplayer.o_quksilver;
74*34601Sbostic Newplayer.p_speed = 0.0; /* game will calculate */
75*34601Sbostic Newplayer.p_magiclvl = Oldplayer.o_magiclvl;
76*34601Sbostic Newplayer.p_mana = Oldplayer.o_mana;
77*34601Sbostic Newplayer.p_brains = Oldplayer.o_brains;
78*34601Sbostic Newplayer.p_poison = Oldplayer.o_poison;
79*34601Sbostic Newplayer.p_gold = Oldplayer.o_gold;
80*34601Sbostic Newplayer.p_gems = Oldplayer.o_gems;
81*34601Sbostic Newplayer.p_sin = Oldplayer.o_sin;
82*34601Sbostic Newplayer.p_x = Oldplayer.o_x;
83*34601Sbostic Newplayer.p_y = Oldplayer.o_y;
84*34601Sbostic Newplayer.p_1scratch = Oldplayer.o_1scratch;
85*34601Sbostic Newplayer.p_2scratch = Oldplayer.o_2scratch;
86*34601Sbostic
87*34601Sbostic Newplayer.p_ring.ring_type = Oldplayer.o_ring.ring_type;
88*34601Sbostic Newplayer.p_ring.ring_duration = Oldplayer.o_ring.ring_duration;
89*34601Sbostic Newplayer.p_ring.ring_inuse = FALSE;
90*34601Sbostic
91*34601Sbostic Newplayer.p_age = (long) Oldplayer.o_degenerated * N_AGE;
92*34601Sbostic
93*34601Sbostic Newplayer.p_degenerated = Oldplayer.o_degenerated + 1;
94*34601Sbostic
95*34601Sbostic /* convert character type into character type and special type */
96*34601Sbostic
97*34601Sbostic if (Oldplayer.o_type < 0)
98*34601Sbostic /* player with crown */
99*34601Sbostic Oldplayer.o_type = -Oldplayer.o_type;
100*34601Sbostic
101*34601Sbostic if (Oldplayer.o_type == 99)
102*34601Sbostic /* valar */
103*34601Sbostic {
104*34601Sbostic Newplayer.p_specialtype = SC_VALAR;
105*34601Sbostic Newplayer.p_type = (short) ROLL(C_MAGIC, C_EXPER - C_MAGIC + 1);
106*34601Sbostic Newplayer.p_lives = Oldplayer.o_ring.ring_duration;
107*34601Sbostic }
108*34601Sbostic else if (Oldplayer.o_type == 90)
109*34601Sbostic /* ex-valar */
110*34601Sbostic {
111*34601Sbostic Newplayer.p_specialtype = SC_EXVALAR;
112*34601Sbostic Newplayer.p_type = (short) ROLL(C_MAGIC, C_EXPER - C_MAGIC + 1);
113*34601Sbostic Newplayer.p_lives = 0;
114*34601Sbostic }
115*34601Sbostic else if (Oldplayer.o_type > 20)
116*34601Sbostic /* council of wise */
117*34601Sbostic {
118*34601Sbostic Newplayer.p_specialtype = SC_COUNCIL;
119*34601Sbostic Newplayer.p_type = Oldplayer.o_type - 20;
120*34601Sbostic Newplayer.p_lives = Oldplayer.o_ring.ring_duration;
121*34601Sbostic }
122*34601Sbostic else if (Oldplayer.o_type > 10)
123*34601Sbostic /* king */
124*34601Sbostic {
125*34601Sbostic Newplayer.p_specialtype = SC_KING;
126*34601Sbostic Newplayer.p_type = Oldplayer.o_type - 10;
127*34601Sbostic Newplayer.p_lives = 0;
128*34601Sbostic }
129*34601Sbostic else
130*34601Sbostic /* normal player */
131*34601Sbostic {
132*34601Sbostic Newplayer.p_specialtype = SC_NONE;
133*34601Sbostic Newplayer.p_type = Oldplayer.o_type;
134*34601Sbostic Newplayer.p_lives = 0;
135*34601Sbostic }
136*34601Sbostic
137*34601Sbostic Newplayer.p_lives = 0;
138*34601Sbostic Newplayer.p_crowns = Oldplayer.o_crowns;
139*34601Sbostic Newplayer.p_charms = Oldplayer.o_charms;
140*34601Sbostic Newplayer.p_amulets = Oldplayer.o_amulets;
141*34601Sbostic Newplayer.p_holywater = Oldplayer.o_holywater;
142*34601Sbostic Newplayer.p_lastused = Oldplayer.o_lastused;
143*34601Sbostic
144*34601Sbostic /* convert status and name into status */
145*34601Sbostic
146*34601Sbostic Newplayer.p_status = Oldplayer.o_status + S_OFF;
147*34601Sbostic if (strcmp(Oldplayer.m_name, "<null>") == 0)
148*34601Sbostic /* unused recored */
149*34601Sbostic Newplayer.p_status = S_NOTUSED;
150*34601Sbostic if (Oldplayer.o_quickness < 0)
151*34601Sbostic /* hung up player */
152*34601Sbostic {
153*34601Sbostic Newplayer.p_quickness = (double) Oldplayer.o_tampered;
154*34601Sbostic Oldplayer.o_tampered = T_OFF;
155*34601Sbostic Newplayer.p_status = S_HUNGUP;
156*34601Sbostic }
157*34601Sbostic
158*34601Sbostic Newplayer.p_tampered = Oldplayer.o_tampered + T_OFF;
159*34601Sbostic Newplayer.p_istat = I_OFF;
160*34601Sbostic
161*34601Sbostic Newplayer.p_palantir = Oldplayer.o_palantir;
162*34601Sbostic Newplayer.p_blessing = Oldplayer.o_blessing;
163*34601Sbostic Newplayer.p_virgin = Oldplayer.o_virgin;
164*34601Sbostic Newplayer.p_blindness = Oldplayer.o_blindness;
165*34601Sbostic
166*34601Sbostic strcpy(Newplayer.p_name, Oldplayer.o_name);
167*34601Sbostic strcpy(Newplayer.p_password, Oldplayer.o_password);
168*34601Sbostic strcpy(Newplayer.p_login, Oldplayer.o_login);
169*34601Sbostic
170*34601Sbostic /* write new structure */
171*34601Sbostic fwrite((char *) &Newplayer, sizeof(Newplayer), 1, newcharac);
172*34601Sbostic }
173*34601Sbostic
174*34601Sbostic fclose(oldcharac); /* close files */
175*34601Sbostic fclose(newcharac);
176*34601Sbostic
177*34601Sbostic exit(0);
178*34601Sbostic }
179*34601Sbostic /**/
180*34601Sbostic /************************************************************************
181*34601Sbostic /
182*34601Sbostic / FUNCTION NAME: drandom()
183*34601Sbostic /
184*34601Sbostic / FUNCTION: return a random number between 0.0 < 1.0
185*34601Sbostic /
186*34601Sbostic / AUTHOR: E. A. Estes, 2/7/86
187*34601Sbostic /
188*34601Sbostic / ARGUMENTS: none
189*34601Sbostic /
190*34601Sbostic / RETURN VALUE: random number
191*34601Sbostic /
192*34601Sbostic / MODULES CALLED: random()
193*34601Sbostic /
194*34601Sbostic / GLOBAL INPUTS: none
195*34601Sbostic /
196*34601Sbostic / GLOBAL OUTPUTS: none
197*34601Sbostic /
198*34601Sbostic / DESCRIPTION:
199*34601Sbostic / Return a random number.
200*34601Sbostic /
201*34601Sbostic /************************************************************************/
202*34601Sbostic
203*34601Sbostic double
drandom()204*34601Sbostic drandom()
205*34601Sbostic {
206*34601Sbostic if (sizeof(int) != 2)
207*34601Sbostic return((double) (random() & 0x7fff) / 32768.0);
208*34601Sbostic else
209*34601Sbostic return((double) random() / 32768.0);
210*34601Sbostic }
211