Mercurial > ~darius > hgwebdir.cgi > paradise_client
comparison input.c @ 3:5a977ccbc7a9 default tip
Empty changelog
author | darius |
---|---|
date | Sat, 06 Dec 1997 05:41:29 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
2:fba0b6e6cdc7 | 3:5a977ccbc7a9 |
---|---|
1 /* $Id: input.c,v 1.1.1.1 1997/12/06 05:41:29 darius Exp $ */ | |
2 | |
3 /* | |
4 * input.c | |
5 * | |
6 * Modified to work as client in socket based protocol | |
7 */ | |
8 #include "copyright.h" | |
9 | |
10 #include <stdio.h> | |
11 #include <math.h> | |
12 #include <sys/types.h> | |
13 #ifdef RS6K | |
14 #include <sys/select.h> | |
15 #endif | |
16 #ifdef hpux | |
17 #include <time.h> | |
18 #else /* hpux */ | |
19 #include <sys/time.h> | |
20 #endif /* hpux */ | |
21 #include <signal.h> | |
22 #include <errno.h> | |
23 #include "Wlib.h" | |
24 #include "defs.h" | |
25 #include "struct.h" | |
26 #include "data.h" | |
27 #include "packets.h" | |
28 #include "proto.h" | |
29 #ifdef SOUND | |
30 #include "Slib.h" | |
31 #endif | |
32 | |
33 #define control(x) (x)+128 | |
34 | |
35 /* Prototypes */ | |
36 static void buttonaction P((W_Event * data)); | |
37 static void keyaction P((W_Event * data)); | |
38 static void scan P((W_Window w, int x, int y)); | |
39 /*static void selectblkbozo P((W_Event *data));*/ | |
40 | |
41 static int tmodeChange = 0; /* handles first change of tmode; including */ | |
42 /* when a play first joins a tmode game */ | |
43 | |
44 void | |
45 initinput() | |
46 { | |
47 /* Nothing doing... */ | |
48 } | |
49 | |
50 void | |
51 dispatch_W_key_event(evt) | |
52 W_Event *evt; | |
53 { | |
54 int i; | |
55 | |
56 /* try to speed up response -JR */ | |
57 if (!messageon && (evt->Window == w || evt->Window == mapw)) { | |
58 keyaction(evt); | |
59 return; | |
60 } | |
61 for (i = 0; i < WNUM; i++) { | |
62 if (evt->Window == messWin[i].window) { | |
63 messageWinEvent(evt); | |
64 return; | |
65 } | |
66 } | |
67 if (evt->Window == optionWin) | |
68 optionaction(evt); | |
69 else if ( | |
70 #ifdef NOWARP | |
71 messageon || | |
72 #endif | |
73 evt->Window == messagew || | |
74 evt->Window == tstatw || | |
75 evt->Window == warnw) { | |
76 smessage(evt->key); | |
77 #ifdef SHORT_PACKETS | |
78 } else if (evt->Window == spWin) { | |
79 spaction(evt); | |
80 #endif | |
81 } else if (evt->Window == motdWin) { | |
82 motdWinEvent(evt->key); | |
83 } else if (evt->Window == playerw) { | |
84 playerwEvent(evt); | |
85 } else if (evt->Window == defWin && evt->key == ' ') { | |
86 W_UnmapWindow(defWin); | |
87 #ifdef SOUND | |
88 } else if (evt->Window == soundWin) { | |
89 soundaction(evt); | |
90 #endif | |
91 #ifdef TOOLS | |
92 } else if (evt->Window == toolsWin) { | |
93 smessage_ahead('!', evt->key); | |
94 #endif | |
95 } else { | |
96 keyaction(evt); | |
97 } | |
98 } | |
99 | |
100 void | |
101 dispatch_W_button_event(evt) | |
102 W_Event *evt; | |
103 { | |
104 int i; | |
105 | |
106 if (evt->Window == w || evt->Window == mapw) { | |
107 buttonaction(evt); | |
108 return; | |
109 } | |
110 for (i = 0; i < WNUM; i++) { | |
111 if (evt->Window == messWin[i].window) { | |
112 messageWinEvent(evt); | |
113 return; | |
114 } | |
115 } | |
116 if (evt->Window == war) | |
117 waraction(evt); | |
118 else if (evt->Window == optionWin) | |
119 optionaction(evt); | |
120 #ifdef ATM | |
121 else if (evt->Window == udpWin) | |
122 udpaction(evt); /* UDP */ | |
123 #endif /* ATM */ | |
124 #ifdef SHORT_PACKETS | |
125 else if (evt->Window == spWin) | |
126 spaction(evt); | |
127 #endif | |
128 #ifdef SOUND | |
129 else if (evt->Window == soundWin) | |
130 soundaction(evt); | |
131 #endif | |
132 else if (evt->Window == playerw) | |
133 selectblkbozo(evt); | |
134 #ifdef MACROS | |
135 else if (evt->Window == macroWin) | |
136 switchmacros(); | |
137 #endif | |
138 #ifdef XTREKRC_HELP | |
139 else if (evt->Window == defWin) | |
140 def_action(evt); | |
141 #endif | |
142 else | |
143 buttonaction(evt); | |
144 } | |
145 | |
146 void | |
147 dispatch_W_expose_event(evt) | |
148 W_Event *evt; | |
149 { | |
150 /* | |
151 if anything but the iconWin is refreshed, turn off the iconified flag. | |
152 [BDyess] | |
153 */ | |
154 if (evt->Window != iconWin) | |
155 iconified = 0; | |
156 if (evt->Window == statwin) | |
157 redrawStats(); | |
158 else if (evt->Window == tstatw) | |
159 redrawTstats(); | |
160 else if (evt->Window == mapw) | |
161 redrawall = 1; | |
162 else if (evt->Window == iconWin) | |
163 drawIcon(); | |
164 else if (evt->Window == helpWin) | |
165 fillhelp(); | |
166 else if (evt->Window == macroWin) | |
167 fillmacro(); | |
168 else if (evt->Window == playerw) | |
169 playerlist(); | |
170 else if (evt->Window == planetw) | |
171 planetlist(); | |
172 else if (evt->Window == planetw2) | |
173 planetlist(); | |
174 else if (evt->Window == rankw) | |
175 ranklist(); | |
176 else if (evt->Window == warnw) | |
177 W_ClearWindow(warnw); | |
178 else if (evt->Window == messagew) | |
179 message_expose(); | |
180 else if (evt->Window == motdWin) | |
181 motdWinEvent('r'); /* 'r' is refresh */ | |
182 /* | |
183 lag meter? maybe later - RF else if (evt->Window == lMeter) | |
184 redrawLMeter(); | |
185 */ | |
186 else if (evt->Window == pStats) | |
187 redrawPStats(); | |
188 #ifdef XTREKRC_HELP | |
189 else if (defWin && (evt->Window == defWin)) | |
190 showdef(); | |
191 #endif | |
192 } | |
193 | |
194 void | |
195 dispatch_W_event(evt) | |
196 W_Event *evt; | |
197 { | |
198 switch ((int) evt->type) { | |
199 case W_EV_KEY: | |
200 dispatch_W_key_event(evt); | |
201 break; | |
202 #ifdef AUTOKEY | |
203 case W_EV_KEY_OFF: | |
204 if (autoKey) | |
205 autoKeyOff(evt); | |
206 break; | |
207 #endif /* AUTOKEY */ | |
208 case W_EV_BUTTON: | |
209 dispatch_W_button_event(evt); | |
210 break; | |
211 case W_EV_EXPOSE: | |
212 dispatch_W_expose_event(evt); | |
213 break; | |
214 default: | |
215 break; | |
216 } | |
217 } | |
218 | |
219 /* this figures out what to set war dec's */ | |
220 void autoWarDecl(scheme) | |
221 int scheme; | |
222 { | |
223 extern int number_of_teams; | |
224 int i, j, k, *team, enemymask = 0; | |
225 struct player *pptr; | |
226 | |
227 if((team = (int *)malloc(number_of_teams * sizeof(int))) == NULL) { | |
228 perror("autoWarDecl: malloc error\n"); | |
229 return; | |
230 } | |
231 memset(team, 0, sizeof(int)*number_of_teams); | |
232 for(i=0, pptr=&players[i]; i < nplayers; i++, pptr++) | |
233 if(pptr->p_status != PFREE && !(pptr->p_status == POUTFIT && | |
234 pptr->p_teami < 0)) { | |
235 team[pptr->p_teami]++; | |
236 } | |
237 switch(scheme) { | |
238 case 1: | |
239 /* war with all non-zero member team */ | |
240 /* peace with teams with 0 players */ | |
241 for(i=0; i < number_of_teams; i++) { | |
242 if(i != me->p_teami) | |
243 enemymask ^= team[i] ? (1<<i) : 0; | |
244 /*printf("team: %i, #: %i\n", i, team[i]); | |
245 */ | |
246 } | |
247 /*printf("mask: %i\n", enemymask); | |
248 */ | |
249 break; | |
250 case 2: | |
251 /* war with only the largest enemy */ | |
252 /* team; peace with everyone else*/ | |
253 for(i=0; i < number_of_teams; i++) { | |
254 if ((i != me->p_teami) && (j < team[i])) { | |
255 j = team[i]; | |
256 k = i; | |
257 } | |
258 } | |
259 enemymask = 0 | (1 << k); | |
260 break; | |
261 } | |
262 sendWarReq(enemymask); | |
263 free(team); | |
264 } /* end of autoWarDecl */ | |
265 | |
266 | |
267 /* this new event loop allows more flexibility in state transitions */ | |
268 void | |
269 input() | |
270 { | |
271 W_Event data; | |
272 fd_set readfds; | |
273 int wsock = W_Socket(); | |
274 int old_tourn = paradise ? status2->tourn : status->tourn, new_tourn; | |
275 | |
276 #ifdef AUTOKEY | |
277 struct timeval timeout; | |
278 | |
279 timeout.tv_sec = 0; | |
280 timeout.tv_usec = 100000; | |
281 #endif /* AUTOKEY */ | |
282 | |
283 #ifdef RECORDER | |
284 if (playback) { | |
285 pb_input(); /* recorder.c */ | |
286 return; | |
287 } | |
288 #endif | |
289 while (me->p_status == PALIVE || | |
290 me->p_status == PEXPLODE || | |
291 me->p_status == PDEAD || | |
292 me->p_status == POBSERVE) { | |
293 | |
294 #ifdef TIMELORD | |
295 /* we're playing. Count the seconds */ | |
296 update_timelord(0); | |
297 #endif | |
298 | |
299 if (keepInfo > 0) { | |
300 if (infowin_up >= 0 && | |
301 --infowin_up == -1 && | |
302 infomapped) { | |
303 destroyInfo(); | |
304 infowin_up = -2; | |
305 } | |
306 } | |
307 exitInputLoop = 0; | |
308 while (W_EventsPending() && !exitInputLoop) { | |
309 fastQuit = 0; /* any event cancel fastquit */ | |
310 W_NextEvent(&data); | |
311 dispatch_W_event(&data); | |
312 } | |
313 | |
314 #if 0 | |
315 /* | |
316 Do some enforcement of non-paradise feature disabling. The options | |
317 menu doesn't deal with this too well. | |
318 */ | |
319 if (!paradise) { | |
320 blk_zoom = 0; | |
321 blk_showStars = 0; | |
322 } | |
323 #endif | |
324 #ifndef AMIGA | |
325 FD_ZERO(&readfds); | |
326 FD_SET(wsock, &readfds); | |
327 FD_SET(sock, &readfds); | |
328 if (udpSock >= 0) | |
329 FD_SET(udpSock, &readfds); | |
330 #ifdef AUTOKEY | |
331 if (autoKey) { | |
332 doAutoKey(); | |
333 if (select(32, &readfds, (fd_set *) 0, (fd_set *) 0, &timeout) == 0) /* timeout */ | |
334 continue; | |
335 } else | |
336 #endif | |
337 select(32, &readfds, (fd_set *) 0, (fd_set *) 0, 0); | |
338 #else /* AMIGA */ | |
339 #ifdef DNET | |
340 sigsPending = Wait(wsock | sockMask | udpSockMask | SIGBREAKF_CTRL_C); | |
341 #else | |
342 /* insert code here for Amiga with TCP/IP... */ | |
343 #endif /* DNET */ | |
344 if (sigsPending & SIGBREAKF_CTRL_C) { | |
345 printf("User break, Ctrl-C, exiting!\n"); | |
346 exit(0); | |
347 } | |
348 /* note: for DNET, FD_ISSET is faked, see amigadefs.h -JR */ | |
349 #endif /* AMIGA */ | |
350 if (FD_ISSET(sock, &readfds) || | |
351 (udpSock >= 0 && FD_ISSET(udpSock, &readfds))) { | |
352 | |
353 #ifdef HANDLER_TIMES | |
354 start_log(); | |
355 #endif | |
356 intrupt(); | |
357 #ifdef HANDLER_TIMES | |
358 stop_log(64); | |
359 #endif | |
360 if (isServerDead()) { | |
361 printf("Whoops! We've been ghostbusted!\n"); | |
362 printf("Pray for a miracle!\n"); | |
363 | |
364 /* UDP fail-safe */ | |
365 commMode = commModeReq = COMM_TCP; | |
366 commSwitchTimeout = 0; | |
367 if (udpSock >= 0) | |
368 closeUdpConn(); | |
369 if (udpWin) { | |
370 udprefresh(UDP_CURRENT); | |
371 udprefresh(UDP_STATUS); | |
372 } | |
373 connectToServer(nextSocket); | |
374 printf("Yea! We've been resurrected!\n"); | |
375 } | |
376 /* | |
377 beep if tmode status changes. Idea from Roger Books. [BDyess] | |
378 */ | |
379 new_tourn = paradise ? status2->tourn : status->tourn; | |
380 | |
381 /* change war dec's at transitions to */ | |
382 /* positive tmode */ | |
383 if (!tmodeChange && new_tourn) { | |
384 autoWarDecl(autoSetWar); | |
385 tmodeChange = 1; | |
386 } | |
387 | |
388 if (old_tourn != new_tourn) { | |
389 #ifndef SOUND | |
390 W_Beep(); | |
391 #else | |
392 S_PlaySound(S_TMODE); | |
393 #endif | |
394 old_tourn = new_tourn; | |
395 } | |
396 continue; | |
397 } | |
398 } | |
399 } | |
400 | |
401 | |
402 static void | |
403 keyaction(data) | |
404 W_Event *data; | |
405 { | |
406 unsigned char course; | |
407 struct obtype *target; | |
408 int key = data->key; | |
409 struct shiplist *temp; | |
410 | |
411 if (data->Window != mapw && data->Window != w | |
412 && data->Window != planetw && data->Window != planetw2 | |
413 && data->Window != rankw | |
414 #ifdef ATM | |
415 && data->Window != scanw | |
416 #endif /* ATM */ | |
417 ) | |
418 return; | |
419 | |
420 #ifdef RECORDER | |
421 if (playback) | |
422 pb_dokey(data); | |
423 #endif | |
424 if (localflags & PFREFIT) { | |
425 temp = shiptypes; | |
426 while (temp) { | |
427 if (temp->ship->s_letter == key) { | |
428 do_refit(temp->ship->s_type); | |
429 return; | |
430 } | |
431 temp = temp->next; | |
432 } | |
433 } else { | |
434 key = doKeymap(data); | |
435 if (key == -1) | |
436 return; | |
437 } | |
438 | |
439 switch (key) { | |
440 case '0': | |
441 case '1': | |
442 case '2': | |
443 case '3': | |
444 case '4': | |
445 case '5': | |
446 case '6': | |
447 case '7': | |
448 case '8': | |
449 case '9': | |
450 set_speed(key - '0'); | |
451 localflags &= ~(PFREFIT); | |
452 break; | |
453 case 'e': /* Turn off docking permission, eject docked | |
454 vessels. */ | |
455 sendDockingReq(!(me->p_flags & PFDOCKOK)); | |
456 break; | |
457 case 'r': | |
458 localflags |= PFREFIT; | |
459 warning(blk_refitstring); | |
460 break; | |
461 case control('0'): /* ctrl 0-9, speed 10-19 */ | |
462 case control('1'): | |
463 case control('2'): | |
464 case control('3'): | |
465 case control('4'): | |
466 case control('5'): | |
467 case control('6'): | |
468 case control('7'): | |
469 case control('8'): | |
470 case control('9'): | |
471 set_speed(10 + key - control('0')); | |
472 localflags &= ~(PFREFIT); | |
473 break; | |
474 case control(')'): /* ctrl-shift 0-9, speed 20-29 */ | |
475 set_speed(20); | |
476 localflags &= ~(PFREFIT); | |
477 break; | |
478 case control('!'): /* ctrl-shift-1, speed 21 */ | |
479 set_speed(21); | |
480 localflags &= ~(PFREFIT); | |
481 break; | |
482 case control('@'): /* ctrl-shift-2, speed 22 */ | |
483 set_speed(22); | |
484 localflags &= ~(PFREFIT); | |
485 break; | |
486 case control('#'): /* ctrl-shift-3, speed 23 */ | |
487 set_speed(23); | |
488 localflags &= ~(PFREFIT); | |
489 break; | |
490 case control('$'): /* ctrl-shift-4, speed 24 */ | |
491 set_speed(24); | |
492 localflags &= ~(PFREFIT); | |
493 break; | |
494 case control('%'): /* ctrl-shift-5, speed 25 */ | |
495 set_speed(25); | |
496 localflags &= ~(PFREFIT); | |
497 break; | |
498 case control('^'): /* ctrl-shift-6, speed 26 */ | |
499 set_speed(26); | |
500 localflags &= ~(PFREFIT); | |
501 break; | |
502 case control('&'): /* ctrl-shift-7, speed 27 */ | |
503 set_speed(27); | |
504 localflags &= ~(PFREFIT); | |
505 break; | |
506 case control('*'): /* ctrl-shift-8, speed 28 */ | |
507 set_speed(28); | |
508 localflags &= ~(PFREFIT); | |
509 break; | |
510 case control('('): /* ctrl-shift-9, speed 29 */ | |
511 set_speed(29); | |
512 localflags &= ~(PFREFIT); | |
513 break; | |
514 case '`': /* afterburners */ | |
515 set_speed(98); | |
516 localflags &= ~(PFREFIT); | |
517 break; | |
518 case '-': | |
519 set_speed(99); /* warp! */ | |
520 localflags &= ~(PFREFIT); | |
521 break; | |
522 case control('-'): /* suspend warp toggle [BDyess] */ | |
523 if (me->p_flags & PFWPSUSPENDED) | |
524 set_speed(96); /* unsuspend */ | |
525 else | |
526 set_speed(97); /* suspend */ | |
527 localflags &= ~(PFREFIT); | |
528 break; | |
529 case '%': /* max impulse */ | |
530 set_speed(me->p_ship->s_maxspeed); | |
531 localflags &= ~(PFREFIT); | |
532 break; | |
533 case '<': /* speed -= 1 */ | |
534 set_speed(me->p_speed - 1); | |
535 localflags &= ~(PFREFIT); | |
536 break; | |
537 case '>': /* speed += 1 */ | |
538 set_speed(me->p_speed + 1); | |
539 localflags &= ~(PFREFIT); | |
540 break; | |
541 case '#': /* halfimpulse */ | |
542 set_speed((me->p_ship->s_maxspeed + 1) / 2); | |
543 localflags &= ~(PFREFIT); | |
544 break; | |
545 case ':': /* toggle message logging */ | |
546 if (logmess) | |
547 warning("Message logging disabled"); | |
548 else | |
549 warning("Message logging enabled"); | |
550 logmess = !logmess; | |
551 break; | |
552 case '!': | |
553 #if 1 | |
554 showKitchenSink = !showKitchenSink; | |
555 warning(showKitchenSink ? | |
556 "Kitchen Sink activated. Bad guys beware!" : | |
557 "Kitchen Sink deactivated."); | |
558 #else | |
559 if (blk_altbits) { | |
560 blk_altbits = 0; | |
561 warning("Switching to old bitmaps."); | |
562 } else { | |
563 blk_altbits = 1; | |
564 warning("Switching to new bitmaps."); | |
565 } | |
566 localflags &= ~(PFREFIT); | |
567 if (optionWin) | |
568 optionredrawoption(&blk_altbits); | |
569 #endif | |
570 break; | |
571 #ifdef TIMER | |
572 case '@': | |
573 timeBank[T_USR] = time(NULL); | |
574 timerType = T_USR; | |
575 break; | |
576 case control('t'): | |
577 timerType++; | |
578 if (timerType >= T_TOTAL) | |
579 timerType = 0; | |
580 break; | |
581 #endif /* TIMER */ | |
582 #ifdef WIDE_PLIST | |
583 case 'K': /* cycle playerlist [BDyess] */ | |
584 while (*playerList && *playerList != ',') | |
585 playerList++; | |
586 if (*playerList == ',') | |
587 playerList++; | |
588 else if (*playerList == 0) | |
589 playerList = playerListStart; | |
590 break; | |
591 #endif /* WIDE_PLIST */ | |
592 case 'a': | |
593 #ifdef ATM | |
594 if (!W_IsMapped(scanwin)) { | |
595 scan(data->Window, data->x, data->y); | |
596 } else { | |
597 if (scanmapped) | |
598 W_UnmapWindow(scanwin); | |
599 scanmapped = 0; | |
600 } | |
601 #endif /* ATM */ | |
602 break; | |
603 case 'm': /* new from galaxy -- works here too */ | |
604 case '\'': /* ' starts message to 'T'eam */ | |
605 #ifdef NOWARP | |
606 message_on(); | |
607 #else | |
608 W_WarpPointer(messagew); | |
609 #endif | |
610 if((key == '\'') && (messpend==0)) { | |
611 smessage(lowercaset ? 't' : 'T'); | |
612 } | |
613 break; | |
614 case 'k': /* k = set course */ | |
615 course = getcourse(data->Window, data->x, data->y); | |
616 set_course(course); | |
617 me->p_flags &= ~(PFPLOCK | PFPLLOCK); | |
618 localflags &= ~(PFREFIT); | |
619 break; | |
620 case 'p': /* p = fire phasers */ | |
621 #ifdef AUTOKEY | |
622 if (autoKey) | |
623 autoKeyPhaserReqOn(); | |
624 else { | |
625 course = getcourse(data->Window, data->x, data->y); | |
626 sendPhaserReq(course); | |
627 } | |
628 #else | |
629 course = getcourse(data->Window, data->x, data->y); | |
630 sendPhaserReq(course); | |
631 #endif /* AUTOKEY */ | |
632 break; | |
633 case 't': /* t = launch torps */ | |
634 #ifdef AUTOKEY | |
635 if (autoKey) | |
636 autoKeyTorpReqOn(); | |
637 else { | |
638 course = getcourse(data->Window, data->x, data->y); | |
639 sendTorpReq(course); | |
640 } | |
641 #else | |
642 course = getcourse(data->Window, data->x, data->y); | |
643 sendTorpReq(course); | |
644 #endif /* AUTOKEY */ | |
645 break; | |
646 case 'f': | |
647 /* f = launch plasma torpedos */ | |
648 #ifdef AUTOKEY | |
649 if (autoKey) | |
650 autoKeyPlasmaReqOn(); | |
651 else { | |
652 course = getcourse(data->Window, data->x, data->y); | |
653 sendPlasmaReq(course); | |
654 } | |
655 #else | |
656 course = getcourse(data->Window, data->x, data->y); | |
657 sendPlasmaReq(course); | |
658 #endif /* AUTOKEY */ | |
659 break; | |
660 case 'd': /* d = detonate other torps */ | |
661 #ifdef AUTOKEY | |
662 if (autoKey) | |
663 autoKeyDetReqOn(); | |
664 else | |
665 sendDetonateReq(); | |
666 #else | |
667 sendDetonateReq(); | |
668 #endif /* AUTOKEY */ | |
669 break; | |
670 case 'D': /* D = detonate my torps */ | |
671 detmine(); | |
672 #ifdef AUTOKEY | |
673 if (autoKey) | |
674 autoKeyAllOff(); /* xx */ | |
675 #endif | |
676 break; | |
677 case '[': | |
678 shield_down(); | |
679 break; | |
680 case ']': | |
681 shield_up(); | |
682 break; | |
683 case 'u': /* u = toggle shields */ | |
684 shield_tog(); | |
685 break; | |
686 case 's': /* For Serge */ | |
687 shield_tog(); | |
688 break; | |
689 case 'b': /* b = bomb planet */ | |
690 #ifdef AUTOKEY | |
691 if (autoKey && !(localflags & PFREFIT)) | |
692 autoKeyBombReqOn(); | |
693 else | |
694 bomb_planet(); | |
695 #else | |
696 bomb_planet(); | |
697 #endif /* AUTOKEY */ | |
698 break; | |
699 case 'z': /* z = beam up */ | |
700 #ifdef AUTOKEY | |
701 if (autoKey) | |
702 autoKeyBeamUpReqOn(); | |
703 else | |
704 #endif | |
705 beam_up(); | |
706 break; | |
707 case 'x': /* x = beam down */ | |
708 #ifdef AUTOKEY | |
709 if (autoKey) | |
710 autoKeyBeamDownReqOn(); | |
711 else | |
712 #endif | |
713 beam_down(); | |
714 break; | |
715 case 'X': /* X = enter macro mode */ | |
716 macroState = 1; | |
717 warning("Macro mode"); | |
718 break; | |
719 case 'R': /* R = Go into repair mode */ | |
720 sendRepairReq(1); | |
721 break; | |
722 case 'y': | |
723 case 'T': | |
724 case '_': /* _ = turn on tractor beam */ | |
725 case '^': /* ^ = turn on pressor beam */ | |
726 if (me->p_flags & (PFTRACT | PFPRESS)) { | |
727 sendTractorReq(0, me->p_no); | |
728 if (key == 'T' || key == 'y') | |
729 break; | |
730 } | |
731 target = gettarget(data->Window, data->x, data->y, TARG_PLAYER); | |
732 me->p_tractor = target->o_num; | |
733 if (key == 'T' || key == '_') { | |
734 sendTractorReq(1, target->o_num); | |
735 } else { | |
736 sendRepressReq(1, target->o_num); | |
737 } | |
738 break; | |
739 case '$': /* turn off tractor/pressor beam */ | |
740 sendTractorReq(0, me->p_no); | |
741 break; | |
742 case 'o': /* o = dock at nearby starbase or orbit | |
743 nearest planet */ | |
744 #ifdef AUTOKEY | |
745 if (autoKey && !(localflags & PFREFIT)) | |
746 autoKeyOrbitReqOn(); | |
747 else | |
748 sendOrbitReq(1); | |
749 #else | |
750 sendOrbitReq(1); | |
751 #endif /* AUTOKEY */ | |
752 break; | |
753 case 'O': /* O = options Window */ | |
754 if (optionWin != NULL && W_IsMapped(optionWin)) | |
755 optiondone(); | |
756 else | |
757 optionwindow(); | |
758 break; | |
759 case 'Q': | |
760 sendQuitReq(); | |
761 break; | |
762 case 'q': /* fastquit */ | |
763 fastQuit = 1; | |
764 sendQuitReq(); | |
765 break; | |
766 case 'V': | |
767 { | |
768 /* configurable showlocal rotation sequence [BDyess] */ | |
769 int i, len = strlen(showLocalSequence); | |
770 for (i = 0; i < len; i++) { | |
771 if (showLocalSequence[i] - '0' == showlocal) { | |
772 showlocal = showLocalSequence[(i + 1) % len] - '0'; | |
773 break; | |
774 } | |
775 } | |
776 if (i == len) | |
777 showlocal = (*showLocalSequence) - '0'; | |
778 if (showlocal > 4) | |
779 showlocal = 4; | |
780 else if (showlocal < 0) | |
781 showlocal = 0; | |
782 } | |
783 if (optionWin) | |
784 optionredrawoption(&showlocal); | |
785 break; | |
786 case 'B': | |
787 { | |
788 /* configurable showgalactic rotation sequence [BDyess] */ | |
789 int i, len = strlen(showGalacticSequence); | |
790 for (i = 0; i < len; i++) { | |
791 if (showGalacticSequence[i] - '0' == showgalactic) { | |
792 showgalactic = showGalacticSequence[(i + 1) % len] - '0'; | |
793 break; | |
794 } | |
795 } | |
796 if (i == len) | |
797 showgalactic = (*showGalacticSequence) - '0'; | |
798 if (!paradise && showgalactic == 3) | |
799 showgalactic = 5; /* force scout ages -> MOO */ | |
800 if (showgalactic > 5) | |
801 showgalactic = 5; | |
802 else if (showgalactic < 0) | |
803 showgalactic = 0; | |
804 } | |
805 redrawall = 1; | |
806 if (optionWin) | |
807 optionredrawoption(&showgalactic); | |
808 break; | |
809 case '?': /* ? = Redisplay all message windows */ | |
810 if (!W_IsMapped(messWin[WREVIEW].window)) { | |
811 if (W_IsMapped(messWin[WALL].window)) { | |
812 int i; | |
813 for (i = 0; i < WNUM; i++) { | |
814 if (W_IsMapped(messWin[i].window)) | |
815 W_UnmapWindow(messWin[i].window); | |
816 } | |
817 } else { | |
818 W_MapWindow(messWin[WREVIEW].window); | |
819 } | |
820 } else { | |
821 W_UnmapWindow(messWin[WREVIEW].window); | |
822 W_MapWindow(messWin[WALL].window); | |
823 W_MapWindow(messWin[WTEAM].window); | |
824 W_MapWindow(messWin[WINDIV].window); | |
825 W_MapWindow(messWin[WKILL].window); | |
826 W_MapWindow(messWin[WPHASER].window); | |
827 } | |
828 if (optionWin) { | |
829 optionredrawtarget(messWin[WREVIEW].window); | |
830 optionredrawtarget(messWin[WALL].window); | |
831 optionredrawtarget(messWin[WKILL].window); | |
832 optionredrawtarget(messWin[WTEAM].window); | |
833 optionredrawtarget(messWin[WINDIV].window); | |
834 optionredrawtarget(messWin[WPHASER].window); | |
835 } | |
836 break; | |
837 case 'c': /* c = cloak */ | |
838 cloak(); | |
839 break; | |
840 case '{': /* { = cloak, no toggle */ | |
841 sendCloakReq(1); | |
842 break; | |
843 case '}': /* } = uncloak, no toggle */ | |
844 sendCloakReq(0); | |
845 break; | |
846 case 'C': /* C = coups */ | |
847 sendCoupReq(); | |
848 break; | |
849 case ';': /* ; = lock onto planet/base */ | |
850 target = gettarget(data->Window, data->x, data->y, | |
851 TARG_BASE | TARG_PLANET); | |
852 if (target->o_type == PLAYERTYPE) { | |
853 sendPlaylockReq(target->o_num); /* a base */ | |
854 me->p_playerl = target->o_num; | |
855 } else { /* It's a planet */ | |
856 sendPlanlockReq(target->o_num); | |
857 me->p_planet = target->o_num; | |
858 } | |
859 break; | |
860 case 'l': /* l = lock onto */ | |
861 target = gettarget(data->Window, data->x, data->y, | |
862 TARG_PLAYER | TARG_ASTRAL); | |
863 if (target->o_type == PLAYERTYPE) { | |
864 sendPlaylockReq(target->o_num); | |
865 me->p_playerl = target->o_num; | |
866 } else { /* It's a planet */ | |
867 sendPlanlockReq(target->o_num); | |
868 me->p_planet = target->o_num; | |
869 } | |
870 break; | |
871 case '/': /* toggle sorted player list */ | |
872 sortPlayers = !sortPlayers; | |
873 break; | |
874 case '*': /* send in practice robot */ | |
875 sendPractrReq(); | |
876 break; | |
877 /* Start of display functions */ | |
878 case ' ': /* ' ' = clear special windows */ | |
879 W_UnmapWindow(planetw); | |
880 W_UnmapWindow(planetw2); | |
881 W_UnmapWindow(rankw); | |
882 if (infomapped) | |
883 destroyInfo(); | |
884 W_UnmapWindow(helpWin); | |
885 W_UnmapWindow(war); | |
886 if (optionWin) | |
887 optiondone(); | |
888 #ifdef ATM | |
889 if (scanmapped) { | |
890 W_UnmapWindow(scanwin); | |
891 scanmapped = 0; | |
892 } | |
893 if (udpWin) | |
894 udpdone(); | |
895 #endif /* ATM */ | |
896 #ifdef XTREKRC_HELP | |
897 if (defWin) | |
898 W_UnmapWindow(defWin); | |
899 #endif | |
900 break; | |
901 case 'E': /* E = send emergency call */ | |
902 if (F_gen_distress) | |
903 rcd(generic, data); | |
904 else | |
905 emergency(); | |
906 break; | |
907 case 'F': /* F = send carry report */ | |
908 if (F_gen_distress) | |
909 rcd(carrying, data); | |
910 else | |
911 carry_report(); | |
912 break; | |
913 case 'L': /* L = Player list */ | |
914 if (W_IsMapped(playerw)) { | |
915 W_UnmapWindow(playerw); | |
916 } else { | |
917 W_MapWindow(playerw); | |
918 } | |
919 break; | |
920 case 'P': /* P = Planet list */ | |
921 if (W_IsMapped(planetw)) { | |
922 W_UnmapWindow(planetw); | |
923 W_UnmapWindow(planetw2); | |
924 } else { | |
925 W_MapWindow(planetw); | |
926 W_MapWindow(planetw2); | |
927 } | |
928 break; | |
929 case 'U': /* U = Rank list */ | |
930 if (W_IsMapped(rankw)) { | |
931 W_UnmapWindow(rankw); | |
932 } else { | |
933 W_MapWindow(rankw); | |
934 } | |
935 break; | |
936 case 'S': /* S = toggle stat mode */ | |
937 if (W_IsMapped(statwin)) { | |
938 W_UnmapWindow(statwin); | |
939 } else { | |
940 W_MapWindow(statwin); | |
941 } | |
942 break; | |
943 #ifdef nodef /* people hit this by accident and think the | |
944 client crashed */ | |
945 case 'M': /* M = Toggle Map mode */ | |
946 mapmode = !mapmode; | |
947 if (optionWin) | |
948 optionredrawoption(&mapmode); | |
949 break; | |
950 #endif | |
951 case 'M': /* map the motd window */ | |
952 showMotdWin(); | |
953 break; | |
954 case 'N': /* N = Toggle Name mode */ | |
955 namemode = !namemode; | |
956 if (optionWin) | |
957 optionredrawoption(&namemode); | |
958 break; | |
959 case 'i': /* i = get information */ | |
960 case 'I': /* I = get extended information */ | |
961 case control('i'): /* ^i = info on a planet [BDyess] */ | |
962 if (!infomapped) | |
963 inform(data->Window, data->x, data->y, key); | |
964 else | |
965 destroyInfo(); | |
966 break; | |
967 case 'h': /* h = Map help window */ | |
968 if (W_IsMapped(helpWin)) { | |
969 W_UnmapWindow(helpWin); | |
970 } else { | |
971 W_MapWindow(helpWin); | |
972 } | |
973 if (optionWin) | |
974 optionredrawtarget(helpWin); | |
975 break; | |
976 case 'w': /* w = map war stuff */ | |
977 if (W_IsMapped(war)) | |
978 W_UnmapWindow(war); | |
979 else | |
980 warwindow(); | |
981 break; | |
982 #ifdef ATM | |
983 case '+': /* UDP: pop up UDP control window */ | |
984 if (udpWin != NULL && W_IsMapped(udpWin)) | |
985 udpdone(); | |
986 else { | |
987 char buf[80]; | |
988 udpwindow(); | |
989 sprintf(buf, "UDP client version %.1f", | |
990 (float) UDPVERSION / 10.0); | |
991 warning(buf); | |
992 } | |
993 if (optionWin) | |
994 optionredrawtarget(udpWin); | |
995 break; | |
996 case '=': /* UDP: request for full update */ | |
997 sendUdpReq(COMM_UPDATE); | |
998 break; | |
999 #endif /* ATM */ | |
1000 | |
1001 case 9: /* tab */ | |
1002 case control('m'): /* because you can't remap to tab */ | |
1003 /* actually, you can, put a literal | |
1004 TAB in a ckeymap entry and it works. | |
1005 So should we keep this? -JR */ | |
1006 if(paradise) { | |
1007 blk_zoom = !blk_zoom; | |
1008 redrawall = 1; | |
1009 auto_zoom_timer = udcounter+autoZoomOverride; | |
1010 if (optionWin) | |
1011 optionredrawoption(&blk_zoom); | |
1012 } | |
1013 break; | |
1014 #ifdef SHORT_PACKETS | |
1015 case '~': | |
1016 if (spWin != NULL && W_IsMapped(spWin)) | |
1017 spdone(); | |
1018 else | |
1019 spwindow(); | |
1020 if (optionWin) | |
1021 optionredrawtarget(spWin); | |
1022 break; | |
1023 case '\\': | |
1024 sendShortReq(SPK_SALL); | |
1025 break; | |
1026 case '|': | |
1027 sendShortReq(SPK_ALL); | |
1028 break; | |
1029 #endif | |
1030 case ',': | |
1031 if (W_IsMapped(pStats)) { | |
1032 W_UnmapWindow(pStats); | |
1033 } else { | |
1034 W_MapWindow(pStats); | |
1035 redrawPStats(); | |
1036 } | |
1037 if (optionWin) | |
1038 optionredrawtarget(pStats); | |
1039 break; | |
1040 case '&': /* reread defaults file */ | |
1041 if (defaultsFile) { | |
1042 char buf[150]; | |
1043 sprintf(buf, "Reading defaults from %s", defaultsFile); | |
1044 warning(buf); | |
1045 freeDefaults(); | |
1046 defaultsFile = initDefaults(defaultsFile); | |
1047 resetDefaults(); | |
1048 } else { | |
1049 warning("No defaults file to read from!"); | |
1050 } | |
1051 break; | |
1052 #ifdef ROTATERACE | |
1053 case '(': | |
1054 rotate--; | |
1055 if (rotate < 0) | |
1056 rotate = 3; | |
1057 if (optionWin) | |
1058 optionredrawoption(&rotate); | |
1059 rotate_all(); | |
1060 break; | |
1061 case ')': | |
1062 rotate++; | |
1063 if (rotate > 3) | |
1064 rotate = 0; | |
1065 if (optionWin) | |
1066 optionredrawoption(&rotate); | |
1067 rotate_all(); | |
1068 break; | |
1069 #endif | |
1070 | |
1071 #ifdef RECORDER | |
1072 case control('r'): | |
1073 stopRecorder(); | |
1074 break; | |
1075 #endif | |
1076 | |
1077 #ifdef SOUND | |
1078 case control('s'): | |
1079 S_SoundWindow(); | |
1080 break; | |
1081 #endif | |
1082 #ifdef TOOLS | |
1083 case '\"': | |
1084 showToolsWin(); | |
1085 break; | |
1086 #endif | |
1087 #ifdef AMIGA | |
1088 case 'A': | |
1089 { | |
1090 extern int flush_speech; | |
1091 flush_speech = 1; | |
1092 break; | |
1093 } | |
1094 #endif /* AMIGA */ | |
1095 default: | |
1096 W_Beep(); | |
1097 break; | |
1098 } | |
1099 } | |
1100 | |
1101 static void | |
1102 buttonaction(data) | |
1103 W_Event *data; | |
1104 { | |
1105 unsigned char course; | |
1106 | |
1107 #ifdef NOWARP | |
1108 if (messageon) | |
1109 message_off(); /* ATM */ | |
1110 #endif | |
1111 | |
1112 if (data->Window != w && data->Window != mapw | |
1113 #ifdef ATM | |
1114 && data->Window != scanwin | |
1115 #endif /* ATM */ | |
1116 ) | |
1117 return; | |
1118 | |
1119 data->key--; | |
1120 if (data->key >= 0 && data->key < 12) { | |
1121 if (myship->s_buttonmap[data->key] != '\0') { | |
1122 data->key = myship->s_buttonmap[data->key]; | |
1123 #if 0 /* do NOT bypass keymap */ | |
1124 data->key += 256; /* simulate alt key so keymap is bypassed | |
1125 [BDyess] */ | |
1126 #endif | |
1127 keyaction(data); | |
1128 return; | |
1129 } else | |
1130 data->key = data->key % 3; | |
1131 /* if alt key is pressed, do default */ | |
1132 } if (data->key > 11) | |
1133 data->key -= 12; | |
1134 data->key++; | |
1135 if (data->key == W_RBUTTON) { | |
1136 course = getcourse(data->Window, data->x, data->y); | |
1137 set_course(course); | |
1138 } else if (data->key == W_LBUTTON) { | |
1139 course = getcourse(data->Window, data->x, data->y); | |
1140 sendTorpReq(course); | |
1141 } else if (data->key == W_MBUTTON) { | |
1142 course = getcourse(data->Window, data->x, data->y); | |
1143 sendPhaserReq(course); | |
1144 } | |
1145 } | |
1146 | |
1147 /* | |
1148 * changed from unsigned char to irint() for precise rounding (from Leonard | |
1149 * Dickens) | |
1150 * | |
1151 * changed from irint (which ULTRIX doesn't have in its math.h header) to | |
1152 * floor(x+0.5) for portability. | |
1153 */ | |
1154 | |
1155 | |
1156 | |
1157 int | |
1158 getcourse(ww, x, y) | |
1159 W_Window ww; | |
1160 int x, y; | |
1161 { | |
1162 if (ww == mapw) { | |
1163 int me_x, me_y; | |
1164 register gwidth, offsetx, offsety; | |
1165 | |
1166 if (blk_zoom) { | |
1167 gwidth = blk_gwidth / 2; | |
1168 offsetx = zoom_offset(me->p_x); | |
1169 offsety = zoom_offset(me->p_y); | |
1170 } else { | |
1171 gwidth = blk_gwidth; | |
1172 offsetx = 0; | |
1173 offsety = 0; | |
1174 } | |
1175 me_x = (me->p_x - offsetx) * WINSIDE / gwidth; | |
1176 me_y = (me->p_y - offsety) * WINSIDE / gwidth; | |
1177 | |
1178 return (unsigned char)(int) | |
1179 floor(0.5 + atan2((double) (x - me_x), | |
1180 (double) (me_y - y)) | |
1181 / 3.14159 * 128.); | |
1182 | |
1183 | |
1184 } else { | |
1185 | |
1186 double result = atan2((double) (x - WINSIDE / 2), | |
1187 (double) (WINSIDE / 2 - y)) / 3.14159 * 128.; | |
1188 | |
1189 return (unsigned char) (int) floor (result + 0.5); | |
1190 } | |
1191 } | |
1192 #ifdef ATM | |
1193 static void | |
1194 scan(w, x, y) | |
1195 W_Window w; | |
1196 int x, y; | |
1197 { | |
1198 } | |
1199 #endif /* ATM */ |