]> git.cameronkatri.com Git - bsdgames-darwin.git/blob - phantasia/convert.c
- WARNSify
[bsdgames-darwin.git] / phantasia / convert.c
1 /* $NetBSD: convert.c,v 1.2 1995/03/24 03:58:34 cgd Exp $ */
2
3 /*
4 * Convert Phantasia 3.3.1 and 3.3.1+ characs file format to 3.3.2
5 *
6 */
7
8 #include "include.h"
9 #include "oldplayer.h"
10
11 struct oldplayer Oldplayer; /* old format structure */
12 struct player Newplayer; /* new format structure */
13
14 char Oldpfile[] = DEST/characs"; /* old format file */
15 char Newpfile[] = DEST/newcharacs"; /* new format file */
16
17 /************************************************************************
18 /
19 / FUNCTION NAME: main()
20 /
21 / FUNCTION: convert old Phantasia player file to new format
22 /
23 / AUTHOR: C. Robertson, 9/1/85 E. A. Estes, 3/12/86
24 /
25 / ARGUMENTS: none
26 /
27 / RETURN VALUE: none
28 /
29 / MODULES CALLED: time(), exit(), fread(), fopen(), srandom(), floor(),
30 / random(), strcmp(), fwrite(), strcpy(), fclose(), fprintf()
31 /
32 / GLOBAL INPUTS: _iob[], Oldplayer, Newplayer
33 /
34 / GLOBAL OUTPUTS: Oldplayer, Newplayer
35 /
36 / DESCRIPTION:
37 / Read in old player structures and write out to new file in
38 / new format.
39 / Old player file is unmodified.
40 / New file is "DEST/newcharacs".
41 / #define PHANTPLUS to convert from 3.3.1+.
42 /
43 /************************************************************************/
44
45 main()
46 {
47 FILE *oldcharac, *newcharac; /* to open old and new files */
48
49 if ((oldcharac = fopen(Oldpfile, "r")) == NULL)
50 {
51 fprintf(stderr, "Cannot open original character file!\n");
52 exit(1);
53 }
54
55 if ((newcharac = fopen(Newpfile, "w")) == NULL)
56 {
57 fprintf(stderr, "Cannot create new character file!\n");
58 exit(1);
59 }
60
61 srandom((unsigned) time((long *) NULL)); /* prime random numbers */
62
63 while (fread((char *) &Oldplayer, sizeof(struct oldplayer), 1, oldcharac) == 1)
64 /* read and convert old structures into new */
65 {
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;
88
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;
92
93 Newplayer.p_age = (long) Oldplayer.o_degenerated * N_AGE;
94
95 Newplayer.p_degenerated = Oldplayer.o_degenerated + 1;
96
97 /* convert character type into character type and special type */
98
99 if (Oldplayer.o_type < 0)
100 /* player with crown */
101 Oldplayer.o_type = -Oldplayer.o_type;
102
103 if (Oldplayer.o_type == 99)
104 /* valar */
105 {
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;
109 }
110 else if (Oldplayer.o_type == 90)
111 /* ex-valar */
112 {
113 Newplayer.p_specialtype = SC_EXVALAR;
114 Newplayer.p_type = (short) ROLL(C_MAGIC, C_EXPER - C_MAGIC + 1);
115 Newplayer.p_lives = 0;
116 }
117 else if (Oldplayer.o_type > 20)
118 /* council of wise */
119 {
120 Newplayer.p_specialtype = SC_COUNCIL;
121 Newplayer.p_type = Oldplayer.o_type - 20;
122 Newplayer.p_lives = Oldplayer.o_ring.ring_duration;
123 }
124 else if (Oldplayer.o_type > 10)
125 /* king */
126 {
127 Newplayer.p_specialtype = SC_KING;
128 Newplayer.p_type = Oldplayer.o_type - 10;
129 Newplayer.p_lives = 0;
130 }
131 else
132 /* normal player */
133 {
134 Newplayer.p_specialtype = SC_NONE;
135 Newplayer.p_type = Oldplayer.o_type;
136 Newplayer.p_lives = 0;
137 }
138
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;
145
146 /* convert status and name into status */
147
148 Newplayer.p_status = Oldplayer.o_status + S_OFF;
149 if (strcmp(Oldplayer.m_name, "<null>") == 0)
150 /* unused recored */
151 Newplayer.p_status = S_NOTUSED;
152 if (Oldplayer.o_quickness < 0)
153 /* hung up player */
154 {
155 Newplayer.p_quickness = (double) Oldplayer.o_tampered;
156 Oldplayer.o_tampered = T_OFF;
157 Newplayer.p_status = S_HUNGUP;
158 }
159
160 Newplayer.p_tampered = Oldplayer.o_tampered + T_OFF;
161 Newplayer.p_istat = I_OFF;
162
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;
167
168 strcpy(Newplayer.p_name, Oldplayer.o_name);
169 strcpy(Newplayer.p_password, Oldplayer.o_password);
170 strcpy(Newplayer.p_login, Oldplayer.o_login);
171
172 /* write new structure */
173 fwrite((char *) &Newplayer, sizeof(Newplayer), 1, newcharac);
174 }
175
176 fclose(oldcharac); /* close files */
177 fclose(newcharac);
178
179 exit(0);
180 }
181 /*\f*/
182 /************************************************************************
183 /
184 / FUNCTION NAME: drandom()
185 /
186 / FUNCTION: return a random number between 0.0 < 1.0
187 /
188 / AUTHOR: E. A. Estes, 2/7/86
189 /
190 / ARGUMENTS: none
191 /
192 / RETURN VALUE: random number
193 /
194 / MODULES CALLED: random()
195 /
196 / GLOBAL INPUTS: none
197 /
198 / GLOBAL OUTPUTS: none
199 /
200 / DESCRIPTION:
201 / Return a random number.
202 /
203 /************************************************************************/
204
205 double
206 drandom()
207 {
208 if (sizeof(int) != 2)
209 return((double) (random() & 0x7fff) / 32768.0);
210 else
211 return((double) random() / 32768.0);
212 }