misc.c revision 1.16 1 1.16 dholland /* $NetBSD: misc.c,v 1.16 2009/05/25 23:08:45 dholland Exp $ */
2 1.2 cgd
3 1.1 jtc /*
4 1.1 jtc * misc.c Phantasia miscellaneous support routines
5 1.1 jtc */
6 1.1 jtc
7 1.1 jtc #include "include.h"
8 1.12 he #undef bool
9 1.11 ross #include <curses.h>
10 1.1 jtc
11 1.1 jtc
12 1.3 lukem void
13 1.16 dholland movelevel(void)
14 1.1 jtc {
15 1.5 jsm const struct charstats *statptr; /* for pointing into Stattable */
16 1.3 lukem double new; /* new level */
17 1.3 lukem double inc; /* increment between new and old levels */
18 1.3 lukem
19 1.3 lukem Changed = TRUE;
20 1.3 lukem
21 1.3 lukem if (Player.p_type == C_EXPER)
22 1.3 lukem /* roll a type to use for increment */
23 1.3 lukem statptr = &Stattable[(int) ROLL(C_MAGIC, C_HALFLING - C_MAGIC + 1)];
24 1.3 lukem else
25 1.3 lukem statptr = Statptr;
26 1.1 jtc
27 1.3 lukem new = explevel(Player.p_experience);
28 1.3 lukem inc = new - Player.p_level;
29 1.3 lukem Player.p_level = new;
30 1.3 lukem
31 1.3 lukem /* add increments to statistics */
32 1.3 lukem Player.p_strength += statptr->c_strength.increase * inc;
33 1.3 lukem Player.p_mana += statptr->c_mana.increase * inc;
34 1.3 lukem Player.p_brains += statptr->c_brains.increase * inc;
35 1.3 lukem Player.p_magiclvl += statptr->c_magiclvl.increase * inc;
36 1.3 lukem Player.p_maxenergy += statptr->c_energy.increase * inc;
37 1.1 jtc
38 1.3 lukem /* rest to maximum upon reaching new level */
39 1.3 lukem Player.p_energy = Player.p_maxenergy + Player.p_shield;
40 1.3 lukem
41 1.3 lukem if (Player.p_crowns > 0 && Player.p_level >= 1000.0)
42 1.3 lukem /* no longer able to be king -- turn crowns into cash */
43 1.1 jtc {
44 1.3 lukem Player.p_gold += ((double) Player.p_crowns) * 5000.0;
45 1.3 lukem Player.p_crowns = 0;
46 1.1 jtc }
47 1.3 lukem if (Player.p_level >= 3000.0 && Player.p_specialtype < SC_COUNCIL)
48 1.3 lukem /* make a member of the council */
49 1.1 jtc {
50 1.3 lukem mvaddstr(6, 0, "You have made it to the Council of the Wise.\n");
51 1.3 lukem addstr("Good Luck on your search for the Holy Grail.\n");
52 1.1 jtc
53 1.3 lukem Player.p_specialtype = SC_COUNCIL;
54 1.1 jtc
55 1.3 lukem /* no rings for council and above */
56 1.3 lukem Player.p_ring.ring_type = R_NONE;
57 1.3 lukem Player.p_ring.ring_duration = 0;
58 1.1 jtc
59 1.3 lukem Player.p_lives = 3; /* three extra lives */
60 1.1 jtc }
61 1.3 lukem if (Player.p_level > 9999.0 && Player.p_specialtype != SC_VALAR)
62 1.3 lukem death("Old age");
63 1.1 jtc }
64 1.1 jtc
65 1.5 jsm const char *
66 1.16 dholland descrlocation(struct player *playerp, phbool shortflag)
67 1.1 jtc {
68 1.3 lukem double circle; /* corresponding circle for coordinates */
69 1.3 lukem int quadrant; /* quandrant of grid */
70 1.5 jsm const char *label; /* pointer to place name */
71 1.5 jsm static const char *const nametable[4][4] = /* names of places */
72 1.3 lukem {
73 1.3 lukem {"Anorien", "Ithilien", "Rohan", "Lorien"},
74 1.3 lukem {"Gondor", "Mordor", "Dunland", "Rovanion"},
75 1.3 lukem {"South Gondor", "Khand", "Eriador", "The Iron Hills"},
76 1.3 lukem {"Far Harad", "Near Harad", "The Northern Waste", "Rhun"}
77 1.1 jtc };
78 1.1 jtc
79 1.3 lukem if (playerp->p_specialtype == SC_VALAR)
80 1.3 lukem return (" is in Valhala");
81 1.1 jtc else
82 1.3 lukem if ((circle = CIRCLE(playerp->p_x, playerp->p_y)) >= 1000.0) {
83 1.3 lukem if (MAX(fabs(playerp->p_x), fabs(playerp->p_y)) > D_BEYOND)
84 1.3 lukem label = "The Point of No Return";
85 1.3 lukem else
86 1.3 lukem label = "The Ashen Mountains";
87 1.3 lukem } else
88 1.3 lukem if (circle >= 55)
89 1.3 lukem label = "Morannon";
90 1.3 lukem else
91 1.3 lukem if (circle >= 35)
92 1.3 lukem label = "Kennaquahair";
93 1.3 lukem else
94 1.3 lukem if (circle >= 20)
95 1.3 lukem label = "The Dead Marshes";
96 1.3 lukem else
97 1.3 lukem if (circle >= 9)
98 1.3 lukem label = "The Outer Waste";
99 1.3 lukem else
100 1.3 lukem if (circle >= 5)
101 1.3 lukem label = "The Moors Adventurous";
102 1.3 lukem else {
103 1.3 lukem if (playerp->p_x == 0.0 && playerp->p_y == 0.0)
104 1.3 lukem label = "The Lord's Chamber";
105 1.3 lukem else {
106 1.3 lukem /* this
107 1.3 lukem *
108 1.3 lukem * expr
109 1.3 lukem * essi
110 1.3 lukem * on
111 1.3 lukem * is
112 1.3 lukem * spli
113 1.3 lukem * t
114 1.3 lukem * to
115 1.3 lukem * prev
116 1.3 lukem * ent
117 1.3 lukem * comp
118 1.3 lukem * iler
119 1.3 lukem *
120 1.3 lukem * loop
121 1.3 lukem *
122 1.3 lukem * with
123 1.3 lukem *
124 1.3 lukem * some
125 1.3 lukem *
126 1.3 lukem * comp
127 1.3 lukem * iler
128 1.3 lukem * s */
129 1.3 lukem quadrant = ((playerp->p_x > 0.0) ? 1 : 0);
130 1.3 lukem quadrant += ((playerp->p_y >= 0.0) ? 2 : 0);
131 1.3 lukem label = nametable[((int) circle) - 1][quadrant];
132 1.3 lukem }
133 1.3 lukem }
134 1.3 lukem
135 1.3 lukem if (shortflag)
136 1.3 lukem sprintf(Databuf, "%.29s", label);
137 1.1 jtc else
138 1.3 lukem sprintf(Databuf, " is in %s (%.0f,%.0f)", label, playerp->p_x, playerp->p_y);
139 1.1 jtc
140 1.3 lukem return (Databuf);
141 1.3 lukem }
142 1.1 jtc
143 1.3 lukem void
144 1.16 dholland tradingpost(void)
145 1.1 jtc {
146 1.3 lukem double numitems; /* number of items to purchase */
147 1.3 lukem double cost; /* cost of purchase */
148 1.3 lukem double blessingcost; /* cost of blessing */
149 1.3 lukem int ch; /* input */
150 1.3 lukem int size; /* size of the trading post */
151 1.3 lukem int loop; /* loop counter */
152 1.3 lukem int cheat = 0; /* number of times player has tried to cheat */
153 1.3 lukem bool dishonest = FALSE; /* set when merchant is dishonest */
154 1.1 jtc
155 1.3 lukem Player.p_status = S_TRADING;
156 1.3 lukem writerecord(&Player, Fileloc);
157 1.1 jtc
158 1.3 lukem clear();
159 1.3 lukem addstr("You are at a trading post. All purchases must be made with gold.");
160 1.3 lukem
161 1.3 lukem size = sqrt(fabs(Player.p_x / 100)) + 1;
162 1.3 lukem size = MIN(7, size);
163 1.1 jtc
164 1.3 lukem /* set up cost of blessing */
165 1.3 lukem blessingcost = 1000.0 * (Player.p_level + 5.0);
166 1.1 jtc
167 1.3 lukem /* print Menu */
168 1.3 lukem move(7, 0);
169 1.3 lukem for (loop = 0; loop < size; ++loop)
170 1.3 lukem /* print Menu */
171 1.3 lukem {
172 1.3 lukem if (loop == 6)
173 1.3 lukem cost = blessingcost;
174 1.1 jtc else
175 1.3 lukem cost = Menu[loop].cost;
176 1.3 lukem printw("(%d) %-12s: %6.0f\n", loop + 1, Menu[loop].item, cost);
177 1.3 lukem }
178 1.1 jtc
179 1.3 lukem mvprintw(5, 0, "L:Leave P:Purchase S:Sell Gems ? ");
180 1.1 jtc
181 1.3 lukem for (;;) {
182 1.3 lukem adjuststats(); /* truncate any bad values */
183 1.1 jtc
184 1.3 lukem /* print some important statistics */
185 1.3 lukem mvprintw(1, 0, "Gold: %9.0f Gems: %9.0f Level: %6.0f Charms: %6d\n",
186 1.3 lukem Player.p_gold, Player.p_gems, Player.p_level, Player.p_charms);
187 1.3 lukem printw("Shield: %9.0f Sword: %9.0f Quicksilver:%3.0f Blessed: %s\n",
188 1.3 lukem Player.p_shield, Player.p_sword, Player.p_quksilver,
189 1.3 lukem (Player.p_blessing ? " True" : "False"));
190 1.3 lukem printw("Brains: %9.0f Mana: %9.0f", Player.p_brains, Player.p_mana);
191 1.1 jtc
192 1.3 lukem move(5, 36);
193 1.3 lukem ch = getanswer("LPS", FALSE);
194 1.3 lukem move(15, 0);
195 1.3 lukem clrtobot();
196 1.3 lukem switch (ch) {
197 1.3 lukem case 'L': /* leave */
198 1.3 lukem case '\n':
199 1.3 lukem altercoordinates(0.0, 0.0, A_NEAR);
200 1.3 lukem return;
201 1.3 lukem
202 1.3 lukem case 'P': /* make purchase */
203 1.3 lukem mvaddstr(15, 0, "What what would you like to buy ? ");
204 1.3 lukem ch = getanswer(" 1234567", FALSE);
205 1.3 lukem move(15, 0);
206 1.3 lukem clrtoeol();
207 1.3 lukem
208 1.3 lukem if (ch - '0' > size)
209 1.3 lukem addstr("Sorry, this merchant doesn't have that.");
210 1.3 lukem else
211 1.3 lukem switch (ch) {
212 1.3 lukem case '1':
213 1.3 lukem printw("Mana is one per %.0f gold piece. How many do you want (%.0f max) ? ",
214 1.3 lukem Menu[0].cost, floor(Player.p_gold / Menu[0].cost));
215 1.3 lukem cost = (numitems = floor(infloat())) * Menu[0].cost;
216 1.3 lukem
217 1.3 lukem if (cost > Player.p_gold || numitems < 0)
218 1.3 lukem ++cheat;
219 1.3 lukem else {
220 1.3 lukem cheat = 0;
221 1.3 lukem Player.p_gold -= cost;
222 1.3 lukem if (drandom() < 0.02)
223 1.3 lukem dishonest = TRUE;
224 1.3 lukem else
225 1.3 lukem Player.p_mana += numitems;
226 1.3 lukem }
227 1.3 lukem break;
228 1.3 lukem
229 1.3 lukem case '2':
230 1.3 lukem printw("Shields are %.0f per +1. How many do you want (%.0f max) ? ",
231 1.3 lukem Menu[1].cost, floor(Player.p_gold / Menu[1].cost));
232 1.3 lukem cost = (numitems = floor(infloat())) * Menu[1].cost;
233 1.3 lukem
234 1.3 lukem if (numitems == 0.0)
235 1.3 lukem break;
236 1.3 lukem else
237 1.3 lukem if (cost > Player.p_gold || numitems < 0)
238 1.3 lukem ++cheat;
239 1.3 lukem else
240 1.3 lukem if (numitems < Player.p_shield)
241 1.3 lukem NOBETTER();
242 1.3 lukem else {
243 1.3 lukem cheat = 0;
244 1.3 lukem Player.p_gold -= cost;
245 1.3 lukem if (drandom() < 0.02)
246 1.3 lukem dishonest = TRUE;
247 1.3 lukem else
248 1.3 lukem Player.p_shield = numitems;
249 1.3 lukem }
250 1.3 lukem break;
251 1.3 lukem
252 1.3 lukem case '3':
253 1.3 lukem printw("A book costs %.0f gp. How many do you want (%.0f max) ? ",
254 1.3 lukem Menu[2].cost, floor(Player.p_gold / Menu[2].cost));
255 1.3 lukem cost = (numitems = floor(infloat())) * Menu[2].cost;
256 1.3 lukem
257 1.3 lukem if (cost > Player.p_gold || numitems < 0)
258 1.3 lukem ++cheat;
259 1.3 lukem else {
260 1.3 lukem cheat = 0;
261 1.3 lukem Player.p_gold -= cost;
262 1.3 lukem if (drandom() < 0.02)
263 1.3 lukem dishonest = TRUE;
264 1.3 lukem else
265 1.3 lukem if (drandom() * numitems > Player.p_level / 10.0
266 1.3 lukem && numitems != 1) {
267 1.3 lukem printw("\nYou blew your mind!\n");
268 1.3 lukem Player.p_brains /= 5;
269 1.3 lukem } else {
270 1.3 lukem Player.p_brains += floor(numitems) * ROLL(20, 8);
271 1.3 lukem }
272 1.3 lukem }
273 1.3 lukem break;
274 1.3 lukem
275 1.3 lukem case '4':
276 1.3 lukem printw("Swords are %.0f gp per +1. How many + do you want (%.0f max) ? ",
277 1.3 lukem Menu[3].cost, floor(Player.p_gold / Menu[3].cost));
278 1.3 lukem cost = (numitems = floor(infloat())) * Menu[3].cost;
279 1.3 lukem
280 1.3 lukem if (numitems == 0.0)
281 1.3 lukem break;
282 1.3 lukem else
283 1.3 lukem if (cost > Player.p_gold || numitems < 0)
284 1.3 lukem ++cheat;
285 1.3 lukem else
286 1.3 lukem if (numitems < Player.p_sword)
287 1.3 lukem NOBETTER();
288 1.3 lukem else {
289 1.3 lukem cheat = 0;
290 1.3 lukem Player.p_gold -= cost;
291 1.3 lukem if (drandom() < 0.02)
292 1.3 lukem dishonest = TRUE;
293 1.3 lukem else
294 1.3 lukem Player.p_sword = numitems;
295 1.3 lukem }
296 1.3 lukem break;
297 1.3 lukem
298 1.3 lukem case '5':
299 1.3 lukem printw("A charm costs %.0f gp. How many do you want (%.0f max) ? ",
300 1.3 lukem Menu[4].cost, floor(Player.p_gold / Menu[4].cost));
301 1.3 lukem cost = (numitems = floor(infloat())) * Menu[4].cost;
302 1.3 lukem
303 1.3 lukem if (cost > Player.p_gold || numitems < 0)
304 1.3 lukem ++cheat;
305 1.3 lukem else {
306 1.3 lukem cheat = 0;
307 1.3 lukem Player.p_gold -= cost;
308 1.3 lukem if (drandom() < 0.02)
309 1.3 lukem dishonest = TRUE;
310 1.3 lukem else
311 1.3 lukem Player.p_charms += numitems;
312 1.3 lukem }
313 1.3 lukem break;
314 1.3 lukem
315 1.3 lukem case '6':
316 1.3 lukem printw("Quicksilver is %.0f gp per +1. How many + do you want (%.0f max) ? ",
317 1.3 lukem Menu[5].cost, floor(Player.p_gold / Menu[5].cost));
318 1.3 lukem cost = (numitems = floor(infloat())) * Menu[5].cost;
319 1.3 lukem
320 1.3 lukem if (numitems == 0.0)
321 1.3 lukem break;
322 1.3 lukem else
323 1.3 lukem if (cost > Player.p_gold || numitems < 0)
324 1.3 lukem ++cheat;
325 1.3 lukem else
326 1.3 lukem if (numitems < Player.p_quksilver)
327 1.3 lukem NOBETTER();
328 1.3 lukem else {
329 1.3 lukem cheat = 0;
330 1.3 lukem Player.p_gold -= cost;
331 1.3 lukem if (drandom() < 0.02)
332 1.3 lukem dishonest = TRUE;
333 1.3 lukem else
334 1.3 lukem Player.p_quksilver = numitems;
335 1.3 lukem }
336 1.3 lukem break;
337 1.3 lukem
338 1.3 lukem case '7':
339 1.3 lukem if (Player.p_blessing) {
340 1.3 lukem addstr("You already have a blessing.");
341 1.3 lukem break;
342 1.3 lukem }
343 1.3 lukem printw("A blessing requires a %.0f gp donation. Still want one ? ", blessingcost);
344 1.3 lukem ch = getanswer("NY", FALSE);
345 1.3 lukem
346 1.4 veego if (ch == 'Y') {
347 1.3 lukem if (Player.p_gold < blessingcost)
348 1.3 lukem ++cheat;
349 1.3 lukem else {
350 1.3 lukem cheat = 0;
351 1.3 lukem Player.p_gold -= blessingcost;
352 1.3 lukem if (drandom() < 0.02)
353 1.3 lukem dishonest = TRUE;
354 1.3 lukem else
355 1.3 lukem Player.p_blessing = TRUE;
356 1.3 lukem }
357 1.4 veego }
358 1.3 lukem break;
359 1.1 jtc }
360 1.3 lukem break;
361 1.1 jtc
362 1.3 lukem case 'S': /* sell gems */
363 1.3 lukem mvprintw(15, 0, "A gem is worth %.0f gp. How many do you want to sell (%.0f max) ? ",
364 1.3 lukem (double) N_GEMVALUE, Player.p_gems);
365 1.3 lukem numitems = floor(infloat());
366 1.1 jtc
367 1.3 lukem if (numitems > Player.p_gems || numitems < 0)
368 1.1 jtc ++cheat;
369 1.3 lukem else {
370 1.1 jtc cheat = 0;
371 1.3 lukem Player.p_gems -= numitems;
372 1.3 lukem Player.p_gold += numitems * N_GEMVALUE;
373 1.1 jtc }
374 1.3 lukem }
375 1.1 jtc
376 1.3 lukem if (cheat == 1)
377 1.3 lukem mvaddstr(17, 0, "Come on, merchants aren't stupid. Stop cheating.\n");
378 1.1 jtc else
379 1.3 lukem if (cheat == 2) {
380 1.3 lukem mvaddstr(17, 0, "You had your chance. This merchant happens to be\n");
381 1.3 lukem printw("a %.0f level magic user, and you made %s mad!\n",
382 1.3 lukem ROLL(Circle * 20.0, 40.0), (drandom() < 0.5) ? "him" : "her");
383 1.3 lukem altercoordinates(0.0, 0.0, A_FAR);
384 1.3 lukem Player.p_energy /= 2.0;
385 1.3 lukem ++Player.p_sin;
386 1.3 lukem more(23);
387 1.3 lukem return;
388 1.3 lukem } else
389 1.3 lukem if (dishonest) {
390 1.3 lukem mvaddstr(17, 0, "The merchant stole your money!");
391 1.3 lukem refresh();
392 1.3 lukem altercoordinates(Player.p_x - Player.p_x / 10.0,
393 1.3 lukem Player.p_y - Player.p_y / 10.0, A_SPECIFIC);
394 1.3 lukem sleep(2);
395 1.3 lukem return;
396 1.3 lukem }
397 1.1 jtc }
398 1.1 jtc }
399 1.1 jtc
400 1.3 lukem void
401 1.16 dholland displaystats(void)
402 1.1 jtc {
403 1.3 lukem mvprintw(0, 0, "%s%s\n", Player.p_name, descrlocation(&Player, FALSE));
404 1.3 lukem mvprintw(1, 0, "Level :%7.0f Energy :%9.0f(%9.0f) Mana :%9.0f Users:%3d\n",
405 1.3 lukem Player.p_level, Player.p_energy, Player.p_maxenergy + Player.p_shield,
406 1.3 lukem Player.p_mana, Users);
407 1.3 lukem mvprintw(2, 0, "Quick :%3.0f(%3.0f) Strength:%9.0f(%9.0f) Gold :%9.0f %s\n",
408 1.3 lukem Player.p_speed, Player.p_quickness + Player.p_quksilver, Player.p_might,
409 1.3 lukem Player.p_strength + Player.p_sword, Player.p_gold, descrstatus(&Player));
410 1.3 lukem }
411 1.1 jtc
412 1.3 lukem void
413 1.16 dholland allstatslist(void)
414 1.1 jtc {
415 1.5 jsm static const char *const flags[] = /* to print value of some bools */
416 1.3 lukem {
417 1.3 lukem "False",
418 1.3 lukem " True"
419 1.3 lukem };
420 1.3 lukem
421 1.3 lukem mvprintw(8, 0, "Type: %s\n", descrtype(&Player, FALSE));
422 1.1 jtc
423 1.3 lukem mvprintw(10, 0, "Experience: %9.0f", Player.p_experience);
424 1.3 lukem mvprintw(11, 0, "Brains : %9.0f", Player.p_brains);
425 1.3 lukem mvprintw(12, 0, "Magic Lvl : %9.0f", Player.p_magiclvl);
426 1.3 lukem mvprintw(13, 0, "Sin : %9.5f", Player.p_sin);
427 1.3 lukem mvprintw(14, 0, "Poison : %9.5f", Player.p_poison);
428 1.3 lukem mvprintw(15, 0, "Gems : %9.0f", Player.p_gems);
429 1.7 jdc mvprintw(16, 0, "Age : %9ld", Player.p_age);
430 1.3 lukem mvprintw(10, 40, "Holy Water: %9d", Player.p_holywater);
431 1.3 lukem mvprintw(11, 40, "Amulets : %9d", Player.p_amulets);
432 1.3 lukem mvprintw(12, 40, "Charms : %9d", Player.p_charms);
433 1.3 lukem mvprintw(13, 40, "Crowns : %9d", Player.p_crowns);
434 1.3 lukem mvprintw(14, 40, "Shield : %9.0f", Player.p_shield);
435 1.3 lukem mvprintw(15, 40, "Sword : %9.0f", Player.p_sword);
436 1.3 lukem mvprintw(16, 40, "Quickslver: %9.0f", Player.p_quksilver);
437 1.3 lukem
438 1.3 lukem mvprintw(18, 0, "Blessing: %s Ring: %s Virgin: %s Palantir: %s",
439 1.3 lukem flags[(int)Player.p_blessing],
440 1.3 lukem flags[Player.p_ring.ring_type != R_NONE],
441 1.3 lukem flags[(int)Player.p_virgin],
442 1.3 lukem flags[(int)Player.p_palantir]);
443 1.3 lukem }
444 1.3 lukem
445 1.5 jsm const char *
446 1.16 dholland descrtype(struct player *playerp, phbool shortflag)
447 1.1 jtc {
448 1.3 lukem int type; /* for caluculating result subscript */
449 1.5 jsm static const char *const results[] =/* description table */
450 1.3 lukem {
451 1.3 lukem " Magic User", " MU",
452 1.3 lukem " Fighter", " F ",
453 1.3 lukem " Elf", " E ",
454 1.3 lukem " Dwarf", " D ",
455 1.3 lukem " Halfling", " H ",
456 1.3 lukem " Experimento", " EX",
457 1.3 lukem " Super", " S ",
458 1.3 lukem " King", " K ",
459 1.3 lukem " Council of Wise", " CW",
460 1.3 lukem " Ex-Valar", " EV",
461 1.3 lukem " Valar", " V ",
462 1.3 lukem " ? ", " ? "
463 1.3 lukem };
464 1.1 jtc
465 1.3 lukem type = playerp->p_type;
466 1.1 jtc
467 1.3 lukem switch (playerp->p_specialtype) {
468 1.1 jtc case SC_NONE:
469 1.3 lukem type = playerp->p_type;
470 1.3 lukem break;
471 1.1 jtc
472 1.1 jtc case SC_KING:
473 1.3 lukem type = 7;
474 1.3 lukem break;
475 1.1 jtc
476 1.1 jtc case SC_COUNCIL:
477 1.3 lukem type = 8;
478 1.3 lukem break;
479 1.1 jtc
480 1.1 jtc case SC_EXVALAR:
481 1.3 lukem type = 9;
482 1.3 lukem break;
483 1.1 jtc
484 1.1 jtc case SC_VALAR:
485 1.3 lukem type = 10;
486 1.3 lukem break;
487 1.1 jtc }
488 1.1 jtc
489 1.3 lukem type *= 2; /* calculate offset */
490 1.1 jtc
491 1.3 lukem if (type > 20)
492 1.3 lukem /* error */
493 1.3 lukem type = 22;
494 1.3 lukem
495 1.3 lukem if (shortflag)
496 1.3 lukem /* use short descriptions */
497 1.3 lukem ++type;
498 1.3 lukem
499 1.3 lukem if (playerp->p_crowns > 0) {
500 1.3 lukem strcpy(Databuf, results[type]);
501 1.3 lukem Databuf[0] = '*';
502 1.3 lukem return (Databuf);
503 1.3 lukem } else
504 1.3 lukem return (results[type]);
505 1.1 jtc }
506 1.1 jtc
507 1.1 jtc long
508 1.16 dholland findname(const char *name, struct player *playerp)
509 1.1 jtc {
510 1.3 lukem long loc = 0; /* location in the file */
511 1.1 jtc
512 1.6 jsm fseek(Playersfp, 0L, SEEK_SET);
513 1.3 lukem while (fread((char *) playerp, SZ_PLAYERSTRUCT, 1, Playersfp) == 1) {
514 1.3 lukem if (strcmp(playerp->p_name, name) == 0) {
515 1.3 lukem if (playerp->p_status != S_NOTUSED || Wizard)
516 1.3 lukem /* found it */
517 1.3 lukem return (loc);
518 1.3 lukem }
519 1.3 lukem loc += SZ_PLAYERSTRUCT;
520 1.1 jtc }
521 1.1 jtc
522 1.3 lukem return (-1);
523 1.1 jtc }
524 1.1 jtc
525 1.1 jtc long
526 1.16 dholland allocrecord(void)
527 1.1 jtc {
528 1.3 lukem long loc = 0L; /* location in file */
529 1.1 jtc
530 1.6 jsm fseek(Playersfp, 0L, SEEK_SET);
531 1.3 lukem while (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) == 1) {
532 1.3 lukem if (Other.p_status == S_NOTUSED)
533 1.3 lukem /* found an empty record */
534 1.3 lukem return (loc);
535 1.3 lukem else
536 1.3 lukem loc += SZ_PLAYERSTRUCT;
537 1.1 jtc }
538 1.1 jtc
539 1.3 lukem /* make a new record */
540 1.3 lukem initplayer(&Other);
541 1.3 lukem Player.p_status = S_OFF;
542 1.3 lukem writerecord(&Other, loc);
543 1.1 jtc
544 1.3 lukem return (loc);
545 1.3 lukem }
546 1.3 lukem
547 1.3 lukem void
548 1.16 dholland freerecord(struct player *playerp, long loc)
549 1.1 jtc {
550 1.3 lukem playerp->p_name[0] = CH_MARKDELETE;
551 1.3 lukem playerp->p_status = S_NOTUSED;
552 1.3 lukem writerecord(playerp, loc);
553 1.3 lukem }
554 1.1 jtc
555 1.3 lukem void
556 1.16 dholland leavegame(void)
557 1.1 jtc {
558 1.1 jtc
559 1.3 lukem if (Player.p_level < 1.0)
560 1.3 lukem /* delete character */
561 1.3 lukem freerecord(&Player, Fileloc);
562 1.3 lukem else {
563 1.3 lukem Player.p_status = S_OFF;
564 1.3 lukem writerecord(&Player, Fileloc);
565 1.1 jtc }
566 1.1 jtc
567 1.3 lukem cleanup(TRUE);
568 1.3 lukem /* NOTREACHED */
569 1.1 jtc }
570 1.1 jtc
571 1.3 lukem void
572 1.16 dholland death(const char *how)
573 1.1 jtc {
574 1.3 lukem FILE *fp; /* for updating various files */
575 1.3 lukem int ch; /* input */
576 1.5 jsm static const char *const deathmesg[] =
577 1.1 jtc /* add more messages here, if desired */
578 1.1 jtc {
579 1.3 lukem "You have been wounded beyond repair. ",
580 1.3 lukem "You have been disemboweled. ",
581 1.3 lukem "You've been mashed, mauled, and spit upon. (You're dead.)\n",
582 1.3 lukem "You died! ",
583 1.3 lukem "You're a complete failure -- you've died!!\n",
584 1.3 lukem "You have been dealt a fatal blow! "
585 1.1 jtc };
586 1.1 jtc
587 1.3 lukem clear();
588 1.1 jtc
589 1.3 lukem if (strcmp(how, "Stupidity") != 0) {
590 1.3 lukem if (Player.p_level > 9999.0)
591 1.3 lukem /* old age */
592 1.3 lukem addstr("Characters must be retired upon reaching level 10000. Sorry.");
593 1.3 lukem else
594 1.3 lukem if (Player.p_lives > 0)
595 1.3 lukem /* extra lives */
596 1.3 lukem {
597 1.3 lukem addstr("You should be more cautious. You've been killed.\n");
598 1.3 lukem printw("You only have %d more chance(s).\n", --Player.p_lives);
599 1.3 lukem more(3);
600 1.3 lukem Player.p_energy = Player.p_maxenergy;
601 1.3 lukem return;
602 1.3 lukem } else
603 1.3 lukem if (Player.p_specialtype == SC_VALAR) {
604 1.3 lukem addstr("You had your chances, but Valar aren't totally\n");
605 1.3 lukem addstr("immortal. You are now left to wither and die . . .\n");
606 1.3 lukem more(3);
607 1.3 lukem Player.p_brains = Player.p_level / 25.0;
608 1.3 lukem Player.p_energy = Player.p_maxenergy /= 5.0;
609 1.3 lukem Player.p_quksilver = Player.p_sword = 0.0;
610 1.3 lukem Player.p_specialtype = SC_COUNCIL;
611 1.3 lukem return;
612 1.3 lukem } else
613 1.3 lukem if (Player.p_ring.ring_inuse &&
614 1.3 lukem (Player.p_ring.ring_type == R_DLREG || Player.p_ring.ring_type == R_NAZREG))
615 1.3 lukem /* good ring in use - saved
616 1.3 lukem * from death */
617 1.3 lukem {
618 1.3 lukem mvaddstr(4, 0, "Your ring saved you from death!\n");
619 1.3 lukem refresh();
620 1.3 lukem Player.p_ring.ring_type = R_NONE;
621 1.3 lukem Player.p_energy = Player.p_maxenergy / 12.0 + 1.0;
622 1.3 lukem if (Player.p_crowns > 0)
623 1.3 lukem --Player.p_crowns;
624 1.3 lukem return;
625 1.3 lukem } else
626 1.3 lukem if (Player.p_ring.ring_type == R_BAD
627 1.3 lukem || Player.p_ring.ring_type == R_SPOILED)
628 1.3 lukem /* bad ring in
629 1.3 lukem * possession; name
630 1.3 lukem * idiot after player */
631 1.3 lukem {
632 1.3 lukem mvaddstr(4, 0,
633 1.3 lukem "Your ring has taken control of you and turned you into a monster!\n");
634 1.6 jsm fseek(Monstfp, 13L * SZ_MONSTERSTRUCT, SEEK_SET);
635 1.3 lukem fread((char *) &Curmonster, SZ_MONSTERSTRUCT, 1, Monstfp);
636 1.3 lukem strcpy(Curmonster.m_name, Player.p_name);
637 1.6 jsm fseek(Monstfp, 13L * SZ_MONSTERSTRUCT, SEEK_SET);
638 1.3 lukem fwrite((char *) &Curmonster, SZ_MONSTERSTRUCT, 1, Monstfp);
639 1.3 lukem fflush(Monstfp);
640 1.3 lukem }
641 1.3 lukem }
642 1.3 lukem enterscore(); /* update score board */
643 1.3 lukem
644 1.3 lukem /* put info in last dead file */
645 1.3 lukem fp = fopen(_PATH_LASTDEAD, "w");
646 1.3 lukem fprintf(fp, "%s (%s, run by %s, level %.0f, killed by %s)",
647 1.3 lukem Player.p_name, descrtype(&Player, TRUE),
648 1.3 lukem Player.p_login, Player.p_level, how);
649 1.3 lukem fclose(fp);
650 1.1 jtc
651 1.3 lukem /* let other players know */
652 1.3 lukem fp = fopen(_PATH_MESS, "w");
653 1.3 lukem fprintf(fp, "%s was killed by %s.", Player.p_name, how);
654 1.3 lukem fclose(fp);
655 1.1 jtc
656 1.3 lukem freerecord(&Player, Fileloc);
657 1.1 jtc
658 1.3 lukem clear();
659 1.3 lukem move(10, 0);
660 1.3 lukem addstr(deathmesg[(int) ROLL(0.0, (double) sizeof(deathmesg) / sizeof(char *))]);
661 1.3 lukem addstr("Care to give it another try ? ");
662 1.3 lukem ch = getanswer("NY", FALSE);
663 1.3 lukem
664 1.3 lukem if (ch == 'Y') {
665 1.3 lukem cleanup(FALSE);
666 1.3 lukem execl(_PATH_GAMEPROG, "phantasia", "-s",
667 1.13 jsm (Wizard ? "-S" : (char *) NULL), (char *) NULL);
668 1.3 lukem exit(0);
669 1.3 lukem /* NOTREACHED */
670 1.1 jtc }
671 1.3 lukem cleanup(TRUE);
672 1.3 lukem /* NOTREACHED */
673 1.1 jtc }
674 1.1 jtc
675 1.3 lukem void
676 1.16 dholland writerecord(struct player *playerp, long place)
677 1.1 jtc {
678 1.6 jsm fseek(Playersfp, place, SEEK_SET);
679 1.3 lukem fwrite((char *) playerp, SZ_PLAYERSTRUCT, 1, Playersfp);
680 1.3 lukem fflush(Playersfp);
681 1.3 lukem }
682 1.1 jtc
683 1.1 jtc double
684 1.16 dholland explevel(double experience)
685 1.1 jtc {
686 1.3 lukem if (experience < 1.1e7)
687 1.3 lukem return (floor(pow((experience / 1000.0), 0.4875)));
688 1.3 lukem else
689 1.3 lukem return (floor(pow((experience / 1250.0), 0.4865)));
690 1.3 lukem }
691 1.1 jtc
692 1.3 lukem void
693 1.16 dholland truncstring(char *string)
694 1.1 jtc {
695 1.3 lukem int length; /* length of string */
696 1.1 jtc
697 1.3 lukem length = strlen(string);
698 1.3 lukem while (string[--length] == ' ')
699 1.3 lukem string[length] = '\0';
700 1.3 lukem }
701 1.1 jtc
702 1.3 lukem void
703 1.16 dholland altercoordinates(double xnew, double ynew, int operation)
704 1.3 lukem {
705 1.3 lukem switch (operation) {
706 1.3 lukem case A_FORCED: /* move with no checks */
707 1.3 lukem break;
708 1.3 lukem
709 1.3 lukem case A_NEAR: /* pick random coordinates near */
710 1.3 lukem xnew = Player.p_x + ROLL(1.0, 5.0);
711 1.3 lukem ynew = Player.p_y - ROLL(1.0, 5.0);
712 1.3 lukem /* fall through for check */
713 1.1 jtc
714 1.1 jtc case A_SPECIFIC: /* just move player */
715 1.3 lukem if (Beyond && fabs(xnew) < D_BEYOND && fabs(ynew) < D_BEYOND)
716 1.3 lukem /*
717 1.3 lukem * cannot move back from point of no return
718 1.3 lukem * pick the largest coordinate to remain unchanged
719 1.3 lukem */
720 1.1 jtc {
721 1.3 lukem if (fabs(xnew) > fabs(ynew))
722 1.3 lukem xnew = SGN(Player.p_x) * MAX(fabs(Player.p_x), D_BEYOND);
723 1.3 lukem else
724 1.3 lukem ynew = SGN(Player.p_y) * MAX(fabs(Player.p_y), D_BEYOND);
725 1.1 jtc }
726 1.3 lukem break;
727 1.1 jtc
728 1.3 lukem case A_FAR: /* pick random coordinates far */
729 1.3 lukem xnew = Player.p_x + SGN(Player.p_x) * ROLL(50 * Circle, 250 * Circle);
730 1.3 lukem ynew = Player.p_y + SGN(Player.p_y) * ROLL(50 * Circle, 250 * Circle);
731 1.3 lukem break;
732 1.1 jtc }
733 1.1 jtc
734 1.3 lukem /* now set location flags and adjust coordinates */
735 1.3 lukem Circle = CIRCLE(Player.p_x = floor(xnew), Player.p_y = floor(ynew));
736 1.3 lukem
737 1.3 lukem /* set up flags based upon location */
738 1.3 lukem Throne = Marsh = Beyond = FALSE;
739 1.3 lukem
740 1.3 lukem if (Player.p_x == 0.0 && Player.p_y == 0.0)
741 1.3 lukem Throne = TRUE;
742 1.3 lukem else
743 1.3 lukem if (Circle < 35 && Circle >= 20)
744 1.3 lukem Marsh = TRUE;
745 1.3 lukem else
746 1.3 lukem if (MAX(fabs(Player.p_x), fabs(Player.p_y)) >= D_BEYOND)
747 1.3 lukem Beyond = TRUE;
748 1.3 lukem
749 1.3 lukem Changed = TRUE;
750 1.3 lukem }
751 1.3 lukem
752 1.3 lukem void
753 1.16 dholland readrecord(struct player *playerp, long loc)
754 1.1 jtc {
755 1.6 jsm fseek(Playersfp, loc, SEEK_SET);
756 1.3 lukem fread((char *) playerp, SZ_PLAYERSTRUCT, 1, Playersfp);
757 1.1 jtc }
758 1.1 jtc
759 1.3 lukem void
760 1.16 dholland adjuststats(void)
761 1.1 jtc {
762 1.3 lukem double dtemp; /* for temporary calculations */
763 1.1 jtc
764 1.3 lukem if (explevel(Player.p_experience) > Player.p_level)
765 1.3 lukem /* move one or more levels */
766 1.1 jtc {
767 1.3 lukem movelevel();
768 1.3 lukem if (Player.p_level > 5.0)
769 1.3 lukem Timeout = TRUE;
770 1.3 lukem }
771 1.3 lukem if (Player.p_specialtype == SC_VALAR)
772 1.3 lukem /* valar */
773 1.3 lukem Circle = Player.p_level / 5.0;
774 1.3 lukem
775 1.3 lukem /* calculate effective quickness */
776 1.3 lukem dtemp = ((Player.p_gold + Player.p_gems / 2.0) - 1000.0) / Statptr->c_goldtote
777 1.8 simonb - Player.p_level;
778 1.3 lukem dtemp = MAX(0.0, dtemp);/* gold slows player down */
779 1.3 lukem Player.p_speed = Player.p_quickness + Player.p_quksilver - dtemp;
780 1.3 lukem
781 1.3 lukem /* calculate effective strength */
782 1.3 lukem if (Player.p_poison > 0.0)
783 1.3 lukem /* poison makes player weaker */
784 1.3 lukem {
785 1.3 lukem dtemp = 1.0 - Player.p_poison * Statptr->c_weakness / 800.0;
786 1.3 lukem dtemp = MAX(0.1, dtemp);
787 1.3 lukem } else
788 1.3 lukem dtemp = 1.0;
789 1.3 lukem Player.p_might = dtemp * Player.p_strength + Player.p_sword;
790 1.3 lukem
791 1.3 lukem /* insure that important things are within limits */
792 1.3 lukem Player.p_quksilver = MIN(99.0, Player.p_quksilver);
793 1.3 lukem Player.p_mana = MIN(Player.p_mana,
794 1.3 lukem Player.p_level * Statptr->c_maxmana + 1000.0);
795 1.3 lukem Player.p_brains = MIN(Player.p_brains,
796 1.3 lukem Player.p_level * Statptr->c_maxbrains + 200.0);
797 1.3 lukem Player.p_charms = MIN(Player.p_charms, Player.p_level + 10.0);
798 1.3 lukem
799 1.3 lukem /*
800 1.3 lukem * some implementations have problems with floating point compare
801 1.3 lukem * we work around it with this stuff
802 1.3 lukem */
803 1.3 lukem Player.p_gold = floor(Player.p_gold) + 0.1;
804 1.3 lukem Player.p_gems = floor(Player.p_gems) + 0.1;
805 1.3 lukem Player.p_mana = floor(Player.p_mana) + 0.1;
806 1.3 lukem
807 1.3 lukem if (Player.p_ring.ring_type != R_NONE)
808 1.3 lukem /* do ring things */
809 1.3 lukem {
810 1.3 lukem /* rest to max */
811 1.3 lukem Player.p_energy = Player.p_maxenergy + Player.p_shield;
812 1.3 lukem
813 1.3 lukem if (Player.p_ring.ring_duration <= 0)
814 1.3 lukem /* clean up expired rings */
815 1.3 lukem switch (Player.p_ring.ring_type) {
816 1.3 lukem case R_BAD: /* ring drives player crazy */
817 1.3 lukem Player.p_ring.ring_type = R_SPOILED;
818 1.3 lukem Player.p_ring.ring_duration = (short) ROLL(10.0, 25.0);
819 1.3 lukem break;
820 1.1 jtc
821 1.3 lukem case R_NAZREG: /* ring disappears */
822 1.3 lukem Player.p_ring.ring_type = R_NONE;
823 1.3 lukem break;
824 1.1 jtc
825 1.3 lukem case R_SPOILED: /* ring kills player */
826 1.3 lukem death("A cursed ring");
827 1.3 lukem break;
828 1.1 jtc
829 1.3 lukem case R_DLREG: /* this ring doesn't expire */
830 1.3 lukem Player.p_ring.ring_duration = 0;
831 1.3 lukem break;
832 1.3 lukem }
833 1.1 jtc }
834 1.3 lukem if (Player.p_age / N_AGE > Player.p_degenerated)
835 1.3 lukem /* age player slightly */
836 1.1 jtc {
837 1.3 lukem ++Player.p_degenerated;
838 1.3 lukem if (Player.p_quickness > 23.0)
839 1.3 lukem Player.p_quickness *= 0.99;
840 1.3 lukem Player.p_strength *= 0.97;
841 1.3 lukem Player.p_brains *= 0.95;
842 1.3 lukem Player.p_magiclvl *= 0.97;
843 1.3 lukem Player.p_maxenergy *= 0.95;
844 1.3 lukem Player.p_quksilver *= 0.95;
845 1.3 lukem Player.p_sword *= 0.93;
846 1.3 lukem Player.p_shield *= 0.93;
847 1.1 jtc }
848 1.1 jtc }
849 1.1 jtc
850 1.3 lukem void
851 1.16 dholland initplayer(struct player *playerp)
852 1.1 jtc {
853 1.3 lukem playerp->p_experience =
854 1.3 lukem playerp->p_level =
855 1.3 lukem playerp->p_strength =
856 1.3 lukem playerp->p_sword =
857 1.3 lukem playerp->p_might =
858 1.3 lukem playerp->p_energy =
859 1.3 lukem playerp->p_maxenergy =
860 1.3 lukem playerp->p_shield =
861 1.3 lukem playerp->p_quickness =
862 1.3 lukem playerp->p_quksilver =
863 1.3 lukem playerp->p_speed =
864 1.3 lukem playerp->p_magiclvl =
865 1.3 lukem playerp->p_mana =
866 1.3 lukem playerp->p_brains =
867 1.3 lukem playerp->p_poison =
868 1.3 lukem playerp->p_gems =
869 1.3 lukem playerp->p_sin =
870 1.3 lukem playerp->p_1scratch =
871 1.3 lukem playerp->p_2scratch = 0.0;
872 1.3 lukem
873 1.3 lukem playerp->p_gold = ROLL(50.0, 75.0) + 0.1; /* give some gold */
874 1.3 lukem
875 1.3 lukem playerp->p_x = ROLL(-125.0, 251.0);
876 1.3 lukem playerp->p_y = ROLL(-125.0, 251.0); /* give random x, y */
877 1.3 lukem
878 1.3 lukem /* clear ring */
879 1.3 lukem playerp->p_ring.ring_type = R_NONE;
880 1.3 lukem playerp->p_ring.ring_duration = 0;
881 1.3 lukem playerp->p_ring.ring_inuse = FALSE;
882 1.3 lukem
883 1.3 lukem playerp->p_age = 0L;
884 1.3 lukem
885 1.3 lukem playerp->p_degenerated = 1; /* don't degenerate initially */
886 1.3 lukem
887 1.3 lukem playerp->p_type = C_FIGHTER; /* default */
888 1.3 lukem playerp->p_specialtype = SC_NONE;
889 1.3 lukem playerp->p_lives =
890 1.3 lukem playerp->p_crowns =
891 1.3 lukem playerp->p_charms =
892 1.3 lukem playerp->p_amulets =
893 1.3 lukem playerp->p_holywater =
894 1.3 lukem playerp->p_lastused = 0;
895 1.3 lukem playerp->p_status = S_NOTUSED;
896 1.3 lukem playerp->p_tampered = T_OFF;
897 1.3 lukem playerp->p_istat = I_OFF;
898 1.3 lukem
899 1.3 lukem playerp->p_palantir =
900 1.3 lukem playerp->p_blessing =
901 1.3 lukem playerp->p_virgin =
902 1.3 lukem playerp->p_blindness = FALSE;
903 1.3 lukem
904 1.3 lukem playerp->p_name[0] =
905 1.3 lukem playerp->p_password[0] =
906 1.3 lukem playerp->p_login[0] = '\0';
907 1.3 lukem }
908 1.1 jtc
909 1.3 lukem void
910 1.16 dholland readmessage(void)
911 1.1 jtc {
912 1.3 lukem move(3, 0);
913 1.3 lukem clrtoeol();
914 1.6 jsm fseek(Messagefp, 0L, SEEK_SET);
915 1.3 lukem if (fgets(Databuf, SZ_DATABUF, Messagefp) != NULL)
916 1.3 lukem addstr(Databuf);
917 1.3 lukem }
918 1.1 jtc
919 1.3 lukem void
920 1.16 dholland error(const char *whichfile)
921 1.1 jtc {
922 1.9 wiz int (*funcp)(const char *,...);
923 1.1 jtc
924 1.3 lukem if (Windows) {
925 1.3 lukem funcp = printw;
926 1.3 lukem clear();
927 1.3 lukem } else
928 1.3 lukem funcp = printf;
929 1.3 lukem
930 1.10 jsm (*funcp) ("An unrecoverable error has occurred reading %s. (%s)\n", whichfile, strerror(errno));
931 1.3 lukem (*funcp) ("Please run 'setup' to determine the problem.\n");
932 1.3 lukem cleanup(TRUE);
933 1.3 lukem /* NOTREACHED */
934 1.3 lukem }
935 1.1 jtc
936 1.1 jtc double
937 1.16 dholland distance(double x_1, double x_2, double y_1, double y_2)
938 1.1 jtc {
939 1.3 lukem double deltax, deltay;
940 1.1 jtc
941 1.15 dholland deltax = x_1 - x_2;
942 1.15 dholland deltay = y_1 - y_2;
943 1.3 lukem return (sqrt(deltax * deltax + deltay * deltay));
944 1.3 lukem }
945 1.1 jtc
946 1.3 lukem void
947 1.16 dholland ill_sig(int whichsig)
948 1.1 jtc {
949 1.3 lukem clear();
950 1.3 lukem if (!(whichsig == SIGINT || whichsig == SIGQUIT))
951 1.3 lukem printw("Error: caught signal # %d.\n", whichsig);
952 1.3 lukem cleanup(TRUE);
953 1.3 lukem /* NOTREACHED */
954 1.3 lukem }
955 1.1 jtc
956 1.5 jsm const char *
957 1.16 dholland descrstatus(struct player *playerp)
958 1.1 jtc {
959 1.3 lukem switch (playerp->p_status) {
960 1.1 jtc case S_PLAYING:
961 1.3 lukem if (playerp->p_energy < 0.2 * (playerp->p_maxenergy + playerp->p_shield))
962 1.3 lukem return ("Low Energy");
963 1.3 lukem else
964 1.3 lukem if (playerp->p_blindness)
965 1.3 lukem return ("Blind");
966 1.3 lukem else
967 1.3 lukem return ("In game");
968 1.1 jtc
969 1.1 jtc case S_CLOAKED:
970 1.3 lukem return ("Cloaked");
971 1.1 jtc
972 1.1 jtc case S_INBATTLE:
973 1.3 lukem return ("In Battle");
974 1.1 jtc
975 1.1 jtc case S_MONSTER:
976 1.3 lukem return ("Encounter");
977 1.1 jtc
978 1.1 jtc case S_TRADING:
979 1.3 lukem return ("Trading");
980 1.1 jtc
981 1.1 jtc case S_OFF:
982 1.3 lukem return ("Off");
983 1.1 jtc
984 1.1 jtc case S_HUNGUP:
985 1.3 lukem return ("Hung up");
986 1.1 jtc
987 1.1 jtc default:
988 1.3 lukem return ("");
989 1.1 jtc }
990 1.1 jtc }
991 1.1 jtc
992 1.1 jtc double
993 1.16 dholland drandom(void)
994 1.1 jtc {
995 1.3 lukem if (sizeof(int) != 2)
996 1.3 lukem /* use only low bits */
997 1.3 lukem return ((double) (random() & 0x7fff) / 32768.0);
998 1.3 lukem else
999 1.3 lukem return ((double) random() / 32768.0);
1000 1.3 lukem }
1001 1.1 jtc
1002 1.3 lukem void
1003 1.16 dholland collecttaxes(double gold, double gems)
1004 1.1 jtc {
1005 1.3 lukem FILE *fp; /* to update Goldfile */
1006 1.3 lukem double dtemp; /* for temporary calculations */
1007 1.3 lukem double taxes; /* tax liability */
1008 1.3 lukem
1009 1.3 lukem /* add to cache */
1010 1.3 lukem Player.p_gold += gold;
1011 1.3 lukem Player.p_gems += gems;
1012 1.1 jtc
1013 1.3 lukem /* calculate tax liability */
1014 1.3 lukem taxes = N_TAXAMOUNT / 100.0 * (N_GEMVALUE * gems + gold);
1015 1.1 jtc
1016 1.3 lukem if (Player.p_gold < taxes)
1017 1.3 lukem /* not enough gold to pay taxes, must convert some gems to
1018 1.3 lukem * gold */
1019 1.1 jtc {
1020 1.3 lukem dtemp = floor(taxes / N_GEMVALUE + 1.0); /* number of gems to
1021 1.3 lukem * convert */
1022 1.1 jtc
1023 1.3 lukem if (Player.p_gems >= dtemp)
1024 1.3 lukem /* player has enough to convert */
1025 1.3 lukem {
1026 1.3 lukem Player.p_gems -= dtemp;
1027 1.3 lukem Player.p_gold += dtemp * N_GEMVALUE;
1028 1.3 lukem } else
1029 1.3 lukem /* take everything; this should never happen */
1030 1.3 lukem {
1031 1.3 lukem Player.p_gold += Player.p_gems * N_GEMVALUE;
1032 1.3 lukem Player.p_gems = 0.0;
1033 1.3 lukem taxes = Player.p_gold;
1034 1.3 lukem }
1035 1.1 jtc }
1036 1.3 lukem Player.p_gold -= taxes;
1037 1.1 jtc
1038 1.3 lukem if ((fp = fopen(_PATH_GOLD, "r+")) != NULL)
1039 1.3 lukem /* update taxes */
1040 1.1 jtc {
1041 1.3 lukem dtemp = 0.0;
1042 1.3 lukem fread((char *) &dtemp, sizeof(double), 1, fp);
1043 1.3 lukem dtemp += floor(taxes);
1044 1.6 jsm fseek(fp, 0L, SEEK_SET);
1045 1.3 lukem fwrite((char *) &dtemp, sizeof(double), 1, fp);
1046 1.3 lukem fclose(fp);
1047 1.1 jtc }
1048 1.1 jtc }
1049