Debian Codegraph @

Descent3/TelCom.cpp

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
1 /*
2 * Descent 3
3 * Copyright (C) 2024 Parallax Software
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 --- HISTORICAL COMMENTS FOLLOW ---
19
20 * $Logfile: /DescentIII/main/TelCom.cpp $
21 * $Revision: 152 $
22 * $Date: 4/19/00 5:13p $
23 * $Author: Matt $
24 *
25 * Contains the code to initialize, use and control TelCom system
26 *
27 * $Log: /DescentIII/main/TelCom.cpp $
28 *
29 * 152 4/19/00 5:13p Matt
30 * From Duane for 1.4
31 * Added checks, asserts, and fixes for bad return values
32 * Removed Mac OpenGL hack
33 *
34 * 151 3/20/00 12:21p Matt
35 * Merge of Duane's post-1.3 changes.
36 * Minor optimization.
37 *
38 * 150 10/21/99 9:29p Jeff
39 * B.A. Macintosh code merge
40 *
41 * 149 10/12/99 11:08a Jeff
42 * fixed bug regarding ship permissions to start (for level 1) if the ship
43 * is non-code default
44 *
45 * 148 7/13/99 3:33p Samir
46 * music plays in automap and all telcom screens from within game.
47 *
48 * 147 5/23/99 7:43p Jason
49 * fixed briefing problem with lowmem textures
50 *
51 * 146 5/13/99 3:42p Ardussi
52 * changes for compiling on the Mac
53 *
54 * 145 5/12/99 1:58p Jason
55 * made telcom use the global AllowedShips array instead of its own local
56 * array
57 *
58 * 144 5/05/99 3:02a Jeff
59 * added single player ship selection text
60 *
61 * 143 5/03/99 1:16p Jeff
62 * play sounds at full volume
63 *
64 * 142 4/26/99 4:33p Samir
65 * mouse input changed a little so that ddio_MouseGetState is called once
66 * per frame.
67 *
68 * 141 4/21/99 11:05a Kevin
69 * new ps_rand and ps_srand to replace rand & srand
70 *
71 * 140 4/20/99 12:46p Jeff
72 * telcom main menu, mouse over button sets focus. if you go into telcom
73 * main menu, when you leave a system it will return you to main menu.
74 *
75 * 139 4/17/99 3:44p Kevin
76 * Demo2 changes & fixes
77 *
78 * 138 4/15/99 10:06p Matt
79 * Changed briefing file foreign-language filenames to be in the form
80 * "level1_frn.brf".
81 *
82 * 137 4/14/99 3:57a Jeff
83 * fixed case mismatch in #includes
84 *
85 * 136 4/06/99 1:53p Samir
86 * added improved progress bar.
87 *
88 * 135 4/02/99 8:32p Jeff
89 * added system event queue. Arrow keys work in main menu and ship
90 * selection
91 *
92 * 134 3/31/99 5:36p Jeff
93 * cargo shouldn't display in main menu (not done...if it will be done)
94 *
95 * 133 3/31/99 5:28p Jeff
96 * new way of key processesing...can capture printscreen now
97 *
98 * 132 3/28/99 12:44p Jeff
99 * fixed table file parsing to add back in the ships
100 *
101 * 131 3/24/99 2:22p Jeff
102 * fixed power button bug
103 *
104 * 130 3/02/99 6:59p Jeff
105 * no cargo in oem
106 *
107 * 129 2/28/99 3:17p Jeff
108 * single player ship selection not called in OEM
109 *
110 * 128 2/25/99 4:14a Jeff
111 * shift-esc always exits to Main Menu, skips past ship selection
112 *
113 * 127 2/22/99 3:37p Jason
114 * fixed markers in telcom
115 *
116 * 126 2/22/99 3:19p Jeff
117 * random bug fixes
118 *
119 * 125 2/20/99 9:22p Jeff
120 * finished telcom level goals screen. Made it so if you go into the
121 * telcom from the game it goes to main menu instead of briefings.
122 *
123 * 124 2/17/99 6:55p Jeff
124 * added jump button type. Added no early render flag for bitmaps. Fixed
125 * color bug for type text
126 *
127 * 123 2/10/99 4:45p Jeff
128 * table file parser stuff
129 *
130 * 122 2/09/99 6:49p Jeff
131 * removed extra call to startframe...no longer needed with stack based
132 *
133 * 121 2/09/99 3:32p Jeff
134 * table file parser takes quotes strings for force keywords
135 *
136 * 120 2/08/99 1:03a Jeff
137 * click made when changing ships in single player ship selection
138 *
139 * 119 2/05/99 7:04p Jeff
140 * table file parsing macros put in
141 *
142 * 118 2/04/99 7:19p Jeff
143 * added sound id for button click. main menu handling., briefing missing
144 * fix
145 *
146 * 117 2/03/99 1:23p Jeff
147 * more updates to single player ship selection...all thats left is stats
148 *
149 * 116 2/03/99 11:44a Jeff
150 * selected ship hooked into the game
151 *
152 * 115 2/03/99 1:03a Jeff
153 * almost done with single player ship selection...added rotating model
154 *
155 * 113 2/02/99 7:32p Jeff
156 * begining of single player ship selection
157 *
158 * 112 2/01/99 4:52p Jeff
159 * screenshots work in telcom
160 *
161 * 111 1/30/99 2:43p Jeff
162 * fixed infinite loop bug
163 *
164 * 110 1/29/99 7:13p Jeff
165 * localization
166 *
167 * 109 1/25/99 11:02a Samir
168 * revamped mouse and key controls.
169 *
170 * 108 12/15/98 4:39p Jason
171 * added some more telcom functions
172 *
173 * 107 12/15/98 10:53a Jason
174 * yet more changes for 1.1
175 *
176 * 106 12/11/98 11:30p Jeff
177 * oops forgot to remove test #define DEMO
178 *
179 * 105 12/11/98 11:22p Jeff
180 * fixed telcom briefings so they can be called within game in the
181 * demo...fixed some minor bugs that needed to be rounded up (typing sound
182 * and initialization screen text)
183 *
184 * 104 12/11/98 1:48p Kevin
185 * Took out automap ifdefs for demo
186 *
187 * 103 12/11/98 11:37a Jason
188 *
189 * 102 12/09/98 2:36p Jeff
190 * added function to enable/disable telcom system keys and disabled most
191 * system keys while in Automap
192 *
193 * 101 12/09/98 1:09p Jason
194 * second draft of automap
195 *
196 * 100 11/02/98 6:00p Jeff
197 * began adding single player ship selection
198 *
199 * 99 10/27/98 4:22p Jeff
200 * changed the framerate cap to use Sleep(), to possibly help sound
201 * performance
202 *
203 * 98 10/22/98 1:31a Jeff
204 * optimized creating the static bitmaps
205 *
206 * 97 10/22/98 12:03a Matt
207 * Disable creation of static bitmaps to speed the briefing startup.
208 *
209 * 96 10/21/98 11:12p Jeff
210 * page in all data on Telcom init
211 *
212 * 95 10/21/98 4:51p Jeff
213 * removed automap
214 *
215 * 94 10/21/98 11:14a Samir
216 * added generic code to skip rendering while in game controller config or
217 * telcom.
218 *
219 * 93 10/16/98 2:43p Jeff
220 * only call Gameframe if not multi_ui_bail_menu
221 *
222 * 92 10/14/98 11:24p Jeff
223 * turn off bilinear filtering in TC now
224 *
225 * 91 10/12/98 11:39p Jeff
226 * finished up new focus system of telcom
227 *
228 * 90 10/12/98 8:32p Jeff
229 * changed the way focus is handled
230 *
231 * 89 10/12/98 3:03p Jeff
232 * fixed Shift-esc, and right arrow doesn't exit out of telcom if on the
233 * last page
234 *
235 * 88 10/11/98 2:59a Jeff
236 * TelCom is completly multiplayer friendly. Removed cheat codes to
237 * GameCheat.cpp. Fixed up TelCom Mainmenu to handle certain systems not
238 * available
239 *
240 * 87 10/09/98 7:47p Jeff
241 * Fixed killrobot cheat
242 *
243 * 86 10/09/98 6:20p Jeff
244 * fixed weapon cheat
245 *
246 * 85 10/09/98 6:18p Jeff
247 * added camera cheat
248 *
249 * 84 10/09/98 3:05p Jeff
250 * commented out slew cheat...
251 *
252 * 83 10/09/98 1:10p Jeff
253 * removed call to SlewStop in cheat code section (not defined in release)
254 *
255 * 82 10/09/98 12:22p Jeff
256 * cheat code system put in here (temporary?)
257 *
258 * 81 10/08/98 4:23p Kevin
259 * Changed code to comply with memory library usage. Always use mem_malloc
260 * , mem_free and mem_strdup
261 *
262 * 80 9/29/98 2:51p Jeff
263 * put internal serial number check function in here to keep it from the
264 * rest of the serialization stuff
265 *
266 * 79 8/28/98 12:57p Jeff
267 * added sounds and some key functionality
268 *
269 * 78 8/27/98 2:51p Jeff
270 * New TelCom finally checked in
271 *
272 * 77 8/19/98 2:29p Jeff
273 * if not a release build then you can escape to main menu
274 *
275 * 76 8/19/98 1:38p Jeff
276 * removed update2dsound
277 *
278 * 75 8/18/98 11:57a Jeff
279 * fixed sound problem
280 *
281 * 74 8/15/98 2:46p Matt
282 * Took out unneeded include
283 *
284 * 73 7/13/98 4:11p Jeff
285 * sped up entering telcom by about 3-4 times
286 *
287 * 72 7/11/98 9:16p Jeff
288 * moved automatically drawing monitor overlay graphics from update() to a
289 * function of it's own, that way the TelCom API can be avoided if needed
290 *
291 * 71 7/08/98 8:06p Jeff
292 * Initial creation of TelComCargo
293 *
294 * 70 6/16/98 10:54a Jeff
295 *
296 * 69 5/24/98 2:56a Jeff
297 * Adjust x offset for main menu buttons
298 *
299 * 68 5/19/98 10:48a Jeff
300 * if D3_FAST is set, TelCom doesn't run
301 *
302 * 67 5/18/98 4:21p Jeff
303 * setup TelCom so D3_FAST zips it through
304 *
305 * 66 5/18/98 2:23p Jeff
306 * Hooked up Automap
307 *
308 * 65 5/15/98 5:16p Jeff
309 * Added Main Menu
310 *
311 * 64 5/11/98 6:22p Jeff
312 * adjusted sound stopping position and removed calls to show/hide mouse
313 *
314 * 63 5/05/98 6:50p Jeff
315 * Telcom doesn't use rend_DrawLFBitmap anymore...more speed!
316 *
317 * 62 5/04/98 6:22p Jeff
318 * fixed possible sound bugs
319 *
320 * 61 5/04/98 5:29p Jeff
321 * Added sounds to TelCom events
322 *
323 * 60 5/04/98 1:35p Jeff
324 * Changes made for mouse handling
325 *
326 * 59 5/03/98 7:58p Jeff
327 * changes made to handle mouse and input from within TelCom instead of UI
328 *
329 * 58 5/01/98 2:16p Jeff
330 * changed default background colors for monitors
331 *
332 * 57 4/30/98 7:17p Jeff
333 * added a main menu and going back and forth between it and systems.
334 * Added a poweron initializing screen
335 *
336 * 56 4/26/98 7:19p Jeff
337 * Power down effect done only when in hardware (some weird bug puts it in
338 * an infinite loop in software
339 *
340 * 55 4/24/98 6:35p Jeff
341 * Move prototypes to telcom.h
342 *
343 * 54 4/24/98 3:28p Jeff
344 * fixed power down effect
345 *
346 * 53 4/23/98 7:09p Jeff
347 * added power up/down support
348 *
349 * 52 4/23/98 6:38p Jason
350 * made bitmaps use 1555 format
351 *
352 * 51 4/22/98 7:43p Jeff
353 * Added support for monitor hilites
354 *
355 * 50 4/21/98 4:22p Jeff
356 * Added functions for drawing hotspot in on/off positions
357 *
358 * 49 4/20/98 6:44p Jeff
359 * removed extra code after briefings, so when you exit briefings you
360 * don't hang around in limbo
361 *
362 * 48 4/17/98 6:54p Jeff
363 * added scanline and changed order or drawing screen and zbuffer state
364 * set on exit
365 *
366 * 47 4/15/98 6:28p Jeff
367 * removed some built in code for the briefings parser
368 *
369 * 46 4/02/98 12:07p Jeff
370 * Added framework for desktop effects, fixed corner bug
371 *
372 * 45 4/01/98 5:10p Jeff
373 * Added speed for Flash text
374 *
375 * 44 3/30/98 10:50a Jeff
376 * Initial Flash text put in
377 *
378 * 43 3/23/98 2:18p Jeff
379 * Moved structures to hotspotmap.h
380 *
381 * 42 3/23/98 11:08a Jeff
382 * Moved monitor and input stuff to seperate file
383 *
384 * 41 3/23/98 9:55a Jeff
385 * Made changes to remove old telcom
386 *
387 * 40 3/18/98 8:00p Jeff
388 * Added some functionality for text and using the monitor borders
389 * correctly in the new Telcom
390 *
391 * 39 3/12/98 3:32p Jeff
392 * Initial changes started for New TelCom
393 *
394 * 38 2/06/98 2:03p Jeff
395 * added start/stop time calls
396 *
397 * 37 2/04/98 5:26p Jeff
398 * Added movie support back into Telcom, and inventory stuff
399 *
400 * 36 1/31/98 8:50p Jeff
401 * Added a very very crude inventory screen to telcom
402 *
403 * 35 1/26/98 6:35p Jeff
404 * added a 'quick fast forward' key (spacebar)
405 *
406 * 34 1/21/98 1:09p Jeff
407 * Prettied up the code, comments
408 *
409 * 33 1/20/98 9:16p Jeff
410 * Added back in fading bitmaps
411 *
412 * 32 1/20/98 6:12p Jeff
413 *
414 * 31 1/20/98 12:08p Jeff
415 *
416 * 30 1/19/98 5:37p Jeff
417 * Got briefing up to par, and even better than before, added timer so
418 * scroll and type fonts are time based.
419 *
420 * 29 1/16/98 2:40p Jeff
421 * Adjusted so everything is displayed in correct spots, took out
422 * DefaultControl timer, added support for non fading bitmaps
423 *
424 * 28 1/15/98 11:11a Jeff
425 * Got TelCom in a working state again, switch from 2d to 3d
426 *
427 * 27 12/19/97 2:26p Jason
428 * more fixes for 2d/3d intergration
429 *
430 * 26 11/10/97 12:36p Samir
431 * Telcom sets screen mode itself, and use menu font, not d2menu.
432 *
433 * 25 10/15/97 5:20p Jason
434 * did a HUGE overhaul of the bitmap system
435 *
436 * 24 9/15/97 4:21p Samir
437 * Added ddio_KeyFlush when quitting telecom to prevent untreated
438 * keystrokes.
439 *
440 * 23 8/19/97 2:11p Matt
441 * Closed files after they've been opened
442 *
443 * 22 8/15/97 3:17p Jeff
444 * Fixed some functions affected by last change
445 *
446 * 21 8/15/97 12:24p Jeff
447 * Changed things around a bit, added code to handle the round corners
448 *
449 * 20 8/13/97 3:13p Jeff
450 * optimized for memory usage (removed the second background from being
451 * stored in memory)
452 *
453 * 19 8/12/97 6:10p Jeff
454 *
455 * 18 8/12/97 5:34p Jeff
456 * Added some comments, made the code a bit spiffier
457 *
458 * 17 8/12/97 12:35p Jeff
459 * added scroll speed, fixed some more bugs and tweaks
460 *
461 * 16 8/11/97 6:43p Jeff
462 * Added user defined function hook for subwindows, fixed some bugs
463 *
464 * 15 8/08/97 6:36p Jeff
465 * fixed various bugs, did some tweaking
466 *
467 * 14 8/07/97 6:18p Jeff
468 *
469 * 13 8/07/97 12:03p Jeff
470 *
471 * 12 8/06/97 6:35p Jeff
472 * added rough multitasking to subwindows
473 *
474 * 11 8/06/97 3:51p Jeff
475 * fixed some bugs with the new subwindowing
476 *
477 * 10 8/06/97 11:57a Jeff
478 *
479 * 9 8/04/97 7:23p Jeff
480 *
481 * 8 8/04/97 6:23p Jeff
482 *
483 * 7 8/01/97 6:57p Jeff
484 * Added enable/disable for vcr and system buttons. Added screensaver
485 *
486 * 6 8/01/97 2:35p Jeff
487 * Added windows to the hotspotmap
488 *
489 * 5 7/30/97 3:59p Jeff
490 * Fixed VCR controls, updated for new artwork
491 *
492 * $NoKeywords: $
493 */
494
495 #include <stdlib.h>
496 #include <string.h>
497 #include <stdarg.h>
498 #include "mono.h"
499 #include "renderer.h"
500 #include "render.h"
501 #include "ddio.h"
502 #include "descent.h"
503 #include "game.h"
504 #include "cfile.h"
505 #include "application.h"
506 #include "TelCom.h"
507 #include "TelComEffects.h"
508 #include "Briefing.h"
509 #include "TelComAutoMap.h"
510 #include "TelComCargo.h"
511 #include "TelComGoals.h"
512 #include "mem.h"
513 #include "Mission.h"
514 #include "stringtable.h"
515 #include "multi.h"
516 #include "ship.h"
517 #include "polymodel.h"
518 #include "localization.h"
519 #include "hlsoundlib.h"
520 #include "soundload.h"
521 #include "textaux.h"
522 #include "psrand.h"
523 #include "controls.h"
524 #include "d3music.h"
525
526 #define FRAME_RATE 30.0f
527 #define TCPE_TIME 0.5f
528
529 //------------------------------New TelCom Stuff---------------------------------------
530
531 static void TelCom_BltToMem(int dest_bmp, int dx, int dy, int src_bmp, int sx, int sy, int sw, int sh,
532 bool trans = true);
533 static void TelCom_BltToScreen(int dx, int dy, chunked_bitmap *src_bmp);
534 static void TelCom_BltToScreen(int dx, int dy, chunked_bitmap *src_bmp, int sx, int sy, int sw, int sh);
535 static void DrawHotSpotOn(int hotspot);
536
537 //*************************************************************************************
538
539 // Globals---------------------------------------------------------------------------
540
541 static bool TelCom_init = false; // Whether the TelComInit() function was called
542 static bool Telcom_first_render = true;
543 static bool Telcom_exit_to_mainmenu = false;
544 bool Telcom_called_from_game = false;
545 static int Telcom_mouse_last_effect = -1; // the last efxnum the mouse was over
546
547 hotspotmap_t hotspotmap; // Holds hotspot data (position)
548 windowmap_t windowmap; // Holds window data (position)
549 tTelComInfo Telcom_system;
550
551 chunked_bitmap Telcom_bitmap; // background bitmap for telcom system
552 static chunked_bitmap *hotspot_bitmaps;
553 static int LoadTelcomBitmap(const char *filename, chunked_bitmap *bmp);
554 static bool TelComMainMenu(tTelComInfo *tcs);
555
556 static void TelCom_PrepareCustomKeyEvents(void);
557 static void TelCom_PostProcessCustomKeyEvents(void);
558
559 static int Telcom_mouse_x, Telcom_mouse_y;
560
561 //===================================================================================================
562 // Functions
563 //===================================================================================================
564
565 // Initializes the TelCom system, only to be called once during game initialization
566 void TelComInit(void) {
567 mprintf(0, "Initializing TelCom System\n");
568
569 // load background screens
570 if (!(cfexist(TELCOM_DISPLAY_OGF))) {
571 mprintf(0, "%s file not found, exiting TelCom Init\n", TELCOM_DISPLAY_OGF);
572 return;
573 }
574
575 if (!LoadTelcomBitmap(TELCOM_DISPLAY_OGF, &Telcom_bitmap))
576 Error("Unable to open %s in TelCom system.", TELCOM_DISPLAY_OGF);
577
578 TelCom_init = true;
579
580 // init telcom system structs
581 InitSystems();
582
583 atexit(TelComFree);
584
585 TelcomPageAllIn();
586 }
587
588 // Cleanup crew, don't worry about calling this guy, it's an atexit() in the init
589 void TelComFree() { bm_DestroyChunkedBitmap(&Telcom_bitmap); }
590
591 // This is the main loop for the active TelCom...think of it as a void main(void)
592 void TelComMain(bool ingame, bool SelectShip) {
593 // Initialize sound system
594 TelcomInitSounds();
595
596 // Initialize screens
597 InitAllScreens();
598
599 // Initialize the Effects
600 EfxInit();
601
602 // Initialize the Telcom Render Engine
603 TelcomRenderInit();
604
605 // Initialize the TelCom System Event Manager
606 TelComInitEventManager();
607 TelcomRenderSetScreen(DUMMY_SCREEN);
608
609 // kinda a quick hack...it may stay only if there is no way to enter the briefings directly from the game
610 bool noescape = false;
611 if (!ingame)
612 noescape = true;
613
614 Telcom_system.state = TCS_POWERON;
615
616 TelcomCreateStartupScreen();
617
618 TelcomStartSound(TCSND_STARTUP);
619 TelcomStartSound(TCSND_RUNNING);
620 TelcomStopSound(TCSND_STARTUP);
621
622 // #ifdef DEMO
623 // Telcom_system.current_status = TS_MISSION;
624 // #endif
625
626 // initialize this to -1 so we get events right away
627 Telcom_mouse_last_effect = -1;
628
629 // if we are coming from the game into the main menu, then any system we select, when
630 // we exit should take us back to main menu
631 bool return_to_main_menu = false;
632 if (ingame && Telcom_system.current_status == TS_MAINMENU) {
633 return_to_main_menu = true;
634 }
635
636 while (Telcom_system.state != TCS_POWEROFF) {
637
638 TelComEnableSystemKey(TCSYS_MAXKEYS, true);
639
640 switch (Telcom_system.current_status) {
641 case TS_MISSION:
642 // if we are in briefings, then show the briefing
643 if (Current_level->flags & LVLFLAG_BRIEFING) {
644 // determine the correct language of briefing to look at
645 char basefilename[_MAX_FNAME];
646 char briefingname[_MAX_FNAME];
647 char extension[_MAX_FNAME];
648 const char *tag[] = {"", "_GER", "_SPN", "_ITN", "_FRN"};
649 bool ok_to_go = false;
650
651 ddio_SplitPath(Current_level->briefname, NULL, basefilename, extension);
652
653 strcpy(briefingname, basefilename);
654 strcat(briefingname, tag[Localization_GetLanguage()]);
655 strcat(briefingname, extension);
656
657 if (!cfexist(briefingname)) {
658 // language version doesn't exist
659 strcpy(briefingname, Current_level->briefname);
660
661 if (cfexist(briefingname)) {
662 ok_to_go = true;
663 }
664
665 } else {
666 ok_to_go = true;
667 }
668
669 if (ok_to_go) {
670 ParseBriefing(briefingname, &Telcom_system);
671
672 if (return_to_main_menu && (!((Game_mode & GM_MULTI) && Multi_bail_ui_menu))) {
673 // return to main menu
674 Telcom_system.current_status = TS_MAINMENU;
675 Telcom_system.state = TCS_POWERON;
676 }
677
678 } else {
679 Telcom_system.current_status = TS_OFF;
680 }
681 } else {
682 Telcom_system.current_status = TS_OFF;
683 }
684 #ifdef DEMO
685 // Telcom_system.state=TCS_POWEROFF;
686 #endif
687 break;
688 case TS_MAP:
689 TelComAutoMap(&Telcom_system);
690 if (return_to_main_menu && (!((Game_mode & GM_MULTI) && Multi_bail_ui_menu))) {
691 // return to main menu
692 Telcom_system.current_status = TS_MAINMENU;
693 Telcom_system.state = TCS_POWERON;
694 }
695
696 #ifdef DEMO
697 // Telcom_system.state=TCS_POWEROFF;
698 #endif
699 break;
700 case TS_CARGO:
701 #ifdef DEMO
702 // Telcom_system.state=TCS_POWEROFF;
703 #else
704 // show the inventory information
705 TelComCargo(&Telcom_system);
706 if (return_to_main_menu && (!((Game_mode & GM_MULTI) && Multi_bail_ui_menu))) {
707 // return to main menu
708 Telcom_system.current_status = TS_MAINMENU;
709 Telcom_system.state = TCS_POWERON;
710 }
711 #endif
712 break;
713 case TS_GOALS:
714 // show goal screen
715 TelComGoalStatus(&Telcom_system);
716 if (return_to_main_menu && (!((Game_mode & GM_MULTI) && Multi_bail_ui_menu))) {
717 // return to main menu
718 Telcom_system.current_status = TS_MAINMENU;
719 Telcom_system.state = TCS_POWERON;
720 }
721 break;
722 default:
723 if (!noescape) {
724 // display main menu
725 TelComMainMenu(&Telcom_system);
726 } else {
727 Telcom_system.state = TCS_POWEROFF;
728 }
729 break;
730 }
731 }
732
733 TelcomStopSound(TCSND_TYPING);
734
735 // see if we should display the Single Player Ship Selection
736 #if (!defined(DEMO)) && (!defined(OEM))
737 if (SelectShip && !Telcom_exit_to_mainmenu)
738 TelComSingleShipSelect(&Telcom_system);
739 #endif
740
741 TelcomStopSound(TCSND_STARTUP);
742 TelcomStopSound(TCSND_RUNNING);
743 TelcomStartSound(TCSND_SHUTDOWN);
744
745 TelcomCreateShutdownScreen();
746 TelcomRenderSetScreen(DUMMY_SCREEN);
747
748 float starttime = timer_GetTime();
749
750 while (timer_GetTime() - starttime < TCPE_TIME) {
751 // Process all waiting events for the TelCom (we may only want to handle this once a frame!)
752 TelComHandleAllEvents(&Telcom_system);
753 TelcomRenderScreen(false, false, 2);
754 Descent->defer();
755 }
756
757 TelcomStopSound(TCSND_SHUTDOWN);
758
759 TelcomCloseSounds();
760
761 TelcomRenderClose();
762
763 DestroyAllScreens(true);
764
765 EfxClose();
766 }
767
768 // This will make the TelCom system active, displaying it on the screen. This version of TelComShow() takes
769 // a system as an argument and it will display that system
770 // Returns true on success
771 bool TelComShow(int system, bool ingame, bool ShipSelect) {
772 if (system > NUMBER_OF_SYSTEMS)
773 Telcom_system.current_status = TS_OFF;
774
775 Telcom_system.current_status = system;
776 return TelComShow(ingame, ShipSelect);
777 }
778
779 // This will make the TelCom system active, displaying it on the screen. This version of TelComShow() will make
780 // whatever the current system (either whatever the last system to be displayed or whatever TelComSetSystem() set
781 // it to.
782 // Returns true on success
783
784 // externed from GameLoop.cpp
785 extern bool Skip_render_game_frame;
786
787 bool TelComShow(bool ingame, bool ShipSelect) {
788 Skip_render_game_frame = true;
789 Telcom_called_from_game = ingame;
790
791 bool result = false;
792 int old_sm;
793
794 Telcom_exit_to_mainmenu = false;
795
796 // must do this to clear out keyboard events
797 ddio_KeyFlush();
798
799 uint8_t oldmip = Render_preferred_state.mipping;
800 uint8_t oldbil = Render_preferred_state.filtering;
801
802 if (!TelCom_init) {
803 mprintf(0, "TELCOM SYSTEM WARNING: TelComInit() error!\n");
804 return false;
805 }
806
807 // Set Screen mode
808 old_sm = GetScreenMode();
809 SetScreenMode(SM_MENU);
810
811 hotspot_bitmaps = NULL;
812
813 int TelCom_bitmap = bm_AllocLoadFileBitmap(IGNORE_TABLE(TELCOM_DISPLAY_OGF), 0);
814 if (!cfexist(HOTSPOT_DISPLAY)) {
815 mprintf(0, "Couldn't find HotSpot map, so I'm going to make one\n");
816 if (!cfexist(TELCOM_DISPLAY_TGA)) {
817 mprintf(0, "Unable to find %s to extract HotSqpots...skipping TelCom System\n", TELCOM_DISPLAY_TGA);
818 FreeViewports();
819 if (windowmap.wm)
820 mem_free(windowmap.wm);
821 goto telcom_bad_error;
822 }
823 menutga_ConvertTGAtoHSM(TELCOM_DISPLAY_TGA);
824 }
825
826 // Load up the hotspot map into the structure
827 menutga_LoadHotSpotMap(TelCom_bitmap, IGNORE_TABLE(HOTSPOT_DISPLAY), &hotspotmap, &windowmap);
828 if (TelCom_bitmap >= 0)
829 bm_FreeBitmap(TelCom_bitmap);
830
831 if (hotspotmap.num_of_hotspots) {
832 int TelCom_onbmp = bm_AllocLoadFileBitmap(IGNORE_TABLE(TELCOM_DISPLAY_OGF_ON), 0);
833 if (TelCom_onbmp != -1) {
834 hotspot_bitmaps = (chunked_bitmap *)mem_malloc(sizeof(chunked_bitmap) * hotspotmap.num_of_hotspots);
835 ASSERT(hotspot_bitmaps);
836 CompressTelComOnImage(TelCom_onbmp, hotspot_bitmaps);
837 bm_FreeBitmap(TelCom_onbmp);
838 }
839 }
840
841 // turn off mipmapping
842 Render_preferred_state.mipping = 0;
843 // turn off bilinear filtering
844 Render_preferred_state.filtering = 1;
845 rend_SetPreferredState(&Render_preferred_state);
846 rend_SetFiltering(0);
847
848 // keep the mouse in view
849 ddio_MouseReset();
850 ddio_MouseSetVCoords(Game_window_w, Game_window_h);
851
852 // hang out in here until the user presses POWER
853 TelComMain(ingame, ShipSelect);
854
855 // do some final deactivation
856 TelComDeactivate();
857
858 result = true;
859
860 telcom_bad_error:
861
862 if (hotspot_bitmaps)
863 mem_free(hotspot_bitmaps);
864
865 // must do this to clear out keyboard events
866 ddio_KeyFlush();
867
868 // reset screen mode
869 SetScreenMode(old_sm);
870
871 // reset some states
872 rend_SetZBufferState(1);
873 Render_preferred_state.mipping = oldmip;
874 Render_preferred_state.filtering = oldbil;
875 rend_SetPreferredState(&Render_preferred_state);
876 rend_SetFiltering(1);
877 rend_SetWrapType(WT_WRAP);
878
879 Skip_render_game_frame = false;
880
881 return Telcom_exit_to_mainmenu;
882 }
883
884 // Initializes the systems so it has correct values
885 void InitSystems() {
886 Telcom_system.current_status = TS_MISSION;
887 Telcom_system.state = TCS_POWERON;
888 }
889
890 // Frees allocated memory used by the windows
891 void FreeViewports() {
892 int count;
893
894 if (windowmap.wm) {
895 for (count = 0; count < windowmap.num_of_windows; count++) {
896 if (windowmap.wm[count].lt_bmp > BAD_BITMAP_HANDLE)
897 bm_FreeBitmap(windowmap.wm[count].lt_bmp);
898 if (windowmap.wm[count].rt_bmp > BAD_BITMAP_HANDLE)
899 bm_FreeBitmap(windowmap.wm[count].rt_bmp);
900 if (windowmap.wm[count].lb_bmp > BAD_BITMAP_HANDLE)
901 bm_FreeBitmap(windowmap.wm[count].lb_bmp);
902 if (windowmap.wm[count].rb_bmp > BAD_BITMAP_HANDLE)
903 bm_FreeBitmap(windowmap.wm[count].rb_bmp);
904 }
905 }
906 }
907
908 // This function 'compresses' the on-state background, to save space
909 void CompressTelComOnImage(int bitmap, chunked_bitmap *array) {
910 if (!array)
911 return;
912 int count;
913 int width, height;
914 int handle;
915
916 // the first hotspot bitmap doesn't exist so we can skip it
917 for (count = 1; count < hotspotmap.num_of_hotspots; count++) {
918 width = HotSpotW(count);
919 ASSERT(width != -1); // DAJ -1FIX
920 height = HotSpotH(count);
921 ASSERT(height != -1); // DAJ -1FIX
922 handle = bm_AllocBitmap(width, height, 0);
923 TelCom_BltToMem(handle, 0, 0, bitmap, HotSpotL(count), HotSpotT(count), width, height);
924 bm_CreateChunkedBitmap(handle, &array[count]);
925 bm_FreeBitmap(handle);
926 }
927 }
928
929 // frees up on-state bitmaps
930 void FreeTelComOnBitmaps(chunked_bitmap *array) {
931 if (!array)
932 return;
933 int count;
934
935 // the first hotspot bitmap doesn't exist, so we can skip it
936 for (count = 1; count < hotspotmap.num_of_hotspots; count++) {
937 bm_DestroyChunkedBitmap(&array[count]);
938 }
939 }
940
941 // This deactivates the TelCom system
942 void TelComDeactivate(void) {
943 mprintf(0, "TelCom System being deactivated\n");
944 FreeTelComOnBitmaps(hotspot_bitmaps);
945 FreeHotSpotMapInternals(&hotspotmap);
946 FreeViewports();
947 if (windowmap.wm)
948 mem_free(windowmap.wm);
949 }
950
951 // draws a hotspot with the on bitmap
952 void DrawHotSpotOn(int hotspot) {
953 if (!hotspot_bitmaps)
954 return;
955 if ((hotspot < 0) || (hotspot >= hotspotmap.num_of_hotspots))
956 return;
957 TelCom_BltToScreen(HotSpotL(hotspot), HotSpotT(hotspot), &hotspot_bitmaps[hotspot]);
958 }
959
960 // ---------------------------------------------------------------------------
961 // performs 16-bit blts.
962
963 void TelCom_BltToScreen(int dx, int dy, chunked_bitmap *src_bmp) {
964 TelCom_BltToScreen(dx, dy, src_bmp, 0, 0, src_bmp->pw, src_bmp->ph);
965 }
966
967 void TelCom_BltToScreen(int dx, int dy, chunked_bitmap *src_bmp, int sx, int sy, int sw, int sh) {
968 rend_DrawScaledChunkedBitmap(src_bmp, dx, dy, sw, sh, 255);
969 }
970
971 void TelCom_BltToMem(int dest_bmp, int dx, int dy, int src_bmp, int sx, int sy, int sw, int sh, bool trans) {
972 uint16_t *dbits;
973 uint16_t *sbits;
974 int srowsize_w, drowsize_w, row, col;
975
976 // set up blt.
977 srowsize_w = bm_w(src_bmp, 0); // rowsize in shorts
978 drowsize_w = bm_w(dest_bmp, 0);
979 dbits = (uint16_t *)bm_data(dest_bmp, 0) + (dy * drowsize_w) + dx;
980 sbits = (uint16_t *)bm_data(src_bmp, 0) + (sy * srowsize_w) + sx;
981
982 if (trans) {
983 for (row = 0; row < sh; row++) {
984 for (col = 0; col < sw; col++)
985 if (sbits[col] & OPAQUE_FLAG)
986 dbits[col] = sbits[col];
987
988 sbits += srowsize_w;
989 dbits += drowsize_w;
990 }
991 } else {
992 for (row = 0; row < sh; row++) {
993 for (col = 0; col < sw; col++)
994 dbits[col] = sbits[col];
995
996 sbits += srowsize_w;
997 dbits += drowsize_w;
998 }
999 }
1000 }
1001
1002 // returns left edge of hotspot
1003 int HotSpotL(int hotspot) {
1004 if (hotspot >= hotspotmap.num_of_hotspots)
1005 return -1;
1006 return hotspotmap.hs[hotspot].x[0].start;
1007 }
1008
1009 // returns width of hotspot
1010 int HotSpotW(int hotspot) {
1011 if (hotspot >= hotspotmap.num_of_hotspots)
1012 return -1;
1013 return hotspotmap.hs[hotspot].x[0].end - hotspotmap.hs[hotspot].x[0].start + 1;
1014 }
1015
1016 // returns the top edge of a hotspot
1017 int HotSpotT(int hotspot) {
1018 if (hotspot >= hotspotmap.num_of_hotspots)
1019 return -1;
1020 return hotspotmap.hs[hotspot].starting_y;
1021 }
1022
1023 // returns the height of a hotspot
1024 int HotSpotH(int hotspot) {
1025 if (hotspot >= hotspotmap.num_of_hotspots)
1026 return -1;
1027 return hotspotmap.hs[hotspot].scanlines;
1028 }
1029
1030 // returns the right edge of a hotspot
1031 int HotSpotR(int hotspot) {
1032 if (hotspot >= hotspotmap.num_of_hotspots)
1033 return -1;
1034 return hotspotmap.hs[hotspot].x[0].end;
1035 }
1036
1037 // returns the bottom edge of a hotspot
1038 int HotSpotB(int hotspot) {
1039 if (hotspot >= hotspotmap.num_of_hotspots)
1040 return -1;
1041 return hotspotmap.hs[hotspot].starting_y + hotspotmap.hs[hotspot].scanlines;
1042 }
1043
1044 int LoadTelcomBitmap(const char *filename, chunked_bitmap *chunk) {
1045 int bm_handle = bm_AllocLoadFileBitmap(IGNORE_TABLE(filename), 0);
1046 if (bm_handle == -1)
1047 return 0;
1048
1049 // make monitor windows transparent
1050 menutga_LoadHotSpotMap(bm_handle, IGNORE_TABLE(HOTSPOT_DISPLAY), &hotspotmap, &windowmap);
1051
1052 uint16_t *data = bm_data(bm_handle, 0);
1053 int wnd, x, y, bmw;
1054 int bord_left, bord_right, bord_top, bord_bottom;
1055
1056 bmw = bm_w(bm_handle, 0);
1057
1058 int starty, startx, endy, endx;
1059 for (wnd = 0; wnd < windowmap.num_of_windows; wnd++) {
1060 bord_left = windowmap.wm[wnd].l_start_x - windowmap.wm[wnd].x;
1061 bord_right = windowmap.wm[wnd].x + windowmap.wm[wnd].width - windowmap.wm[wnd].r_end_x;
1062 bord_top = windowmap.wm[wnd].t_top_y - windowmap.wm[wnd].y;
1063 bord_bottom = windowmap.wm[wnd].y + windowmap.wm[wnd].height - windowmap.wm[wnd].b_bottom_y;
1064
1065 starty = windowmap.wm[wnd].y + bord_top;
1066 endy = windowmap.wm[wnd].y + windowmap.wm[wnd].height - bord_bottom;
1067 startx = windowmap.wm[wnd].x + bord_left;
1068 endx = windowmap.wm[wnd].x + windowmap.wm[wnd].width - bord_right;
1069 for (y = starty; y < endy; y++)
1070 for (x = startx; x < endx; x++) {
1071 data[y * bmw + x] = NEW_TRANSPARENT_COLOR;
1072 }
1073 }
1074
1075 FreeHotSpotMapInternals(&hotspotmap);
1076 FreeViewports();
1077 if (windowmap.wm)
1078 mem_free(windowmap.wm);
1079
1080 bm_CreateChunkedBitmap(bm_handle, chunk);
1081
1082 if (bm_handle > BAD_BITMAP_HANDLE)
1083 bm_FreeBitmap(bm_handle);
1084
1085 return 1;
1086 }
1087
1088 #define MAINMENU_BUTTON "TelComMenuButton.ogf"
1089 #define MAINMENU_BUTTONGLOW "TelComMenuButtonGlow.ogf"
1090 #define MAINMENU_BUTTONFOCUS "Forward.ogf"
1091 #define MAINMENU_BUTTONGLOWFOCUS "ForwardFocus.ogf"
1092 /*
1093 $$TABLE_GAMEFILE "TelComMenuButton.ogf"
1094 $$TABLE_GAMEFILE "TelComMenuButtonGlow.ogf"
1095 $$TABLE_GAMEFILE "Forward.ogf"
1096 $$TABLE_GAMEFILE "ForwardFocus.ogf"
1097 */
1098 #define BOFF_L 40
1099 #define BOFF_T 15
1100 #define MM_BUTTONX 99
1101 #define MM_BUTTONY 60
1102 #define MM_BUTTONOFFSET 50
1103
1104 // Main Menu button info
1105 #define TCBRIEFING 0
1106 #define TCCARGO 1
1107 #define TCAUTOMAP 2
1108 #define TCGOALS 3
1109 #define TCMAX_MMBUTTONS 4
1110
1111 int TCMMButtonDesc[] = {TXI_TCMM_BRIEFINGS, TXI_TCMM_CARGO, TXI_TCMM_AUTOMAP, TXI_TCMM_GOALS};
1112
1113 int mainmenu_system;
1114
1115 struct tMenuButton {
1116 bool enabled;
1117 int efxid;
1118 int system;
1119 char text[128];
1120 };
1121 tMenuButton MMButtons[TCMAX_MMBUTTONS];
1122
1123 void TCMainMenuCallback(int efxnum) { mainmenu_system = efxnum; }
1124 void TCMainMenuRenderCallback(void) {
1125 grtext_SetFont(BIG_BRIEFING_FONT);
1126 grtext_SetColor(GR_RGB(255, 255, 255));
1127 grtext_SetAlpha(255);
1128
1129 int mm_y, mm_x;
1130 mm_y = Telcom_system.Monitor_coords[MONITOR_MAIN].top + BOFF_T + MM_BUTTONY;
1131 mm_x = Telcom_system.Monitor_coords[MONITOR_MAIN].left + BOFF_L + MM_BUTTONX;
1132
1133 for (int i = 0; i < TCMAX_MMBUTTONS; i++) {
1134 if (MMButtons[i].enabled) {
1135 // draw the button text
1136 grtext_Printf(mm_x, mm_y, MMButtons[i].text);
1137
1138 // adjust y value
1139 mm_y += MM_BUTTONOFFSET;
1140 }
1141 }
1142 }
1143
1144 // Main menu
1145 bool TelComMainMenu(tTelComInfo *tcs) {
1146 bool exitparse = false;
1147 int mm;
1148
1149 mainmenu_system = -1;
1150
1151 DestroyAllScreens();
1152
1153 for (mm = 0; mm < TCMAX_MMBUTTONS; mm++) {
1154 MMButtons[mm].enabled = false;
1155 MMButtons[mm].system = TS_OFF;
1156 }
1157
1158 TCBKGDESC backg;
1159 backg.color = BACKGROUND_COLOR;
1160 backg.caps = TCBGD_COLOR;
1161 backg.type = TC_BACK_STATIC;
1162
1163 TCBMPDESC bmpdesc;
1164 bmpdesc.type = TC_BMP_STATIC;
1165 bmpdesc.flags = 0;
1166 bmpdesc.caps = TCBD_XY;
1167 bmpdesc.x = 0;
1168 bmpdesc.y = 0;
1169 strcpy(bmpdesc.filename, "TelComMainMenu.ogf");
1170 /*
1171 $$TABLE_GAMEFILE "TelComMainMenu.ogf"
1172 */
1173
1174 TCTEXTDESC textdesc;
1175 textdesc.type = TC_TEXT_STATIC;
1176 textdesc.font = BBRIEF_FONT_INDEX;
1177 textdesc.caps = TCTD_TEXTBOX | TCTD_COLOR | TCTD_FONT;
1178 textdesc.textbox.left = 65;
1179 textdesc.textbox.right = 380;
1180 textdesc.textbox.top = 2;
1181 textdesc.textbox.bottom = 50;
1182 textdesc.color = GR_RGB(255, 255, 255);
1183
1184 TCBUTTONDESC buttdesc;
1185 strcpy(buttdesc.filename, MAINMENU_BUTTON);
1186 strcpy(buttdesc.flash_filename, MAINMENU_BUTTONGLOW);
1187
1188 #if 0 // def DEMO
1189 // strcpy(buttdesc.filename_focus, MAINMENU_BUTTONFOCUS);
1190 // strcpy(buttdesc.flash_filename_focus, MAINMENU_BUTTONGLOWFOCUS);
1191 #else
1192 strcpy(buttdesc.filename_focus, MAINMENU_BUTTONGLOW);
1193 strcpy(buttdesc.flash_filename_focus, MAINMENU_BUTTONGLOW);
1194 #endif
1195 buttdesc.sibling_id = buttdesc.parent_id = -1;
1196 buttdesc.internal = TCMainMenuCallback;
1197 buttdesc.flash_time = 0;
1198 buttdesc.button_type = BUTT_INTERNAL;
1199 buttdesc.flasher = true;
1200 buttdesc.click_type = CLICKTYPE_CLICKUP;
1201 buttdesc.osflags = OBF_GLOW | OBF_MOUSEOVERFOCUS;
1202 buttdesc.x = 0;
1203 buttdesc.y = 0;
1204 buttdesc.tab_stop = true; // all main menu buttons can have focus
1205
1206 // Add effects to screen 0
1207 TelcomStartScreen(0);
1208 CreateBitmapEffect(&bmpdesc, MONITOR_MAIN, 0);
1209
1210 int mm_y, mm_x;
1211 mm_y = MM_BUTTONY + Telcom_system.Monitor_coords[MONITOR_MAIN].top;
1212 mm_x = MM_BUTTONX + Telcom_system.Monitor_coords[MONITOR_MAIN].left;
1213
1214 bool ok_to_run = false;
1215
1216 // Now create all the main menu buttons
1217 for (mm = 0; mm < TCMAX_MMBUTTONS; mm++) {
1218 // first determine if this button should be enabled (they are all disabled by default)
1219 // also set all the systems in here
1220 switch (mm) {
1221 case TCBRIEFING:
1222 // Briefings should only be enabled if there is a briefing
1223 if (Current_level->flags & LVLFLAG_BRIEFING) {
1224 MMButtons[mm].enabled = true;
1225 MMButtons[mm].system = TS_MISSION;
1226 ok_to_run = true;
1227 } else {
1228 MMButtons[mm].enabled = false;
1229 MMButtons[mm].system = TS_OFF;
1230 }
1231 break;
1232 case TCCARGO:
1233 // #if (defined DEMO)||(defined OEM)
1234 MMButtons[mm].enabled = false;
1235 MMButtons[mm].system = TS_OFF;
1236 /*
1237 #else
1238 //Cargo should only be enabled if we are in the game
1239 if(Telcom_called_from_game){
1240 MMButtons[mm].enabled = true;
1241 MMButtons[mm].system = TS_CARGO;
1242 ok_to_run = true;
1243 }else{
1244 MMButtons[mm].enabled = false;
1245 MMButtons[mm].system = TS_OFF;
1246 }
1247 #endif
1248 */
1249 break;
1250 case TCGOALS:
1251 if (Telcom_called_from_game) {
1252 MMButtons[mm].enabled = true;
1253 MMButtons[mm].system = TS_GOALS;
1254 ok_to_run = true;
1255 } else {
1256 MMButtons[mm].enabled = false;
1257 MMButtons[mm].system = TS_OFF;
1258 }
1259 break;
1260 case TCAUTOMAP:
1261 // Automap should only be enabled if we are in the game
1262 if (Telcom_called_from_game) {
1263 MMButtons[mm].enabled = true;
1264 MMButtons[mm].system = TS_MAP;
1265 ok_to_run = true;
1266 } else {
1267 MMButtons[mm].enabled = false;
1268 MMButtons[mm].system = TS_OFF;
1269 }
1270 break;
1271 }
1272
1273 strcpy(MMButtons[mm].text, TXT(TCMMButtonDesc[mm]));
1274
1275 // now if it's enabled,fill in it's info
1276 // create the button
1277 if (MMButtons[mm].enabled) {
1278 buttdesc.x = mm_x;
1279 buttdesc.y = mm_y;
1280 MMButtons[mm].efxid = CreateButtonEffect(&buttdesc, MONITOR_MAIN, 0);
1281 // adjust y
1282 mm_y += MM_BUTTONOFFSET;
1283 } else {
1284 MMButtons[mm].efxid = -1;
1285 }
1286 }
1287
1288 if (!ok_to_run) {
1289 // no systems available
1290 tcs->state = TCS_POWEROFF;
1291 }
1292
1293 CreateBackgroundEffect(&backg, MONITOR_TOP, 0);
1294 CreateTextEffect(&textdesc, format(TXT_TCMAINMENU), MONITOR_TOP, 0);
1295 TelcomEndScreen();
1296
1297 TelcomRenderSetCallback(TCMainMenuRenderCallback);
1298
1299 // Set the screen active
1300 TelcomRenderSetScreen(0);
1301
1302 bool done = false;
1303
1304 TelCom_ClearCustomKeyEvents();
1305 TelCom_AddCustomKeyEvent(KEY_DOWN, 0x13); // down arrow
1306 TelCom_AddCustomKeyEvent(KEY_UP, 0x14); // up arrow
1307
1308 while (!done) {
1309 Sound_system.BeginSoundFrame(Telcom_called_from_game);
1310
1311 if (tcs->state == TCS_POWEROFF || mainmenu_system != -1 || tcs->current_status != TS_OFF) {
1312 // we're done with the loop
1313 done = true;
1314
1315 if (mainmenu_system != -1) {
1316 // go through the buttons and compare efx id's
1317 for (int i = 0; i < TCMAX_MMBUTTONS; i++) {
1318 if (MMButtons[i].enabled && MMButtons[i].efxid == mainmenu_system) {
1319 // we found our system
1320 tcs->current_status = MMButtons[i].system;
1321 } // endif
1322 } // endfor
1323 } // endif
1324 }
1325
1326 // Process all waiting events for the TelCom (we may only want to handle this once a frame!)
1327 TelComHandleAllEvents(&Telcom_system);
1328
1329 // Process custom events
1330 tTCEvent evt;
1331 while (TelCom_PopSystemEvent(&evt)) {
1332 switch (evt.id) {
1333 case 0x13: // up arrow
1334 TelComSendEvent(TEVT_FAKEKEYPRESS, TCSYS_TAB);
1335 break;
1336 case 0x14: // down arrow
1337 TelComSendEvent(TEVT_FAKEKEYPRESS, TCSYS_REVERSETAB);
1338 break;
1339 }
1340 }
1341
1342 TelcomRenderScreen();
1343 Descent->defer();
1344 if (KEY_STATE(KEY_ESC))
1345 Telcom_system.state = TCS_POWEROFF;
1346
1347 Sound_system.EndSoundFrame();
1348 }
1349 TelCom_ClearCustomKeyEvents();
1350
1351 DestroyAllScreens();
1352 TelcomRenderSetScreen(DUMMY_SCREEN);
1353 TelcomRenderSetCallback(NULL);
1354 return true;
1355 }
1356
1357 /*
1358 ************************************************************************
1359 * TelCom Render Functions *
1360 ************************************************************************
1361 *
1362 */
1363 /// internal prototypes *************************************
1364 // Creates the screen overlays for the main monitor
1365 static void TelcomCreateScreenOverlays(void);
1366 // Destroys the screen overlays that were used for the main monitor
1367 static void TelcomDestroyScreenOverlays(void);
1368 // Renders the screen overlays
1369 static void TelcomRenderOverlays(void);
1370 // Renders the screen hilights
1371 static void TelcomRenderDrawHiLites(void);
1372 // Loads the Hilites for a monitor
1373 static void TelcomLoadHiLites(const char *filelist[], int monitor, int xoff, int yoff);
1374 // Frees all the memory allocated for the hilites
1375 static void TelcomFreeHiLites(void);
1376 // Renders the scanline to be drawn
1377 static void TelcomRenderScanline(void);
1378 // Creates the scanline
1379 static void TelcomCreateScanLine(void);
1380 // Destroys the scanline
1381 static void TelcomDestroyScanLine(void);
1382 // Loads the mouse cursor
1383 static void TelcomLoadMouseCursor(void);
1384 // Frees the mouse cursor
1385 static void TelcomFreeMouseCursor(void);
1386 // Renders the mouse cursor
1387 static void TelcomRenderMouse(void);
1388 // draws the telcom background, handles flickering lights, power button etc
1389 static void TelcomDrawScreen(bool poweron, bool powerup);
1390 // used to display the rounded corners of the monitor screens
1391 static void TelcomDisplayCorners(void);
1392 // Frees the bitmaps used for the corners of each monitor
1393 static void TelcomFreeCorners(void);
1394 // Allocates the bitmaps for corners of each monitor
1395 static void TelcomCreateCorners(void);
1396 // Displays static on the screen
1397 static void TelcomDisplayStatic(float amount);
1398 // Frees the static bitmap overlays
1399 static void TelcomFreeStaticOverlays(void);
1400 // Creates the static bitmap overlays
1401 static void TelcomCreateStaticOverlays(void);
1402 // Initializes the bitmaps, etc needed for power up/down effect
1403 static void TelcomInitPowerEffect(void);
1404 // Frees the bitmaps, etc for power up/down effect
1405 static void TelcomFreePowerEffect(void);
1406 // Draws a frame of the power up/down effect
1407 static void TelcomDoPowerEffect(bool power_down, float frametime);
1408
1409 /// global variables ****************************************
1410 // Telcom rendering globals
1411 static void (*TC_callback)() = NULL;
1412 static int TC_current_screen = DUMMY_SCREEN;
1413 int TC_cursor = -1;
1414
1415 // Monitor hilight variables
1416 static int TelcomHiLiteCount[MAX_MONITOR];
1417 static int *TelcomHiLites[MAX_MONITOR];
1418 struct {
1419 int x, y;
1420 } TelcomHiLiteOffset[MAX_MONITOR];
1421 // Main monitor scanline info
1422 static float scanline_nexttime, scanline_speed;
1423 static int scanliney, scanline_handle;
1424 static float last_rendertime = 0;
1425 float last_frametime = 0;
1426 // Monitor corner variables
1427 static chunked_bitmap lt_corners[MAX_MONITOR];
1428 static chunked_bitmap rt_corners[MAX_MONITOR];
1429 static chunked_bitmap lb_corners[MAX_MONITOR];
1430 static chunked_bitmap rb_corners[MAX_MONITOR];
1431 static bool has_corners[MAX_MONITOR];
1432 // Screen variables
1433 static int TCWorking_screen;
1434 // Static variables
1435 #define STATIC_BMPS 12
1436 static int StaticBmps[STATIC_BMPS];
1437 static bool Telcom_show_static = false;
1438 static bool Telcom_static_last_frame = false;
1439 static float Telcom_static_setting = 0;
1440 // Glitch variables
1441 static bool Telcom_show_glitch = false;
1442 static bool Telcom_glitch_screen = false;
1443 static float Telcom_glitch_setting = 0;
1444 static float myrand(float max);
1445 // Powereffect variables
1446 static int PowerBmps[2];
1447
1448 // Initializes the Telcom rendering engine
1449 void TelcomRenderInit(void) {
1450 for (int monitor = 0; monitor < MAX_MONITOR; monitor++) {
1451 ASSERT(monitor < windowmap.num_of_windows);
1452
1453 Telcom_system.Monitor_coords[monitor].left = windowmap.wm[monitor].x;
1454 Telcom_system.Monitor_coords[monitor].top = windowmap.wm[monitor].y;
1455 Telcom_system.Monitor_coords[monitor].right = windowmap.wm[monitor].x + windowmap.wm[monitor].width;
1456 Telcom_system.Monitor_coords[monitor].bottom = windowmap.wm[monitor].y + windowmap.wm[monitor].height;
1457
1458 // Do we want to save these seperatly?
1459 Telcom_system.Monitor_coords[monitor].left += windowmap.wm[monitor].l_start_x - windowmap.wm[monitor].x;
1460 Telcom_system.Monitor_coords[monitor].right -=
1461 windowmap.wm[monitor].x + windowmap.wm[monitor].width - windowmap.wm[monitor].r_end_x;
1462 Telcom_system.Monitor_coords[monitor].top += windowmap.wm[monitor].t_top_y - windowmap.wm[monitor].y;
1463 Telcom_system.Monitor_coords[monitor].bottom -=
1464 windowmap.wm[monitor].y + windowmap.wm[monitor].height - windowmap.wm[monitor].b_bottom_y;
1465 }
1466
1467 TC_callback = NULL;
1468 TC_current_screen = DUMMY_SCREEN;
1469 TelcomCreateScreenOverlays();
1470 last_rendertime = timer_GetTime();
1471 TelcomCreateDummyScreen();
1472 TelcomRenderSetScreen(DUMMY_SCREEN);
1473 TelcomDisableGlitch();
1474 TelcomDisableStatic();
1475 Telcom_first_render = true;
1476 }
1477
1478 // Closes down the Telcom rendering engine
1479 void TelcomRenderClose(void) {
1480 TelcomDestroyScreenOverlays();
1481 TC_current_screen = DUMMY_SCREEN;
1482 }
1483
1484 // Renders the current screen for 1 frame
1485 void TelcomRenderScreen(bool poweron, bool powerup, uint8_t power_effect) {
1486 if (TC_current_screen == -1)
1487 return;
1488
1489 float frametime, newtime;
1490 newtime = timer_GetTime();
1491
1492 float cap_time = last_rendertime + (1.0f / FRAME_RATE);
1493 if (cap_time > newtime) {
1494 Descent->delay(cap_time - newtime);
1495 newtime = timer_GetTime();
1496 }
1497
1498 frametime = newtime - last_rendertime;
1499 last_rendertime = newtime;
1500 last_frametime = frametime;
1501
1502 if (Telcom_first_render) {
1503 Telcom_first_render = false;
1504 frametime = 0;
1505 }
1506
1507 StartFrame(0, 0, Game_window_w, Game_window_h);
1508
1509 if (Telcom_show_glitch) {
1510 if (((int)myrand(100 * (1.0 - Telcom_glitch_setting))) == 0) {
1511 Telcom_glitch_screen = true;
1512 glitch_dx = (int)(myrand(20) - 10.0);
1513 glitch_dy = (int)(myrand(12) - 6.0);
1514 }
1515 }
1516
1517 // first render all the effects
1518 RenderScreen(TC_current_screen, &Telcom_system, frametime);
1519
1520 // call the callback if it exists to render anything on the monitor screen
1521 if (TC_callback)
1522 TC_callback();
1523
1524 // Render the screen overlays
1525 TelcomRenderOverlays();
1526
1527 grtext_Flush();
1528
1529 switch (power_effect) {
1530 case 1:
1531 TelcomDoPowerEffect(false, frametime);
1532 break;
1533 case 2:
1534 TelcomDoPowerEffect(true, frametime);
1535 break;
1536 };
1537
1538 // Draw the TelCom System
1539 TelcomDrawScreen(poweron, powerup);
1540
1541 TelcomRenderMouse();
1542
1543 EndFrame();
1544 rend_Flip();
1545
1546 Telcom_glitch_screen = false;
1547 }
1548
1549 // Sets the callback of the Render. This will get called after Effects are drawn, before the screen overlays
1550 void TelcomRenderSetCallback(void (*callback)()) { TC_callback = callback; }
1551
1552 // Sets what screen should be drawn by the Telcom
1553 void TelcomRenderSetScreen(int screen) {
1554 ASSERT(screen >= 0 && screen < MAX_TELCOM_SCREENS);
1555
1556 if (Telcom_system.Screen_state[screen] != SS_READY) {
1557 mprintf(0, "Telcom Warning: Trying to set screen %d active when it isn't ready\n", screen);
1558 return;
1559 }
1560 TC_current_screen = screen;
1561 }
1562
1563 // Creates a placeholder screen that can be used if no screens are available
1564 void TelcomCreateDummyScreen(void) {
1565 TelcomStartScreen(DUMMY_SCREEN);
1566
1567 TCBKGDESC backg;
1568 backg.color = BACKGROUND_COLOR;
1569 backg.caps = TCBGD_COLOR;
1570 backg.type = TC_BACK_STATIC;
1571 TCBMPDESC bmpdesc;
1572 bmpdesc.caps = 0;
1573 bmpdesc.type = TC_BMP_STATIC;
1574 bmpdesc.flags = 0;
1575 strcpy(bmpdesc.filename, "TelComInit.ogf");
1576 /*
1577 $$TABLE_GAMEFILE "TelComInit.ogf"
1578 */
1579 TCTEXTDESC textdesc;
1580 textdesc.type = TC_TEXT_FADE;
1581 textdesc.flags = TC_TEXTF_IN;
1582 textdesc.speed = 1.0f;
1583 textdesc.font = BBRIEF_FONT_INDEX;
1584 textdesc.caps = TCTD_TEXTBOX | TCTD_COLOR | TCTD_SPEED | TCTD_FONT;
1585 textdesc.textbox.left = 25;
1586 textdesc.textbox.right = 540;
1587 textdesc.textbox.top = 113;
1588 textdesc.textbox.bottom = 260;
1589 textdesc.color = GR_RGB(255, 255, 255);
1590
1591 CreateBitmapEffect(&bmpdesc, MONITOR_MAIN, DUMMY_SCREEN);
1592 #ifdef DEMO
1593 // CreateTextEffect(&textdesc,TXT_TCINITIALIZING,MONITOR_MAIN,DUMMY_SCREEN);
1594 #else
1595 CreateTextEffect(&textdesc, TXT_TCPLEASEWAIT, MONITOR_MAIN, DUMMY_SCREEN);
1596 #endif
1597 CreateBackgroundEffect(&backg, MONITOR_TOP, DUMMY_SCREEN);
1598
1599 TelcomEndScreen();
1600 }
1601
1602 // Creates a placeholder screen that can be used for startup
1603 void TelcomCreateStartupScreen(void) {
1604 TelcomStartScreen(DUMMY_SCREEN);
1605
1606 TCBKGDESC backg;
1607 backg.color = BACKGROUND_COLOR;
1608 backg.caps = TCBGD_COLOR;
1609 backg.type = TC_BACK_STATIC;
1610 TCBMPDESC bmpdesc;
1611 bmpdesc.caps = 0;
1612 bmpdesc.type = TC_BMP_STATIC;
1613 bmpdesc.flags = 0;
1614 strcpy(bmpdesc.filename, "TelComInit.ogf");
1615 /*
1616 $$TABLE_GAMEFILE "TelComInit.ogf"
1617 */
1618 TCTEXTDESC textdesc;
1619 textdesc.type = TC_TEXT_FADE;
1620 textdesc.flags = TC_TEXTF_IN;
1621 textdesc.speed = 1.0f;
1622 textdesc.font = BBRIEF_FONT_INDEX;
1623 textdesc.caps = TCTD_TEXTBOX | TCTD_COLOR | TCTD_SPEED | TCTD_FONT;
1624 textdesc.textbox.left = 25;
1625 textdesc.textbox.right = 280;
1626 textdesc.textbox.top = 113;
1627 textdesc.textbox.bottom = 260;
1628 textdesc.color = GR_RGB(255, 255, 255);
1629
1630 CreateBitmapEffect(&bmpdesc, MONITOR_MAIN, DUMMY_SCREEN);
1631 CreateTextEffect(&textdesc, TXT_TCPLEASEWAIT, MONITOR_MAIN, DUMMY_SCREEN);
1632 CreateBackgroundEffect(&backg, MONITOR_TOP, DUMMY_SCREEN);
1633
1634 TelcomEndScreen();
1635 }
1636
1637 // Creates a placeholder screen that can be used for shutdown
1638 void TelcomCreateShutdownScreen(void) {
1639 TelcomStartScreen(DUMMY_SCREEN);
1640
1641 TCBKGDESC backg;
1642 backg.color = BACKGROUND_COLOR;
1643 backg.caps = TCBGD_COLOR;
1644 backg.type = TC_BACK_STATIC;
1645 TCBMPDESC bmpdesc;
1646 bmpdesc.caps = 0;
1647 bmpdesc.type = TC_BMP_STATIC;
1648 bmpdesc.flags = 0;
1649 strcpy(bmpdesc.filename, "TelComInit.ogf");
1650
1651 /*
1652 $$TABLE_GAMEFILE "TelComInit.ogf"
1653 */
1654 TCTEXTDESC textdesc;
1655 textdesc.type = TC_TEXT_FADE;
1656 textdesc.flags = TC_TEXTF_IN;
1657 textdesc.speed = 1.0f;
1658 textdesc.font = BBRIEF_FONT_INDEX;
1659 textdesc.caps = TCTD_TEXTBOX | TCTD_COLOR | TCTD_SPEED | TCTD_FONT;
1660 textdesc.textbox.left = 25;
1661 textdesc.textbox.right = 280;
1662 textdesc.textbox.top = 113;
1663 textdesc.textbox.bottom = 260;
1664 textdesc.color = GR_RGB(255, 255, 255);
1665
1666 CreateBitmapEffect(&bmpdesc, MONITOR_MAIN, DUMMY_SCREEN);
1667 CreateTextEffect(&textdesc, TXT_TCSHUTDOWN, MONITOR_MAIN, DUMMY_SCREEN);
1668 CreateBackgroundEffect(&backg, MONITOR_TOP, DUMMY_SCREEN);
1669
1670 TelcomEndScreen();
1671 }
1672
1673 // Enables Static on the Telcom main screen, setting is the probability of static happening
1674 void TelcomEnableStatic(float setting) {
1675 Telcom_show_static = true;
1676 Telcom_static_setting = setting;
1677 }
1678
1679 // Disables static on the Telcom main screen
1680 void TelcomDisableStatic(void) {
1681 Telcom_show_static = false;
1682 // TCEndStaticSound();
1683 Telcom_static_last_frame = false;
1684 }
1685
1686 // Enables glitching on the Telcom main screen
1687 void TelcomEnableGlitch(float setting) {
1688 Telcom_show_glitch = true;
1689 Telcom_glitch_setting = setting;
1690 }
1691
1692 // Disables glitching on the TelCom
1693 void TelcomDisableGlitch(void) { Telcom_show_glitch = false; }
1694
1695 #define NEON_STATEOFF 85.0
1696 #define NEON_OFF 0
1697 #define NEON_OFF2 1
1698 #define NEON_OFF3 2
1699 #define NEON_ON1 10
1700 #define NEON_ON2 11
1701 #define NEON_ON3 12
1702 #define NEON_ON1_TIME 0.05
1703 #define NEON_OFF2_TIME 0.02
1704 #define NEON_ON2_TIME 0.03
1705 #define NEON_OFF3_TIME 0.02
1706 // draws the telcom background, handles flickering lights, power button etc
1707 void TelcomDrawScreen(bool poweron, bool powerup) {
1708 static int neon_state = NEON_OFF;
1709 static float start_time = 0;
1710 static float off_time = 0, on_time = 0;
1711
1712 if (powerup) {
1713 neon_state = NEON_OFF;
1714 start_time = timer_GetTime();
1715 off_time = myrand(5);
1716 }
1717
1718 switch (neon_state) {
1719 case NEON_OFF:
1720 if (((timer_GetTime() - start_time) > off_time) && (myrand(100.0) >= NEON_STATEOFF)) {
1721 start_time = timer_GetTime();
1722 neon_state = NEON_ON1;
1723 }
1724 break;
1725 case NEON_ON1:
1726 TelcomStartSound(TCSND_LIGHTBULB);
1727 if ((timer_GetTime() - start_time) > NEON_ON1_TIME) {
1728 start_time = timer_GetTime();
1729 neon_state = NEON_OFF2;
1730 }
1731 break;
1732 case NEON_OFF2:
1733 if ((timer_GetTime() - start_time) > NEON_OFF2_TIME) {
1734 start_time = timer_GetTime();
1735 neon_state = NEON_ON2;
1736 }
1737 break;
1738 case NEON_ON2:
1739 if ((timer_GetTime() - start_time) > NEON_ON2_TIME) {
1740 start_time = timer_GetTime();
1741 neon_state = NEON_OFF3;
1742 }
1743 break;
1744 case NEON_OFF3:
1745 if ((timer_GetTime() - start_time) > NEON_OFF3_TIME) {
1746 start_time = timer_GetTime();
1747 neon_state = NEON_ON3;
1748 on_time = myrand(3);
1749 }
1750 break;
1751 case NEON_ON3:
1752 if (((timer_GetTime() - start_time) > on_time) && (myrand(100.0) < NEON_STATEOFF)) {
1753 start_time = timer_GetTime();
1754 neon_state = NEON_OFF;
1755 off_time = myrand(5);
1756 }
1757 break;
1758 }
1759
1760 rend_SetFiltering(0);
1761
1762 // draw telcom background
1763 rend_DrawChunkedBitmap(&Telcom_bitmap, 0, 0, 255);
1764
1765 if (neon_state >= NEON_ON1)
1766 DrawHotSpotOn(NEON_LIGHT);
1767 if (poweron)
1768 DrawHotSpotOn(POWER_BUTTON);
1769
1770 rend_SetFiltering(1);
1771
1772 TelcomDisplayCorners();
1773 }
1774
1775 // Allocates the bitmaps for corners of each monitor
1776 void TelcomCreateCorners(void) {
1777 for (int monitor = 0; monitor < MAX_MONITOR; monitor++) {
1778 if ((windowmap.wm[monitor].t_top_y != -1) && (windowmap.wm[monitor].b_top_y != -1)) {
1779 bm_CreateChunkedBitmap(windowmap.wm[monitor].lt_bmp, &lt_corners[monitor]);
1780 bm_CreateChunkedBitmap(windowmap.wm[monitor].rt_bmp, &rt_corners[monitor]);
1781 bm_CreateChunkedBitmap(windowmap.wm[monitor].lb_bmp, &lb_corners[monitor]);
1782 bm_CreateChunkedBitmap(windowmap.wm[monitor].rb_bmp, &rb_corners[monitor]);
1783 has_corners[monitor] = true;
1784 } else {
1785 lt_corners[monitor].pw = lt_corners[monitor].ph = 0;
1786 rt_corners[monitor].pw = rt_corners[monitor].ph = 0;
1787 lb_corners[monitor].pw = lb_corners[monitor].ph = 0;
1788 rb_corners[monitor].pw = rb_corners[monitor].ph = 0;
1789 has_corners[monitor] = false;
1790 }
1791 }
1792 }
1793
1794 // Frees the bitmaps used for the corners of each monitor
1795 void TelcomFreeCorners(void) {
1796 for (int monitor = 0; monitor < MAX_MONITOR; monitor++) {
1797 if (!has_corners[monitor])
1798 continue;
1799
1800 // destroy the chunked bitmaps of the corners
1801 if (lt_corners[monitor].pw != 0) {
1802 bm_DestroyChunkedBitmap(&lt_corners[monitor]);
1803 lt_corners[monitor].pw = lt_corners[monitor].ph = 0;
1804 }
1805 if (rt_corners[monitor].pw != 0) {
1806 bm_DestroyChunkedBitmap(&rt_corners[monitor]);
1807 rt_corners[monitor].pw = rt_corners[monitor].ph = 0;
1808 }
1809 if (lb_corners[monitor].pw != 0) {
1810 bm_DestroyChunkedBitmap(&lb_corners[monitor]);
1811 lb_corners[monitor].pw = lb_corners[monitor].ph = 0;
1812 }
1813 if (rb_corners[monitor].pw != 0) {
1814 bm_DestroyChunkedBitmap(&rb_corners[monitor]);
1815 rb_corners[monitor].pw = rb_corners[monitor].ph = 0;
1816 }
1817 }
1818 }
1819
1820 void TelcomDisplayCorners(void) {
1821 for (int monitor = 0; monitor < MAX_MONITOR; monitor++) {
1822 if (!has_corners[monitor])
1823 continue;
1824
1825 int left = Telcom_system.Monitor_coords[monitor].left;
1826 int right = Telcom_system.Monitor_coords[monitor].right;
1827 int top = Telcom_system.Monitor_coords[monitor].top;
1828 int bottom = Telcom_system.Monitor_coords[monitor].bottom;
1829
1830 BltBmpToScreen(left, top, &lt_corners[monitor]);
1831 BltBmpToScreen(right - rt_corners[monitor].pw, top, &rt_corners[monitor]);
1832 BltBmpToScreen(left, bottom - lb_corners[monitor].ph, &lb_corners[monitor]);
1833 BltBmpToScreen(right - rb_corners[monitor].pw, bottom - rb_corners[monitor].ph, &rb_corners[monitor]);
1834 }
1835 }
1836
1837 const char *hilites[] = {"hilite0", "hilite1", "hilite2", "hilite3", "hilite4", "hilite5", NULL};
1838 const char *smhilites[] = {"smhilite01", "smhilite11", "smhilite21", "smhilite31", "smhilite41",
1839 "smhilite51", "smhilite61", "smhilite71", NULL};
1840
1841 /*
1842 $$TABLE_TEXTURE "hilite0"
1843 $$TABLE_TEXTURE "hilite1"
1844 $$TABLE_TEXTURE "hilite2"
1845 $$TABLE_TEXTURE "hilite3"
1846 $$TABLE_TEXTURE "hilite4"
1847 $$TABLE_TEXTURE "hilite5"
1848 $$TABLE_TEXTURE "smhilite01"
1849 $$TABLE_TEXTURE "smhilite11"
1850 $$TABLE_TEXTURE "smhilite21"
1851 $$TABLE_TEXTURE "smhilite31"
1852 $$TABLE_TEXTURE "smhilite41"
1853 $$TABLE_TEXTURE "smhilite51"
1854 $$TABLE_TEXTURE "smhilite61"
1855 $$TABLE_TEXTURE "smhilite71"
1856 */
1857
1858 // Creates the screen overlays for the main monitor
1859 void TelcomCreateScreenOverlays(void) {
1860 TelcomLoadHiLites(hilites, MONITOR_MAIN, 130, -2);
1861 TelcomLoadHiLites(smhilites, MONITOR_TOP, 0, -8);
1862
1863 TelcomCreateScanLine();
1864 TelcomLoadMouseCursor();
1865 TelcomCreateCorners();
1866 // TelcomCreateStaticOverlays();
1867 TelcomInitPowerEffect();
1868 }
1869
1870 // Destroys the screen overlays that were used for the main monitor
1871 void TelcomDestroyScreenOverlays(void) {
1872 TelcomFreeHiLites();
1873 TelcomDestroyScanLine();
1874 TelcomFreeMouseCursor();
1875 TelcomFreeCorners();
1876 // TelcomFreeStaticOverlays();
1877 TelcomFreePowerEffect();
1878 }
1879
1880 #define HIGH_STATIC 50.0
1881 #define NEG_CUT 40.0
1882 #define LOW_LEVEL -20.0
1883 #define HIGH_LEVEL 40.0
1884 // Renders the screen overlays
1885 void TelcomRenderOverlays(void) {
1886 static float stat = 0;
1887
1888 TelcomRenderScanline();
1889 TelcomRenderDrawHiLites();
1890
1891 // Display static
1892 if (Telcom_show_static) {
1893 stat += (myrand(HIGH_STATIC) - NEG_CUT);
1894 if (stat > 0) {
1895 Telcom_static_last_frame = true;
1896 float amp = stat * Telcom_static_setting / HIGH_STATIC;
1897 // TCStartStaticSound(amp);
1898 TelcomDisplayStatic(amp);
1899 } else {
1900 if (Telcom_glitch_screen) {
1901 float amp = myrand(1) - 0.3;
1902 Telcom_static_last_frame = true;
1903 // TCStartStaticSound(amp);
1904 TelcomDisplayStatic(amp);
1905 } else {
1906 /*
1907 if(Telcom_static_last_frame)
1908 TCEndStaticSound();
1909 */
1910 Telcom_static_last_frame = false;
1911 }
1912 }
1913
1914 if (stat > HIGH_STATIC)
1915 stat = HIGH_LEVEL;
1916 if (stat < LOW_LEVEL)
1917 stat = 0;
1918 }
1919 }
1920
1921 // Renders the screen hilights
1922 void TelcomRenderDrawHiLites(void) {
1923 float alphas[4];
1924
1925 rend_SetAlphaType(AT_SATURATE_TEXTURE_VERTEX);
1926 rend_SetAlphaValue(120);
1927 rend_SetLighting(LS_NONE);
1928 rend_SetColorModel(CM_MONO);
1929 rend_SetOverlayType(OT_NONE);
1930 rend_SetFiltering(0);
1931 rend_SetWrapType(WT_CLAMP);
1932
1933 alphas[0] = 0.3f;
1934 alphas[1] = 0.3f;
1935 alphas[2] = 0;
1936 alphas[3] = 0;
1937
1938 for (int monitor = 0; monitor < MAX_MONITOR; monitor++) {
1939 if ((!TelcomHiLiteCount[monitor]) || (!TelcomHiLites[monitor]))
1940 continue;
1941
1942 int curr_x, curr_y, i, w, h;
1943 int *HiLites;
1944
1945 curr_x = TelcomHiLiteOffset[monitor].x + Telcom_system.Monitor_coords[monitor].left;
1946 curr_y = TelcomHiLiteOffset[monitor].y + Telcom_system.Monitor_coords[monitor].top;
1947 HiLites = TelcomHiLites[monitor];
1948
1949 for (i = 0; i < TelcomHiLiteCount[monitor]; i++) {
1950 w = bm_w(HiLites[i], 0);
1951 h = bm_h(HiLites[i], 0);
1952 rend_DrawScaledBitmap(curr_x, curr_y, curr_x + w, curr_y + h, HiLites[i], 0, 0, 1, 1, -1, alphas);
1953 curr_x += w;
1954 }
1955 }
1956
1957 rend_SetFiltering(1);
1958 }
1959
1960 // Loads the Hilites for a monitor
1961 void TelcomLoadHiLites(const char *filelist[], int monitor, int xoff, int yoff) {
1962 if (!filelist)
1963 return;
1964 ASSERT(monitor >= 0 && monitor < MAX_MONITOR);
1965
1966 TelcomHiLiteCount[monitor] = 0;
1967 while (filelist[TelcomHiLiteCount[monitor]])
1968 TelcomHiLiteCount[monitor]++;
1969
1970 if (!TelcomHiLiteCount[monitor])
1971 TelcomHiLites[monitor] = NULL;
1972
1973 TelcomHiLites[monitor] = (int *)mem_malloc(sizeof(int) * TelcomHiLiteCount[monitor]);
1974 if (!TelcomHiLites[monitor]) {
•1975 mprintf(0, "Unable to allocate memory for HiLites monitor=%d\n", monitor);
1976 TelcomHiLiteCount[monitor] = 0;
1977 return;
1978 }
1979
1980 int *HiLites;
1981 HiLites = TelcomHiLites[monitor];
1982 for (int i = 0; i < TelcomHiLiteCount[monitor]; i++) {
1983 HiLites[i] = FindTextureName(IGNORE_TABLE(filelist[i]));
1984 if (HiLites[i] == -1)
1985 HiLites[i] = BAD_BITMAP_HANDLE;
1986 else
1987 HiLites[i] = GetTextureBitmap(HiLites[i], 0);
1988 }
1989
1990 TelcomHiLiteOffset[monitor].x = xoff;
1991 TelcomHiLiteOffset[monitor].y = yoff;
1992 }
1993
1994 // Frees all the memory allocated for the hilites
1995 void TelcomFreeHiLites(void) {
1996 int *HiLites;
1997 for (int monitor = 0; monitor < MAX_MONITOR; monitor++) {
1998 HiLites = TelcomHiLites[monitor];
1999
2000 if (HiLites) {
2001 mem_free(HiLites);
2002 }
2003 TelcomHiLiteCount[monitor] = 0;
2004 }
2005 }
2006
2007 // Renders the scanline to be drawn
2008 void TelcomRenderScanline(void) {
2009 if (scanline_handle <= BAD_BITMAP_HANDLE)
2010 return;
2011
2012 rend_SetAlphaType(AT_SATURATE_TEXTURE_VERTEX);
2013 rend_SetAlphaValue(120);
2014 rend_SetLighting(LS_NONE);
2015 rend_SetColorModel(CM_MONO);
2016 rend_SetOverlayType(OT_NONE);
2017 rend_SetFiltering(0);
2018 rend_SetWrapType(WT_CLAMP);
2019
2020 int x, end_x, start_x;
2021 float alphas[4];
2022 alphas[0] = 0;
2023 alphas[1] = 0;
2024 alphas[2] = 0.05f;
2025 alphas[3] = 0.05f;
2026
2027 start_x = Telcom_system.Monitor_coords[MONITOR_MAIN].left;
2028 end_x = start_x + Telcom_system.Monitor_coords[MONITOR_MAIN].right - Telcom_system.Monitor_coords[MONITOR_MAIN].left;
2029
2030 float end_time = timer_GetTime();
2031
2032 while (end_time > scanline_nexttime) {
2033 for (x = start_x; x < end_x; x += 32)
2034 rend_DrawScaledBitmap(x, scanliney, x + 32, scanliney + 16, scanline_handle, 0, 0, 1, 1, -1, alphas);
2035 scanliney++;
2036 scanline_nexttime += scanline_speed;
2037 }
2038
2039 if (scanliney > Telcom_system.Monitor_coords[MONITOR_MAIN].bottom)
2040 scanliney = Telcom_system.Monitor_coords[MONITOR_MAIN].top - 32;
2041
2042 rend_SetFiltering(1);
2043 }
2044
2045 // Creates the scanline
2046 void TelcomCreateScanLine(void) {
2047 scanliney = Telcom_system.Monitor_coords[MONITOR_MAIN].top - 32;
2048 scanline_speed = 1.0f / 50.0f;
2049 scanline_nexttime = timer_GetTime() + scanline_speed;
2050 scanline_handle = bm_AllocBitmap(32, 32, 0);
2051
2052 if (scanline_handle <= BAD_BITMAP_HANDLE) {
2053 return;
2054 }
2055
2056 int start_pixel;
2057 start_pixel = 0;
2058
2059 uint16_t *data = bm_data(scanline_handle, 0);
2060
2061 int x, y;
2062 for (y = 0; y < 32; y++) {
2063 for (x = 0; x < 32; x++) {
2064 if (y >= start_pixel)
2065 data[y * 32 + x] = OPAQUE_FLAG | GR_RGB16(128, 128, 200);
2066 else
2067 data[y * 32 + x] = NEW_TRANSPARENT_COLOR;
2068 }
2069 }
2070 }
2071
2072 // Destroys the scanline
2073 void TelcomDestroyScanLine(void) {
2074 if (scanline_handle <= BAD_BITMAP_HANDLE)
2075 return;
2076
2077 bm_FreeBitmap(scanline_handle);
2078 scanline_handle = -1;
2079 }
2080
2081 // Loads the mouse cursor
2082 void TelcomLoadMouseCursor(void) {
2083 TC_cursor = bm_AllocLoadFileBitmap("StdCursor.ogf", 0);
2084 if (TC_cursor == -1)
2085 TC_cursor = BAD_BITMAP_HANDLE;
2086 }
2087
2088 // Renders the mouse cursor
2089 void TelcomRenderMouse(void) {
2090 rend_SetOverlayType(OT_NONE);
2091 rend_SetLighting(LS_NONE);
2092 rend_SetColorModel(CM_MONO);
2093 rend_SetZBufferState(0);
2094 rend_SetAlphaType(AT_CONSTANT + AT_TEXTURE);
2095 rend_SetAlphaValue(255);
2096
2097 if (TC_cursor > -1) {
2098 int mx, my;
2099 mx = Telcom_mouse_x;
2100 my = Telcom_mouse_y;
2101
2102 float u0 = 0.0f, v0 = 0.0f, u1 = 1.0f, v1 = 1.0f;
2103 int cur_w = bm_w(TC_cursor, 0);
2104 int cur_h = bm_h(TC_cursor, 0);
2105
2106 if (mx > (Game_window_w - cur_w))
2107 u1 = ((float)(Game_window_w - mx)) / ((float)cur_w);
2108 if (my > (Game_window_h - cur_h))
2109 v1 = ((float)(Game_window_h - my)) / ((float)cur_h);
2110
2111 rend_DrawScaledBitmap(mx, my, mx + (int)((float)cur_w * u1), my + (int)((float)cur_h * v1), TC_cursor, u0, v0, u1,
2112 v1);
2113 }
2114 rend_SetZBufferState(1);
2115 }
2116
2117 // Creates the static bitmap overlays
2118 void TelcomCreateStaticOverlays(void) {
2119 int i;
2120 for (i = 0; i < STATIC_BMPS; i++)
2121 StaticBmps[i] = BAD_BITMAP_HANDLE;
2122
2123 int j;
2124 int size;
2125 int saturation = 10;
2126 int result;
2127 float amount;
2128 uint16_t *data[8];
2129
2130 amount = ((float)saturation) * 0.4f;
2131
2132 uint16_t def_color = OPAQUE_FLAG | GR_RGB16(24, 255, 0);
2133
2134 size = 64 * 64;
2135 for (i = 0; i < 4; i++) {
2136 // last 4 bitmaps
2137 StaticBmps[i + 8] = bm_AllocBitmap(64, 64, 0);
2138 data[i + 4] = bm_data(StaticBmps[i + 8], 0);
2139
2140 // middle 4 bitmaps
2141 StaticBmps[i + 4] = bm_AllocBitmap(64, 64, 0);
2142 data[i] = bm_data(StaticBmps[i + 4], 0);
2143
2144 // first 4 bitmaps
2145 StaticBmps[i] = bm_AllocBitmap(128, 128, 0);
2146 data[i] = bm_data(StaticBmps[i], 0);
2147 }
2148
2149 float t = timer_GetTime();
2150
2151 for (j = 0; j < size; j++) {
2152 for (i = 0; i < 4; i++) {
2153
2154 // last 4 bitmaps
2155 result = (int)myrand(amount);
2156 if (!result) {
2157 if ((int)myrand(5) == 3)
2158 data[i + 4][j] = def_color;
2159 else {
2160 uint8_t grey = (uint8_t)myrand(200) + 55;
2161 data[i + 4][j] = OPAQUE_FLAG | GR_RGB16(grey, grey, grey);
2162 }
2163 } else
2164 data[i + 4][j] = NEW_TRANSPARENT_COLOR;
2165
2166 // middle 4 bitmaps
2167 ps_srand(t * 674338);
2168 result = (int)myrand(amount);
2169 if (!result) {
2170 if ((int)myrand(5) == 3)
2171 data[i][j] = def_color;
2172 else {
2173 uint8_t grey = (uint8_t)myrand(200) + 55;
2174 data[i][j] = OPAQUE_FLAG | GR_RGB16(grey, grey, grey);
2175 }
2176 } else
2177 data[i][j] = NEW_TRANSPARENT_COLOR;
2178 }
2179 }
2180
2181 // first 4 bitmaps
2182 size = 128 * 128;
2183 for (j = 0; j < size; j++) {
2184 for (i = 0; i < 4; i++) {
2185 ps_srand((t * 43243 + ps_rand()));
2186 result = (int)myrand(amount);
2187 if (!result) {
2188 if ((int)myrand(5) == 3)
2189 data[i][j] = def_color;
2190 else {
2191 uint8_t grey = (uint8_t)myrand(200) + 55;
2192 data[i][j] = OPAQUE_FLAG | GR_RGB16(grey, grey, grey);
2193 }
2194 } else
2195 data[i][j] = NEW_TRANSPARENT_COLOR;
2196 }
2197 }
2198 }
2199
2200 // Frees the static bitmap overlays
2201 void TelcomFreeStaticOverlays(void) {
2202 for (int i = 0; i < STATIC_BMPS; i++)
2203 if ((StaticBmps[i] != -1) && (StaticBmps[i] != BAD_BITMAP_HANDLE))
2204 bm_FreeBitmap(StaticBmps[i]);
2205 }
2206
2207 // Displays static on the screen
2208 void TelcomDisplayStatic(float alpha) {
2209 int x, y;
2210 int height = (Telcom_system.Monitor_coords[MONITOR_MAIN].bottom) - (Telcom_system.Monitor_coords[MONITOR_MAIN].top);
2211 int width = (Telcom_system.Monitor_coords[MONITOR_MAIN].right) - (Telcom_system.Monitor_coords[MONITOR_MAIN].left);
2212 int type;
2213
2214 if (alpha < 0)
2215 alpha = 0;
2216 if (alpha > 1)
2217 alpha = 1;
2218
2219 type = (int)myrand(21);
2220 if ((type < 7))
2221 type = 0;
2222 else if ((type < 14))
2223 type = 4;
2224 else
2225 type = 8;
2226
2227 int xoff = Telcom_system.Monitor_coords[MONITOR_MAIN].left;
2228 int yoff = Telcom_system.Monitor_coords[MONITOR_MAIN].top;
2229
2230 rend_SetAlphaType(AT_CONSTANT_TEXTURE);
2231 rend_SetAlphaValue(alpha * 255.0);
2232 rend_SetLighting(LS_NONE);
2233 rend_SetColorModel(CM_MONO);
2234 rend_SetOverlayType(OT_NONE);
2235 rend_SetWrapType(WT_CLAMP);
2236 rend_SetFiltering(0);
2237
2238 int dy = ((int)myrand(32)) - 16;
2239
2240 int h = bm_h(StaticBmps[type], 0);
2241 int w = bm_w(StaticBmps[type], 0);
2242 int j = 0;
2243 for (y = dy; y < height; y += h)
2244 for (x = 0; x < width; x += w) {
2245 rend_DrawScaledBitmap(x + xoff, y + yoff, x + w + xoff, y + h + yoff, StaticBmps[type + (j % 4)], 0, 0, 1, 1);
2246 h = bm_h(StaticBmps[type + (j % 4)], 0);
2247 w = bm_w(StaticBmps[type + (j % 4)], 0);
2248 j++;
2249 }
2250
2251 rend_SetFiltering(1);
2252 }
2253
2254 // Frees the mouse cursor
2255 void TelcomFreeMouseCursor(void) {
2256 // remove the mouse cursor
2257 if (TC_cursor > BAD_BITMAP_HANDLE) {
2258 bm_FreeBitmap(TC_cursor);
2259 TC_cursor = -1;
2260 }
2261 }
2262
2263 float TC_effect_position;
2264
2265 // Initializes the bitmaps, etc needed for power up/down effect
2266 void TelcomInitPowerEffect(void) {
2267 PowerBmps[0] = bm_AllocBitmap(32, 32, 0);
2268 if (PowerBmps[0] == -1)
2269 return;
2270
2271 int i;
2272 uint16_t *bmpdata = bm_data(PowerBmps[0], 0);
2273 for (i = 0; i < 32 * 32; i++)
2274 bmpdata[i] = OPAQUE_FLAG | GR_RGB(0, 0, 0);
2275
2276 PowerBmps[1] = FindTextureName("TelcomPowerbar");
2277 if (PowerBmps[1] == -1)
2278 return;
2279 PowerBmps[1] = GetTextureBitmap(PowerBmps[1], 0);
2280 TC_effect_position = 0;
2281 }
2282
2283 // Frees the bitmaps, etc for power up/down effect
2284 void TelcomFreePowerEffect(void) {
2285 if ((PowerBmps[0] != -1) && (PowerBmps[0] != BAD_BITMAP_HANDLE))
2286 bm_FreeBitmap(PowerBmps[0]);
2287 }
2288
2289 #define TCPE_START 0.1f
2290 #define TCPE_STAGE1 0.3f
2291 #define TCPE_STAGE2 0.8f
2292 #define TCPE_END 1.0f
2293
2294 // Draws a frame of the power up/down effect
2295 void TelcomDoPowerEffect(bool power_down, float frametime) {
2296 int height = (Telcom_system.Monitor_coords[MONITOR_MAIN].bottom) - (Telcom_system.Monitor_coords[MONITOR_MAIN].top);
2297 int width = (Telcom_system.Monitor_coords[MONITOR_MAIN].right) - (Telcom_system.Monitor_coords[MONITOR_MAIN].left);
2298 int xoff = Telcom_system.Monitor_coords[MONITOR_MAIN].left;
2299 int yoff = Telcom_system.Monitor_coords[MONITOR_MAIN].top;
2300
2301 if (!power_down && TC_effect_position >= TCPE_STAGE2)
2302 goto tcpe_adjust;
2303
2304 // draw the power effect at it's current state
2305 rend_SetAlphaType(AT_CONSTANT_TEXTURE);
2306 rend_SetAlphaValue(255);
2307 rend_SetLighting(LS_NONE);
2308 rend_SetColorModel(CM_MONO);
2309 rend_SetOverlayType(OT_NONE);
2310 rend_SetWrapType(WT_CLAMP);
2311 rend_SetFiltering(0);
2312 rend_SetZBufferState(0);
2313
2314 if (TC_effect_position <= TCPE_STAGE1) {
2315 // stage 1
2316 int i, x, y;
2317 int line_count = (TC_effect_position - TCPE_START) / (TCPE_STAGE1 - TCPE_START) * ((float)((width / 32) + 3));
2318 if (line_count < 0)
2319 line_count = 0;
2320
2321 for (y = 0; y < height; y += 32)
2322 for (x = 0; x < width; x += 32) {
2323 rend_DrawScaledBitmap(x + xoff, y + yoff, x + 32 + xoff, y + 32 + yoff, PowerBmps[0], 0, 0, 1, 1);
2324 }
2325
2326 if (TC_effect_position < TCPE_START)
2327 goto tcpe_adjust;
2328
2329 x = (width / 2) - (16 * line_count) + xoff;
2330 y = (height / 2) - 16 + yoff;
2331
2332 for (i = 0; i < line_count; i++) {
2333 rend_DrawScaledBitmap(x, y, x + 32, y + 32, PowerBmps[1], 0, 0, 1, 1);
2334 x += 32;
2335 }
2336 } else {
2337 // stage 2
2338 int x, y, i;
2339 int gap;
2340
2341 gap = ((float)height) * (TC_effect_position - TCPE_STAGE1) / (TCPE_STAGE2 - TCPE_STAGE1);
2342 int hcount = ((((float)height) / 2.0f) - (((float)gap) / 2.0f)) / 32.0f;
2343
2344 for (i = 0; i < hcount; i++)
2345 for (x = 0; x < width; x += 32) {
2346 y = (i << 5);
2347 if (i == (hcount - 1)) {
2348 rend_SetAlphaType(AT_SATURATE_TEXTURE);
2349 rend_DrawScaledBitmap(x + xoff, y + 10 + yoff, x + 32 + xoff, y + 42 + yoff, PowerBmps[1], 0, 0, 1, 1);
2350 rend_SetAlphaType(AT_CONSTANT_TEXTURE);
2351 }
2352 rend_DrawScaledBitmap(x + xoff, y + yoff, x + 32 + xoff, y + 32 + yoff, PowerBmps[0], 0, 0, 1, 1);
2353 }
2354
2355 y = height - 32;
2356 for (i = 0; i < hcount; i++) {
2357 for (x = 0; x < width; x += 32) {
2358 if (i == (hcount - 1)) {
2359 rend_SetAlphaType(AT_SATURATE_TEXTURE);
2360 rend_DrawScaledBitmap(x + xoff, y - 10 + yoff, x + 32 + xoff, y + 22 + yoff, PowerBmps[1], 0, 0, 1, 1);
2361 rend_SetAlphaType(AT_CONSTANT_TEXTURE);
2362 }
2363 rend_DrawScaledBitmap(x + xoff, y + yoff, x + 32 + xoff, y + 32 + yoff, PowerBmps[0], 0, 0, 1, 1);
2364 }
2365 y -= 32;
2366 }
2367 }
2368
2369 tcpe_adjust:
2370
2371 // Now adjust effect
2372 if (power_down)
2373 frametime = -frametime;
2374
2375 frametime = frametime / TCPE_TIME; // scale it to a percentage of total time
2376
2377 TC_effect_position += frametime;
2378 if (TC_effect_position < 0)
2379 TC_effect_position = 0;
2380 if (TC_effect_position > 1)
2381 TC_effect_position = 1;
2382
2383 rend_SetFiltering(1);
2384 rend_SetZBufferState(1);
2385 }
2386
2387 /***************************************************
2388 * TelCom Event Handling
2389 ***************************************************
2390 */
2391
2392 // returns the true if there is a next screen (from the current)
2393 static bool TelComIsThereANextScreen(void);
2394
2395 /*
2396 * Initializes the TelCom Event manager system
2397 * Call this as soon as possible
2398 * You can call it whenever the events need to be flushed
2399 */
2400 void TelComInitEventManager(void) {
2401 int i;
2402
2403 for (i = 0; i < MAX_TELCOM_EVENTS; i++) {
2404 Telcom_system.Telcom_event_queue[i].id = -1;
2405 }
2406 for (i = 0; i < TCSYS_MAXKEYS; i++) {
2407 Telcom_system.Telcom_systemkey_states[i] = false;
2408 }
2409
2410 // Setup the key translation table
2411 Telcom_system.TranslateSysKey[TCSYS_TAB] = KEY_TAB;
2412 Telcom_system.TranslateSysKey[TCSYS_UP] = KEY_UP;
2413 Telcom_system.TranslateSysKey[TCSYS_DOWN] = KEY_DOWN;
2414 Telcom_system.TranslateSysKey[TCSYS_LEFT] = KEY_LEFT;
2415 Telcom_system.TranslateSysKey[TCSYS_RIGHT] = KEY_RIGHT;
2416 Telcom_system.TranslateSysKey[TCSYS_ENTER] = KEY_ENTER;
2417 Telcom_system.TranslateSysKey[TCSYS_SPACE] = KEY_SPACEBAR;
2418 Telcom_system.TranslateSysKey[TCSYS_Q] = KEY_Q;
2419 Telcom_system.TranslateSysKey[TCSYS_F1] = KEY_F1;
2420 Telcom_system.TranslateSysKey[TCSYS_F2] = KEY_F2;
2421 Telcom_system.TranslateSysKey[TCSYS_F3] = KEY_F3;
2422 Telcom_system.TranslateSysKey[TCSYS_PRINTSCRN] = KEY_PRINT_SCREEN;
2423 Telcom_system.TranslateSysKey[TCSYS_1] = KEY_1;
2424 Telcom_system.TranslateSysKey[TCSYS_2] = KEY_2;
2425 Telcom_system.TranslateSysKey[TCSYS_3] = KEY_3;
2426 Telcom_system.TranslateSysKey[TCSYS_4] = KEY_4;
2427 Telcom_system.TranslateSysKey[TCSYS_5] = KEY_5;
2428 Telcom_system.TranslateSysKey[TCSYS_6] = KEY_6;
2429 Telcom_system.TranslateSysKey[TCSYS_7] = KEY_7;
2430 Telcom_system.TranslateSysKey[TCSYS_8] = KEY_8;
2431 Telcom_system.TranslateSysKey[TCSYS_REVERSETAB] = KEY_TAB + KEY_SHIFTED;
2432
2433 Telcom_system.Telcom_mouse_downtime = 0;
2434 }
2435
2436 /*
2437 * Enables/Disables a TelCom system key, pass in TCSYS_MAXKEYS to enable/disable all keys
2438 *
2439 */
2440 void TelComEnableSystemKey(int key, bool enable) {
2441 if (key < 0 || key > TCSYS_MAXKEYS)
2442 return;
2443
2444 int bit = 0x01;
2445
2446 if (key == TCSYS_MAXKEYS) {
2447 bit = 0xFFFFFFFF;
2448 } else {
2449 bit = (bit << key);
2450 }
2451
2452 if (enable)
2453 Telcom_system.TelComSysKeyEnable |= bit;
2454 else
2455 Telcom_system.TelComSysKeyEnable &= ~bit;
2456 }
2457
2458 /*
2459 * Calling this sends an event message to the TelCom, adding it to it's event queue
2460 *
2461 */
2462 void TelComSendEvent(int event_num, int parm1, int parm2) {
2463 for (int i = 0; i < MAX_TELCOM_EVENTS; i++) {
2464 if (Telcom_system.Telcom_event_queue[i].id == -1) {
2465 // add the event here
2466 Telcom_system.Telcom_event_queue[i].id = event_num;
2467 Telcom_system.Telcom_event_queue[i].parms[0] = parm1;
2468 Telcom_system.Telcom_event_queue[i].parms[1] = parm2;
2469 return;
2470 }
2471 }
2472
2473 mprintf(0, "Warning: TelCom Event Queue Overflow\n");
2474 }
2475
2476 /*
2477 * Call this when handling the TelCom system events, returns true if there is an event waiting, it will then fill
2478 * in the passed struct. You should call this repeatedly until a value of false is returned, signaling no more
2479 * events in the queue
2480 */
2481 bool TelComPopEvent(tTCEvent *evt) {
2482 if (Telcom_system.Telcom_event_queue[0].id != -1) {
2483 memcpy(evt, &Telcom_system.Telcom_event_queue[0], sizeof(tTCEvent));
2484
2485 // move all items up in the queue
2486 for (int i = 1; i < MAX_TELCOM_EVENTS; i++) {
2487 memcpy(&Telcom_system.Telcom_event_queue[i - 1], &Telcom_system.Telcom_event_queue[i], sizeof(tTCEvent));
2488 }
2489 Telcom_system.Telcom_event_queue[MAX_TELCOM_EVENTS - 1].id = -1;
2490 return true;
2491 }
2492
2493 return false;
2494 }
2495
2496 /*
2497 * Forces an effect to have focus (if is allowed to have focus)
2498 *
2499 */
2500 void TelComSetFocusOnEffect(int efxnum) {
2501 int screen;
2502 int effect_with_focus;
2503
2504 if (TCEffects[efxnum].type == EFX_NONE)
2505 return;
2506
2507 screen = TCEffects[efxnum].screen;
2508
2509 if (TCEffects[efxnum].has_focus)
2510 return; // already has focus
2511
2512 if (!TCEffects[efxnum].tab_stop)
2513 return; // not allowed to have focus
2514
2515 // find the effect on the screen with focus
2516 int i = Screen_roots[screen];
2517 effect_with_focus = -1;
2518
2519 while (i != -1) {
2520 if (TCEffects[i].tab_stop && TCEffects[i].has_focus) {
2521 effect_with_focus = i;
2522 break;
2523 }
2524
2525 i = TCEffects[i].next;
2526 }
2527
2528 bool send_click = false;
2529
2530 if (TCEffects[efxnum].flags & OBF_CHANGEFOCUSISCLICK)
2531 send_click = true;
2532
2533 // send out our events and process focus change
2534 if (i != -1)
2535 TCEffects[i].has_focus = false;
2536 TCEffects[efxnum].has_focus = true;
2537
2538 if (i != -1)
2539 SendEventToEffect(i, TEVT_LOSTFOCUS);
2540 SendEventToEffect(efxnum, TEVT_GAINFOCUS);
2541
2542 if (send_click)
2543 SendEventToEffect(efxnum, TEVT_MOUSECLICK);
2544 }
2545
2546 /*
2547 * This should be called once a frame, it will handle all events in the TelCom system and send off any system
2548 * events to the effects/buttons
2549 */
2550 #define TELCOM_FRAMERATE_CAP 25.0f
2551 void GameFrame(void);
2552 void TelComHandleAllEvents(tTelComInfo *tcs) {
2553 static float last_frame_time = 0;
2554 float frame_time;
2555
2556 volatile float curr_time = timer_GetTime();
2557 volatile float next_time = last_frame_time + (1 / TELCOM_FRAMERATE_CAP);
2558
2559 if (curr_time < next_time) {
2560 Sleep((next_time - curr_time) * 1000.0f);
2561 }
2562 if (last_frame_time == 0) {
2563 frame_time = 0.1f;
2564 }
2565 frame_time = curr_time - last_frame_time;
2566 last_frame_time = curr_time;
2567
2568 // First handle all events that the TelCom system has waiting
2569 tTCEvent event;
2570 while (TelComPopEvent(&event)) {
2571 // handle the event
2572 switch (event.id) {
2573 case -1:
2574 mprintf(0, "TelCom Error: Trying to process an event of type -1\n");
2575 Int3(); // Hey!! How'd we pop off a -1!!! Get Jeff
2576 break;
2577 case TEVT_TCQUIT: {
2578 // the user wants to quit out of the TelCom
2579 tcs->current_status = TS_OFF;
2580 } break;
2581 case TEVT_SCREENSHOT: {
2582 // take a screenshot
2583 mprintf(0, "Taking Screenshot\n");
2584 DoScreenshot();
2585 } break;
2586 case TEVT_TCNEXT: {
2587 // the user wants to go to the next screen
2588 if (TelcomAdvanceScreen() && tcs->current_status == TS_MISSION && !Telcom_called_from_game) {
2589 // exit out of TelCom
2590 tcs->state = TCS_POWEROFF;
2591 }
2592 } break;
2593 case TEVT_TCPREV: {
2594 // the user wants to go to the prev screen
2595 TelcomBackupScreen();
2596 } break;
2597 case TEVT_TCJUMP: {
2598 int screen = event.parms[0];
2599 ASSERT(screen >= 0 && screen < MAX_TELCOM_SCREENS);
2600
2601 // the user wants to jump to a screen
2602 TelComJumpScreen(screen);
2603 } break;
2604 case TEVT_FAKEKEYPRESS: {
2605 TelComHandleKeyPress(event.parms[0], true, TC_current_screen);
2606 } break;
2607 default:
2608 mprintf(0, "TelCom System Warning: Unhandled event %d\n", event.id);
2609 break;
2610 }
2611 }
2612
2613 // Now that all the events for the TelCom system have been handled, send off any events that need
2614 // to be sent to the effects or buttons
2615
2616 // First check all TelCom system keys
2617 int screen = TC_current_screen;
2618 int key;
2619
2620 if ((KEY_STATE(KEY_LSHIFT) || KEY_STATE(KEY_RSHIFT)) && KEY_STATE(KEY_ESC)) {
2621 Telcom_exit_to_mainmenu = true;
2622 Telcom_system.state = TCS_POWEROFF;
2623 }
2624
2625 int i;
2626 bool processed[TCSYS_MAXKEYS];
2627 for (i = 0; i < TCSYS_MAXKEYS; i++)
2628 processed[i] = false;
2629
2630 TelCom_PrepareCustomKeyEvents();
2631
2632 while ((key = ddio_KeyInKey()) != 0) {
2633 for (i = 0; i < TCSYS_MAXKEYS; i++) {
2634 TelCom_ProcessCustomKeyEvent(key);
2635
2636 if (Telcom_system.TranslateSysKey[i] != key)
2637 continue;
2638
2639 if (!Telcom_system.Telcom_systemkey_states[i]) {
2640 // the key has just been pressed, handle button press
2641 TelComHandleKeyPress(i, true, screen);
2642 }
2643
2644 if (Telcom_system.Telcom_systemkey_states[i]) {
2645 // the key is being held down, handle button down
2646 TelComHandleKeyPress(i, false, screen);
2647 }
2648 Telcom_system.Telcom_systemkey_states[i] = true;
2649 processed[i] = true;
2650 }
2651 }
2652
2653 for (i = 0; i < TCSYS_MAXKEYS; i++) {
2654 if (!processed[i]) {
2655 Telcom_system.Telcom_systemkey_states[i] = false;
2656 }
2657 }
2658
2659 TelCom_PostProcessCustomKeyEvents();
2660
2661 // Now check mouse position and button state
2662 int x, y;
2663 int buttons;
2664 int effect_clicktype;
2665 float frametime;
2666
2667 if (Control_poll_flag) {
2668 buttons = Controller->get_mouse_raw_values(&x, &y);
2669 } else {
2670 buttons = ddio_MouseGetState(&x, &y, NULL, NULL);
2671 }
2672
2673 Telcom_mouse_x = x;
2674 Telcom_mouse_y = y;
2675
2676 // check to see if the power button was clicked
2677 if (!buttons && Telcom_system.Telcom_mouse_downtime > 0 && (x >= HotSpotL(POWER_BUTTON)) &&
2678 (x <= HotSpotR(POWER_BUTTON)) && (y >= HotSpotT(POWER_BUTTON)) && (y <= HotSpotB(POWER_BUTTON))) {
2679 Telcom_system.state = TCS_POWEROFF;
2680 }
2681
2682 frametime = last_frametime;
2683
2684 // see if the mouse is over any button
2685 int efxnum = FindButtonEffectByXY(x, y, screen);
2686
2687 if (efxnum != -1) {
2688 // check to see if this is the effect num the mouse was last over, if not, then
2689 // register it as mouse enter
2690 if (Telcom_mouse_last_effect != efxnum) {
2691 SendEventToEffect(efxnum, TEVT_MOUSEENTER);
2692 Telcom_mouse_last_effect = efxnum;
2693 }
2694
2695 // the mouse is over a button
2696 SendEventToEffect(efxnum, TEVT_MOUSEOVER);
2697
2698 effect_clicktype = TCEffects[efxnum].buttoninfo.click_type;
2699
2700 if (buttons) {
2701 if (effect_clicktype == CLICKTYPE_DOWN) {
2702 SendEventToEffect(efxnum, TEVT_MOUSEDOWN);
2703 } else if (Telcom_system.Telcom_mouse_downtime == 0 && effect_clicktype == CLICKTYPE_CLICKDOWN) {
2704 SendEventToEffect(efxnum, TEVT_MOUSECLICK);
2705 }
2706 } else {
2707 if (Telcom_system.Telcom_mouse_downtime > 0 && effect_clicktype == CLICKTYPE_CLICKUP) {
2708 // send the mouse up event
2709 SendEventToEffect(efxnum, TEVT_MOUSEUP);
2710 }
2711 }
2712 } else {
2713 // the mouse is not over any effect, reset it's efxnum owner (we can do a mouseleave event here)
2714 Telcom_mouse_last_effect = -1;
2715 }
2716
2717 if (buttons) {
2718 Telcom_system.Telcom_mouse_downtime += frametime;
2719 } else {
2720 Telcom_system.Telcom_mouse_downtime = 0;
2721 }
2722
2723 // If we are calling the telcom from inside the game, than we have some processing to do
2724 if (Telcom_called_from_game && (Game_mode & GM_MULTI)) {
2725 // Process all game frames
2726 if (!Multi_bail_ui_menu)
2727 GameFrame();
2728
2729 // If we are in a multiplayer game and we have been told to bail, than do so!
2730 if (Multi_bail_ui_menu) {
2731 tcs->current_status = TS_OFF;
2732 tcs->state = TCS_POWEROFF;
2733 }
2734 }
2735
2736 // handle music if in game.
2737 if (Telcom_called_from_game) {
2738 tMusicSeqInfo music_info;
2739 music_info.frametime = frame_time;
2740 music_info.player_dead = false;
2741 music_info.started_level = false;
2742 D3MusicDoFrame(&music_info);
2743 }
2744 }
2745
2746 /*
2747 * Given the key that has been pressed, or being held down, it processes the event depending on what key
2748 * it is.
2749 *
2750 */
2751
2752 extern int AM_terrain, AM_realign, AM_center_on_player, AM_current_marker;
2753 void TelComHandleKeyPress(int key, bool click, int screen_id) {
2754 int bit = 0x01;
2755 bit = (bit << key);
2756 if (!(Telcom_system.TelComSysKeyEnable & bit))
2757 return;
2758
2759 switch (key) {
2760 case TCSYS_REVERSETAB: {
2761 if (!click)
2762 break;
2763
2764 int first = -1, curr_focus = -1;
2765 int i = Screen_roots[screen_id];
2766
2767 while (i != -1) {
2768 if (TCEffects[i].tab_stop) {
2769 // this is effect is a tab stop
2770 if (first == -1)
2771 first = i;
2772 if (TCEffects[i].has_focus) {
2773 // this effect is the one with focus
2774 curr_focus = i;
2775 break;
2776 }
2777 }
2778 i = TCEffects[i].next;
2779 }
2780
2781 if (curr_focus == -1) {
2782 // none currently have focus!, make the effect we found (if any) have focus
2783 if (first != -1) {
2784 SendEventToEffect(first, TEVT_GAINFOCUS);
2785 TCEffects[first].has_focus = true;
2786 }
2787 break; // our work is done here
2788 }
2789
2790 bool done = false;
2791 int end_node = Screen_roots[screen_id];
2792 int t = end_node;
2793 if (t == -1) {
2794 Int3();
2795 break;
2796 }
2797
2798 while (!done) {
2799 if (TCEffects[t].next == -1) {
2800 done = true;
2801 end_node = t;
2802 } else {
2803 t = TCEffects[t].next;
2804 }
2805 }
2806
2807 done = false;
2808 int new_focus = -1;
2809 while (!done) {
2810 if (i == -1) {
2811 // start back at the end of the monitor list
2812 i = end_node;
2813 } else
2814 i = TCEffects[i].prev;
2815
2816 if (i == curr_focus)
2817 done = true;
2818 else {
2819 if (TCEffects[i].tab_stop) {
2820 // we found another effect on the screen
2821 new_focus = i;
2822 done = true;
2823 }
2824 }
2825 }
2826
2827 if (new_focus == -1) {
2828 // there is only 1 button on this screen, no change of focus
2829 break;
2830 }
2831 bool send_click = false;
2832
2833 if (TCEffects[new_focus].flags & OBF_CHANGEFOCUSISCLICK)
2834 send_click = true;
2835
2836 // send out our events and process focus change
2837 TCEffects[curr_focus].has_focus = false;
2838 TCEffects[new_focus].has_focus = true;
2839 SendEventToEffect(new_focus, TEVT_GAINFOCUS);
2840
2841 if (send_click)
2842 SendEventToEffect(new_focus, TEVT_MOUSECLICK);
2843 SendEventToEffect(curr_focus, TEVT_LOSTFOCUS);
2844
2845 } break;
2846 case TCSYS_TAB: {
2847 if (!click)
2848 break;
2849
2850 int first = -1, curr_focus = -1;
2851 int i = Screen_roots[screen_id];
2852
2853 while (i != -1) {
2854 if (TCEffects[i].tab_stop) {
2855 // this is effect is a tab stop
2856 if (first == -1)
2857 first = i;
2858 if (TCEffects[i].has_focus) {
2859 // this effect is the one with focus
2860 curr_focus = i;
2861 break;
2862 }
2863 }
2864 i = TCEffects[i].next;
2865 }
2866
2867 if (curr_focus == -1) {
2868 // none currently have focus!, make the effect we found (if any) have focus
2869 if (first != -1) {
2870 SendEventToEffect(first, TEVT_GAINFOCUS);
2871 TCEffects[first].has_focus = true;
2872 }
2873 break; // our work is done here
2874 }
2875
2876 bool done = false;
2877 int new_focus = -1;
2878 while (!done) {
2879 if (i == -1) {
2880 // start back at the beginning of the monitor list
2881 i = Screen_roots[screen_id];
2882 } else
2883 i = TCEffects[i].next;
2884
2885 if (i == curr_focus)
2886 done = true;
2887 else {
2888 if (TCEffects[i].tab_stop) {
2889 // we found another effect on the screen
2890 new_focus = i;
2891 done = true;
2892 }
2893 }
2894 }
2895
2896 if (new_focus == -1) {
2897 // there is only 1 button on this screen, no change of focus
2898 break;
2899 }
2900 bool send_click = false;
2901
2902 if (TCEffects[new_focus].flags & OBF_CHANGEFOCUSISCLICK)
2903 send_click = true;
2904
2905 // send out our events and process focus change
2906 TCEffects[curr_focus].has_focus = false;
2907 TCEffects[new_focus].has_focus = true;
2908 SendEventToEffect(new_focus, TEVT_GAINFOCUS);
2909
2910 if (send_click)
2911 SendEventToEffect(new_focus, TEVT_MOUSECLICK);
2912 SendEventToEffect(curr_focus, TEVT_LOSTFOCUS);
2913 } break;
2914 case TCSYS_UP:
2915 case TCSYS_DOWN: {
2916 int curr_focus = -1;
2917 int node = Screen_roots[screen_id];
2918 while (node != -1) {
2919 if (TCEffects[node].has_focus) {
2920 // this guy has focus
2921 curr_focus = node;
2922 break;
2923 }
2924 node = TCEffects[node].next;
2925 }
2926
2927 if (curr_focus == -1) {
2928 // nothing has focus
2929 break;
2930 }
2931
2932 bool need_to_find_text = false;
2933
2934 // the up/down arrow keys require either a text box to have focus
2935 // or an up/down arrow to have focus
2936 if (TCEffects[curr_focus].type != EFX_BUTTON && TCEffects[curr_focus].type != EFX_TEXT_STATIC &&
2937 TCEffects[curr_focus].type != EFX_TEXT_TYPE && TCEffects[curr_focus].type != EFX_TEXT_FADE) {
2938 // we don't have a text box or a button as focus
2939 need_to_find_text = true;
2940 }
2941
2942 if (TCEffects[curr_focus].type == EFX_BUTTON && TCEffects[curr_focus].buttoninfo.button_type != BUTT_UPARROW &&
2943 TCEffects[curr_focus].buttoninfo.button_type != BUTT_DOWNARROW) {
2944 // we have a button, but it's not an up/down arrow
2945 need_to_find_text = true;
2946 }
2947
2948 if (need_to_find_text) {
2949 // we need to hunt through the effect list, find the first text box with a tabstop
2950 // and use that as the text to scroll
2951 int found = -1;
2952 int node = Screen_roots[screen_id];
2953 while (node != -1) {
2954 if (TCEffects[node].has_focus) {
2955 // this guy has focus
2956 found = node;
2957 break;
2958 }
2959 node = TCEffects[node].next;
2960 }
2961
2962 if (found == -1) {
2963 // we found nothing, we're done
2964 break;
2965 }
2966 curr_focus = found;
2967 }
2968
2969 // if the effect to use (curr_focus) is a button, than get it's parent ID, make sure it is a text effect
2970 if (TCEffects[curr_focus].type == EFX_BUTTON) {
2971 int parent_id = TCEffects[curr_focus].buttoninfo.parent;
2972 if (parent_id == -1 ||
2973 (TCEffects[parent_id].type != EFX_TEXT_STATIC && TCEffects[parent_id].type != EFX_TEXT_TYPE &&
2974 TCEffects[parent_id].type != EFX_TEXT_FADE)) {
2975 // there is no parent, or it's not a text effect
2976 break;
2977 }
2978
2979 curr_focus = parent_id;
2980 }
2981
2982 // when we get here curr_focus should be pointing to a text effect to scroll
2983 ASSERT(curr_focus >= 0 && curr_focus < MAX_TCEFFECTS);
2984 ASSERT(TCEffects[curr_focus].type == EFX_TEXT_STATIC || TCEffects[curr_focus].type == EFX_TEXT_TYPE ||
2985 TCEffects[curr_focus].type == EFX_TEXT_FADE);
2986 ASSERT(TCEffects[curr_focus].tab_stop);
2987
2988 if (key == TCSYS_UP) {
2989 // scroll up
2990 SendEventToEffect(curr_focus, TEVT_SCROLLUP);
2991 } else {
2992 // scroll down
2993 SendEventToEffect(curr_focus, TEVT_SCROLLDOWN);
2994 }
2995 } break;
2996 case TCSYS_LEFT: {
2997 if (!click)
2998 break;
2999 TelComSendEvent(TEVT_TCPREV);
3000 } break;
3001 case TCSYS_SPACE: {
3002 if (!click)
3003 break;
3004 TelComSendEvent(TEVT_TCNEXT);
3005 } break;
3006 case TCSYS_RIGHT: {
3007 if (!click)
3008 break;
3009 // check to see if there is a next page, if there is go to it, else don't
3010 if (TelComIsThereANextScreen())
3011 TelComSendEvent(TEVT_TCNEXT);
3012 } break;
3013 case TCSYS_ENTER: {
3014 int curr_focus = -1;
3015 for (int i = 0; i < MAX_TCEFFECTS; i++) {
3016 if (TCEffects[i].type == EFX_BUTTON && TCEffects[i].screen == screen_id) {
3017 // this is a button on the screen
3018 if (TCEffects[i].has_focus) {
3019 // this button is the one with focus currently
3020 curr_focus = i;
3021 break;
3022 }
3023 }
3024 }
3025 if (curr_focus == -1)
3026 break;
3027 if (TCEffects[curr_focus].buttoninfo.click_type == CLICKTYPE_DOWN) {
3028 SendEventToEffect(curr_focus, TEVT_MOUSEDOWN);
3029 } else if (click) {
3030 SendEventToEffect(curr_focus, TEVT_MOUSECLICK);
3031 }
3032 } break;
3033 case TCSYS_Q: {
3034 if (!click)
3035 break;
3036
3037 TelComSendEvent(TEVT_TCQUIT);
3038 } break;
3039 case TCSYS_F1: {
3040 if (!click)
3041 break;
3042
3043 AM_terrain = !AM_terrain;
3044 } break;
3045 case TCSYS_F2: {
3046 if (!click)
3047 break;
3048
3049 AM_center_on_player = 1;
3050 } break;
3051 case TCSYS_F3: {
3052 if (!click)
3053 break;
3054
3055 AM_realign = 1;
3056 } break;
3057 case TCSYS_PRINTSCRN: {
3058 if (!click)
3059 break;
3060
3061 TelComSendEvent(TEVT_SCREENSHOT);
3062
3063 } break;
3064 case TCSYS_1:
3065 case TCSYS_2:
3066 case TCSYS_3:
3067 case TCSYS_4:
3068 case TCSYS_5:
3069 case TCSYS_6:
3070 case TCSYS_7:
3071 case TCSYS_8: {
3072 int index = key - TCSYS_1;
3073
3074 if (index < Players[Player_num].num_markers)
3075 AM_current_marker = index;
3076
3077 break;
3078 }
3079 default:
3080 mprintf(0, "TelCom Warning: Keypressed not valid\n");
3081 }
3082 }
3083
3084 /*
3085 *****************************************************************************
3086 * TelCom Screen Control Functions *
3087 *****************************************************************************
3088 *
3089 */
3090
3091 // Initializes the TelCom Screens so they're ready for input
3092 void InitAllScreens(void) {
3093 for (int i = 0; i < MAX_TELCOM_SCREENS; i++) {
3094 Telcom_system.Screen_state[i] = SS_EMPTY;
3095 }
3096 TCWorking_screen = -1;
3097 }
3098
3099 // Advances to the next screen
3100 // returns true is there is no screen (it's not being made, nor ready)
3101 bool TelcomAdvanceScreen(void) {
3102 int next_screen = TC_current_screen + 1;
3103 if (next_screen >= MAX_TELCOM_SCREENS)
3104 return true;
3105 switch (Telcom_system.Screen_state[next_screen]) {
3106 case SS_EMPTY:
3107 // no screen even being worked on...return true
3108 return true;
3109 break;
3110 case SS_BEING_MADE:
3111 return false;
3112 break;
3113 case SS_READY:
3114 TelcomRenderSetScreen(TC_current_screen + 1);
3115 return false;
3116 break;
3117 }
3118 return true;
3119 }
3120
3121 // returns the true if there is a next screen (from the current)
3122 bool TelComIsThereANextScreen(void) {
3123 int next_screen = TC_current_screen + 1;
3124 if (next_screen >= MAX_TELCOM_SCREENS)
3125 return false;
3126 switch (Telcom_system.Screen_state[next_screen]) {
3127 case SS_EMPTY:
3128 // no screen even being worked on...return true
3129 return false;
3130 break;
3131 case SS_READY:
3132 case SS_BEING_MADE:
3133 return true;
3134 break;
3135 }
3136 return false;
3137 }
3138
3139 // Backs up a screen
3140 // returns true is there is no screen (it's not being made, nor ready)
3141 bool TelcomBackupScreen(void) {
3142 int next_screen = TC_current_screen - 1;
3143 if (next_screen < 0)
3144 return true;
3145 switch (Telcom_system.Screen_state[next_screen]) {
3146 case SS_EMPTY:
3147 // no screen even being worked on...return true
3148 return true;
3149 break;
3150 case SS_BEING_MADE:
3151 return false;
3152 break;
3153 case SS_READY:
3154 TelcomRenderSetScreen(TC_current_screen - 1);
3155 return false;
3156 break;
3157 }
3158 return true;
3159 }
3160
3161 bool TelComJumpScreen(int screen) {
3162 if (screen < 0 || screen >= MAX_TELCOM_SCREENS)
3163 return true;
3164 switch (Telcom_system.Screen_state[screen]) {
3165 case SS_EMPTY:
3166 // no screen even being worked on...return true
3167 return true;
3168 break;
3169 case SS_BEING_MADE:
3170 return false;
3171 break;
3172 case SS_READY:
3173 TelcomRenderSetScreen(screen);
3174 return false;
3175 break;
3176 }
3177
3178 return true;
3179 }
3180
3181 // Destroys and clears all screens of the TelCom
3182 void DestroyAllScreens(bool remove_dummy) {
3183 int end = (remove_dummy) ? MAX_TELCOM_SCREENS : DUMMY_SCREEN;
3184
3185 for (int i = 0; i < end; i++) {
3186 if (Telcom_system.Screen_state[i] != SS_EMPTY) {
3187 Telcom_system.Screen_state[i] = SS_EMPTY;
3188 EfxDestroyScreen(i);
3189 }
3190 }
3191 TCWorking_screen = -1;
3192 }
3193
3194 // Starts a TelCom screen so it can be created
3195 void TelcomStartScreen(int screen) {
3196 ASSERT(screen >= 0 && screen < MAX_TELCOM_SCREENS);
3197 ASSERT(TCWorking_screen == -1);
3198
3199 if (Telcom_system.Screen_state[screen] != SS_EMPTY) {
3200 EfxDestroyScreen(screen);
3201 }
3202
3203 Telcom_system.Screen_state[screen] = SS_BEING_MADE;
3204 TCWorking_screen = screen;
3205 }
3206
3207 // Ends a TelCom screen. Calling this enables the screen to be displayed
3208 void TelcomEndScreen(void) {
3209 ASSERT(TCWorking_screen != -1);
3210
3211 Telcom_system.Screen_state[TCWorking_screen] = SS_READY;
3212 TCWorking_screen = -1;
3213 }
3214
3215 float myrand(float max) { return (max * (((float)ps_rand()) / ((float)D3_RAND_MAX))); }
3216
3217 /////////////////////////////////////////////////////////////////////////////
3218 // These are the functions used for serialization, yes they are out of place,
3219 // But that is to keep them away from other parts of the code that has
3220 // the rest of the serialization. These probably can be moved to some other
3221 // file....if this function returns:
3222 // 1 : than it's a serialized exe, num will be given the serial num
3223 // 0 : than it isn't a serialized exe
3224 // -1 : detected a hacked exe
3225 #define INTERNAL_SERIALNUM_TAG "XFCABBFFAX"
3226 char GetInternalSerializationNumber(int *num) {
3227 static char mydata[] = INTERNAL_SERIALNUM_TAG;
3228
3229 // first check to see if the value is the same (non-serialized EXE)
3230 if (mydata[0] == 'X' && ((mydata[9] + 2) == 'Z')) {
3231 int value = 0;
3232 char c;
3233 for (int i = 0; i < 8; i++) {
3234 c = mydata[i + 1];
3235 if (c >= 'A' && c <= 'F') {
3236 value = value * 16 + (c - 'A' + 10);
3237 } else
3238 goto get_num;
3239 }
3240
3241 if (value == 0xFCABBFFA)
3242 return 0;
3243 }
3244
3245 get_num:
3246 // we got to get the serial num if we can
3247 int value = 0;
3248 char c;
3249 for (int i = 0; i < 8; i++) {
3250 c = mydata[i + 1];
3251 if (c >= '0' && c <= '9') {
3252 value = value * 16 + c - '0';
3253 } else if (c >= 'A' && c <= 'F') {
3254 value = value * 16 + c - 'A' + 10;
3255 } else
3256 return -1;
3257 }
3258
3259 // now byte swap the value to get it to it's original value
3260 value = (((value & 0xFF000000) >> 24) | ((value & 0xFF0000) >> 8) | ((value & 0xFF) << 24) | ((value & 0xFF00) << 8));
3261
3262 *num = value;
3263 return 1;
3264 }
3265
3266 /*
3267 ****************************************************************
3268 * TelCom Sound Functions *
3269 ****************************************************************
3270 *
3271 */
3272
3273 struct TCSound {
3274 int hlhandle, handle;
3275 };
3276
3277 TCSound TelcomSounds[TCSND_SOUNDCOUNT];
3278
3279 const char *TCSoundFiles[] = {"Briefstartup1", "BriefStatic", "Briefmonitoroff1", "Briefingrunning",
3280 "Briefbulb1", "Briefingtype", "Menu Slider Click"};
3281
3282 /*
3283 $$TABLE_SOUND "Briefstartup1"
3284 $$TABLE_SOUND "BriefStatic"
3285 $$TABLE_SOUND "Briefmonitoroff1"
3286 $$TABLE_SOUND "Briefingrunning"
3287 $$TABLE_SOUND "Briefbulb1"
3288 $$TABLE_SOUND "Briefingtype"
3289 $$TABLE_SOUND "Menu Slider Click"
3290 */
3291
3292 // Initalizes the Telcom sound sytem
3293 void TelcomInitSounds(void) {
3294 for (int i = 0; i < TCSND_SOUNDCOUNT; i++) {
3295 TelcomSounds[i].hlhandle = -1;
3296 TelcomSounds[i].handle = FindSoundName(IGNORE_TABLE(TCSoundFiles[i]));
3297 }
3298 }
3299
3300 // Closes down the Telcom sound system
3301 void TelcomCloseSounds(void) {
3302 Sound_system.BeginSoundFrame(Telcom_called_from_game);
3303 for (int i = 0; i < TCSND_SOUNDCOUNT; i++) {
3304 if (TelcomSounds[i].hlhandle != -1) {
3305 Sound_system.StopSoundImmediate(TelcomSounds[i].hlhandle);
3306 }
3307 }
3308 Sound_system.EndSoundFrame();
3309 }
3310
3311 // Starts a sound playing (if it isn't already)
3312 void TelcomStartSound(int sid) {
3313 ASSERT(sid >= 0 && sid < TCSND_SOUNDCOUNT);
3314
3315 // make sure the handle is there
3316 if (TelcomSounds[sid].handle == -1) {
3317 mprintf(0, "TelCom Sound Warning: '%s' hasn't been loaded yet, trying to load\n", TCSoundFiles[sid]);
3318 TelcomSounds[sid].handle = FindSoundName(IGNORE_TABLE(TCSoundFiles[sid]));
3319
3320 if (TelcomSounds[sid].handle == -1) {
3321 mprintf(0, "TelCom Sound Warning: 2nd try failed, bailing\n");
3322 return;
3323 }
3324 }
3325
3326 // see if the sound is already playing
3327 if (TelcomSounds[sid].hlhandle != -1) {
3328 if (Sound_system.IsSoundPlaying(TelcomSounds[sid].hlhandle)) {
3329 // the sound is still playing, we don't need to play again
3330 return;
3331 }
3332 }
3333
3334 TelcomSounds[sid].hlhandle = Sound_system.Play2dSound(TelcomSounds[sid].handle, MAX_GAME_VOLUME);
3335 }
3336
3337 // Stops a sound playing
3338 void TelcomStopSound(int sid) {
3339 ASSERT(sid >= 0 && sid < TCSND_SOUNDCOUNT);
3340
3341 // see if the sound is already playing
3342 if (TelcomSounds[sid].hlhandle != -1) {
3343 Sound_system.StopSoundLooping(TelcomSounds[sid].hlhandle);
3344 }
3345 TelcomSounds[sid].hlhandle = -1;
3346 }
3347
3348 //------------------------------------------------------------------------------
3349 // Pages a texture into memory, optionally resizing it if in low mem mode
3350 void PageInTexture(int n, bool resize);
3351
3352 // Pages in all the necessary bitmaps, textures & sounds for the TelCom so that they are in memory
3353 void TelcomPageAllIn(void) {
3354 extern void UpdateInitMessage(float amount); // amount is 0 to 1
3355 const float TELCOM_SOUND_PORTION = 0.3f, TELCOM_BITMAP_PORTION = 0.3f, TELCOM_TEXTUREHI_PORTION = 0.2f,
3356 TELCOM_TEXTURELO_PORTION = 0.2f;
3357
3358 int i;
3359 int count;
3360 float amount_loaded = 0.0f;
3361
3362 // Page in all sounds
3363 for (i = 0; i < TCSND_SOUNDCOUNT; i++) {
3364 int id = FindSoundName(IGNORE_TABLE(TCSoundFiles[i]));
3365 if (id != -1) {
3366 Sound_system.CheckAndForceSoundDataAlloc(id);
3367 amount_loaded += (1.0f * TELCOM_SOUND_PORTION) / (float)TCSND_SOUNDCOUNT;
3368 if ((i % 4) == 0) {
3369 UpdateInitMessage(amount_loaded);
3370 }
3371 }
3372 }
3373
3374 // Page in all bitmaps
3375 count = Telcom_bitmap.w * Telcom_bitmap.h;
3376 for (i = 0; i < count; i++) {
3377 bm_data(Telcom_bitmap.bm_array[i], 0);
3378 UpdateInitMessage(amount_loaded);
3379 }
3380 amount_loaded += TELCOM_BITMAP_PORTION;
3381
3382 // Page in all textures
3383 count = 0;
3384 while (hilites[count]) {
3385 i = FindTextureName(IGNORE_TABLE(hilites[count]));
3386 if (i != -1) {
3387 PageInTexture(i, false);
3388 }
3389 count++;
3390 }
3391 amount_loaded += TELCOM_TEXTURELO_PORTION;
3392 UpdateInitMessage(amount_loaded);
3393
3394 count = 0;
3395 while (smhilites[count]) {
3396 i = FindTextureName(IGNORE_TABLE(smhilites[count]));
3397 if (i != -1)
3398 PageInTexture(i, false);
3399 count++;
3400 }
3401
3402 i = FindTextureName("TelcomPowerbar");
3403 if (i != -1)
3404 PageInTexture(i, false);
3405
3406 amount_loaded += TELCOM_TEXTURELO_PORTION;
3407 UpdateInitMessage(amount_loaded);
3408 }
3409
3410 /*
3411 ****************************************************************************************
3412 Single Player Ship Selection
3413 ****************************************************************************************
3414 */
3415 void TCSSSCallback(void);
3416 // collects information about the ships, returns the number of ships available
3417 int TCSSCollectInfo(void);
3418 void TCSSButtonCallback(int efxnum);
3419 void TCSSPutButtonsOnScreen(void);
3420 int TCSSGetSelectedShipIndex(void);
3421
3422 struct {
3423 int ShipCount;
3424 int CurrentSelectID;
3425 matrix orient;
3426 int ship_model;
3427 float cam_dist;
3428 } TCShipSelect;
3429
3430 struct tShipInfo {
3431 int max_speed;
3432 int maneuverability;
3433 int shield;
3434 int ordnance;
3435 int wingspan;
3436 int length;
3437 int height;
3438 int weight;
3439 };
3440
3441 #define MAX_NUM_SHIPS 3
3442
3443 tShipInfo TCSSInfo[MAX_NUM_SHIPS] = {{TXI_SS_PY_SPEED, TXI_SS_PY_MANEUVERABILITY, TXI_SS_PY_SHIELDS, TXI_SS_PY_ORDANCE,
3444 TXI_SS_PY_WINGSPAN, TXI_SS_PY_LENGTH, TXI_SS_PY_HEIGHT, TXI_SS_PY_WEIGHT},
3445 {TXI_SS_PH_SPEED, TXI_SS_PH_MANEUVERABILITY, TXI_SS_PH_SHIELDS, TXI_SS_PH_ORDANCE,
3446 TXI_SS_PH_WINGSPAN, TXI_SS_PH_LENGTH, TXI_SS_PH_HEIGHT, TXI_SS_PH_WEIGHT},
3447 {TXI_SS_M_SPEED, TXI_SS_M_MANEUVERABILITY, TXI_SS_M_SHIELDS, TXI_SS_M_ORDANCE,
3448 TXI_SS_M_WINGSPAN, TXI_SS_M_LENGTH, TXI_SS_M_HEIGHT, TXI_SS_M_WEIGHT}};
3449
3450 /*
3451 $$TABLE_SHIP "Pyro-GL"
3452 $$TABLE_SHIP "Phoenix"
3453 $$TABLE_SHIP "Magnum-AHT"
3454 */
3455 struct tSSShipInfo {
3456 bool found;
3457 int ship_index;
3458 int efxnum;
3459 };
3460 tSSShipInfo SSShips[MAX_NUM_SHIPS];
3461
3462 // two buttons
3463 #define SSA_LEFTX 165
3464 #define SSA_TOPY 360
3465 #define SSA_GAP -2
3466
3467 // three buttons
3468 #define SSB_LEFTX 165
3469 #define SSB_TOPY 360
3470 #define SSB_GAP -2
3471
3472 // This is the function called by TelCom to choose a ship
3473 void TelComSingleShipSelect(tTelComInfo *tcs) {
3474 int found_ships = TCSSCollectInfo();
3475 if (found_ships < 2 || found_ships > 3) {
3476 // not supported
3477 mprintf(0, "Skipping Single Player Ship Selecting, %d ships found\n", found_ships);
3478
3479 int ship_index_to_use = 0;
3480 int bit = 0x01;
3481 bool found = true;
3482
3483 for (ship_index_to_use = 0; ship_index_to_use < MAX_SHIPS; ship_index_to_use++) {
3484 if (Players[Player_num].ship_permissions & bit) {
3485 found = true;
3486 break;
3487 }
3488 bit = bit << 1;
3489 }
3490
3491 if (!found) {
3492 bit = 0x01;
3493 for (ship_index_to_use = 0; ship_index_to_use < MAX_SHIPS; ship_index_to_use++) {
3494 if (Default_ship_permission & bit) {
3495 found = true;
3496 break;
3497 }
3498 bit = bit << 1;
3499 }
3500 }
3501
3502 Players[Player_num].ship_index = ship_index_to_use;
3503 return;
3504 }
3505
3506 bool done = false;
3507
3508 TCShipSelect.CurrentSelectID = -1;
3509 TCShipSelect.ship_model = -1;
3510 vm_MakeIdentity(&TCShipSelect.orient);
3511
3512 TelcomStartScreen(0);
3513
3514 // setup general background, plain color
3515 TCBKGDESC backg;
3516 backg.color = BACKGROUND_COLOR;
3517 backg.caps = TCBGD_COLOR;
3518 backg.type = TC_BACK_STATIC;
3519
3520 TCBMPDESC bmpdesc;
3521 bmpdesc.type = TC_BMP_STATIC;
3522 bmpdesc.flags = 0;
3523 bmpdesc.caps = TCBD_XY;
3524 bmpdesc.x = 0;
3525 bmpdesc.y = 0;
3526 strcpy(bmpdesc.filename, "SS Background.ogf");
3527 /*
3528 $$TABLE_GAMEFILE "SS Background.ogf"
3529 */
3530
3531 // setup text for the top monitor "Select Ship"
3532 TCTEXTDESC textdesc;
3533 textdesc.type = TC_TEXT_STATIC;
3534 textdesc.font = BBRIEF_FONT_INDEX;
3535 textdesc.caps = TCTD_TEXTBOX | TCTD_COLOR | TCTD_FONT;
3536 textdesc.textbox.left = 5;
3537 textdesc.textbox.right = 380;
3538 textdesc.textbox.top = 33;
3539 textdesc.textbox.bottom = 68;
3540 textdesc.color = GR_RGB(255, 255, 255);
3541
3542 // Setup Main Monitor
3543 CreateBitmapEffect(&bmpdesc, MONITOR_MAIN, 0);
3544 CreateTextEffect(&textdesc, TXT_SELECTSHIP, MONITOR_MAIN, 0);
3545
3546 // Create buttons to select ship (either 2 or 3)
3547 TCSSPutButtonsOnScreen();
3548
3549 // Setup Location Monitor (small window at top)
3550 textdesc.textbox.left = 65;
3551 textdesc.textbox.right = 380;
3552 textdesc.textbox.top = 5;
3553 textdesc.textbox.bottom = 50;
3554 CreateBackgroundEffect(&backg, MONITOR_TOP, 0);
3555 CreateTextEffect(&textdesc, TXT_SELECTSHIP, MONITOR_TOP, 0);
3556
3557 TelcomEndScreen();
3558 TelcomRenderSetScreen(0);
3559 TelcomRenderSetCallback(TCSSSCallback);
3560
3561 Telcom_system.state = TCS_POWERON; // turn back on telcom
3562 tcs->current_status = TS_SHIPSELECT;
3563
3564 // set focus to the ship we currently have selected
3565 int focus_ship = -1;
3566 for (int j = 0; j < MAX_NUM_SHIPS; j++) {
3567 if (SSShips[j].found && SSShips[j].ship_index == Players[Player_num].ship_index) {
3568 mprintf(0, "Current Ship: %s\n", Ships[SSShips[j].ship_index].name);
3569 focus_ship = SSShips[j].efxnum;
3570 break;
3571 }
3572 }
3573
3574 if (focus_ship != -1) {
3575 if (TCEffects[focus_ship].has_focus)
3576 TCSSButtonCallback(focus_ship);
3577 else
3578 TelComSetFocusOnEffect(focus_ship);
3579 }
3580
3581 TelCom_ClearCustomKeyEvents();
3582 TelCom_AddCustomKeyEvent(KEY_LEFT, 0x13); // left arrow
3583 TelCom_AddCustomKeyEvent(KEY_RIGHT, 0x14); // right arrow
3584 TelCom_AddCustomKeyEvent(KEY_ENTER, 0x15); // enter key
3585
3586 while (!done) {
3587 Sound_system.BeginSoundFrame(Telcom_called_from_game);
3588
3589 if (Telcom_system.state != TCS_POWERON || tcs->current_status != TS_SHIPSELECT) {
3590 // we're done with the loop
3591 done = true;
3592 }
3593
3594 // Process all waiting events for the TelCom (we may only want to handle this once a frame!)
3595 TelComHandleAllEvents(tcs);
3596
3597 // Process custom events
3598 tTCEvent evt;
3599 while (TelCom_PopSystemEvent(&evt)) {
3600 switch (evt.id) {
3601 case 0x13: // left arrow
3602 TelComSendEvent(TEVT_FAKEKEYPRESS, TCSYS_REVERSETAB);
3603 break;
3604 case 0x14: // right arrow
3605 TelComSendEvent(TEVT_FAKEKEYPRESS, TCSYS_TAB);
3606 break;
3607 case 0x15: // enter key
3608 tcs->state = TCS_POWEROFF;
3609 break;
3610 }
3611 }
3612
3613 TelcomRenderScreen();
3614 Descent->defer();
3615 if (KEY_STATE(KEY_ESC))
3616 tcs->state = TCS_POWEROFF;
3617
3618 Sound_system.EndSoundFrame();
3619 }
3620
3621 Telcom_system.state = TCS_POWEROFF; // turn back off telcom
3622
3623 DestroyAllScreens();
3624 TelcomRenderSetScreen(DUMMY_SCREEN);
3625 TelcomRenderSetCallback(NULL);
3626
3627 int ship_index_to_use = TCSSGetSelectedShipIndex();
3628 mprintf(0, "Selected: %s\n", Ships[ship_index_to_use].name);
3629 Players[Player_num].ship_index = ship_index_to_use;
3630
3631 TelCom_ClearCustomKeyEvents();
3632 }
3633
3634 // returns the ship index that is selected
3635 int TCSSGetSelectedShipIndex(void) {
3636 int id = SSShips[SHIP_PYRO_ID].ship_index;
3637 for (int i = 0; i < MAX_NUM_SHIPS; i++) {
3638 if (SSShips[i].found) {
3639 int efxnum = SSShips[i].efxnum;
3640 if (TCEffects[efxnum].has_focus) {
3641 id = SSShips[i].ship_index;
3642 break;
3643 }
3644 }
3645 }
3646
3647 return id;
3648 }
3649
3650 // collects information about the ships, returns the number of ships available
3651 int TCSSCollectInfo(void) {
3652 int found = 0;
3653 int i, j;
3654
3655 for (i = 0; i < MAX_NUM_SHIPS; i++) {
3656 SSShips[i].found = false;
3657 }
3658
3659 for (i = 0; i < MAX_SHIPS; i++) {
3660 #ifdef _DEBUG
3661 if (Ships[i].used) {
3662 #else
3663 if (Ships[i].used && PlayerIsShipAllowed(Player_num, i)) {
3664 #endif
3665 for (j = 0; j < MAX_NUM_SHIPS; j++) {
3666 if (!stricmp(Ships[i].name, AllowedShips[j])) {
3667 // found the ship
3668 SSShips[j].found = true;
3669 SSShips[j].ship_index = i;
3670 found++;
3671 break;
3672 }
3673 }
3674 }
3675 }
3676
3677 mprintf(0, "Collecting Ship Info: %d ships available\n", found);
3678 TCShipSelect.ShipCount = found;
3679
3680 return found;
3681 }
3682
3683 //====================================
3684 // returns the optimal distance to place the camera
3685 float getdist(angle ang, float height); // in pilot.cpp
3686 extern float Render_zoom;
3687
3688 //====================================
3689
3690 void TCSSButtonCallback(int efxnum) {
3691 if (!TCEffects[efxnum].has_focus) {
3692 // make sure we have focus...be careful, because by setting focus
3693 // the call is going to come back into this function
3694 TelComSetFocusOnEffect(efxnum);
3695 return;
3696 }
3697
3698 int selected_id = -1;
3699
3700 // which ship id are we talking about?
3701 for (int i = 0; i < MAX_NUM_SHIPS; i++) {
3702 if (SSShips[i].found && SSShips[i].efxnum == efxnum) {
3703 // this is the id;
3704 selected_id = i;
3705 break;
3706 }
3707 }
3708
3709 if (selected_id == -1) {
3710 mprintf(0, "Invalid selected id for efxnum %d\n", efxnum);
3711 return;
3712 }
3713
3714 bool first_click = false;
3715
3716 if (TCShipSelect.CurrentSelectID == -1)
3717 first_click = true;
3718
3719 if (TCShipSelect.CurrentSelectID == selected_id) {
3720 // not a change
3721 return;
3722 }
3723
3724 TCShipSelect.CurrentSelectID = selected_id;
3725
3726 // PUT CODE TO HANDLE NEW SHIP BEING SELECTED HERE
3727 float size;
3728 TCShipSelect.ship_model = Ships[SSShips[selected_id].ship_index].model_handle;
3729 if (TCShipSelect.ship_model == -1) {
3730 mprintf(0, "ship_model is -1\n");
3731 Int3();
3732 }
3733
3734 PageInPolymodel(TCShipSelect.ship_model, OBJ_PLAYER, &size);
3735 poly_model *pm = GetPolymodelPointer(TCShipSelect.ship_model);
3736 TCShipSelect.cam_dist = pm->anim_size / Render_zoom + 6;
3737
3738 TelcomStopSound(TCSND_CLICK);
3739 if (!first_click)
3740 TelcomStartSound(TCSND_CLICK);
3741 }
3742
3743 void TCSSSCallback(void) {
3744 if (TCShipSelect.ship_model == -1) {
3745 // no ship selected yet
3746 return;
3747 }
3748
3749 vector viewer_eye = {0, 0, 0};
3750 matrix viewer_orient = IDENTITY_MATRIX;
3751 viewer_eye.z = -TCShipSelect.cam_dist;
3752
3753 grtext_Flush();
3754 StartFrame(325, 142, 535, 280);
3755
3756 // backup user-specified aspect ratio, than disable it for ship select screen
3757 float aspect = g3_GetAspectRatio();
3758 g3_SetAspectRatio(0.0f);
3759
3760 g3_StartFrame(&viewer_eye, &viewer_orient, D3_DEFAULT_ZOOM);
3761 rend_SetFlatColor(0);
3762
3763 float normalized_time[MAX_SUBOBJECTS];
3764 float light_scalar, size;
3765 PageInPolymodel(TCShipSelect.ship_model, OBJ_PLAYER, &size);
3766 poly_model *pm = GetPolymodelPointer(TCShipSelect.ship_model);
3767 vector view_pos;
3768 vector light_vec;
3769 matrix view_orient = IDENTITY_MATRIX;
3770 matrix final_mat = IDENTITY_MATRIX;
3771 matrix rot_mat;
3772
3773 // draw model.
3774 SetNormalizedTimeAnim(0, normalized_time, pm);
3775
3776 view_pos = pm->anim_size_offset;
3777
3778 // move 30 degrees a sec
3779 vm_AnglesToMatrix(&rot_mat, 0, (last_frametime) * (65535 / 360) * 30, 0);
3780
3781 vm_MatrixMul(&view_orient, &rot_mat, &TCShipSelect.orient);
3782 vm_Orthogonalize(&view_orient);
3783 TCShipSelect.orient = view_orient;
3784
3785 light_vec.x = 0.0f;
3786 light_vec.y = -1.0f;
3787 light_vec.z = -1.0f;
3788 light_scalar = 0.8f;
3789 vm_NormalizeVector(&light_vec);
3790
3791 rend_SetZBufferState(1);
3792 rend_SetAlphaType(AT_CONSTANT_TEXTURE);
3793 rend_SetAlphaValue(255);
3794 rend_SetLighting(LS_NONE);
3795 rend_SetColorModel(CM_MONO);
3796 rend_SetOverlayType(OT_NONE);
3797
3798 DrawPolygonModel(&view_pos, &view_orient, TCShipSelect.ship_model, normalized_time, 0, &light_vec, light_scalar,
3799 light_scalar, light_scalar);
3800
3801 // restore user-specified aspect ratio
3802 g3_SetAspectRatio(aspect);
3803
3804 g3_EndFrame();
3805 EndFrame();
3806
3807 // Render the name of the selected ship
3808 uint8_t old_alpha = grtext_GetAlpha();
3809 int old_font = grtext_GetFont();
3810 ddgr_color old_color = grtext_GetColor();
3811 grtext_SetAlpha(255);
3812 grtext_SetFont(BIG_BRIEFING_FONT);
3813 grtext_SetColor(GR_WHITE);
3814
3815 char *name = Ships[SSShips[TCShipSelect.CurrentSelectID].ship_index].name;
3816 int line_length = grtext_GetTextLineWidth(name);
3817 int line_height = grfont_GetHeight(BIG_BRIEFING_FONT);
3818 int bar_width = 177;
3819 int bar_height = 34;
3820 int bar_x = 287 + Telcom_system.Monitor_coords[MONITOR_MAIN].left;
3821 int bar_y = 246 + Telcom_system.Monitor_coords[MONITOR_MAIN].top;
3822
3823 int x, y;
3824 x = bar_x + ((bar_width / 2) - (line_length / 2));
3825 y = bar_y + ((bar_height / 2) - (line_height / 2));
3826
3827 grtext_Printf(x, y, name);
3828
3829 // write ship descriptions
3830 tShipInfo *si = &TCSSInfo[TCShipSelect.CurrentSelectID];
3831 x = 115;
3832 y = 130;
3833 int width = 210;
3834 int max_height = y + 150;
3835 grtext_SetFont(BRIEFING_FONT);
3836 int height = grfont_GetHeight(BRIEFING_FONT);
3837 const char *line_text;
3838 char buffy[512];
3839 char linebuffer[512];
3840
3841 for (int q = 0; q < 8; q++) {
3842 switch (q) {
3843 case 0:
3844 line_text = TXT(si->max_speed);
3845 break;
3846 case 1:
3847 line_text = TXT(si->maneuverability);
3848 break;
3849 case 2:
3850 line_text = TXT(si->shield);
3851 break;
3852 case 3:
3853 line_text = TXT(si->ordnance);
3854 break;
3855 case 4:
3856 line_text = TXT(si->wingspan);
3857 break;
3858 case 5:
3859 line_text = TXT(si->length);
3860 break;
3861 case 6:
3862 line_text = TXT(si->height);
3863 break;
3864 case 7:
3865 line_text = TXT(si->weight);
3866 break;
3867 }
3868
3869 textaux_WordWrap(line_text, buffy, width, BRIEFING_FONT);
3870
3871 line_text = textaux_CopyTextLine(buffy, linebuffer);
3872 while ((line_text) && ((y + height) < max_height)) {
3873 grtext_Printf(x, y, linebuffer);
3874 y += height;
3875 line_text = textaux_CopyTextLine(line_text, linebuffer);
3876 }
3877 grtext_Printf(x, y, linebuffer);
3878 y += height;
3879 }
3880
3881 grtext_SetAlpha(old_alpha);
3882 grtext_SetFont(old_font);
3883 grtext_SetColor(old_color);
3884 grtext_Flush();
3885 }
3886
3887 void TCSSPutButtonsOnScreen(void) {
3888 int monitor_y, monitor_x;
3889 monitor_y = Telcom_system.Monitor_coords[MONITOR_MAIN].top;
3890 monitor_x = Telcom_system.Monitor_coords[MONITOR_MAIN].left;
3891
3892 TCBMPDESC bmpdesc;
3893 bmpdesc.type = TC_BMP_STATIC;
3894 bmpdesc.flags = 0;
3895 bmpdesc.caps = TCBD_XY;
3896
3897 TCBUTTONDESC buttdesc;
3898 buttdesc.sibling_id = buttdesc.parent_id = -1;
3899 buttdesc.internal = TCSSButtonCallback;
3900 buttdesc.flash_time = 0;
3901 buttdesc.button_type = BUTT_INTERNAL;
3902 buttdesc.flasher = false;
3903 buttdesc.click_type = CLICKTYPE_CLICKUP;
3904 buttdesc.osflags = OBF_GLOW | OBF_CHANGEFOCUSISCLICK;
3905 buttdesc.tab_stop = true; // all main menu buttons can have focus
3906
3907 int left_x, top_y, gap;
3908 if (TCShipSelect.ShipCount == 2) {
3909 left_x = SSA_LEFTX;
3910 top_y = SSA_TOPY;
3911 gap = SSA_GAP;
3912
3913 bmpdesc.x = left_x - monitor_x;
3914 bmpdesc.y = top_y - monitor_y;
3915 strcpy(bmpdesc.filename, "SS 2 button group.ogf");
3916 } else {
3917 left_x = SSB_LEFTX;
3918 top_y = SSB_TOPY;
3919 gap = SSB_GAP;
3920
3921 bmpdesc.x = left_x - monitor_x;
3922 bmpdesc.y = top_y - monitor_y;
3923 strcpy(bmpdesc.filename, "SS 3 button group.ogf");
3924 }
3925 /*
3926 $$TABLE_GAMEFILE "SS 3 button group.ogf"
3927 $$TABLE_GAMEFILE "SS 2 button group.ogf"
3928 */
3929 CreateBitmapEffect(&bmpdesc, MONITOR_MAIN, 0);
3930
3931 int i;
3932 int width;
3933 int curr_x, curr_y;
3934 curr_x = left_x + 3;
3935 curr_y = top_y + 2;
3936 const char *lit_name, *name;
3937
3938 for (i = 0; i < MAX_NUM_SHIPS; i++) {
3939 if (SSShips[i].found) {
3940 buttdesc.x = curr_x;
3941 buttdesc.y = curr_y;
3942
3943 switch (i) {
3944 case SHIP_PYRO_ID:
3945 lit_name = "SS Lit Pyro button.ogf";
3946 name = "SS Pyro button.ogf";
3947 break;
3948 case SHIP_MAGNUM_ID:
3949 lit_name = "SS Lit Magnum button.ogf";
3950 name = "SS Magnum button.ogf";
3951 break;
3952 case SHIP_PHOENIX_ID:
3953 lit_name = "SS Lit Phoenix button.ogf";
3954 name = "SS Phoenix button.ogf";
3955 break;
3956 }
3957
3958 /*
3959 $$TABLE_GAMEFILE "SS Lit Pyro button.ogf"
3960 $$TABLE_GAMEFILE "SS Pyro button.ogf"
3961 $$TABLE_GAMEFILE "SS Lit Magnum button.ogf"
3962 $$TABLE_GAMEFILE "SS Magnum button.ogf"
3963 $$TABLE_GAMEFILE "SS Lit Phoenix button.ogf"
3964 $$TABLE_GAMEFILE "SS Phoenix button.ogf"
3965 */
3966
3967 int bmp_handle = bm_AllocLoadFileBitmap(IGNORE_TABLE(name), 0);
3968 if (bmp_handle <= BAD_BITMAP_HANDLE) {
3969 width = 10;
3970 } else {
3971 width = bm_w(bmp_handle, 0);
3972 bm_FreeBitmap(bmp_handle);
3973 }
3974
3975 strcpy(buttdesc.filename, name);
3976 strcpy(buttdesc.flash_filename, name);
3977 strcpy(buttdesc.filename_focus, lit_name);
3978 strcpy(buttdesc.flash_filename_focus, lit_name);
3979 SSShips[i].efxnum = CreateButtonEffect(&buttdesc, MONITOR_MAIN, 0);
3980
3981 curr_x += (width + gap);
3982 }
3983 }
3984 }
3985
3986 /////////////////////////////////////////
3987 tTCEvent Telcom_system_queue[MAX_TELCOM_EVENTS]; // Event queue for TelCom System
3988
3989 void TelCom_ClearSystemQueue(void) {
3990 for (int i = 0; i < MAX_TELCOM_EVENTS; i++) {
3991 Telcom_system_queue[i].id = -1;
3992 }
3993 }
3994
3995 /*
3996 * Calling this sends an event message to the TelCom System Queue, adding it to it's event queue
3997 *
3998 */
3999 void TelCom_SendSystemEvent(int event_num, int parm1, int parm2) {
4000 for (int i = 0; i < MAX_TELCOM_EVENTS; i++) {
4001 if (Telcom_system_queue[i].id == -1) {
4002 // add the event here
4003 Telcom_system_queue[i].id = event_num;
4004 Telcom_system_queue[i].parms[0] = parm1;
4005 Telcom_system_queue[i].parms[1] = parm2;
4006 return;
4007 }
4008 }
4009
4010 mprintf(0, "Warning: TelCom System Event Queue Overflow\n");
4011 }
4012
4013 /*
4014 * Call this when handling the TelCom system events, returns true if there is an event waiting, it will then fill
4015 * in the passed struct. You should call this repeatedly until a value of false is returned, signaling no more
4016 * events in the queue
4017 */
4018 bool TelCom_PopSystemEvent(tTCEvent *evt) {
4019 if (Telcom_system_queue[0].id != -1) {
4020 memcpy(evt, &Telcom_system_queue[0], sizeof(tTCEvent));
4021
4022 // move all items up in the queue
4023 for (int i = 1; i < MAX_TELCOM_EVENTS; i++) {
4024 memcpy(&Telcom_system_queue[i - 1], &Telcom_system_queue[i], sizeof(tTCEvent));
4025 }
4026 Telcom_system_queue[MAX_TELCOM_EVENTS - 1].id = -1;
4027 return true;
4028 }
4029
4030 return false;
4031 }
4032
4033 struct tCustomKeyEventID {
4034 int downcount;
4035 int key_id;
4036 int event_id;
4037 tCustomKeyEventID *next;
4038 };
4039 tCustomKeyEventID *Telcom_custom_key_event_root = NULL;
4040
4041 /*
4042 Removes any custom key event translation masks
4043 */
4044 void TelCom_ClearCustomKeyEvents(void) {
4045 tCustomKeyEventID *next, *curr = Telcom_custom_key_event_root;
4046
4047 while (curr) {
4048 next = curr->next;
4049
4050 mem_free(curr);
4051 curr = next;
4052 }
4053 Telcom_custom_key_event_root = NULL;
4054 }
4055
4056 /*
4057 Adds a custom key event translation mask
4058 */
4059 void TelCom_AddCustomKeyEvent(int key_id, int event_id) {
4060 tCustomKeyEventID *curr = Telcom_custom_key_event_root;
4061
4062 if (!curr) {
4063 curr = Telcom_custom_key_event_root = (tCustomKeyEventID *)mem_malloc(sizeof(tCustomKeyEventID));
4064 } else {
4065 while (curr->next) {
4066 curr = curr->next;
4067 }
4068 curr->next = (tCustomKeyEventID *)mem_malloc(sizeof(tCustomKeyEventID));
4069 curr = curr->next;
4070 }
4071
4072 curr->next = NULL;
4073 curr->event_id = event_id;
4074 curr->key_id = key_id;
4075 }
4076
4077 /*
4078 Prepares to handle custom keys
4079 */
4080 void TelCom_PrepareCustomKeyEvents(void) {
4081 tCustomKeyEventID *curr = Telcom_custom_key_event_root;
4082
4083 while (curr) {
4084 curr->downcount = 0;
4085 curr = curr->next;
4086 }
4087 }
4088
4089 /*
4090 Post process custom keys
4091 */
4092 void TelCom_PostProcessCustomKeyEvents(void) {
4093 tCustomKeyEventID *curr = Telcom_custom_key_event_root;
4094
4095 while (curr) {
4096 if (curr->downcount) {
4097 TelCom_SendSystemEvent(curr->event_id);
4098 return;
4099 }
4100
4101 curr = curr->next;
4102 }
4103 }
4104
4105 /*
4106 Handles a possible custom key event
4107 */
4108 void TelCom_ProcessCustomKeyEvent(int key_id) {
4109 tCustomKeyEventID *curr = Telcom_custom_key_event_root;
4110
4111 while (curr) {
4112 if (key_id == curr->key_id) {
4113 curr->downcount++;
4114 return;
4115 }
4116
4117 curr = curr->next;
4118 }
4119 }