interplayer.c revision 1.2 1 1.2 cgd /* $NetBSD: interplayer.c,v 1.2 1995/03/24 03:58:47 cgd Exp $ */
2 1.2 cgd
3 1.1 jtc /*
4 1.1 jtc * interplayer.c - player to player routines for Phantasia
5 1.1 jtc */
6 1.1 jtc
7 1.1 jtc #include "include.h"
8 1.1 jtc
9 1.1 jtc /************************************************************************
10 1.1 jtc /
11 1.1 jtc / FUNCTION NAME: checkbattle()
12 1.1 jtc /
13 1.1 jtc / FUNCTION: check to see if current player should battle another
14 1.1 jtc /
15 1.1 jtc / AUTHOR: E. A. Estes, 12/4/85
16 1.1 jtc /
17 1.1 jtc / ARGUMENTS: none
18 1.1 jtc /
19 1.1 jtc / RETURN VALUE: none
20 1.1 jtc /
21 1.1 jtc / MODULES CALLED: battleplayer(), fread(), fseek()
22 1.1 jtc /
23 1.1 jtc / GLOBAL INPUTS: Other, Users, Player, Fileloc, *Playersfp
24 1.1 jtc /
25 1.1 jtc / GLOBAL OUTPUTS: Users
26 1.1 jtc /
27 1.1 jtc / DESCRIPTION:
28 1.1 jtc / Seach player file for a foe at the same coordinates as the
29 1.1 jtc / current player.
30 1.1 jtc / Also update user count.
31 1.1 jtc /
32 1.1 jtc /************************************************************************/
33 1.1 jtc
34 1.1 jtc checkbattle()
35 1.1 jtc {
36 1.1 jtc long foeloc = 0L; /* location in file of person to fight */
37 1.1 jtc
38 1.1 jtc Users = 0;
39 1.1 jtc fseek(Playersfp, 0L, 0);
40 1.1 jtc
41 1.1 jtc while (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) == 1)
42 1.1 jtc {
43 1.1 jtc if (Other.p_status != S_OFF
44 1.1 jtc && Other.p_status != S_NOTUSED
45 1.1 jtc && Other.p_status != S_HUNGUP
46 1.1 jtc && (Other.p_status != S_CLOAKED || Other.p_specialtype != SC_VALAR))
47 1.1 jtc /* player is on and not a cloaked valar */
48 1.1 jtc {
49 1.1 jtc ++Users;
50 1.1 jtc
51 1.1 jtc if (Player.p_x == Other.p_x
52 1.1 jtc && Player.p_y == Other.p_y
53 1.1 jtc /* same coordinates */
54 1.1 jtc && foeloc != Fileloc
55 1.1 jtc /* not self */
56 1.1 jtc && Player.p_status == S_PLAYING
57 1.1 jtc && (Other.p_status == S_PLAYING || Other.p_status == S_INBATTLE)
58 1.1 jtc /* both are playing */
59 1.1 jtc && Other.p_specialtype != SC_VALAR
60 1.1 jtc && Player.p_specialtype != SC_VALAR)
61 1.1 jtc /* neither is valar */
62 1.1 jtc {
63 1.1 jtc battleplayer(foeloc);
64 1.1 jtc return;
65 1.1 jtc }
66 1.1 jtc }
67 1.1 jtc foeloc += SZ_PLAYERSTRUCT;
68 1.1 jtc }
69 1.1 jtc }
70 1.1 jtc /**/
72 1.1 jtc /************************************************************************
73 1.1 jtc /
74 1.1 jtc / FUNCTION NAME: battleplayer()
75 1.1 jtc /
76 1.1 jtc / FUNCTION: inter-terminal battle with another player
77 1.1 jtc /
78 1.1 jtc / AUTHOR: E. A. Estes, 2/15/86
79 1.1 jtc /
80 1.1 jtc / ARGUMENTS:
81 1.1 jtc / long foeplace - location in player file of person to battle
82 1.1 jtc /
83 1.1 jtc / RETURN VALUE: none
84 1.1 jtc /
85 1.1 jtc / MODULES CALLED: readrecord(), readmessage(), writerecord(), collecttaxes(),
86 1.1 jtc / displaystats(), fabs(), more(), death(), sleep(), wmove(), waddch(), printw(),
87 1.1 jtc / myturn(), altercoordinates(), waddstr(), wrefresh(), mvprintw(),
88 1.1 jtc / getanswer(), wclrtoeol(), wclrtobot()
89 1.1 jtc /
90 1.1 jtc / GLOBAL INPUTS: Foestrikes, LINES, Lines, Other, Shield, Player, *stdscr,
91 1.1 jtc / Fileloc, *Enemyname
92 1.1 jtc /
93 1.1 jtc / GLOBAL OUTPUTS: Foestrikes, Lines, Shield, Player, Luckout, *Enemyname
94 1.1 jtc /
95 1.1 jtc / DESCRIPTION:
96 1.1 jtc / Inter-terminal battle is a very fragile and slightly klugy thing.
97 1.1 jtc / At any time, one player is master and the other is slave.
98 1.1 jtc / We pick who is master first by speed and level. After that,
99 1.1 jtc / the slave waits for the master to relinquish its turn, and
100 1.1 jtc / the slave becomes master, and so on.
101 1.1 jtc /
102 1.1 jtc / The items in the player structure which control the handshake are:
103 1.1 jtc / p_tampered:
104 1.1 jtc / master increments this to relinquish control
105 1.1 jtc / p_istat:
106 1.1 jtc / master sets this to specify particular action
107 1.1 jtc / p_1scratch:
108 1.1 jtc / set to total damage inflicted so far; changes to indicate action
109 1.1 jtc /
110 1.1 jtc /************************************************************************/
111 1.1 jtc
112 1.1 jtc battleplayer(foeplace)
113 1.1 jtc long foeplace;
114 1.1 jtc {
115 1.1 jtc double dtemp; /* for temporary calculations */
116 1.1 jtc double oldhits = 0.0; /* previous damage inflicted by foe */
117 1.1 jtc register int loop; /* for timing out */
118 1.1 jtc int ch; /* input */
119 1.1 jtc short oldtampered; /* old value of foe's p_tampered */
120 1.1 jtc
121 1.1 jtc Lines = 8;
122 1.1 jtc Luckout = FALSE;
123 1.1 jtc mvaddstr(4, 0, "Preparing for battle!\n");
124 1.1 jtc refresh();
125 1.1 jtc
126 1.1 jtc #ifdef SYS5
127 1.1 jtc flushinp();
128 1.1 jtc #endif
129 1.1 jtc
130 1.1 jtc /* set up variables, file, etc. */
131 1.1 jtc Player.p_status = S_INBATTLE;
132 1.1 jtc Shield = Player.p_energy;
133 1.1 jtc
134 1.1 jtc /* if p_tampered is not 0, someone else may try to change it (king, etc.) */
135 1.1 jtc Player.p_tampered = oldtampered = 1;
136 1.1 jtc Player.p_1scratch = 0.0;
137 1.1 jtc Player.p_istat = I_OFF;
138 1.1 jtc
139 1.1 jtc readrecord(&Other, foeplace);
140 1.1 jtc if (fabs(Player.p_level - Other.p_level) > 20.0)
141 1.1 jtc /* see if players are greatly mismatched */
142 1.1 jtc {
143 1.1 jtc dtemp = (Player.p_level - Other.p_level) / MAX(Player.p_level, Other.p_level);
144 1.1 jtc if (dtemp < -0.5)
145 1.1 jtc /* foe outweighs this one */
146 1.1 jtc Player.p_speed *= 2.0;
147 1.1 jtc }
148 1.1 jtc
149 1.1 jtc writerecord(&Player, Fileloc); /* write out all our info */
150 1.1 jtc
151 1.1 jtc if (Player.p_blindness)
152 1.1 jtc Enemyname = "someone";
153 1.1 jtc else
154 1.1 jtc Enemyname = Other.p_name;
155 1.1 jtc
156 1.1 jtc mvprintw(6, 0, "You have encountered %s Level: %.0f\n", Enemyname, Other.p_level);
157 1.1 jtc refresh();
158 1.1 jtc
159 1.1 jtc for (loop = 0; Other.p_status != S_INBATTLE && loop < 30; ++loop)
160 1.1 jtc /* wait for foe to respond */
161 1.1 jtc {
162 1.1 jtc readrecord(&Other, foeplace);
163 1.1 jtc sleep(1);
164 1.1 jtc }
165 1.1 jtc
166 1.1 jtc if (Other.p_status != S_INBATTLE)
167 1.1 jtc /* foe did not respond */
168 1.1 jtc {
169 1.1 jtc mvprintw(5, 0, "%s is not responding.\n", Enemyname);
170 1.1 jtc goto LEAVE;
171 1.1 jtc }
172 1.1 jtc /* else, we are ready to battle */
173 1.1 jtc
174 1.1 jtc move(4, 0);
175 1.1 jtc clrtoeol();
176 1.1 jtc
177 1.1 jtc /*
178 1.1 jtc * determine who is first master
179 1.1 jtc * if neither player is faster, check level
180 1.1 jtc * if neither level is greater, battle is not allowed
181 1.1 jtc * (this should never happen, but we have to handle it)
182 1.1 jtc */
183 1.1 jtc if (Player.p_speed > Other.p_speed)
184 1.1 jtc Foestrikes = FALSE;
185 1.1 jtc else if (Other.p_speed > Player.p_speed)
186 1.1 jtc Foestrikes = TRUE;
187 1.1 jtc else if (Player.p_level > Other.p_level)
188 1.1 jtc Foestrikes = FALSE;
189 1.1 jtc else if (Other.p_level > Player.p_level)
190 1.1 jtc Foestrikes = TRUE;
191 1.1 jtc else
192 1.1 jtc /* no one is faster */
193 1.1 jtc {
194 1.1 jtc printw("You can't fight %s yet.", Enemyname);
195 1.1 jtc goto LEAVE;
196 1.1 jtc }
197 1.1 jtc
198 1.1 jtc for (;;)
199 1.1 jtc {
200 1.1 jtc displaystats();
201 1.1 jtc readmessage();
202 1.1 jtc mvprintw(1, 26, "%20.0f", Shield); /* overprint energy */
203 1.1 jtc
204 1.1 jtc if (!Foestrikes)
205 1.1 jtc /* take action against foe */
206 1.1 jtc myturn();
207 1.1 jtc else
208 1.1 jtc /* wait for foe to take action */
209 1.1 jtc {
210 1.1 jtc mvaddstr(4, 0, "Waiting...\n");
211 1.1 jtc clrtoeol();
212 1.1 jtc refresh();
213 1.1 jtc
214 1.1 jtc for (loop = 0; loop < 20; ++loop)
215 1.1 jtc /* wait for foe to act */
216 1.1 jtc {
217 1.1 jtc readrecord(&Other, foeplace);
218 1.1 jtc if (Other.p_1scratch != oldhits)
219 1.1 jtc /* p_1scratch changes to indicate action */
220 1.1 jtc break;
221 1.1 jtc else
222 1.1 jtc /* wait and try again */
223 1.1 jtc {
224 1.1 jtc sleep(1);
225 1.1 jtc addch('.');
226 1.1 jtc refresh();
227 1.1 jtc }
228 1.1 jtc }
229 1.1 jtc
230 1.1 jtc if (Other.p_1scratch == oldhits)
231 1.1 jtc {
232 1.1 jtc /* timeout */
233 1.1 jtc mvaddstr(22, 0, "Timeout: waiting for response. Do you want to wait ? ");
234 1.1 jtc ch = getanswer("NY", FALSE);
235 1.1 jtc move(22, 0);
236 1.1 jtc clrtobot();
237 1.1 jtc if (ch == 'Y')
238 1.1 jtc continue;
239 1.1 jtc else
240 1.1 jtc break;
241 1.1 jtc }
242 1.1 jtc else
243 1.1 jtc /* foe took action */
244 1.1 jtc {
245 1.1 jtc switch (Other.p_istat)
246 1.1 jtc {
247 1.1 jtc case I_RAN: /* foe ran away */
248 1.1 jtc mvprintw(Lines++, 0, "%s ran away!", Enemyname);
249 1.1 jtc break;
250 1.1 jtc
251 1.1 jtc case I_STUCK: /* foe tried to run, but couldn't */
252 1.1 jtc mvprintw(Lines++, 0, "%s tried to run away.", Enemyname);
253 1.1 jtc break;
254 1.1 jtc
255 1.1 jtc case I_BLEWIT: /* foe tried to luckout, but didn't */
256 1.1 jtc mvprintw(Lines++, 0, "%s tried to luckout!", Enemyname);
257 1.1 jtc break;
258 1.1 jtc
259 1.1 jtc default:
260 1.1 jtc dtemp = Other.p_1scratch - oldhits;
261 1.1 jtc mvprintw(Lines++, 0, "%s hit you %.0f times!", Enemyname, dtemp);
262 1.1 jtc Shield -= dtemp;
263 1.1 jtc break;
264 1.1 jtc }
265 1.1 jtc
266 1.1 jtc oldhits = Other.p_1scratch; /* keep track of old hits */
267 1.1 jtc
268 1.1 jtc if (Other.p_tampered != oldtampered)
269 1.1 jtc /* p_tampered changes to relinquish turn */
270 1.1 jtc {
271 1.1 jtc oldtampered = Other.p_tampered;
272 1.1 jtc Foestrikes = FALSE;
273 1.1 jtc }
274 1.1 jtc }
275 1.1 jtc }
276 1.1 jtc
277 1.1 jtc /* decide what happens next */
278 1.1 jtc refresh();
279 1.1 jtc if (Lines > LINES - 2)
280 1.1 jtc {
281 1.1 jtc more(Lines);
282 1.1 jtc move(Lines = 8, 0);
283 1.1 jtc clrtobot();
284 1.1 jtc }
285 1.1 jtc
286 1.1 jtc if (Other.p_istat == I_KILLED || Shield < 0.0)
287 1.1 jtc /* we died */
288 1.1 jtc {
289 1.1 jtc Shield = -2.0; /* insure this value is negative */
290 1.1 jtc break;
291 1.1 jtc }
292 1.1 jtc
293 1.1 jtc if (Player.p_istat == I_KILLED)
294 1.1 jtc /* we killed foe; award treasre */
295 1.1 jtc {
296 1.1 jtc mvprintw(Lines++, 0, "You killed %s!", Enemyname);
297 1.1 jtc Player.p_experience += Other.p_experience;
298 1.1 jtc Player.p_crowns += (Player.p_level < 1000.0) ? Other.p_crowns : 0;
299 1.1 jtc Player.p_amulets += Other.p_amulets;
300 1.1 jtc Player.p_charms += Other.p_charms;
301 1.1 jtc collecttaxes(Other.p_gold, Other.p_gems);
302 1.1 jtc Player.p_sword = MAX(Player.p_sword, Other.p_sword);
303 1.1 jtc Player.p_shield = MAX(Player.p_shield, Other.p_shield);
304 1.1 jtc Player.p_quksilver = MAX(Player.p_quksilver, Other.p_quksilver);
305 1.1 jtc if (Other.p_virgin && !Player.p_virgin)
306 1.1 jtc {
307 1.1 jtc mvaddstr(Lines++, 0, "You have rescued a virgin. Will you be honorable ? ");
308 1.1 jtc if ((ch = getanswer("YN", FALSE)) == 'Y')
309 1.1 jtc Player.p_virgin = TRUE;
310 1.1 jtc else
311 1.1 jtc {
312 1.1 jtc ++Player.p_sin;
313 1.1 jtc Player.p_experience += 8000.0;
314 1.1 jtc }
315 1.1 jtc }
316 1.1 jtc sleep(3); /* give other person time to die */
317 1.1 jtc break;
318 1.1 jtc }
319 1.1 jtc else if (Player.p_istat == I_RAN || Other.p_istat == I_RAN)
320 1.1 jtc /* either player ran away */
321 1.1 jtc break;
322 1.1 jtc }
323 1.1 jtc
324 1.1 jtc LEAVE:
325 1.1 jtc /* clean up things and leave */
326 1.1 jtc writerecord(&Player, Fileloc); /* update a final time */
327 1.1 jtc altercoordinates(0.0, 0.0, A_NEAR); /* move away from battle site */
328 1.1 jtc Player.p_energy = Shield; /* set energy to actual value */
329 1.1 jtc Player.p_tampered = T_OFF; /* clear p_tampered */
330 1.1 jtc
331 1.1 jtc more(Lines); /* pause */
332 1.1 jtc
333 1.1 jtc move(4, 0);
334 1.1 jtc clrtobot(); /* clear bottom area of screen */
335 1.1 jtc
336 1.1 jtc if (Player.p_energy < 0.0)
337 1.1 jtc /* we are dead */
338 1.1 jtc death("Interterminal battle");
339 1.1 jtc }
340 1.1 jtc /**/
342 1.1 jtc /************************************************************************
343 1.1 jtc /
344 1.1 jtc / FUNCTION NAME: myturn()
345 1.1 jtc /
346 1.1 jtc / FUNCTION: process players action against foe in battle
347 1.1 jtc /
348 1.1 jtc / AUTHOR: E. A. Estes, 2/7/86
349 1.1 jtc /
350 1.1 jtc / ARGUMENTS: none
351 1.1 jtc /
352 1.1 jtc / RETURN VALUE: none
353 1.1 jtc /
354 1.1 jtc / MODULES CALLED: writerecord(), inputoption(), floor(), wmove(), drandom(),
355 1.1 jtc / waddstr(), wrefresh(), mvprintw(), wclrtoeol(), wclrtobot()
356 1.1 jtc /
357 1.1 jtc / GLOBAL INPUTS: Lines, Other, Player, *stdscr, Fileloc, Luckout,
358 1.1 jtc / *Enemyname
359 1.1 jtc /
360 1.1 jtc / GLOBAL OUTPUTS: Foestrikes, Lines, Player, Luckout
361 1.1 jtc /
362 1.1 jtc / DESCRIPTION:
363 1.1 jtc / Take action action against foe, and decide who is master
364 1.1 jtc / for next iteration.
365 1.1 jtc /
366 1.1 jtc /************************************************************************/
367 1.1 jtc
368 1.1 jtc myturn()
369 1.1 jtc {
370 1.1 jtc double dtemp; /* for temporary calculations */
371 1.1 jtc int ch; /* input */
372 1.1 jtc
373 1.1 jtc mvaddstr(7, 0, "1:Fight 2:Run Away! 3:Power Blast ");
374 1.1 jtc if (Luckout)
375 1.1 jtc clrtoeol();
376 1.1 jtc else
377 1.1 jtc addstr("4:Luckout ");
378 1.1 jtc
379 1.1 jtc ch = inputoption();
380 1.1 jtc move(Lines = 8, 0);
381 1.1 jtc clrtobot();
382 1.1 jtc
383 1.1 jtc switch (ch)
384 1.1 jtc {
385 1.1 jtc default: /* fight */
386 1.1 jtc dtemp = ROLL(2.0, Player.p_might);
387 1.1 jtc HIT:
388 1.1 jtc mvprintw(Lines++, 0, "You hit %s %.0f times!", Enemyname, dtemp);
389 1.1 jtc Player.p_sin += 0.5;
390 1.1 jtc Player.p_1scratch += dtemp;
391 1.1 jtc Player.p_istat = I_OFF;
392 1.1 jtc break;
393 1.1 jtc
394 1.1 jtc case '2': /* run away */
395 1.1 jtc Player.p_1scratch -= 1.0; /* change this to indicate action */
396 1.1 jtc if (drandom() > 0.25)
397 1.1 jtc {
398 1.1 jtc mvaddstr(Lines++, 0, "You got away!");
399 1.1 jtc Player.p_istat = I_RAN;
400 1.1 jtc }
401 1.1 jtc else
402 1.1 jtc {
403 1.1 jtc mvprintw(Lines++, 0, "%s is still after you!", Enemyname);
404 1.1 jtc Player.p_istat = I_STUCK;
405 1.1 jtc }
406 1.1 jtc break;
407 1.1 jtc
408 1.1 jtc case '3': /* power blast */
409 1.1 jtc dtemp = MIN(Player.p_mana, Player.p_level * 5.0);
410 1.1 jtc Player.p_mana -= dtemp;
411 1.1 jtc dtemp *= (drandom() + 0.5) * Player.p_magiclvl * 0.2 + 2.0;
412 1.1 jtc mvprintw(Lines++, 0, "You blasted %s !", Enemyname);
413 1.1 jtc goto HIT;
414 1.1 jtc
415 1.1 jtc case '4': /* luckout */
416 1.1 jtc if (Luckout || drandom() > 0.1)
417 1.1 jtc {
418 1.1 jtc if (Luckout)
419 1.1 jtc mvaddstr(Lines++, 0, "You already tried that!");
420 1.1 jtc else
421 1.1 jtc {
422 1.1 jtc mvaddstr(Lines++, 0, "Not this time . . .");
423 1.1 jtc Luckout = TRUE;
424 1.1 jtc }
425 1.1 jtc
426 1.1 jtc Player.p_1scratch -= 1.0;
427 1.1 jtc Player.p_istat = I_BLEWIT;
428 1.1 jtc }
429 1.1 jtc else
430 1.1 jtc {
431 1.1 jtc mvaddstr(Lines++, 0, "You just lucked out!");
432 1.1 jtc Player.p_1scratch = Other.p_energy * 1.1;
433 1.1 jtc }
434 1.1 jtc break;
435 1.1 jtc }
436 1.1 jtc
437 1.1 jtc refresh();
438 1.1 jtc Player.p_1scratch = floor(Player.p_1scratch); /* clean up any mess */
439 1.1 jtc
440 1.1 jtc if (Player.p_1scratch > Other.p_energy)
441 1.1 jtc Player.p_istat = I_KILLED;
442 1.1 jtc else if (drandom() * Player.p_speed < drandom() * Other.p_speed)
443 1.1 jtc /* relinquish control */
444 1.1 jtc {
445 1.1 jtc ++Player.p_tampered;
446 1.1 jtc Foestrikes = TRUE;
447 1.1 jtc }
448 1.1 jtc
449 1.1 jtc writerecord(&Player, Fileloc); /* let foe know what we did */
450 1.1 jtc }
451 1.1 jtc /**/
453 1.1 jtc /************************************************************************
454 1.1 jtc /
455 1.1 jtc / FUNCTION NAME: checktampered()
456 1.1 jtc /
457 1.1 jtc / FUNCTION: check if current player has been tampered with
458 1.1 jtc /
459 1.1 jtc / AUTHOR: E. A. Estes, 12/4/85
460 1.1 jtc /
461 1.1 jtc / ARGUMENTS: none
462 1.1 jtc /
463 1.1 jtc / RETURN VALUE: none
464 1.1 jtc /
465 1.1 jtc / MODULES CALLED: readrecord(), fread(), fseek(), tampered(), writevoid()
466 1.1 jtc /
467 1.1 jtc / GLOBAL INPUTS: *Energyvoidfp, Other, Player, Fileloc, Enrgyvoid
468 1.1 jtc /
469 1.1 jtc / GLOBAL OUTPUTS: Enrgyvoid
470 1.1 jtc /
471 1.1 jtc / DESCRIPTION:
472 1.1 jtc / Check for energy voids, holy grail, and tampering by other
473 1.1 jtc / players.
474 1.1 jtc /
475 1.1 jtc /************************************************************************/
476 1.1 jtc
477 1.1 jtc checktampered()
478 1.1 jtc {
479 1.1 jtc long loc = 0L; /* location in energy void file */
480 1.1 jtc
481 1.1 jtc /* first check for energy voids */
482 1.1 jtc fseek(Energyvoidfp, 0L, 0);
483 1.1 jtc while (fread((char *) &Enrgyvoid, SZ_VOIDSTRUCT, 1, Energyvoidfp) == 1)
484 1.1 jtc if (Enrgyvoid.ev_active
485 1.1 jtc && Enrgyvoid.ev_x == Player.p_x
486 1.1 jtc && Enrgyvoid.ev_y == Player.p_y)
487 1.1 jtc /* sitting on one */
488 1.1 jtc {
489 1.1 jtc if (loc > 0L)
490 1.1 jtc /* not the holy grail; inactivate energy void */
491 1.1 jtc {
492 1.1 jtc Enrgyvoid.ev_active = FALSE;
493 1.1 jtc writevoid(&Enrgyvoid, loc);
494 1.1 jtc tampered(T_NRGVOID, 0.0, 0.0);
495 1.1 jtc }
496 1.1 jtc else if (Player.p_status != S_CLOAKED)
497 1.1 jtc /* holy grail */
498 1.1 jtc tampered(T_GRAIL, 0.0, 0.0);
499 1.1 jtc break;
500 1.1 jtc }
501 1.1 jtc else
502 1.1 jtc loc += SZ_VOIDSTRUCT;
503 1.1 jtc
504 1.1 jtc /* now check for other things */
505 1.1 jtc readrecord(&Other, Fileloc);
506 1.1 jtc if (Other.p_tampered != T_OFF)
507 1.1 jtc tampered(Other.p_tampered, Other.p_1scratch, Other.p_2scratch);
508 1.1 jtc }
509 1.1 jtc /**/
511 1.1 jtc /************************************************************************
512 1.1 jtc /
513 1.1 jtc / FUNCTION NAME: tampered()
514 1.1 jtc /
515 1.1 jtc / FUNCTION: take care of tampering by other players
516 1.1 jtc /
517 1.1 jtc / AUTHOR: E. A. Estes, 12/4/85
518 1.1 jtc /
519 1.1 jtc / ARGUMENTS:
520 1.1 jtc / int what - what type of tampering
521 1.1 jtc / double arg1, arg2 - rest of tampering info
522 1.1 jtc /
523 1.1 jtc / RETURN VALUE: none
524 1.1 jtc /
525 1.1 jtc / MODULES CALLED: writerecord(), more(), fread(), death(), fseek(), sleep(),
526 1.1 jtc / floor(), wmove(), waddch(), drandom(), printw(), altercoordinates(),
527 1.1 jtc / waddstr(), wrefresh(), encounter(), writevoid()
528 1.1 jtc /
529 1.1 jtc / GLOBAL INPUTS: Other, Player, *stdscr, Enrgyvoid, *Playersfp
530 1.1 jtc /
531 1.1 jtc / GLOBAL OUTPUTS: Other, Player, Changed, Enrgyvoid
532 1.1 jtc /
533 1.1 jtc / DESCRIPTION:
534 1.1 jtc / Take care of energy voids, holy grail, decree and intervention
535 1.1 jtc / action on current player.
536 1.1 jtc /
537 1.1 jtc /************************************************************************/
538 1.1 jtc
539 1.1 jtc tampered(what, arg1, arg2)
540 1.1 jtc int what;
541 1.1 jtc double arg1;
542 1.1 jtc double arg2;
543 1.1 jtc {
544 1.1 jtc long loc; /* location in file of other players */
545 1.1 jtc
546 1.1 jtc Changed = TRUE;
547 1.1 jtc move(4,0);
548 1.1 jtc
549 1.1 jtc Player.p_tampered = T_OFF; /* no longer tampered with */
550 1.1 jtc
551 1.1 jtc switch (what)
552 1.1 jtc {
553 1.1 jtc case T_NRGVOID:
554 1.1 jtc addstr("You've hit an energy void !\n");
555 1.1 jtc Player.p_mana /= 3.0;
556 1.1 jtc Player.p_energy /= 2.0;
557 1.1 jtc Player.p_gold = floor(Player.p_gold/1.25) + 0.1;
558 1.1 jtc altercoordinates(0.0, 0.0, A_NEAR);
559 1.1 jtc break;
560 1.1 jtc
561 1.1 jtc case T_TRANSPORT:
562 1.1 jtc addstr("The king transported you ! ");
563 1.1 jtc if (Player.p_charms > 0)
564 1.1 jtc {
565 1.1 jtc addstr("But your charm saved you. . .\n");
566 1.1 jtc --Player.p_charms;
567 1.1 jtc }
568 1.1 jtc else
569 1.1 jtc {
570 1.1 jtc altercoordinates(0.0, 0.0, A_FAR);
571 1.1 jtc addch('\n');
572 1.1 jtc }
573 1.1 jtc break;
574 1.1 jtc
575 1.1 jtc case T_BESTOW:
576 1.1 jtc printw("The king has bestowed %.0f gold pieces on you !\n", arg1);
577 1.1 jtc Player.p_gold += arg1;
578 1.1 jtc break;
579 1.1 jtc
580 1.1 jtc case T_CURSED:
581 1.1 jtc addstr("You've been cursed ! ");
582 1.1 jtc if (Player.p_blessing)
583 1.1 jtc {
584 1.1 jtc addstr("But your blessing saved you. . .\n");
585 1.1 jtc Player.p_blessing = FALSE;
586 1.1 jtc }
587 1.1 jtc else
588 1.1 jtc {
589 1.1 jtc addch('\n');
590 1.1 jtc Player.p_poison += 2.0;
591 1.1 jtc Player.p_energy = 10.0;
592 1.1 jtc Player.p_maxenergy *= 0.95;
593 1.1 jtc Player.p_status = S_PLAYING; /* no longer cloaked */
594 1.1 jtc }
595 1.1 jtc break;
596 1.1 jtc
597 1.1 jtc case T_VAPORIZED:
598 1.1 jtc addstr("You have been vaporized!\n");
599 1.1 jtc more(7);
600 1.1 jtc death("Vaporization");
601 1.1 jtc break;
602 1.1 jtc
603 1.1 jtc case T_MONSTER:
604 1.1 jtc addstr("The Valar zapped you with a monster!\n");
605 1.1 jtc more(7);
606 1.1 jtc encounter((int) arg1);
607 1.1 jtc return;
608 1.1 jtc
609 1.1 jtc case T_BLESSED:
610 1.1 jtc addstr("The Valar has blessed you!\n");
611 1.1 jtc Player.p_energy = (Player.p_maxenergy *= 1.05) + Player.p_shield;
612 1.1 jtc Player.p_mana += 500.0;
613 1.1 jtc Player.p_strength += 0.5;
614 1.1 jtc Player.p_brains += 0.5;
615 1.1 jtc Player.p_magiclvl += 0.5;
616 1.1 jtc Player.p_poison = MIN(0.5, Player.p_poison);
617 1.1 jtc break;
618 1.1 jtc
619 1.1 jtc case T_RELOCATE:
620 1.1 jtc addstr("You've been relocated. . .\n");
621 1.1 jtc altercoordinates(arg1, arg2, A_FORCED);
622 1.1 jtc break;
623 1.1 jtc
624 1.1 jtc case T_HEAL:
625 1.1 jtc addstr("You've been healed!\n");
626 1.1 jtc Player.p_poison -= 0.25;
627 1.1 jtc Player.p_energy = Player.p_maxenergy + Player.p_shield;
628 1.1 jtc break;
629 1.1 jtc
630 1.1 jtc case T_EXVALAR:
631 1.1 jtc addstr("You are no longer Valar!\n");
632 1.1 jtc Player.p_specialtype = SC_COUNCIL;
633 1.1 jtc break;
634 1.1 jtc
635 1.1 jtc case T_GRAIL:
636 1.1 jtc addstr("You have found The Holy Grail!!\n");
637 1.1 jtc if (Player.p_specialtype < SC_COUNCIL)
638 1.1 jtc /* must be council of wise to behold grail */
639 1.1 jtc {
640 1.1 jtc addstr("However, you are not experienced enough to behold it.\n");
641 1.1 jtc Player.p_sin *= Player.p_sin;
642 1.1 jtc Player.p_mana += 1000;
643 1.1 jtc }
644 1.1 jtc else if (Player.p_specialtype == SC_VALAR
645 1.1 jtc || Player.p_specialtype == SC_EXVALAR)
646 1.1 jtc {
647 1.1 jtc addstr("You have made it to the position of Valar once already.\n");
648 1.1 jtc addstr("The Grail is of no more use to you now.\n");
649 1.1 jtc }
650 1.1 jtc else
651 1.1 jtc {
652 1.1 jtc addstr("It is now time to see if you are worthy to behold it. . .\n");
653 1.1 jtc refresh();
654 1.1 jtc sleep(4);
655 1.1 jtc
656 1.1 jtc if (drandom() / 2.0 < Player.p_sin)
657 1.1 jtc {
658 1.1 jtc addstr("You have failed!\n");
659 1.1 jtc Player.p_strength =
660 1.1 jtc Player.p_mana =
661 1.1 jtc Player.p_energy =
662 1.1 jtc Player.p_maxenergy =
663 1.1 jtc Player.p_magiclvl =
664 1.1 jtc Player.p_brains =
665 1.1 jtc Player.p_experience =
666 1.1 jtc Player.p_quickness = 1.0;
667 1.1 jtc
668 1.1 jtc altercoordinates(1.0, 1.0, A_FORCED);
669 1.1 jtc Player.p_level = 0.0;
670 1.1 jtc }
671 1.1 jtc else
672 1.1 jtc {
673 1.1 jtc addstr("You made to position of Valar!\n");
674 1.1 jtc Player.p_specialtype = SC_VALAR;
675 1.1 jtc Player.p_lives = 5;
676 1.1 jtc fseek(Playersfp, 0L, 0);
677 1.1 jtc loc = 0L;
678 1.1 jtc while (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) == 1)
679 1.1 jtc /* search for existing valar */
680 1.1 jtc if (Other.p_specialtype == SC_VALAR
681 1.1 jtc && Other.p_status != S_NOTUSED)
682 1.1 jtc /* found old valar */
683 1.1 jtc {
684 1.1 jtc Other.p_tampered = T_EXVALAR;
685 1.1 jtc writerecord(&Other, loc);
686 1.1 jtc break;
687 1.1 jtc }
688 1.1 jtc else
689 1.1 jtc loc += SZ_PLAYERSTRUCT;
690 1.1 jtc }
691 1.1 jtc }
692 1.1 jtc
693 1.1 jtc /* move grail to new location */
694 1.1 jtc Enrgyvoid.ev_active = TRUE;
695 1.1 jtc Enrgyvoid.ev_x = ROLL(-1.0e6, 2.0e6);
696 1.1 jtc Enrgyvoid.ev_y = ROLL(-1.0e6, 2.0e6);
697 1.1 jtc writevoid(&Enrgyvoid, 0L);
698 1.1 jtc break;
699 1.1 jtc }
700 1.1 jtc refresh();
701 1.1 jtc sleep(2);
702 1.1 jtc }
703 1.1 jtc /**/
705 1.1 jtc /************************************************************************
706 1.1 jtc /
707 1.1 jtc / FUNCTION NAME: userlist()
708 1.1 jtc /
709 1.1 jtc / FUNCTION: print list of players and locations
710 1.1 jtc /
711 1.1 jtc / AUTHOR: E. A. Estes, 2/28/86
712 1.1 jtc /
713 1.1 jtc / ARGUMENTS:
714 1.1 jtc / bool ingameflag - set if called while playing
715 1.1 jtc /
716 1.1 jtc / RETURN VALUE: none
717 1.1 jtc /
718 1.1 jtc / MODULES CALLED: descrstatus(), descrlocation(), more(), fread(), fseek(),
719 1.1 jtc / floor(), wmove(), printw(), waddstr(), distance(), wrefresh(),
720 1.1 jtc / descrtype(), wclrtobot()
721 1.1 jtc /
722 1.1 jtc / GLOBAL INPUTS: LINES, Other, Circle, Wizard, Player, *stdscr, *Playersfp
723 1.1 jtc /
724 1.1 jtc / GLOBAL OUTPUTS: none
725 1.1 jtc /
726 1.1 jtc / DESCRIPTION:
727 1.1 jtc / We can only see the coordinate of those closer to the origin
728 1.1 jtc / from us.
729 1.1 jtc / Kings and council of the wise can see and can be seen by everyone.
730 1.1 jtc / Palantirs are good for seeing everyone; and the valar can use
731 1.1 jtc / one to see through a 'cloak' spell.
732 1.1 jtc / The valar has no coordinates, and is completely invisible if
733 1.1 jtc / cloaked.
734 1.1 jtc /
735 1.1 jtc /************************************************************************/
736 1.1 jtc
737 1.1 jtc userlist(ingameflag)
738 1.1 jtc bool ingameflag;
739 1.1 jtc {
740 1.1 jtc register int numusers = 0; /* number of users on file */
741 1.1 jtc
742 1.1 jtc if (ingameflag && Player.p_blindness)
743 1.1 jtc {
744 1.1 jtc mvaddstr(8, 0, "You cannot see anyone.\n");
745 1.1 jtc return;
746 1.1 jtc }
747 1.1 jtc
748 1.1 jtc fseek(Playersfp, 0L, 0);
749 1.1 jtc mvaddstr(8, 0,
750 1.1 jtc "Name X Y Lvl Type Login Status\n");
751 1.1 jtc
752 1.1 jtc while (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) == 1)
753 1.1 jtc {
754 1.1 jtc if (Other.p_status == S_NOTUSED
755 1.1 jtc /* record is unused */
756 1.1 jtc || (Other.p_specialtype == SC_VALAR && Other.p_status == S_CLOAKED))
757 1.1 jtc /* cloaked valar */
758 1.1 jtc {
759 1.1 jtc if (!Wizard)
760 1.1 jtc /* wizard can see everything on file */
761 1.1 jtc continue;
762 1.1 jtc }
763 1.1 jtc
764 1.1 jtc ++numusers;
765 1.1 jtc
766 1.1 jtc if (ingameflag &&
767 1.1 jtc /* must be playing for the rest of these conditions */
768 1.1 jtc (Player.p_specialtype >= SC_KING
769 1.1 jtc /* kings and higher can see others */
770 1.1 jtc || Other.p_specialtype >= SC_KING
771 1.1 jtc /* kings and higher can be seen by others */
772 1.1 jtc || Circle >= CIRCLE(Other.p_x, Other.p_y)
773 1.1 jtc /* those nearer the origin can be seen */
774 1.1 jtc || Player.p_palantir)
775 1.1 jtc /* palantir enables one to see others */
776 1.1 jtc && (Other.p_status != S_CLOAKED
777 1.1 jtc || (Player.p_specialtype == SC_VALAR && Player.p_palantir))
778 1.1 jtc /* not cloaked; valar can see through cloak with a palantir */
779 1.1 jtc && Other.p_specialtype != SC_VALAR)
780 1.1 jtc /* not a valar */
781 1.1 jtc /* coordinates should be printed */
782 1.1 jtc printw("%-20s %8.0f %8.0f ",
783 1.1 jtc Other.p_name, Other.p_x, Other.p_y);
784 1.1 jtc else
785 1.1 jtc /* cannot see player's coordinates */
786 1.1 jtc printw("%-20s %19.19s ",
787 1.1 jtc Other.p_name, descrlocation(&Other, TRUE));
788 1.1 jtc
789 1.1 jtc printw("%6.0f %s %-9.9s%s\n", Other.p_level, descrtype(&Other, TRUE),
790 1.1 jtc Other.p_login, descrstatus(&Other));
791 1.1 jtc
792 1.1 jtc if ((numusers % (LINES - 10)) == 0)
793 1.1 jtc {
794 1.1 jtc more(LINES - 1);
795 1.1 jtc move(9, 0);
796 1.1 jtc clrtobot();
797 1.1 jtc }
798 1.1 jtc }
799 1.1 jtc
800 1.1 jtc printw("Total players on file = %d\n", numusers);
801 1.1 jtc refresh();
802 1.1 jtc }
803 1.1 jtc /**/
805 1.1 jtc /************************************************************************
806 1.1 jtc /
807 1.1 jtc / FUNCTION NAME: throneroom()
808 1.1 jtc /
809 1.1 jtc / FUNCTION: king stuff upon entering throne
810 1.1 jtc /
811 1.1 jtc / AUTHOR: E. A. Estes, 12/16/85
812 1.1 jtc /
813 1.1 jtc / ARGUMENTS: none
814 1.1 jtc /
815 1.1 jtc / RETURN VALUE: none
816 1.1 jtc /
817 1.1 jtc / MODULES CALLED: writerecord(), fread(), fseek(), fopen(), wmove(), fclose(),
818 1.1 jtc / fwrite(), altercoordinates(), waddstr(), fprintf()
819 1.1 jtc /
820 1.1 jtc / GLOBAL INPUTS: *Energyvoidfp, Other, Player, *stdscr,
821 1.1 jtc / Enrgyvoid, *Playersfp
822 1.1 jtc /
823 1.1 jtc / GLOBAL OUTPUTS: Other, Player, Changed
824 1.1 jtc /
825 1.1 jtc / DESCRIPTION:
826 1.1 jtc / If player is not already king, make him/her so if the old king
827 1.1 jtc / is not playing.
828 1.1 jtc / Clear energy voids with new king.
829 1.1 jtc / Print 'decree' prompt.
830 1.1 jtc /
831 1.1 jtc /************************************************************************/
832 1.1 jtc
833 1.1 jtc throneroom()
834 1.1 jtc {
835 1.1 jtc FILE *fp; /* to clear energy voids */
836 1.1 jtc long loc = 0L; /* location of old king in player file */
837 1.1 jtc
838 1.1 jtc if (Player.p_specialtype < SC_KING)
839 1.1 jtc /* not already king -- assumes crown */
840 1.1 jtc {
841 1.1 jtc fseek(Playersfp, 0L, 0);
842 1.1 jtc while (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) == 1)
843 1.1 jtc if (Other.p_specialtype == SC_KING && Other.p_status != S_NOTUSED)
844 1.1 jtc /* found old king */
845 1.1 jtc {
846 1.1 jtc if (Other.p_status != S_OFF)
847 1.1 jtc /* old king is playing */
848 1.1 jtc {
849 1.1 jtc mvaddstr( 4, 0, "The king is playing, so you cannot steal his throne\n");
850 1.1 jtc altercoordinates(0.0, 0.0, A_NEAR);
851 1.1 jtc move(6, 0);
852 1.1 jtc return;
853 1.1 jtc }
854 1.1 jtc else
855 1.1 jtc /* old king is not playing - remove him/her */
856 1.1 jtc {
857 1.1 jtc Other.p_specialtype = SC_NONE;
858 1.1 jtc if (Other.p_crowns)
859 1.1 jtc --Other.p_crowns;
860 1.1 jtc writerecord(&Other, loc);
861 1.1 jtc break;
862 1.1 jtc }
863 1.1 jtc }
864 1.1 jtc else
865 1.1 jtc loc += SZ_PLAYERSTRUCT;
866 1.1 jtc
867 1.1 jtc /* make player new king */
868 1.1 jtc Changed = TRUE;
869 1.1 jtc Player.p_specialtype = SC_KING;
870 1.1 jtc mvaddstr(4, 0, "You have become king!\n");
871 1.1 jtc
872 1.1 jtc /* let everyone else know */
873 1.1 jtc fp = fopen(_PATH_MESS, "w");
874 1.1 jtc fprintf(fp, "All hail the new king!");
875 1.1 jtc fclose(fp);
876 1.1 jtc
877 1.1 jtc /* clear all energy voids; retain location of holy grail */
878 1.1 jtc fseek(Energyvoidfp, 0L, 0);
879 1.1 jtc fread((char *) &Enrgyvoid, SZ_VOIDSTRUCT, 1, Energyvoidfp);
880 1.1 jtc fp = fopen(_PATH_VOID, "w");
881 1.1 jtc fwrite((char *) &Enrgyvoid, SZ_VOIDSTRUCT, 1, fp);
882 1.1 jtc fclose(fp);
883 1.1 jtc }
884 1.1 jtc
885 1.1 jtc mvaddstr(6, 0, "0:Decree ");
886 1.1 jtc }
887 1.1 jtc /**/
889 1.1 jtc /************************************************************************
890 1.1 jtc /
891 1.1 jtc / FUNCTION NAME: dotampered()
892 1.1 jtc /
893 1.1 jtc / FUNCTION: king and valar special options
894 1.1 jtc /
895 1.1 jtc / AUTHOR: E. A. Estes, 2/28/86
896 1.1 jtc /
897 1.1 jtc / ARGUMENTS: none
898 1.1 jtc /
899 1.1 jtc / RETURN VALUE: none
900 1.1 jtc /
901 1.1 jtc / MODULES CALLED: writerecord(), truncstring(), fread(), fseek(), fopen(),
902 1.1 jtc / floor(), wmove(), drandom(), fclose(), fwrite(), sscanf(), strcmp(),
903 1.1 jtc / infloat(), waddstr(), findname(), distance(), userlist(), mvprintw(),
904 1.1 jtc / allocvoid(), getanswer(), getstring(), wclrtoeol(), writevoid()
905 1.1 jtc /
906 1.1 jtc / GLOBAL INPUTS: *Energyvoidfp, Other, Illcmd[], Wizard, Player, *stdscr,
907 1.1 jtc / Databuf[], Enrgyvoid
908 1.1 jtc /
909 1.1 jtc / GLOBAL OUTPUTS: Other, Player, Enrgyvoid
910 1.1 jtc /
911 1.1 jtc / DESCRIPTION:
912 1.1 jtc / Tamper with other players. Handle king/valar specific options.
913 1.1 jtc /
914 1.1 jtc /************************************************************************/
915 1.1 jtc
916 1.1 jtc dotampered()
917 1.1 jtc {
918 1.1 jtc short tamper; /* value for tampering with other players */
919 1.1 jtc char *option; /* pointer to option description */
920 1.1 jtc double temp1 = 0.0, temp2 = 0.0; /* other tampering values */
921 1.1 jtc int ch; /* input */
922 1.1 jtc long loc; /* location in energy void file */
923 1.1 jtc FILE *fp; /* for opening gold file */
924 1.1 jtc
925 1.1 jtc move(6, 0);
926 1.1 jtc clrtoeol();
927 1.1 jtc if (Player.p_specialtype < SC_COUNCIL && !Wizard)
928 1.1 jtc /* king options */
929 1.1 jtc {
930 1.1 jtc addstr("1:Transport 2:Curse 3:Energy Void 4:Bestow 5:Collect Taxes ");
931 1.1 jtc
932 1.1 jtc ch = getanswer(" ", TRUE);
933 1.1 jtc move(6, 0);
934 1.1 jtc clrtoeol();
935 1.1 jtc move(4, 0);
936 1.1 jtc switch (ch)
937 1.1 jtc {
938 1.1 jtc case '1': /* transport someone */
939 1.1 jtc tamper = T_TRANSPORT;
940 1.1 jtc option = "transport";
941 1.1 jtc break;
942 1.1 jtc
943 1.1 jtc case '2': /* curse another */
944 1.1 jtc tamper = T_CURSED;
945 1.1 jtc option = "curse";
946 1.1 jtc break;
947 1.1 jtc
948 1.1 jtc case '3': /* create energy void */
949 1.1 jtc if ((loc = allocvoid()) > 20L * SZ_VOIDSTRUCT)
950 1.1 jtc /* can only have 20 void active at once */
951 1.1 jtc mvaddstr(5, 0, "Sorry, void creation limit reached.\n");
952 1.1 jtc else
953 1.1 jtc {
954 1.1 jtc addstr("Enter the X Y coordinates of void ? ");
955 1.1 jtc getstring(Databuf, SZ_DATABUF);
956 1.1 jtc sscanf(Databuf, "%lf %lf", &temp1, &temp2);
957 1.1 jtc Enrgyvoid.ev_x = floor(temp1);
958 1.1 jtc Enrgyvoid.ev_y = floor(temp2);
959 1.1 jtc Enrgyvoid.ev_active = TRUE;
960 1.1 jtc writevoid(&Enrgyvoid, loc);
961 1.1 jtc mvaddstr(5, 0, "It is done.\n");
962 1.1 jtc }
963 1.1 jtc return;
964 1.1 jtc
965 1.1 jtc case '4': /* bestow gold to subject */
966 1.1 jtc tamper = T_BESTOW;
967 1.1 jtc addstr("How much gold to bestow ? ");
968 1.1 jtc temp1 = infloat();
969 1.1 jtc if (temp1 > Player.p_gold || temp1 < 0)
970 1.1 jtc {
971 1.1 jtc mvaddstr(5, 0, "You don't have that !\n");
972 1.1 jtc return;
973 1.1 jtc }
974 1.1 jtc
975 1.1 jtc /* adjust gold after we are sure it will be given to someone */
976 1.1 jtc option = "give gold to";
977 1.1 jtc break;
978 1.1 jtc
979 1.1 jtc case '5': /* collect accumulated taxes */
980 1.1 jtc if ((fp = fopen(_PATH_GOLD, "r+")) != NULL)
981 1.1 jtc /* collect taxes */
982 1.1 jtc {
983 1.1 jtc fread((char *) &temp1, sizeof(double), 1, fp);
984 1.1 jtc fseek(fp, 0L, 0);
985 1.1 jtc /* clear out value */
986 1.1 jtc temp2 = 0.0;
987 1.1 jtc fwrite((char *) &temp2, sizeof(double), 1, fp);
988 1.1 jtc fclose(fp);
989 1.1 jtc }
990 1.1 jtc
991 1.1 jtc mvprintw(4, 0, "You have collected %.0f in gold.\n", temp1);
992 1.1 jtc Player.p_gold += floor(temp1);
993 1.1 jtc return;
994 1.1 jtc
995 1.1 jtc default:
996 1.1 jtc return;
997 1.1 jtc }
998 1.1 jtc /* end of king options */
999 1.1 jtc }
1000 1.1 jtc else
1001 1.1 jtc /* council of wise, valar, wizard options */
1002 1.1 jtc {
1003 1.1 jtc addstr("1:Heal ");
1004 1.1 jtc if (Player.p_palantir || Wizard)
1005 1.1 jtc addstr("2:Seek Grail ");
1006 1.1 jtc if (Player.p_specialtype == SC_VALAR || Wizard)
1007 1.1 jtc addstr("3:Throw Monster 4:Relocate 5:Bless ");
1008 1.1 jtc if (Wizard)
1009 1.1 jtc addstr("6:Vaporize ");
1010 1.1 jtc
1011 1.1 jtc ch = getanswer(" ", TRUE);
1012 1.1 jtc if (!Wizard)
1013 1.1 jtc {
1014 1.1 jtc if (ch > '2' && Player.p_specialtype != SC_VALAR)
1015 1.1 jtc {
1016 1.1 jtc ILLCMD();
1017 1.1 jtc return;
1018 1.1 jtc }
1019 1.1 jtc
1020 1.1 jtc if (Player.p_mana < MM_INTERVENE)
1021 1.1 jtc {
1022 1.1 jtc mvaddstr(5, 0, "No mana left.\n");
1023 1.1 jtc return;
1024 1.1 jtc }
1025 1.1 jtc else
1026 1.1 jtc Player.p_mana -= MM_INTERVENE;
1027 1.1 jtc }
1028 1.1 jtc
1029 1.1 jtc switch (ch)
1030 1.1 jtc {
1031 1.1 jtc case '1': /* heal another */
1032 1.1 jtc tamper = T_HEAL;
1033 1.1 jtc option = "heal";
1034 1.1 jtc break;
1035 1.1 jtc
1036 1.1 jtc case '2': /* seek grail */
1037 1.1 jtc if (Player.p_palantir)
1038 1.1 jtc /* need a palantir to seek */
1039 1.1 jtc {
1040 1.1 jtc fseek(Energyvoidfp, 0L, 0);
1041 1.1 jtc fread((char *) &Enrgyvoid, SZ_VOIDSTRUCT, 1, Energyvoidfp);
1042 1.1 jtc temp1 = distance(Player.p_x, Enrgyvoid.ev_x, Player.p_y, Enrgyvoid.ev_y);
1043 1.1 jtc temp1 += ROLL(-temp1 / 10.0, temp1 / 5.0); /* add some error */
1044 1.1 jtc mvprintw(5, 0, "The palantir says the Grail is about %.0f away.\n", temp1);
1045 1.1 jtc }
1046 1.1 jtc else
1047 1.1 jtc /* no palantir */
1048 1.1 jtc mvaddstr(5, 0, "You need a palantir to seek the Grail.\n");
1049 1.1 jtc return;
1050 1.1 jtc
1051 1.1 jtc case '3': /* lob monster at someone */
1052 1.1 jtc mvaddstr(4, 0, "Which monster [0-99] ? ");
1053 1.1 jtc temp1 = infloat();
1054 1.1 jtc temp1 = MAX(0.0, MIN(99.0, temp1));
1055 1.1 jtc tamper = T_MONSTER;
1056 1.1 jtc option = "throw a monster at";
1057 1.1 jtc break;
1058 1.1 jtc
1059 1.1 jtc case '4': /* move another player */
1060 1.1 jtc mvaddstr(4, 0, "New X Y coordinates ? ");
1061 1.1 jtc getstring(Databuf, SZ_DATABUF);
1062 1.1 jtc sscanf(Databuf, "%lf %lf", &temp1, &temp2);
1063 1.1 jtc tamper = T_RELOCATE;
1064 1.1 jtc option = "relocate";
1065 1.1 jtc break;
1066 1.1 jtc
1067 1.1 jtc case '5': /* bless a player */
1068 1.1 jtc tamper = T_BLESSED;
1069 1.1 jtc option = "bless";
1070 1.1 jtc break;
1071 1.1 jtc
1072 1.1 jtc case '6': /* kill off a player */
1073 1.1 jtc if (Wizard)
1074 1.1 jtc {
1075 1.1 jtc tamper = T_VAPORIZED;
1076 1.1 jtc option = "vaporize";
1077 1.1 jtc break;
1078 1.1 jtc }
1079 1.1 jtc else
1080 1.1 jtc return;
1081 1.1 jtc
1082 1.1 jtc default:
1083 1.1 jtc return;
1084 1.1 jtc }
1085 1.1 jtc
1086 1.1 jtc /* adjust age after we are sure intervention will be done */
1087 1.1 jtc /* end of valar, etc. options */
1088 1.1 jtc }
1089 1.1 jtc
1090 1.1 jtc for (;;)
1091 1.1 jtc /* prompt for player to affect */
1092 1.1 jtc {
1093 1.1 jtc mvprintw(4, 0, "Who do you want to %s ? ", option);
1094 1.1 jtc getstring(Databuf, SZ_DATABUF);
1095 1.1 jtc truncstring(Databuf);
1096 1.1 jtc
1097 1.1 jtc if (Databuf[0] == '\0')
1098 1.1 jtc userlist(TRUE);
1099 1.1 jtc else
1100 1.1 jtc break;
1101 1.1 jtc }
1102 1.1 jtc
1103 1.1 jtc if (strcmp(Player.p_name, Databuf) != 0)
1104 1.1 jtc /* name other than self */
1105 1.1 jtc {
1106 1.1 jtc if ((loc = findname(Databuf, &Other)) >= 0L)
1107 1.1 jtc {
1108 1.1 jtc if (Other.p_tampered != T_OFF)
1109 1.1 jtc {
1110 1.1 jtc mvaddstr(5, 0, "That person has something pending already.\n");
1111 1.1 jtc return;
1112 1.1 jtc }
1113 1.1 jtc else
1114 1.1 jtc {
1115 1.1 jtc if (tamper == T_RELOCATE
1116 1.1 jtc && CIRCLE(temp1, temp2) < CIRCLE(Other.p_x, Other.p_y)
1117 1.1 jtc && !Wizard)
1118 1.1 jtc mvaddstr(5, 0, "Cannot move someone closer to the Lord's Chamber.\n");
1119 1.1 jtc else
1120 1.1 jtc {
1121 1.1 jtc if (tamper == T_BESTOW) Player.p_gold -= floor(temp1);
1122 1.1 jtc if (!Wizard && (tamper == T_HEAL || tamper == T_MONSTER ||
1123 1.1 jtc tamper == T_RELOCATE || tamper == T_BLESSED))
1124 1.1 jtc Player.p_age += N_AGE; /* age penalty */
1125 1.1 jtc Other.p_tampered = tamper;
1126 1.1 jtc Other.p_1scratch = floor(temp1);
1127 1.1 jtc Other.p_2scratch = floor(temp2);
1128 1.1 jtc writerecord(&Other, loc);
1129 1.1 jtc mvaddstr(5, 0, "It is done.\n");
1130 1.1 jtc }
1131 1.1 jtc return;
1132 1.1 jtc }
1133 1.1 jtc }
1134 1.1 jtc else
1135 1.1 jtc /* player not found */
1136 1.1 jtc mvaddstr(5, 0, "There is no one by that name.\n");
1137 1.1 jtc }
1138 1.1 jtc else
1139 1.1 jtc /* self */
1140 1.1 jtc mvaddstr(5, 0, "You may not do it to yourself!\n");
1141 1.1 jtc }
1142 1.1 jtc /**/
1144 1.1 jtc /************************************************************************
1145 1.1 jtc /
1146 1.1 jtc / FUNCTION NAME: writevoid()
1147 1.1 jtc /
1148 1.1 jtc / FUNCTION: update energy void entry in energy void file
1149 1.1 jtc /
1150 1.1 jtc / AUTHOR: E. A. Estes, 12/4/85
1151 1.1 jtc /
1152 1.1 jtc / ARGUMENTS:
1153 1.1 jtc / struct energyvoid *vp - pointer to structure to write to file
1154 1.1 jtc / long loc - location in file to update
1155 1.1 jtc /
1156 1.1 jtc / RETURN VALUE: none
1157 1.1 jtc /
1158 1.1 jtc / MODULES CALLED: fseek(), fwrite(), fflush()
1159 1.1 jtc /
1160 1.1 jtc / GLOBAL INPUTS: *Energyvoidfp
1161 1.1 jtc /
1162 1.1 jtc / GLOBAL OUTPUTS: none
1163 1.1 jtc /
1164 1.1 jtc / DESCRIPTION:
1165 1.1 jtc / Write out energy void structure at specified location.
1166 1.1 jtc /
1167 1.1 jtc /************************************************************************/
1168 1.1 jtc
1169 1.1 jtc writevoid(vp, loc)
1170 1.1 jtc register struct energyvoid *vp;
1171 1.1 jtc long loc;
1172 1.1 jtc {
1173 1.1 jtc
1174 1.1 jtc fseek(Energyvoidfp, loc, 0);
1175 1.1 jtc fwrite((char *) vp, SZ_VOIDSTRUCT, 1, Energyvoidfp);
1176 1.1 jtc fflush(Energyvoidfp);
1177 1.1 jtc fseek(Energyvoidfp, 0L, 0);
1178 1.1 jtc }
1179 1.1 jtc /**/
1181 1.1 jtc /************************************************************************
1182 1.1 jtc /
1183 1.1 jtc / FUNCTION NAME: allocvoid()
1184 1.1 jtc /
1185 1.1 jtc / FUNCTION: allocate space for a new energy void
1186 1.1 jtc /
1187 1.1 jtc / AUTHOR: E. A. Estes, 12/4/85
1188 1.1 jtc /
1189 1.1 jtc / ARGUMENTS: none
1190 1.1 jtc /
1191 1.1 jtc / RETURN VALUE: location of new energy void space
1192 1.1 jtc /
1193 1.1 jtc / MODULES CALLED: fread(), fseek()
1194 1.1 jtc /
1195 1.1 jtc / GLOBAL INPUTS: *Energyvoidfp, Enrgyvoid
1196 1.1 jtc /
1197 1.1 jtc / GLOBAL OUTPUTS: none
1198 1.1 jtc /
1199 1.1 jtc / DESCRIPTION:
1200 1.1 jtc / Search energy void file for an inactive entry and return its
1201 1.1 jtc / location.
1202 1.1 jtc / If no inactive ones are found, return one more than last location.
1203 1.1 jtc /
1204 1.1 jtc /************************************************************************/
1205 1.1 jtc
1206 1.1 jtc long
1207 1.1 jtc allocvoid()
1208 1.1 jtc {
1209 1.1 jtc long loc = 0L; /* location of new energy void */
1210 1.1 jtc
1211 fseek(Energyvoidfp, 0L, 0);
1212 while (fread((char *) &Enrgyvoid, SZ_VOIDSTRUCT, 1, Energyvoidfp) == 1)
1213 if (Enrgyvoid.ev_active)
1214 loc += SZ_VOIDSTRUCT;
1215 else
1216 break;
1217
1218 return(loc);
1219 }
1220