Debian Codegraph @

Descent3/hud.cpp

raw symbols SCIP
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/hud.cpp $
21 * $Revision: 143 $
22 * $Date: 4/19/00 5:07p $
23 * $Author: Matt $
24 *
25 * $Log: /DescentIII/main/hud.cpp $
26 *
27 * 143 4/19/00 5:07p Matt
28 * From Duane for 1.4
29 * Added checks, asserts, and fixes for bad return values
30 *
31 * 142 4/06/00 9:25a Matt
32 * Fixed a screen clear problem on at ATI Rage Fury Maxx in dual-chip mode
33 * by forcing the screen to clear four times (instead of three).
34 *
35 * 141 3/20/00 12:10p Matt
36 * Merge of Duane's post-1.3 changes.
37 * Endian/enum fix.
38 *
39 * 140 10/21/99 4:28p Matt
40 * Mac merge
41 *
42 * 139 7/08/99 6:20p Jason
43 * fixed reticle bug
44 *
45 * 138 5/23/99 9:07p Matt
46 * Changed the customtext2 multisafe functions to create the item when
47 * it's updated, instead of having a separate create and update functions.
48 * This deals with players who join a netgame after the level has started
49 * (i.e., everyone but the server).
50 *
51 * 137 5/21/99 11:15p Samir
52 * savegames save hud timer and special text states. restore too.
53 *
54 * 136 5/21/99 4:06p Matt
55 * For customtext2 HUD items, store the buffer length in the HUD item.
56 *
57 * 135 5/21/99 3:06p Matt
58 * Changed customtext2 HUD items so that the HUD system keeps the text
59 * buffer an no one else references it directly.
60 *
61 * 134 5/20/99 5:48p Matt
62 * Added a HUD item flag, for use by Dallas-created items, that makes a
63 * HUD item persisitent for the duration of one level, but get cleared
64 * between levels.
65 *
66 * 133 5/20/99 2:12a Matt
67 * Don't blow away custom HUD items when resetting the HUD. This fixes
68 * one probem, but means that custom HUD items will never go away. I'll
69 * deal with that tomorrow.
70 *
71 * 132 5/19/99 11:25a Matt
72 * Added multisafe functions & Dallas actions for showing a timer on the
73 * screen and adding custom HUD messages.
74 *
75 * 131 5/17/99 6:04p Kevin
76 * new training mission localized text
77 *
78 * 130 5/17/99 5:27p Kevin
79 * changed enabled controls display for training mission
80 *
81 * 129 5/14/99 10:30a Kevin
82 * fixed misplaced #endif
83 *
84 * 128 5/13/99 12:24p Kevin
85 * added code for "Beta version"
86 *
87 * 127 5/05/99 5:45p Samir
88 * initialize reticle in cockpit code now.
89 *
90 * 126 5/01/99 5:52p Samir
91 * removed RenderHudMessages, and redid RenderHUDMessages so it did what
92 * RenderHudMessages did, resets on screen hud messages. The HUD message
93 * console is resetted in ResetGameMessages.
94 *
95 * 125 5/01/99 1:56a Samir
96 * timer always in debug builds, SCORE is off when dead.
97 *
98 * 124 4/26/99 5:51p Jason
99 * fixed guided bug
100 *
101 * 123 4/24/99 10:38p Samir
102 * cleaned up hud text problems in 'small mode'
103 *
104 * 122 4/24/99 8:43p Samir
105 * when shrinking screen hud messages get rendered in black region.
106 *
107 * 121 4/22/99 3:43p Kevin
108 * Training missions show controls on screen
109 *
110 * 120 4/21/99 9:29p Samir
111 * don't draw score in multiplayer.
112 *
113 * 119 4/21/99 4:17p Matt
114 * Added comments for table file filter
115 *
116 * 118 4/20/99 11:47a Samir
117 * shrinking hud fixes.
118 *
119 * 117 4/08/99 4:08p Samir
120 * moved timer below score and don't compile timer in release builds.
121 *
122 * 116 4/06/99 6:02p Matt
123 * Added score system
124 *
125 * 115 4/06/99 2:00p Samir
126 * added function to initialize hud items that don't go through config
127 * file.
128 *
129 * 114 4/06/99 11:39a Samir
130 * added more formatting options for hud items (added two other full
131 * screen hud infs for different ships)
132 *
133 * 113 4/01/99 4:50p Matt
134 * Took out Warning() function, chaning those calls to mprintf()
135 *
136 * 112 3/30/99 5:26p Samir
137 * fixed quad weapon reticle problem.
138 *
139 * 111 3/30/99 2:39p Samir
140 * added custom config file for fullscreen hud and hacked mass driver
141 * reticle in special reticle code.
142 *
143 * 110 3/29/99 10:50a Samir
144 * added command to move reticle in hud inf file.
145 *
146 * 109 3/26/99 12:46p Samir
147 * configurable reticle.
148 *
149 * 108 3/22/99 4:26p Samir
150 * added toggles for guided missile view and reticle.
151 *
152 * 107 3/09/99 12:20p Samir
153 * do quick close of cockpit if entering letterbox or observer mode from
154 * cockpit.
155 *
156 * 106 3/05/99 3:01p Jeff
157 * fixed crash when a persistant message is displayed during a IGC
158 *
159 * 105 3/04/99 8:11p Samir
160 * Don't assert if screen mode != SM_GAME in SetHUDMode, just Int3 and
161 * allow user to return.
162 *
163 * 104 3/03/99 5:34p Matt
164 * Added fade-out for goal complete messages
165 *
166 * 103 3/03/99 3:43a Samir
167 * fixed font aspect ratio problem in hires screens.
168 *
169 * 102 3/02/99 6:26p Samir
170 * hires font madness.
171 *
172 * 101 2/28/99 3:25a Samir
173 * stream name debug out.
174 *
175 * 100 2/27/99 5:07p Jason
176 * clear screen 3 times for triple buffer
177 *
178 * 99 2/24/99 12:25p Jeff
179 * fixed guided missile/mass driver reticle/view problems when going into
180 * a cinematic
181 *
182 * 98 2/18/99 4:02p Jeff
183 * only save hud mode to pilot file if fullscreen->cockpit or vice-versa
184 *
185 * 97 2/17/99 2:45p Kevin
186 * Adde movie making capabilities to the demo playback system
187 *
188 * 96 2/15/99 7:49p Jeff
189 * new pilot file class and read/write system checked in...should be more
190 * robust than old
191 *
192 * 95 2/10/99 3:03p Samir
193 * table file parse changes.
194 *
195 * 94 1/31/99 9:05p Jeff
196 * handle HUD_OBSERVER in render
197 *
198 * 93 1/31/99 7:26p Matt
199 * Renamed a bunch of functions to have HUD capitalized
200 *
201 * 92 1/29/99 6:29p Samir
202 * implemented hud scrollback for hud messages.
203 *
204 * 91 1/29/99 2:08p Jeff
205 * localization
206 *
207 * 90 1/28/99 2:22p Samir
208 * simplified music system for D3.
209 *
210 * 89 1/27/99 6:05p Samir
211 * added scrollback for game messages on HUD.
212 *
213 * 88 1/08/99 2:55p Samir
214 * Ripped out OSIRIS1.
215 *
216 * 87 12/16/98 1:57p Samir
217 * Replaced CleanupString2 with CleanupStr
218 *
219 * 86 12/03/98 12:52p Samir
220 * added hud music debug info timers.
221 *
222 * 85 12/01/98 3:34p Matt
223 * Got rear view working.
224 *
225 * 84 11/23/98 4:52p Kevin
226 * Demo system enhancments
227 *
228 * 83 11/19/98 5:40p Kevin
229 * Demo system
230 *
231 * 82 11/13/98 4:25p Jason
232 * changes for better weapon effects
233 *
234 * 81 11/13/98 2:28p Samir
235 * added debug code for music.
236 *
237 * 80 10/30/98 1:13p Samir
238 * dont' do SetHUDMode if in dedicated server mode.
239 *
240 * 79 10/22/98 2:40p Samir
241 * redid HUD sequencing so multiplayer hud stuff works.
242 *
243 * 78 10/20/98 1:46p Samir
244 * don't close cockpit if it's already open.
245 *
246 * 77 10/19/98 11:22p Samir
247 * added hud observer mode and fixed problems with hud switching and
248 * screen size.
249 *
250 * 76 10/14/98 4:27p Samir
251 * improved HUD_ITEM_CUSTOMTEXT
252 *
253 * 75 10/07/98 5:52p Samir
254 * fixed small bug in hud stat masks.
255 *
256 * 74 10/02/98 5:47p Samir
257 * moved reticle down a bit.
258 *
259 * 73 9/28/98 11:00a Samir
260 * fixed stupid bug.
261 *
262 * 72 9/18/98 4:33p Samir
263 * added dummy code for New Inf format hud files.
264 *
265 * 71 8/31/98 3:39p Samir
266 * if no energy or ammo, reticle will reflect this.
267 *
268 * 70 8/25/98 3:07p Samir
269 * when cockpit fails redo hud switch to fullscreen.
270 *
271 * 69 8/18/98 1:11a Samir
272 * fixed some stuff for multi cockpit configs.
273 *
274 * 68 8/15/98 10:51p Matt
275 * Added function ToggleHUDMode(), and made StartHudInputMessage() public.
276 *
277 * 67 7/06/98 7:34p Samir
278 * added countermeasures.
279 *
280 * 66 6/25/98 12:52p Samir
281 * draw afterburner hud in cockpit (special version)
282 *
283 * 65 6/24/98 7:38p Samir
284 * redid graphical/text/cockpit hud item management.
285 *
286 * 64 6/19/98 5:39p Samir
287 * use pilot information to get hud layout.
288 *
289 * 63 6/17/98 6:31p Samir
290 * Added anti-grav warning when dying.
291 *
292 * 62 6/15/98 6:54p Samir
293 * added invulnerability and cloak effect.
294 *
295 * 61 6/05/98 5:34p Samir
296 * if cockpit already up, when setting cockpit mode, do quick open.
297 *
298 * 60 5/26/98 10:49p Samir
299 * default to cockpit.
300 *
301 * 59 5/26/98 5:05p Samir
302 * cockpit and hud config file now 'unified'. cockpit adds to hudconfig
303 * load's funtionality, so cockpit info files can contain same syntax as
304 * hud file.
305 *
306 * 58 5/25/98 8:30p Samir
307 * guided missile reticle and added a hud timer.
308 *
309 * 57 5/22/98 1:36p Samir
310 * implemented a lot of hud items.
311 *
312 * 56 5/15/98 5:36p Samir
313 * use correct font scale for lores screens.
314 *
315 * 55 5/15/98 3:39p Samir
316 * reticle alphaed.
317 *
318 * 54 5/07/98 6:01p Samir
319 * allow for certain hud items to not be resettable.
320 *
321 * 53 5/07/98 2:51p Samir
322 * took out extern functions.
323 *
324 * 52 5/05/98 6:27p Samir
325 * added hud aspect ratio values and reticle is scaled correctly.
326 *
327 * 51 4/28/98 4:25p Samir
328 * scale font with hud shrink.
329 *
330 * 50 4/27/98 1:14p Jason
331 * cleaned up afterburner stuff
332 *
333 * 49 4/24/98 5:32p Samir
334 * new reticle implemented.
335 *
336 * 48 4/24/98 8:01a Samir
337 * don't pass zoom argument to Render functions.
338 *
339 * 47 4/23/98 4:13a Samir
340 * new hud system.
341 *
342 * 46 4/19/98 5:00p Jason
343 * added cool napalm effect, plus made object effects dynamically
344 * allocated
345 *
346 * 45 4/17/98 1:59p Jason
347 * added cool object effects
348 *
349 * 44 4/16/98 6:52a Samir
350 * initialize bitmap handle to -1 always when initializing hud item.
351 *
352 * 43 4/14/98 9:19p Samir
353 * made hacked good looking reticle for mag demo.
354 *
355 * 42 4/13/98 7:02p Samir
356 * beginning reticle code.
357 *
358 * 41 4/01/98 6:23p Jason
359 * added a slew of stuff for multiplayer
360 *
361 * 40 3/25/98 11:59a Samir
362 * implemented energy analog fully.
363 *
364 * 39 3/24/98 4:27p Samir
365 * modified energy gauges.
366 *
367 * 38 3/22/98 5:03p Samir
368 * updated cockpit.
369 *
370 * 37 3/20/98 8:23p Samir
371 * new hud and cockpit customization system.
372 *
373 * 36 3/19/98 9:19p Samir
374 * removed dependency of hud.h on game.h.
375 *
376 * 35 3/18/98 6:25p Samir
377 * Added new STAT_ constants/
378 *
379 * 34 3/17/98 2:40p Samir
380 * reorg of cockpit/gauges and hud systems.
381 *
382 * 33 3/16/98 3:30p Samir
383 * incremental checkin.
384 *
385 * 32 3/13/98 12:09p Samir
386 * made changes to reflect new cockpit.cpp and cockpit.h
387 *
388 * 31 2/17/98 2:22p Jason
389 * fixed some potential z sorting problems
390 *
391 * 30 2/14/98 10:48p Jason
392 * got preferred rendering working
393 *
394 * 29 2/12/98 4:20p Matt
395 * Made letterbox window shorter.
396 *
397 * 28 1/28/98 10:34a Samir
398 * Reticle.
399 *
400 * 27 1/13/98 4:27p Samir
401 * Fixed clear screen strangeness.
402 *
403 * 26 12/29/97 5:44p Samir
404 * Took out references to grViewport and old 2d library.
405 *
406 *
407 * 1 5/14/97 11:12a Jason
408 * file rendering stuff on the hud
409 *
410 * $NoKeywords: $
411 */
412
413 #include "hud.h"
414 #include "gauges.h"
415 #include "grdefs.h"
416 #include "game.h"
417 #include "ddio.h"
418 #include "player.h"
419 #include "renderer.h"
420 #include "descent.h"
421 #include "object.h"
422 #include "gamefont.h"
423 #include "polymodel.h"
424 #include "cockpit.h"
425 #include "game2dll.h"
426 #include "ship.h"
427 #include "pilot.h"
428 #include "mem.h"
429 #include "d3music.h"
430 #include "demofile.h"
431 #include "stringtable.h"
432 #include "pstring.h"
433 #include "config.h"
434
435 #include <stdio.h>
436 #include <stdlib.h>
437 #include <stdarg.h>
438 #include <string.h>
439 #include "gamecinematics.h"
440 #include "CtlCfgElem.h"
441 #include "ctlconfig.h"
442
443 //////////////////////////////////////////////////////////////////////////////
444 // constants
445
446 #define FRAMERATE_TIME_DELAY 0.25 // update every quarter second
447
448 //////////////////////////////////////////////////////////////////////////////
449
450 // PLAYER SAVEGAME PREFERENCES START
451 // determines what's displayable on the hud
452 #ifdef E3_DEMO
453 tStatMask Hud_stat_mask = STAT_TIMER;
454 #else
455 tStatMask Hud_stat_mask = 0;
456 #endif
457
458 #define STAT_SCORE STAT_TIMER
459
460 // PLAYER SAVEGAME PREFERENCES END
461
462 // hud aspect
463 float Hud_aspect_x = 1.0f;
464 float Hud_aspect_y = 1.0f;
465 bool Small_hud_flag = false; // changes how hud items are drawn in small huds.
466
467 // used by reticle system.
468 static int16_t Ret_x_off, Ret_y_off;
469 static char Reticle_prefix[PSFILENAME_LEN + 1];
470
471 // Hud mode of display
472 static tHUDMode Hud_mode = HUD_COCKPIT;
473
474 // hud item array.
475 static tHUDItem HUD_array[MAX_HUD_ITEMS];
476
477 #define HUDITEMUSED(_c) (HUD_array[_c].stat ? true : false)
478
479 // hud resource structure
480 struct sHUDResources HUD_resources;
481
482 // initializes non configurable hud items.
483 static void InitDefaultHUDItems();
484
485 // initializes items based off their type (information, etc.)
486 static void InitHUDItem(int new_item, tHUDItem *item);
487
488 // iterate through entire hud item list to draw.
489 static void RenderHUDItems(tStatMask stat_mask);
490
491 // renders the reticle
492 static void RenderReticle();
493
494 // renders missile reticle
495 static void RenderMissileReticle();
496
497 // renders zoom reticle
498 static void RenderZoomReticle();
499
500 // hack!
501
502 // functions in HudDisplay.cpp
503 extern void HudDisplayRouter(tHUDItem *item);
504
505 bool Hud_show_controls = false;
506
507 //////////////////////////////////////////////////////////////////////////////
508
509 // initializes hud.
510 void InitHUD() {
511 int i;
512 extern bool HUD_disabled; // from gameloop.cpp
513
514 for (i = 0; i < MAX_HUD_ITEMS; i++) {
515 HUD_array[i].stat = 0;
516 HUD_array[i].flags = 0;
517 HUD_array[i].id = HUD_INVALID_ID;
518 }
519
520 // load static hud image resources to be used by HudDisplay.cpp
521 HUD_resources.arrow_bmp = -1;
522 HUD_resources.goal_bmp = -1;
523 HUD_resources.goal_complete_bmp = -1;
524 HUD_resources.lock_bmp[0] = -1;
525 HUD_resources.lock_bmp[1] = -1;
526 HUD_resources.wpn_bmp = -1;
527 HUD_resources.dot_bmp = -1;
528 HUD_resources.antigrav_bmp[0] = -1;
529 HUD_resources.antigrav_bmp[1] = -1;
530 strcpy(HUD_resources.hud_inf_name, "hud.inf");
531
532 strcpy(Reticle_prefix, "ret");
533 Ret_x_off = 0;
534 Ret_y_off = 0;
535
536 for (i = 0; i < NUM_SHIELD_GAUGE_FRAMES; i++)
537 HUD_resources.shield_bmp[i] = -1;
538 HUD_resources.energy_bmp = -1;
539 HUD_resources.afterburn_bmp = -1;
540 HUD_resources.invpulse_bmp = -1;
541
542 // this call may be unnecessary since it's called again in InitCockpit.
543 // InitReticle(-1,-1); // initialize reticle system
544
545 // scrollback windows
546 ResetGameMessages(); // resets game message rollback screen.
547 ResetHUDMessages();
548 HUD_disabled = 0;
549 }
550
551 // closes hud.
552 void CloseHUD() {
553 int i;
554
555 CloseHUDMessageConsole(); // closes down rollback console
556 CloseGameMessageConsole(); // closes game journal rollback
557 ResetGameMessages(); // reset game message system.
558 ResetHUDMessages();
559
560 // free hud items.
561 for (i = 0; i < MAX_HUD_ITEMS; i++) {
562 if (HUD_array[i].stat) {
563 FreeHUDItem(i);
564 }
565 }
566 }
567
568 tHUDItem *GetHUDItem(int id) { return &HUD_array[id]; }
569
570 // initializes hud.
571 void InitShipHUD(int ship) {
572 int i;
573
574 // load static hud image resources to be used by HudDisplay.cpp
575 HUD_resources.arrow_bmp = bm_AllocLoadFileBitmap("hudarrow.ogf", 0);
576 HUD_resources.goal_bmp = bm_AllocLoadFileBitmap("hudgoal.ogf", 0);
577 HUD_resources.goal_complete_bmp = bm_AllocLoadFileBitmap("hudgoalon.ogf", 0);
578 HUD_resources.lock_bmp[0] = bm_AllocLoadFileBitmap("hudlockl.ogf", 0);
579 HUD_resources.lock_bmp[1] = bm_AllocLoadFileBitmap("hudlockr.ogf", 0);
580 HUD_resources.wpn_bmp = bm_AllocLoadFileBitmap("hudicon.ogf", 0);
581 HUD_resources.dot_bmp = bm_AllocLoadFileBitmap("huddot.ogf", 0);
582 HUD_resources.antigrav_bmp[0] = bm_AllocLoadFileBitmap("hudantigravl.ogf", 0);
583 HUD_resources.antigrav_bmp[1] = bm_AllocLoadFileBitmap("hudantigravr.ogf", 0);
584
585 for (i = 0; i < NUM_SHIELD_GAUGE_FRAMES; i++)
586 HUD_resources.shield_bmp[i] = -1;
587 HUD_resources.energy_bmp = -1;
588 HUD_resources.afterburn_bmp = -1;
589 HUD_resources.invpulse_bmp = -1;
590
591 // sets current hud mode static global
592 // DAJ Current_pilot.get_hud_data((uint8_t *)&Hud_mode);
593 uint8_t hud_tmp;
594 Current_pilot.get_hud_data(&hud_tmp);
595 Hud_mode = (tHUDMode)hud_tmp;
596 }
597
598 // closes hud for current ship
599 void CloseShipHUD() {
600 FreeReticle();
601
602 // free hud resources
603 bm_FreeBitmap(HUD_resources.antigrav_bmp[1]);
604 bm_FreeBitmap(HUD_resources.antigrav_bmp[0]);
605 bm_FreeBitmap(HUD_resources.dot_bmp);
606 bm_FreeBitmap(HUD_resources.wpn_bmp);
607 bm_FreeBitmap(HUD_resources.lock_bmp[1]);
608 bm_FreeBitmap(HUD_resources.lock_bmp[0]);
609 bm_FreeBitmap(HUD_resources.goal_complete_bmp);
610 bm_FreeBitmap(HUD_resources.goal_bmp);
611 bm_FreeBitmap(HUD_resources.arrow_bmp);
612 }
613
614 // places an item on the hud
615 void AddHUDItem(tHUDItem *item) {
616 // find free hud slot.
617 int i;
618
619 for (i = 0; i < MAX_HUD_ITEMS; i++) {
620 if (!HUD_array[i].stat) {
621 // we will initialize the hud item.
622 InitHUDItem(i, item);
623 break;
624 }
625 }
626
627 if (i == MAX_HUD_ITEMS) {
628 mprintf(0, "Unable to add hud item (type=%d).\n", item->type);
629 }
630 }
631
632 // resets hud
633 void ResetHUD() {
634 int i;
635
636 for (i = 0; i < MAX_HUD_ITEMS; i++) {
637 if (HUD_array[i].stat && !(HUD_array[i].flags & HUD_FLAG_LEVEL) && !(HUD_array[i].flags & HUD_FLAG_PERSISTANT)) {
638 FreeHUDItem(i);
639 }
640 }
641 }
642
643 // clears out HUD level items
644 void ResetHUDLevelItems() {
645 int i;
646 for (i = 0; i < MAX_HUD_ITEMS; i++) {
647 if (HUD_array[i].stat && (HUD_array[i].flags & HUD_FLAG_LEVEL)) {
648 FreeHUDItem(i);
649 }
650 }
651 }
652
653 // from game.cpp
654 extern void InitGameScreen(int, int);
655 extern bool Dedicated_server;
656
657 // manually sets the cockpit display.
658 void SetHUDMode(tHUDMode mode) {
659 static int saved_window_w = 0, saved_window_h = 0;
660
661 if (Dedicated_server)
662 return;
663
664 if (GetScreenMode() != SM_GAME) {
665 #ifdef _DEBUG
666 Int3();
667 #endif
668 return;
669 }
670
671 // clear the screen.
672 Clear_screen = 4;
673
674 // free poly model of cockpit if we're not switching to a cockpit mode.
675 if (Hud_mode == HUD_COCKPIT && IsValidCockpit()) {
676 if (mode == HUD_LETTERBOX || mode == HUD_OBSERVER) {
677 QuickCloseCockpit();
678 } else if (mode != HUD_COCKPIT) {
679 CloseCockpit();
680 }
681 }
682
683 // do cockpit specific thing.
684 redo_hud_switch:
685 switch (mode) {
686 uint16_t cp_hud_stat, cp_hud_graphical_stat;
687
688 case HUD_LETTERBOX:
689 // our objective here is to display a letterbox screen for the cockpit.
690 // we save the old width and height of the windows.
691 saved_window_w = Game_window_w;
692 saved_window_h = Game_window_h;
693
694 Game_window_w = Max_window_w;
695 Game_window_h = Max_window_h - (Max_window_h / 3);
696
697 if (Game_window_h > Max_window_h)
698 Game_window_h = Max_window_h;
699
700 if (Game_window_w > Max_window_w)
701 Game_window_w = Max_window_w;
702
703 Game_window_x = (Max_window_w - Game_window_w) / 2;
704 Game_window_y = (Max_window_h - Game_window_h) / 2;
705
706 SetHUDState(STAT_MESSAGES | (Hud_stat_mask & STAT_FPS), 0);
707 break;
708
709 case HUD_FULLSCREEN:
710 // our objective here is to display a fullscreen box that is resizable.
711 LoadHUDConfig(HUD_resources.hud_inf_name);
712
713 InitGameScreen(saved_window_w ? saved_window_w : Game_window_w, saved_window_h ? saved_window_h : Game_window_h);
714 saved_window_w = 0;
715 saved_window_h = 0;
716
717 Current_pilot.get_hud_data(NULL, &cp_hud_stat, &cp_hud_graphical_stat);
718
719 SetHUDState(cp_hud_stat | STAT_SCORE | (Hud_stat_mask & STAT_FPS), cp_hud_graphical_stat);
720
721 break;
722
723 case HUD_COCKPIT:
724 if (!IsValidCockpit()) {
725 mode = HUD_FULLSCREEN;
726 AddHUDMessage(TXT_NOCOCKPIT);
727 goto redo_hud_switch;
728 }
729 if (Hud_mode == HUD_COCKPIT || Hud_mode == HUD_LETTERBOX || Hud_mode == HUD_OBSERVER)
730 QuickOpenCockpit();
731 else
732 OpenCockpit();
733
734 InitGameScreen(saved_window_w ? saved_window_w : Game_window_w, saved_window_h ? saved_window_h : Game_window_h);
735
736 saved_window_w = 0;
737 saved_window_h = 0;
738
739 Current_pilot.get_hud_data(NULL, &cp_hud_stat, &cp_hud_graphical_stat);
740
741 SetHUDState(STAT_MESSAGES | STAT_SHIELDS | STAT_ENERGY | STAT_GOALS | STAT_CUSTOM | STAT_AFTERBURN |
742 STAT_INVENTORY | STAT_CNTRMEASURE | STAT_SCORE | (Hud_stat_mask & STAT_WARNING) |
743 (Hud_stat_mask & STAT_FPS) | (Hud_stat_mask & STAT_SCORE),
744 (cp_hud_graphical_stat & STAT_WARNING));
745 break;
746
747 case HUD_OBSERVER:
748 InitGameScreen(saved_window_w ? saved_window_w : Game_window_w, saved_window_h ? saved_window_h : Game_window_h);
749 saved_window_w = 0;
750 saved_window_h = 0;
751
752 SetHUDState(STAT_MESSAGES | (Hud_stat_mask & STAT_FPS), 0);
753 break;
754
755 default:
756 Int3();
757 }
758
759 // save out current hud mode
760 // JEFF: (only if going from HUD_FULLSCREEN->HUD_COCKPIT or vice-versa)
761 if ((Hud_mode == HUD_FULLSCREEN && mode == HUD_COCKPIT) || (Hud_mode == HUD_COCKPIT && mode == HUD_FULLSCREEN)) {
762 uint8_t bmode = mode; // DAJ MAC using enums always int
763 Current_pilot.set_hud_data((uint8_t *)&bmode);
764 mprintf(0, "Saving new hud mode to pilot\n");
765 PltWriteFile(&Current_pilot);
766 }
767
768 Hud_mode = mode;
769 }
770
771 // the current cockpit mode;
772 tHUDMode GetHUDMode() { return Hud_mode; }
773
774 // toggle the hud between cockput & fullscreen modes
775 void ToggleHUDMode() {
776 if (GetHUDMode() == HUD_COCKPIT)
777 SetHUDMode(HUD_FULLSCREEN);
778 else if (GetHUDMode() == HUD_FULLSCREEN)
779 SetHUDMode(HUD_COCKPIT);
780 }
781
782 // sets the hud item state(what's visible, how it's drawn, etc)
783 void SetHUDState(uint16_t hud_mask, uint16_t hud_gr_mask) {
784 int i;
785
786 Hud_stat_mask = (hud_mask | hud_gr_mask);
787
788 // now go through each hud item, check if it's hud stat mask includes the requested hud_gr_mask
789 // if it does, then set hud mask to graphical
790 for (i = 0; i < MAX_HUD_ITEMS; i++) {
791 HUD_array[i].stat &= ~(STAT_GRAPHICAL);
792 if (HUD_array[i].stat & hud_gr_mask)
793 HUD_array[i].stat |= STAT_GRAPHICAL;
794 }
795 }
796
797 // initializes items based off their type (information, etc.)
798 void InitHUDItem(int new_item, tHUDItem *item) {
799 ASSERT(new_item < MAX_HUD_ITEMS);
800 uint16_t stat = 0x0000;
801
802 item->id = new_item;
803
804 switch (item->type) {
805 case HUD_ITEM_PRIMARY:
806 stat = STAT_PRIMARYLOAD;
807 break;
808
809 case HUD_ITEM_SECONDARY:
810 stat = STAT_SECONDARYLOAD;
811 break;
812
813 case HUD_ITEM_SHIELD:
814 stat = STAT_SHIELDS;
815 break;
816
817 case HUD_ITEM_ENERGY:
818 stat = STAT_ENERGY;
819 break;
820
821 case HUD_ITEM_AFTERBURNER:
822 stat = STAT_AFTERBURN;
823 break;
824
825 case HUD_ITEM_INVENTORY:
826 stat = STAT_INVENTORY;
827 break;
828
829 case HUD_ITEM_SHIPSTATUS:
830 stat = STAT_SHIP;
831 break;
832
833 case HUD_ITEM_CNTRMEASURE:
834 stat = STAT_CNTRMEASURE;
835 break;
836
837 case HUD_ITEM_CUSTOMTEXT:
838 if (item->data.text) {
839 char *text = mem_strdup(item->data.text);
840 HUD_array[new_item].data.text = text;
841 }
842 stat = STAT_CUSTOM;
843 break;
844
845 case HUD_ITEM_CUSTOMTEXT2: // malloc buffer to be updated later
846 HUD_array[new_item].data.text = (char *)mem_malloc(item->buffer_size);
847 HUD_array[new_item].data.text[0] = 0;
848 HUD_array[new_item].buffer_size = item->buffer_size;
849 stat = STAT_CUSTOM;
850 break;
851
852 case HUD_ITEM_CUSTOMIMAGE:
853 stat = STAT_CUSTOM;
854 break;
855
856 case HUD_ITEM_WARNINGS:
857 stat = STAT_WARNING;
858 break;
859
860 case HUD_ITEM_GOALS:
861 case HUD_ITEM_GOALSTATES:
862 stat = STAT_GOALS;
863 break;
864
865 case HUD_ITEM_SCORE:
866 stat = STAT_SCORE;
867 break;
868
869 case HUD_ITEM_TIMER:
870 HUD_array[new_item].data.timer_handle = item->data.timer_handle;
871 stat = STAT_CUSTOM;
872 break;
873
874 default:
875 Int3();
876 }
877
878 // copy hud item structure.
879 HUD_array[new_item].x = item->x;
880 HUD_array[new_item].y = item->y;
881 HUD_array[new_item].xa = item->xa;
882 HUD_array[new_item].ya = item->ya;
883 HUD_array[new_item].xb = item->xb;
884 HUD_array[new_item].yb = item->yb;
885 HUD_array[new_item].tx = item->tx;
886 HUD_array[new_item].ty = item->ty;
887 HUD_array[new_item].grscalex = item->grscalex;
888 HUD_array[new_item].grscaley = item->grscaley;
889 HUD_array[new_item].type = item->type;
890 HUD_array[new_item].stat = item->stat | stat;
891 HUD_array[new_item].flags = item->flags;
892 HUD_array[new_item].alpha = item->alpha;
893 HUD_array[new_item].color = item->color;
894 HUD_array[new_item].tcolor = item->tcolor;
895 HUD_array[new_item].saturation_count = item->saturation_count;
896 HUD_array[new_item].render_fn = item->render_fn;
897 HUD_array[new_item].id = item->id;
898 HUD_array[new_item].dirty_rect.reset();
899 }
900
901 // Returns the item number if there's a customtext2 item, else -1
902 int FindCustomtext2HUDItem() {
903 int i;
904 for (i = 0; i < MAX_HUD_ITEMS; i++) {
905 if (HUD_array[i].stat && (HUD_array[i].type == HUD_ITEM_CUSTOMTEXT2))
906 return i;
907 }
908
909 return -1;
910 }
911
912 // Updates the customtext2 item, if there is one
913 void UpdateCustomtext2HUDItem(char *text) {
914 int i;
915
916 for (i = 0; i < MAX_HUD_ITEMS; i++) {
917 if (HUD_array[i].stat && (HUD_array[i].type == HUD_ITEM_CUSTOMTEXT2)) {
918 ASSERT(HUD_array[i].data.text != NULL);
919 strncpy(HUD_array[i].data.text, text, HUD_array[i].buffer_size);
920 HUD_array[i].data.text[HUD_array[i].buffer_size - 1];
921 break;
922 }
923 }
924 }
925
926 // savegame system hooks
927 void SGSHudState(CFILE *fp) {
928 int i;
929 tHUDItem *huditem;
930
931 for (i = 0; i < MAX_HUD_ITEMS; i++) {
932 // save custom text2 and timer hud items
933 huditem = &HUD_array[i];
934 if (huditem->stat) {
935 if (huditem->type == HUD_ITEM_CUSTOMTEXT2) {
936 cf_WriteShort(fp, (int16_t)huditem->stat);
937 cf_WriteByte(fp, (int8_t)huditem->type);
938 cf_WriteShort(fp, huditem->x);
939 cf_WriteShort(fp, huditem->y);
940 cf_WriteInt(fp, huditem->color);
941 cf_WriteShort(fp, (int16_t)huditem->flags);
942 cf_WriteByte(fp, (int8_t)huditem->alpha);
943
944 cf_WriteShort(fp, (int16_t)huditem->buffer_size);
945 cf_WriteString(fp, huditem->data.text);
946 mprintf(0, "sg: saved customtext2 (%x,%x,bufsize=%d)\n", huditem->x, huditem->y, huditem->buffer_size);
947 } else if (huditem->type == HUD_ITEM_TIMER) {
948 cf_WriteShort(fp, (int16_t)huditem->stat);
949 cf_WriteByte(fp, (int8_t)huditem->type);
950 cf_WriteShort(fp, huditem->x);
951 cf_WriteShort(fp, huditem->y);
952 cf_WriteInt(fp, huditem->color);
953 cf_WriteShort(fp, (int16_t)huditem->flags);
954 cf_WriteByte(fp, (int8_t)huditem->alpha);
955
956 cf_WriteInt(fp, huditem->data.timer_handle);
957 mprintf(0, "sg: restored timer (%x,%x,timer_hndl=%d)\n", huditem->x, huditem->y, huditem->data.timer_handle);
958 } else if (huditem->type == HUD_ITEM_CUSTOMTEXT) {
959 // commented out because persistent hud messages are custom text, and its a mess to save the current
960 // state of hud persistent messages.
961 // cf_WriteShort(fp, (int16_t)huditem->stat);
962 // cf_WriteByte(fp, (int8_t)huditem->type);
963 // cf_WriteShort(fp, huditem->x);
964 // cf_WriteShort(fp, huditem->y);
965 // cf_WriteInt(fp, huditem->color);
966 // cf_WriteShort(fp, (int16_t)huditem->flags);
967 // cf_WriteByte(fp, (int8_t)huditem->alpha);
968 //
969 // cf_WriteString(fp, huditem->data.timer_handle);
970 }
971 }
972 }
973
974 cf_WriteShort(fp, 0); // mark end of saved hud items.
975 }
976
977 bool LGSHudState(CFILE *fp) {
978 // restore hud items
979 uint16_t stat_mask = 0;
980
981 while ((stat_mask = (uint16_t)cf_ReadShort(fp)) != 0) {
982 tHUDItem huditem;
983 uint8_t item_type = (uint8_t)cf_ReadByte(fp);
984
985 memset(&huditem, 0, sizeof(huditem));
986 huditem.type = item_type;
987 huditem.stat = stat_mask;
988
989 switch (item_type) {
990 char *buffer;
991 extern void RenderHUDTimer(tHUDItem * item);
992
993 case HUD_ITEM_CUSTOMTEXT2:
994 huditem.x = cf_ReadShort(fp);
995 huditem.y = cf_ReadShort(fp);
996 huditem.color = (ddgr_color)cf_ReadInt(fp);
997 huditem.flags = (uint16_t)cf_ReadShort(fp);
998 huditem.alpha = (uint8_t)cf_ReadByte(fp);
999
1000 huditem.buffer_size = (int)cf_ReadShort(fp);
1001 huditem.render_fn = NULL; // use pointer to function void (*fn)(struct tHUDItem *)
1002 AddHUDItem(&huditem);
1003
1004 buffer = (char *)mem_malloc(huditem.buffer_size);
1005 cf_ReadString(buffer, huditem.buffer_size, fp);
1006 UpdateCustomtext2HUDItem(buffer);
1007 mem_free(buffer);
1008 mprintf(0, "lg: restored customtext2 (%x,%x,bufsize=%d)\n", huditem.x, huditem.y, huditem.buffer_size);
1009 break;
1010
1011 case HUD_ITEM_TIMER:
1012 huditem.x = cf_ReadShort(fp);
1013 huditem.y = cf_ReadShort(fp);
1014 huditem.color = (ddgr_color)cf_ReadInt(fp);
1015 huditem.flags = (uint16_t)cf_ReadShort(fp);
1016 huditem.alpha = (uint8_t)cf_ReadByte(fp);
1017
1018 huditem.data.timer_handle = cf_ReadInt(fp);
1019 huditem.render_fn = RenderHUDTimer; // use pointer to function void (*fn)(struct tHUDItem *)
1020 AddHUDItem(&huditem);
1021 mprintf(0, "lg: restored timer (%x,%x,timer_hndl=%d)\n", huditem.x, huditem.y, huditem.data.timer_handle);
1022 break;
1023
1024 // case HUD_ITEM_CUSTOMTEXT:
1025 // break;
1026 default:
1027 return false;
1028 }
1029 }
1030
1031 return true;
1032 }
1033
1034 // frees hud items based off their type class.
1035 void FreeHUDItem(int item) {
1036 ASSERT(item < MAX_HUD_ITEMS);
1037
1038 HUD_array[item].stat = 0;
1039 HUD_array[item].flags = 0;
1040 HUD_array[item].id = HUD_INVALID_ID;
1041 if (((HUD_array[item].type == HUD_ITEM_CUSTOMTEXT) || (HUD_array[item].type == HUD_ITEM_CUSTOMTEXT2)) &&
1042 HUD_array[item].data.text) {
1043 mem_free(HUD_array[item].data.text);
1044 HUD_array[item].data.text = NULL;
1045 }
1046 }
1047
1048 extern void RenderHUDScore(tHUDItem *item);
1049
1050 // initializes non configurable hud items.
1051 void InitDefaultHUDItems() {
1052 tHUDItem huditem;
1053
1054 memset(&huditem, 0, sizeof(huditem));
1055 huditem.type = HUD_ITEM_SCORE; // KEEP THIS
1056 huditem.stat = STAT_SCORE; // This is bound to timer. in release builds, no timer code but just score
1057 huditem.x = 640; // position on HUD in 640,480 coordinates
1058 huditem.y = 5;
1059 huditem.color = HUD_COLOR; // you can ignore this if you dont use this value passed into your render function
1060 huditem.render_fn = RenderHUDScore; // use pointer to function void (*fn)(struct tHUDItem *)
1061 AddHUDItem(&huditem);
1062 }
1063
1064 // loads in hud configuration file, adds hud items.
1065 void LoadHUDConfig(const char *filename, bool (*fn)(const char *, const char *, void *), void *ext_data) {
1066 CFILE *fp;
1067 char srcline[128]; // One line of mission source
1068 bool text_pos = false; // text position defined?
1069
1070 // start over.
1071 ResetHUD();
1072 InitDefaultHUDItems();
1073
1074 // open file
1075 fp = cfopen(filename, "rt");
1076 if (!fp) {
1077 mprintf(0, "Unable to find hud.inf file.\n");
1078 return;
1079 }
1080
1081 // check if valid cockpit file
1082 cf_ReadString(srcline, sizeof(srcline), fp);
1083
1084 if (stricmp(srcline, "[hud file]") == 0) {
1085 tHUDItem hud_item;
1086
1087 memset(&hud_item, 0, sizeof(hud_item));
1088 hud_item.alpha = HUD_ALPHA;
1089 hud_item.color = HUD_COLOR;
1090 hud_item.tcolor = HUD_COLOR;
1091
1092 while (!cfeof(fp)) {
1093 char command[32]; // Command read from line.
1094 char operand[96]; // operand read from line
1095 char *keyword; // parsed keyword
1096 int readcount; // read-in count
1097
1098 readcount = cf_ReadString(srcline, sizeof(srcline), fp);
1099 if (readcount) {
1100 // we have a line of source. parse out primary keyword
1101 // then parse out remainder.
1102 keyword = strtok(srcline, " \t=");
1103 CleanupStr(command, srcline, sizeof(command));
1104 CleanupStr(operand, srcline + strlen(command) + 1, sizeof(operand));
1105
1106 // skip comments
1107 if (command[0] == '@')
1108 continue;
1109
1110 // find command,
1111 if (!stricmp(command, "type")) {
1112 // get operand.
1113 hud_item.type = atoi(operand);
1114 } else if (!stricmp(command, "pos")) {
1115 // get two numbers from line
1116 int ix, iy;
1117 sscanf(operand, "%d,%d", &ix, &iy);
1118 hud_item.x = ix;
1119 hud_item.y = iy;
1120 } else if (!stricmp(command, "posA")) {
1121 // get two numbers from line
1122 int ix, iy;
1123 sscanf(operand, "%d,%d", &ix, &iy);
1124 hud_item.xa = ix;
1125 hud_item.ya = iy;
1126 } else if (!stricmp(command, "posB")) {
1127 // get two numbers from line
1128 int ix, iy;
1129 sscanf(operand, "%d,%d", &ix, &iy);
1130 hud_item.xb = ix;
1131 hud_item.yb = iy;
1132 } else if (!stricmp(command, "grscale")) {
1133 sscanf(operand, "%f,%f", &hud_item.grscalex, &hud_item.grscaley);
1134 } else if (!stricmp(command, "textpos")) {
1135 // get two numbers from line
1136 int ix, iy;
1137 sscanf(operand, "%d,%d", &ix, &iy);
1138 hud_item.tx = ix;
1139 hud_item.ty = iy;
1140 text_pos = true;
1141 } else if (!stricmp(command, "alpha")) {
1142 // get alpha value.
1143 hud_item.alpha = atoi(operand);
1144 } else if (!stricmp(command, "sat")) {
1145 // saturation count
1146 hud_item.saturation_count = atoi(operand);
1147 } else if (!stricmp(command, "rgb")) {
1148 // saturation count
1149 int r, g, b;
1150 sscanf(operand, "%d,%d,%d", &r, &g, &b);
1151 hud_item.color = GR_RGB(r, g, b);
1152 } else if (!stricmp(command, "textrgb")) {
1153 int r, g, b;
1154 sscanf(operand, "%d,%d,%d", &r, &g, &b);
1155 hud_item.tcolor = GR_RGB(r, g, b);
1156 } else if (!stricmp(command, "special")) {
1157 hud_item.stat |= STAT_SPECIAL;
1158 } else if (!stricmp(command, "create")) {
1159 // create hud item.
1160 if (!text_pos) {
1161 hud_item.tx = hud_item.x;
1162 hud_item.ty = hud_item.y;
1163 }
1164 hud_item.render_fn = HudDisplayRouter;
1165 AddHUDItem(&hud_item);
1166
1167 // reset hud item.
1168 memset(&hud_item, 0, sizeof(hud_item));
1169 hud_item.alpha = HUD_ALPHA;
1170 hud_item.color = HUD_COLOR;
1171 hud_item.tcolor = HUD_COLOR;
1172 text_pos = false;
1173 } else if (!stricmp(command, "reticleprefix")) {
1174 // copy prefix of reticle bitmaps.
1175 strcpy(Reticle_prefix, operand);
1176 } else if (!stricmp(command, "reticleoffset")) {
1177 int x, y;
1178 sscanf(operand, "%d,%d", &x, &y);
1179 Ret_x_off = (int16_t)x;
1180 Ret_y_off = (int16_t)y;
1181 } else if (fn && (*fn)(command, operand, ext_data)) {
1182 continue;
1183 } else {
1184 mprintf(0, "Error reading hud file.\n");
1185 Int3(); // contact samir.
1186 break;
1187 }
1188 }
1189 }
1190 } else {
1191 mprintf(0, "Not a valid hud file.\n");
1192 }
1193
1194 // use any reticle specified.
1195 FreeReticle();
1196 InitReticle(0, 0);
1197
1198 cfclose(fp);
1199 }
1200
1201 //////////////////////////////////////////////////////////////////////////////
1202 // render cockpit and gauges frame
1203 // checks to see what cockpit mode we are in.
1204 // draws stuff accordingly.
1205 // render internal gauges too.
1206
1207 void RenderHUDFrame() {
1208 extern bool Guided_missile_smallview; // from smallviews.cpp
1209
1210 rend_SetOverlayType(OT_NONE);
1211
1212 // determine hud rendering properties.
1213 Hud_aspect_x = (float)Game_window_w / DEFAULT_HUD_WIDTH;
1214 Hud_aspect_y = (float)Game_window_h / DEFAULT_HUD_HEIGHT;
1215 Small_hud_flag = (((float)Game_window_w / (float)Max_window_w) <= 0.80f) ? true : false;
1216
1217 // render special missile hud if available
1218 if (Players[Player_num].guided_obj && !Guided_missile_smallview) {
1219 if (!Cinematic_inuse)
1220 RenderMissileReticle();
1221 } else if (Players[Player_num].flags & PLAYER_FLAGS_ZOOMED) {
1222 if (!Cinematic_inuse)
1223 RenderZoomReticle();
1224 } else if (!(Players[Player_num].flags & PLAYER_FLAGS_REARVIEW)) {
1225 switch (GetHUDMode()) {
1226 case HUD_FULLSCREEN:
1227 RenderHUDItems(Hud_stat_mask);
1228 RenderCockpit(); // needed to render animated deactivation sequence and should be dormant
1229 if (Game_toggles.show_reticle) {
1230 RenderReticle();
1231 }
1232 break;
1233
1234 case HUD_COCKPIT:
1235 RenderHUDItems(Hud_stat_mask);
1236 RenderCockpit(); // called when cockpit is activating and functioning.
1237 if (Game_toggles.show_reticle) {
1238 RenderReticle();
1239 }
1240 break;
1241
1242 case HUD_LETTERBOX:
1243 if (!Cinematic_inuse)
1244 RenderHUDItems(Hud_stat_mask);
1245 break;
1246
1247 case HUD_OBSERVER:
1248 if (!Cinematic_inuse)
1249 RenderHUDItems(Hud_stat_mask);
1250 break;
1251
1252 default:
1253 Int3();
1254 }
1255 }
1256
1257 // Do dll stuff
1258 CallGameDLL(EVT_CLIENT_HUD_INTERVAL, &DLLInfo);
1259
1260 rend_SetZBufferState(1);
1261 mprintf_at(2, 0, 0, "FPS: %f", GetFPS());
1262 }
1263
1264 // renders hud frame before any graphics are drawn
1265 void RenderPreHUDFrame() {
1266 extern void RenderHUDMsgDirtyRects();
1267
1268 // render any dirty rectangles if small hud flag is set
1269 if (Small_hud_flag) {
1270 int i;
1271
1272 for (i = 0; i < MAX_HUD_ITEMS; i++) {
1273 if ((Hud_stat_mask & HUD_array[i].stat) && (HUD_array[i].flags & HUD_FLAG_SMALL)) {
1274 HUD_array[i].dirty_rect.fill(GR_BLACK);
1275 }
1276 }
1277
1278 // messages.
1279 if ((Hud_stat_mask & STAT_MESSAGES)) {
1280 RenderHUDMsgDirtyRects();
1281 }
1282 }
1283 }
1284
1285 extern MsgListConsole Game_msg_con;
1286 extern MsgListConsole HUD_msg_con;
1287
1288 // render auxillary hud
1289 void RenderAuxHUDFrame() {
1290 // take care of any 'small hud' stuff
1291 // render hud array list for items drawn differently on a smaller hud.
1292 if (Small_hud_flag) {
1293 int cur_game_win_w = Game_window_w;
1294 int cur_game_win_h = Game_window_h;
1295 int cur_game_win_x = Game_window_x;
1296 int cur_game_win_y = Game_window_y;
1297 int i;
1298 uint16_t stat_mask = Hud_stat_mask;
1299
1300 // emulating hud that takes up entire screen
1301 Game_window_w = Max_window_w;
1302 Game_window_h = Max_window_h;
1303 Game_window_x = 0;
1304 Game_window_y = 0;
1305
1306 // determine hud rendering properties.
1307 Hud_aspect_x = (float)Game_window_w / DEFAULT_HUD_WIDTH;
1308 Hud_aspect_y = (float)Game_window_h / DEFAULT_HUD_HEIGHT;
1309
1310 for (i = 0; i < MAX_HUD_ITEMS; i++) {
1311 if ((stat_mask & HUD_array[i].stat) && (HUD_array[i].flags & HUD_FLAG_SMALL)) {
1312 if (!HUD_array[i].render_fn) {
1313 HudDisplayRouter(&HUD_array[i]);
1314 } else {
1315 (*HUD_array[i].render_fn)(&HUD_array[i]);
1316 }
1317 }
1318 }
1319
1320 // messages.
1321 if ((stat_mask & STAT_MESSAGES)) {
1322 RenderHUDMessages();
1323 }
1324
1325 grtext_Flush();
1326
1327 Game_window_w = cur_game_win_w;
1328 Game_window_h = cur_game_win_h;
1329 Game_window_x = cur_game_win_x;
1330 Game_window_y = cur_game_win_y;
1331 }
1332
1333 // render game and hud message consoles.
1334 Game_msg_con.DoInput();
1335 Game_msg_con.Draw();
1336 HUD_msg_con.DoInput();
1337 HUD_msg_con.Draw();
1338 }
1339
1340 char *GetControllerBindingText(int fidcont) {
1341 static char *cont_bind_txt;
1342 ct_type ctype[CTLBINDS_PER_FUNC];
1343 uint8_t cfgflags[CTLBINDS_PER_FUNC];
1344 ct_config_data cfgdata;
1345 tCfgDataParts cfgparts;
1346 if (-1 == fidcont)
1347 return NULL;
1348 cont_bind_txt = NULL;
1349 fidcont = CtlFindBinding(fidcont, false);
1350 if (fidcont == -1) // DAJ -1FIX
1351 return NULL;
1352
1353 Controller->get_controller_function(Cfg_joy_elements[fidcont].fn_id, ctype, &cfgdata, cfgflags);
1354 parse_config_data(&cfgparts, ctype[0], ctype[1], cfgdata);
1355 uint8_t one_binding = cfgparts.bind_0;
1356 uint8_t one_ctrlbind = cfgparts.ctrl_0;
1357
1358 cont_bind_txt = (char *)cfg_binding_text(ctype[0], one_ctrlbind, one_binding);
1359 return cont_bind_txt;
1360 }
1361
1362 char *GetKeyBindingText(int fidkey) {
1363 static char *key_bind_txt;
1364 ct_type ctype[CTLBINDS_PER_FUNC];
1365 uint8_t cfgflags[CTLBINDS_PER_FUNC];
1366 ct_config_data cfgdata;
1367 tCfgDataParts cfgparts;
1368 if (-1 == fidkey)
1369 return NULL;
1370 key_bind_txt = NULL;
1371 fidkey = CtlFindBinding(fidkey, true);
1372 if (fidkey == -1) // DAJ -1FIX
1373 return NULL;
1374
1375 Controller->get_controller_function(Cfg_key_elements[fidkey].fn_id, ctype, &cfgdata, cfgflags);
1376 parse_config_data(&cfgparts, ctype[0], ctype[1], cfgdata);
1377 uint8_t one_binding = cfgparts.bind_0;
1378 uint8_t one_ctrlbind = cfgparts.ctrl_0;
1379
1380 key_bind_txt = (char *)cfg_binding_text(ctype[0], one_ctrlbind, one_binding);
1381 return key_bind_txt;
1382 }
1383
1384 void DoEnabledControlsLine(const char *controlp, const char *keyp, const char *label, int y, const char *axis = NULL) {
1385 char control_text[200] = "";
1386
1387 strcpy(control_text, label);
1388 strcat(control_text, " : ");
1389 if (keyp)
1390 strcat(control_text, keyp);
1391 if (keyp && (controlp || axis))
1392 strcat(control_text, " / ");
1393 if (controlp)
1394 strcat(control_text, controlp);
1395 if (controlp && axis)
1396 strcat(control_text, " / ");
1397 if (axis)
1398 strcat(control_text, axis);
1399
1400 if (keyp || controlp || axis)
1401 RenderHUDTextFlags(0, GR_GREEN, HUD_ALPHA, 0, 30, y, control_text);
1402 }
1403
1404 extern bool Demo_make_movie;
1405
1406 #define HUD_KEYS_NEXT_LINE hudconty += 14
1407
1408 // iterate through entire hud item list to draw.
1409 void RenderHUDItems(tStatMask stat_mask) {
1410 static float framerate_timer = 0;
1411 static float last_fps;
1412 float font_aspect_x, font_aspect_y;
1413 int i;
1414
1415 grtext_Reset();
1416 grtext_SetFont(HUD_FONT);
1417
1418 // for lores screens, we use different fonts, so DONT SCALE.
1419 font_aspect_x = (float)Game_window_w / Max_window_w;
1420 font_aspect_y = (float)Game_window_h / Max_window_h;
1421
1422 if (font_aspect_x <= 0.60f) {
1423 grtext_SetFontScale(0.60f);
1424 } else if (font_aspect_x <= 0.80f) {
1425 grtext_SetFontScale(0.80f);
1426 } else {
1427 grtext_SetFontScale(1.0f);
1428 }
1429
1430 // do framerate calculations
1431 framerate_timer -= Frametime;
1432 while (framerate_timer < 0) {
1433 framerate_timer += FRAMERATE_TIME_DELAY;
1434 last_fps = GetFPS();
1435 }
1436
1437 // show framerate text gauge
1438 if (stat_mask & STAT_FPS) {
1439 RenderHUDText(HUD_COLOR, HUD_ALPHA, 0, 10, 10, "FPS: %.1f", last_fps);
1440 }
1441
1442 // show music spew
1443
1444 #ifdef _DEBUG
1445 if (Music_debug_verbose) {
1446 int min, sec;
1447 RenderHUDText(HUD_COLOR, HUD_ALPHA, 0, 10, 60, "Music: %s", IsD3MusicOn() ? "ON" : "OFF");
1448 RenderHUDText(HUD_COLOR, HUD_ALPHA, 0, 10, 72, "Region: %d", D3MusicGetRegion());
1449 RenderHUDText(HUD_COLOR, HUD_ALPHA, 0, 10, 84, "Song: %s", Music_type_names[Game_music_info.cur_song]);
1450 min = (int)(Game_music_info.peace_timer / 60);
1451 sec = (int)((Game_music_info.peace_timer / 60.0f - (float)min) * 60.0f);
1452 RenderHUDText(HUD_COLOR, HUD_ALPHA, 0, 10, 96, "Peace time: %d:%.2d", min, sec);
1453
1454 if (Game_music_info.cur_loop_name) {
1455 RenderHUDText(HUD_COLOR, HUD_ALPHA, 0, 10, 108, "Loop: %s", Game_music_info.cur_loop_name);
1456 }
1457 }
1458
1459 // show timer
1460 if (1) {
1461 // timer always displayed in debug builds.
1462 int min, sec, y;
1463
1464 min = (int)(Gametime / 60);
1465 sec = (int)((Gametime / 60.0f - (float)min) * 60.0f);
1466
1467 y = (Game_mode & GM_MULTI) ? 10 : 40;
1468
1469 RenderHUDText(HUD_COLOR, HUD_ALPHA, 0, 605, y, "%d:%.2d", min, sec);
1470 }
1471 #endif
1472
1473 // render hud array list.
1474 for (i = 0; i < MAX_HUD_ITEMS; i++) {
1475 if ((HUD_array[i].flags & HUD_FLAG_SMALL) && Small_hud_flag) {
1476 continue; // skip items renderered differently on a small hud if we are in a small hud (see RenderAUXHUDFrame)
1477 }
1478 if ((stat_mask & HUD_array[i].stat)) {
1479 if (!HUD_array[i].render_fn) {
1480 HudDisplayRouter(&HUD_array[i]);
1481 } else {
1482 (*HUD_array[i].render_fn)(&HUD_array[i]);
1483 }
1484 }
1485 }
1486 if (Demo_flags == DF_RECORDING) {
1487 RenderHUDTextFlags(HUDTEXT_CENTERED, GR_BLUE, HUD_ALPHA, 0, 10, 300, TXT_RECORDINGDEMO);
1488 } else if (Demo_flags == DF_PLAYBACK) {
1489 if (!Demo_make_movie) {
1490 if (Demo_paused) {
1491 RenderHUDTextFlags(HUDTEXT_CENTERED, GR_BLUE, HUD_ALPHA, 0, 10, 300, TXT_DEMOPAUSED);
1492 } else {
1493 RenderHUDTextFlags(HUDTEXT_CENTERED, GR_BLUE, HUD_ALPHA, 0, 10, 300, TXT_PLAYINGDEMO);
1494 }
1495 }
1496 }
1497
1498 // This is a big pain in the butt. It's for the training mission.
1499 if (Hud_show_controls && (Players[Player_num].controller_bitflags != 0xffffffff)) {
1500 char *controlp = NULL;
1501 char *keyp = NULL;
1502 char *axis = NULL;
1503 player *pp = &Players[Player_num];
1504 int fidkey = -1, fidcont = -1;
1505 int hudconty = 130;
1506
1507 RenderHUDTextFlags(0, GR_GREEN, HUD_ALPHA, 0, 15, hudconty, TXT_ENABLED_CONTROLS);
1508 HUD_KEYS_NEXT_LINE;
1509
1510 if (pp->controller_bitflags & PCBF_FORWARD) {
1511 keyp = GetKeyBindingText(ctfFORWARD_THRUSTKEY);
1512 controlp = GetControllerBindingText(ctfFORWARD_BUTTON);
1513 if (keyp || controlp) {
1514 DoEnabledControlsLine(controlp, keyp, TXT_ENABLED_CONT_FORWARD, hudconty);
1515 HUD_KEYS_NEXT_LINE;
1516 }
1517 }
1518 if (pp->controller_bitflags & PCBF_REVERSE) {
1519 keyp = GetKeyBindingText(ctfREVERSE_THRUSTKEY);
1520
1521 controlp = GetControllerBindingText(ctfREVERSE_BUTTON);
1522 if (keyp || controlp) {
1523 DoEnabledControlsLine(controlp, keyp, TXT_ENABLED_CONT_REVERSE, hudconty);
1524 HUD_KEYS_NEXT_LINE;
1525 }
1526 }
1527 if (pp->controller_bitflags & PCBF_LEFT) {
1528 keyp = GetKeyBindingText(ctfLEFT_THRUSTKEY);
1529 controlp = GetControllerBindingText(ctfLEFT_BUTTON);
1530 if (keyp || controlp) {
1531 DoEnabledControlsLine(controlp, keyp, TXT_ENABLED_CONT_SLIDELEFT, hudconty);
1532 HUD_KEYS_NEXT_LINE;
1533 }
1534 }
1535 if (pp->controller_bitflags & PCBF_RIGHT) {
1536 keyp = GetKeyBindingText(ctfRIGHT_THRUSTKEY);
1537 controlp = GetControllerBindingText(ctfRIGHT_BUTTON);
1538 if (keyp || controlp) {
1539 DoEnabledControlsLine(controlp, keyp, TXT_ENABLED_CONT_SLIDERIGHT, hudconty);
1540 HUD_KEYS_NEXT_LINE;
1541 }
1542 }
1543 if (pp->controller_bitflags & PCBF_UP) {
1544 keyp = GetKeyBindingText(ctfUP_THRUSTKEY);
1545 controlp = GetControllerBindingText(ctfUP_BUTTON);
1546 if (keyp || controlp) {
1547 DoEnabledControlsLine(controlp, keyp, TXT_ENABLED_CONT_SLIDEUP, hudconty);
1548 HUD_KEYS_NEXT_LINE;
1549 }
1550 }
1551 if (pp->controller_bitflags & PCBF_DOWN) {
1552 keyp = GetKeyBindingText(ctfDOWN_THRUSTKEY);
1553 controlp = GetControllerBindingText(ctfDOWN_BUTTON);
1554 if (keyp || controlp) {
1555 DoEnabledControlsLine(controlp, keyp, TXT_ENABLED_CONT_SLIDEDOWN, hudconty);
1556 HUD_KEYS_NEXT_LINE;
1557 }
1558 }
1559 if (pp->controller_bitflags & PCBF_PITCHUP) {
1560 axis = NULL;
1561 if ((pp->controller_bitflags & PCBF_PITCHUP) && (pp->controller_bitflags & PCBF_PITCHDOWN)) {
1562 axis = GetControllerBindingText(ctfPITCH_DOWNAXIS);
1563 }
1564 keyp = GetKeyBindingText(ctfPITCH_UPKEY);
1565 controlp = GetControllerBindingText(ctfPITCH_UPBUTTON);
1566 if (keyp || controlp || axis) {
1567 DoEnabledControlsLine(controlp, keyp, TXT_ENABLED_CONT_PITCHUP, hudconty, axis);
1568 HUD_KEYS_NEXT_LINE;
1569 }
1570 }
1571 if (pp->controller_bitflags & PCBF_PITCHDOWN) {
1572 axis = NULL;
1573 if ((pp->controller_bitflags & PCBF_PITCHUP) && (pp->controller_bitflags & PCBF_PITCHDOWN)) {
1574 axis = GetControllerBindingText(ctfPITCH_DOWNAXIS);
1575 }
1576 keyp = GetKeyBindingText(ctfPITCH_DOWNKEY);
1577 controlp = GetControllerBindingText(ctfPITCH_DOWNBUTTON);
1578 if (keyp || controlp || axis) {
1579 DoEnabledControlsLine(controlp, keyp, TXT_ENABLED_CONT_PITCHDOWN, hudconty, axis);
1580 HUD_KEYS_NEXT_LINE;
1581 }
1582 }
1583 /*
1584 else if((pp->controller_bitflags & PCBF_HEADINGLEFT) && (pp->controller_bitflags & PCBF_HEADINGRIGHT))
1585 {
1586 axis = GetControllerBindingText(ctfHEADING_RIGHTAXIS);
1587 DoEnabledControlsLine(NULL,NULL,"Pitch",hudconty);
1588 HUD_KEYS_NEXT_LINE;
1589
1590 }
1591 */
1592 if (pp->controller_bitflags & PCBF_HEADINGLEFT) {
1593 axis = NULL;
1594 if ((pp->controller_bitflags & PCBF_HEADINGLEFT) && (pp->controller_bitflags & PCBF_HEADINGRIGHT)) {
1595 axis = GetControllerBindingText(ctfHEADING_RIGHTAXIS);
1596 }
1597 keyp = GetKeyBindingText(ctfHEADING_LEFTKEY);
1598 controlp = GetControllerBindingText(ctfHEADING_LEFTBUTTON);
1599 if (keyp || controlp || axis) {
1600 DoEnabledControlsLine(controlp, keyp, TXT_ENABLED_CONT_HEADLEFT, hudconty, axis);
1601 HUD_KEYS_NEXT_LINE;
1602 }
1603 }
1604 if (pp->controller_bitflags & PCBF_HEADINGRIGHT) {
1605 axis = NULL;
1606 if ((pp->controller_bitflags & PCBF_HEADINGLEFT) && (pp->controller_bitflags & PCBF_HEADINGRIGHT)) {
1607 axis = GetControllerBindingText(ctfHEADING_RIGHTAXIS);
1608 }
1609 keyp = GetKeyBindingText(ctfHEADING_RIGHTKEY);
1610 controlp = GetControllerBindingText(ctfHEADING_RIGHTBUTTON);
1611 if (keyp || controlp || axis) {
1612 DoEnabledControlsLine(controlp, keyp, TXT_ENABLED_CONT_HEADRIGHT, hudconty, axis);
1613 HUD_KEYS_NEXT_LINE;
1614 }
1615 }
1616 if (pp->controller_bitflags & PCBF_BANKLEFT) {
1617 axis = NULL;
1618 if ((pp->controller_bitflags & PCBF_BANKLEFT) && (pp->controller_bitflags & PCBF_BANKLEFT)) {
1619 axis = GetControllerBindingText(ctfBANK_RIGHTAXIS);
1620 }
1621 keyp = GetKeyBindingText(ctfBANK_LEFTKEY);
1622 controlp = GetControllerBindingText(ctfBANK_LEFTBUTTON);
1623 if (keyp || controlp || axis) {
1624 DoEnabledControlsLine(controlp, keyp, TXT_ENABLED_CONT_BANKLEFT, hudconty, axis);
1625 HUD_KEYS_NEXT_LINE;
1626 }
1627 }
1628 if (pp->controller_bitflags & PCBF_BANKRIGHT) {
1629 axis = NULL;
1630 if ((pp->controller_bitflags & PCBF_BANKLEFT) && (pp->controller_bitflags & PCBF_BANKLEFT)) {
1631 axis = GetControllerBindingText(ctfBANK_RIGHTAXIS);
1632 }
1633 keyp = GetKeyBindingText(ctfBANK_RIGHTKEY);
1634 controlp = GetControllerBindingText(ctfBANK_RIGHTBUTTON);
1635 if (keyp || controlp || axis) {
1636 DoEnabledControlsLine(controlp, keyp, TXT_ENABLED_CONT_BANKRIGHT, hudconty, axis);
1637 HUD_KEYS_NEXT_LINE;
1638 }
1639 }
1640 if (pp->controller_bitflags & PCBF_PRIMARY) {
1641 keyp = GetKeyBindingText(ctfFIREPRIMARY_KEY);
1642 controlp = GetControllerBindingText(ctfFIREPRIMARY_BUTTON);
1643 if (keyp || controlp) {
1644 DoEnabledControlsLine(controlp, keyp, TXT_ENABLED_CONT_PRIMWEAP, hudconty);
1645 HUD_KEYS_NEXT_LINE;
1646 }
1647 }
1648 if (pp->controller_bitflags & PCBF_SECONDARY) {
1649 keyp = GetKeyBindingText(ctfFIRESECONDARY_KEY);
1650 controlp = GetControllerBindingText(ctfFIRESECONDARY_BUTTON);
1651 if (keyp || controlp) {
1652 DoEnabledControlsLine(controlp, keyp, TXT_ENABLED_CONT_SECWEAP, hudconty);
1653 HUD_KEYS_NEXT_LINE;
1654 }
1655 }
1656 if (pp->controller_bitflags & PCBF_AFTERBURNER) {
1657 keyp = GetKeyBindingText(ctfAFTERBURN_KEY);
1658 controlp = GetControllerBindingText(ctfAFTERBURN_BUTTON);
1659 if (keyp || controlp) {
1660 DoEnabledControlsLine(controlp, keyp, TXT_ENABLED_CONT_AFTERBURN, hudconty);
1661 HUD_KEYS_NEXT_LINE;
1662 }
1663 }
1664 }
1665
1666 // render hud messages. if in a small hud, don't do it now but inside RenderAuxHUDFrame
1667 if ((stat_mask & STAT_MESSAGES) && !Small_hud_flag) {
1668 RenderHUDMessages();
1669 }
1670 #if 0
1671 grtext_SetColor(GR_GREEN);
1672 grtext_SetAlpha(128);
1673 grtext_SetFont(BIG_BRIEFING_FONT);
1674 grtext_CenteredPrintf(0,300,"Beta Version");
1675 #endif
1676 grtext_Flush();
1677 }
1678
1679 //////////////////////////////////////////////////////////////////////////////
1680 // RETICLE SYSTEM
1681
1682 #include "robotfire.h"
1683
1684 #define RET_IMAGE_WIDTH 32
1685 #define RET_IMAGE_HEIGHT 32
1686
1687 #define MAX_RETICLE_ELEMS 18
1688 #define RET_CPRIMARY 0
1689 #define RET_L1PRIMARY 1
1690 #define RET_R1PRIMARY 2
1691 #define RET_L2PRIMARY 3
1692 #define RET_R2PRIMARY 4
1693 #define RET_CPRIMARY2 5
1694 #define RET_CSECONDARY 8
1695 #define RET_L1SECONDARY 9
1696 #define RET_R1SECONDARY 10
1697 #define RET_L2SECONDARY 11
1698 #define RET_R2SECONDARY 12
1699 #define RET_LGUNSIGHT 16
1700 #define RET_RGUNSIGHT 17
1701
1702 /*
1703 $$TABLE_GAMEFILE "ret_pr0a.ogf"
1704 $$TABLE_GAMEFILE "ret_pr0b.ogf"
1705 $$TABLE_GAMEFILE "ret_pr1b.ogf"
1706 $$TABLE_GAMEFILE "ret_pr2b.ogf"
1707 $$TABLE_GAMEFILE "ret_pr3b.ogf"
1708 $$TABLE_GAMEFILE "ret_pr4b.ogf"
1709 $$TABLE_GAMEFILE "ret_pr13a.ogf"
1710 $$TABLE_GAMEFILE "ret_pr24a.ogf"
1711 $$TABLE_GAMEFILE "ret_se0a.ogf"
1712 $$TABLE_GAMEFILE "ret_se1a.ogf"
1713 $$TABLE_GAMEFILE "ret_se2a.ogf"
1714 $$TABLE_GAMEFILE "ret_se3a.ogf"
1715 $$TABLE_GAMEFILE "ret_se4a.ogf"
1716 $$TABLE_GAMEFILE "ret_se0b.ogf"
1717 $$TABLE_GAMEFILE "ret_se1b.ogf"
1718 $$TABLE_GAMEFILE "ret_se2b.ogf"
1719 $$TABLE_GAMEFILE "ret_se3b.ogf"
1720 $$TABLE_GAMEFILE "ret_se4b.ogf"
1721 $$TABLE_GAMEFILE "ret_lguna.ogf"
1722 $$TABLE_GAMEFILE "ret_rguna.ogf"
1723 $$TABLE_GAMEFILE "ret_pr5a.ogf"
1724 $$TABLE_GAMEFILE "ret_pr5b.ogf"
1725
1726 $$TABLE_GAMEFILE "phx_pr0a.ogf"
1727 $$TABLE_GAMEFILE "phx_pr0b.ogf"
1728 $$TABLE_GAMEFILE "phx_pr1b.ogf"
1729 $$TABLE_GAMEFILE "phx_pr2b.ogf"
1730 $$TABLE_GAMEFILE "phx_pr3b.ogf"
1731 $$TABLE_GAMEFILE "phx_pr4b.ogf"
1732 $$TABLE_GAMEFILE "phx_pr13a.ogf"
1733 $$TABLE_GAMEFILE "phx_pr24a.ogf"
1734 $$TABLE_GAMEFILE "phx_se0a.ogf"
1735 $$TABLE_GAMEFILE "phx_se1a.ogf"
1736 $$TABLE_GAMEFILE "phx_se2a.ogf"
1737 $$TABLE_GAMEFILE "phx_se3a.ogf"
1738 $$TABLE_GAMEFILE "phx_se4a.ogf"
1739 $$TABLE_GAMEFILE "phx_se0b.ogf"
1740 $$TABLE_GAMEFILE "phx_se1b.ogf"
1741 $$TABLE_GAMEFILE "phx_se2b.ogf"
1742 $$TABLE_GAMEFILE "phx_se3b.ogf"
1743 $$TABLE_GAMEFILE "phx_se4b.ogf"
1744 $$TABLE_GAMEFILE "phx_lguna.ogf"
1745 $$TABLE_GAMEFILE "phx_rguna.ogf"
1746 $$TABLE_GAMEFILE "phx_pr5a.ogf"
1747 $$TABLE_GAMEFILE "phx_pr5b.ogf"
1748
1749 $$TABLE_GAMEFILE "mag_pr0a.ogf"
1750 $$TABLE_GAMEFILE "mag_pr0b.ogf"
1751 $$TABLE_GAMEFILE "mag_pr1b.ogf"
1752 $$TABLE_GAMEFILE "mag_pr2b.ogf"
1753 $$TABLE_GAMEFILE "mag_pr3b.ogf"
1754 $$TABLE_GAMEFILE "mag_pr4b.ogf"
1755 $$TABLE_GAMEFILE "mag_pr13a.ogf"
1756 $$TABLE_GAMEFILE "mag_pr24a.ogf"
1757 $$TABLE_GAMEFILE "mag_se0a.ogf"
1758 $$TABLE_GAMEFILE "mag_se1a.ogf"
1759 $$TABLE_GAMEFILE "mag_se2a.ogf"
1760 $$TABLE_GAMEFILE "mag_se3a.ogf"
1761 $$TABLE_GAMEFILE "mag_se4a.ogf"
1762 $$TABLE_GAMEFILE "mag_se0b.ogf"
1763 $$TABLE_GAMEFILE "mag_se1b.ogf"
1764 $$TABLE_GAMEFILE "mag_se2b.ogf"
1765 $$TABLE_GAMEFILE "mag_se3b.ogf"
1766 $$TABLE_GAMEFILE "mag_se4b.ogf"
1767 $$TABLE_GAMEFILE "mag_lguna.ogf"
1768 $$TABLE_GAMEFILE "mag_rguna.ogf"
1769 $$TABLE_GAMEFILE "mag_pr5a.ogf"
1770 $$TABLE_GAMEFILE "mag_pr5b.ogf"
1771 */
1772
1773 // this should map to the reticle element defines
1774 // column 0 = off bitmap
1775 // column 1 = on bitmap (if any).
1776 // column 2 = left, center or right aligned bitmap.
1777 const char *Reticle_image_names[MAX_RETICLE_ELEMS][3] = {
1778 {"_pr0a.ogf", "_pr0b.ogf", "c"},
1779 {"_pr13a.ogf", "_pr1b.ogf", "l"}, // gp1
1780 {"_pr24a.ogf", "_pr2b.ogf", "r"}, // gp2
1781 {"_pr13a.ogf", "_pr3b.ogf", "l"}, // since off version is same as gp1
1782 {"_pr24a.ogf", "_pr4b.ogf", "r"}, // since off version is same as gp2
1783 {"_pr5a.ogf", "_pr5b.ogf", "c"}, // center gunpoint version of gp0 (ammo based, single gp)
1784 {NULL, NULL, "l"},
1785 {NULL, NULL, "l"},
1786 {"_se0a.ogf", "_se0b.ogf", "c"},
1787 {"_se1a.ogf", "_se1b.ogf", "l"},
1788 {"_se2a.ogf", "_se2b.ogf", "r"},
1789 {"_se3a.ogf", "_se3b.ogf", "l"},
1790 {"_se4a.ogf", "_se4b.ogf", "r"},
1791 {NULL, NULL, "l"},
1792 {NULL, NULL, "l"},
1793 {NULL, NULL, "l"},
1794 {"_lguna.ogf", NULL, "l"},
1795 {"_rguna.ogf", NULL, "r"}};
1796
1797 // reticle slot element array
1798 static struct {
1799 int bmp_off;
1800 int bmp_on;
1801 char align; // 'l', 'r', or 'c' (clever, huh?)
1802 } Reticle_elem_array[MAX_RETICLE_ELEMS];
1803
1804 const int Ret_prim_wb[MAX_WB_GUNPOINTS + 1] = {
1805 RET_CPRIMARY, // reserved for NON mass driver
1806 RET_R1PRIMARY, RET_L1PRIMARY, RET_R2PRIMARY, RET_L2PRIMARY, -1, -1, -1,
1807 RET_CPRIMARY2 // reserved for mass driver slot weapons.
1808 };
1809
1810 const int Ret_sec_wb[MAX_WB_GUNPOINTS + 1] = {
1811 RET_CSECONDARY, RET_R1SECONDARY, RET_L1SECONDARY, RET_R2SECONDARY, RET_L2SECONDARY, -1, -1, -1, -1};
1812
1813 #define RETMASK_FLAG_AUXPRIMARY0 (1 << 8) // matches 9th bit (bit 8) of reticle mask
1814
1815 static uint16_t Ret_prim_mask = 0;
1816 static uint16_t Ret_sec_mask = 0;
1817
1818 // Initializes Reticle on Hud. Usually called when weapon changes.
1819 void InitReticle(int primary_slots, int secondary_slots) {
1820 int i;
1821
1822 for (i = 0; i < MAX_RETICLE_ELEMS; i++) {
1823 char filename[PSFILENAME_LEN + 1];
1824
1825 if (Reticle_image_names[i][0] && primary_slots >= 0) {
1826 snprintf(filename, sizeof(filename), "%s%s", Reticle_prefix, Reticle_image_names[i][0]);
1827 Reticle_elem_array[i].bmp_off = bm_AllocLoadFileBitmap(IGNORE_TABLE(filename), 0);
1828 if (Reticle_elem_array[i].bmp_off <= BAD_BITMAP_HANDLE) {
1829 Reticle_elem_array[i].bmp_off = -1;
1830 mprintf(0, "Unable to load %s reticle image.\n", filename);
1831 }
1832 } else {
1833 Reticle_elem_array[i].bmp_off = -1;
1834 }
1835
1836 if (Reticle_image_names[i][1] && primary_slots >= 0) {
1837 snprintf(filename, sizeof(filename), "%s%s", Reticle_prefix, Reticle_image_names[i][1]);
1838 Reticle_elem_array[i].bmp_on = bm_AllocLoadFileBitmap(IGNORE_TABLE(filename), 0);
1839 if (Reticle_elem_array[i].bmp_on <= BAD_BITMAP_HANDLE) {
1840 mprintf(0, "Unable to load %s reticle image.\n", filename);
1841 Reticle_elem_array[i].bmp_on = -1;
1842 }
1843 } else {
1844 Reticle_elem_array[i].bmp_on = -1;
1845 }
1846
1847 Reticle_elem_array[i].align = Reticle_image_names[i][2][0];
1848 }
1849 }
1850
1851 // frees up bitmaps associated with reticle.
1852 void FreeReticle() {
1853 int i;
1854
1855 for (i = 0; i < MAX_RETICLE_ELEMS; i++) {
1856 if (Reticle_elem_array[i].bmp_off > BAD_BITMAP_HANDLE)
1857 bm_FreeBitmap(Reticle_elem_array[i].bmp_off);
1858 Reticle_elem_array[i].bmp_off = -1;
1859 if (Reticle_elem_array[i].bmp_on > BAD_BITMAP_HANDLE)
1860 bm_FreeBitmap(Reticle_elem_array[i].bmp_on);
1861 Reticle_elem_array[i].bmp_on = -1;
1862 }
1863 }
1864
1865 // resets reticle based off current player object.
1866 // and the ship's weapon configuration
1867 void ResetReticle() {
1868 player *player = &Players[Player_num];
1869 object *pobj = &Objects[player->objnum];
1870
1871 ASSERT(player->objnum >= 0);
1872
1873 // Make sure we're not resetting a non-existent object
1874 if (!pobj || (pobj->type != OBJ_PLAYER && pobj->type != OBJ_GHOST && pobj->type != OBJ_OBSERVER))
1875 return;
1876
1877 poly_model *pm = &Poly_models[Objects[player->objnum].rtype.pobj_info.model_num];
1878 otype_wb_info *prim_wb = &Ships[player->ship_index].static_wb[player->weapon[PW_PRIMARY].index];
1879 otype_wb_info *sec_wb = &Ships[player->ship_index].static_wb[player->weapon[PW_SECONDARY].index];
1880 dynamic_wb_info *prim_dyn_wb = &pobj->dynamic_wb[player->weapon[PW_PRIMARY].index];
1881
1882 int i, j;
1883
1884 // assign reticle elements to the Ret_prim_xx array.
1885 // create battery mask
1886 Ret_prim_mask = 0;
1887
1888 // iterate through all battery masks to determine which gun points occupy the primary weapon
1889 // on the player ship!
1890 for (j = 0; j < prim_wb->num_masks; j++) {
1891 for (i = 0; i < pm->poly_wb[0].num_gps; i++) {
1892 if (prim_wb->gp_fire_masks[j] & (1 << i)) {
1893 Ret_prim_mask |= (1 << i);
1894 } else if ((prim_dyn_wb->flags & DWBF_QUAD) && (prim_wb->gp_quad_fire_mask & (1 << i))) {
1895 Ret_prim_mask |= (1 << i);
1896 }
1897 }
1898 }
1899
1900 if (player->weapon[PW_PRIMARY].index == MASSDRIVER_INDEX && (Ret_prim_mask & (1 << 0))) {
1901 // special hack for mass driver weapons
1902 Ret_prim_mask &= (~(1 << 0));
1903 Ret_prim_mask |= RETMASK_FLAG_AUXPRIMARY0;
1904 }
1905
1906 // iterate through all battery masks to determine which gun points occupy the secondary weapon
1907 // on the player ship!
1908 Ret_sec_mask = 0;
1909
1910 for (j = 0; j < sec_wb->num_masks; j++) {
1911 for (i = 0; i < pm->poly_wb[0].num_gps; i++) {
1912 if (sec_wb->gp_fire_masks[j] & (1 << i))
1913 Ret_sec_mask |= (1 << i);
1914 }
1915 }
1916 }
1917
1918 // creates the reticle display bitmap mask to be used by the reticle renderer.
1919 static inline uint16_t reticle_mask(object *pobj, otype_wb_info *static_wb, int wb_index) {
1920 poly_model *pm = &Poly_models[pobj->rtype.pobj_info.model_num];
1921 dynamic_wb_info *dyn_wb = &pobj->dynamic_wb[wb_index];
1922 unsigned mask = 0;
1923 int i;
1924
1925 // determine if weapon battery is charged, if not, then return 0, indicating no 'on' weapon baterries
1926 if (!WBIsBatteryReady(pobj, static_wb, wb_index))
1927 return 0;
1928
1929 if (static_wb->ammo_usage) {
1930 if (Players[pobj->id].weapon_ammo[wb_index] == 0)
1931 return 0;
1932 } else if (static_wb->energy_usage) {
1933 if (Players[pobj->id].energy < static_wb->energy_usage)
1934 return 0;
1935 }
1936
1937 // create battery mask
1938 for (i = 0; i < pm->poly_wb[0].num_gps; i++) {
1939 if (static_wb->gp_fire_masks[dyn_wb->cur_firing_mask] & (1 << i)) {
1940 mask |= (1 << i);
1941 } else if ((dyn_wb->flags & DWBF_QUAD) && (static_wb->gp_quad_fire_mask & (1 << i))) {
1942 mask |= (1 << i);
1943 }
1944 }
1945
1946 if (wb_index == MASSDRIVER_INDEX && (mask & (1 << 0))) {
1947 // special hack for mass driver weapons
1948 mask &= (~(1 << 0));
1949 mask |= RETMASK_FLAG_AUXPRIMARY0;
1950 }
1951
1952 return mask;
1953 }
1954
1955 static inline void draw_reticle_sub(int cx, int cy, int rw, int rh, uint16_t on_mask, uint16_t gp_mask, const int *wb_elem_array) {
1956 int i, x, y;
1957 int bmp_handle;
1958 char align;
1959
1960 for (i = 0; i < (MAX_WB_GUNPOINTS + 1); i++) {
1961 if (gp_mask & (1 << i)) {
1962 // we can definitely draw a reticle image, which one is the question now.
1963 ASSERT(wb_elem_array[i] > -1);
1964 if (on_mask & (1 << i))
1965 bmp_handle = Reticle_elem_array[wb_elem_array[i]].bmp_on;
1966 else
1967 bmp_handle = Reticle_elem_array[wb_elem_array[i]].bmp_off;
1968 align = Reticle_elem_array[wb_elem_array[i]].align;
1969
1970 if (bmp_handle > -1) {
1971 // draw on image based off of alignment to cx,cy and 'align'
1972 switch (align) {
1973 case 'l':
1974 x = cx - rw;
1975 y = cy - rh / 2;
1976 break;
1977 case 'r':
1978 x = cx;
1979 y = cy - rh / 2;
1980 break;
1981 case 'c':
1982 x = cx - rw / 2;
1983 y = cy - rh / 2;
1984 break;
1985 default:
1986 x = cx;
1987 y = cy;
1988 Int3();
1989 }
1990
1991 RenderHUDQuad(x, y, rw, rh, 0, 0, 1, 1, bmp_handle, 192);
1992 }
1993 }
1994 }
1995 }
1996
1997 // renders the reticle
1998 void RenderReticle() {
1999 static uint16_t primary_index_last_frame = 0xffff;
2000 static bool quad_primary_last_frame = false;
2001 player *player = &Players[Player_num];
2002 object *pobj = &Objects[player->objnum];
2003 ship *ship = &Ships[player->ship_index];
2004 player_weapon *prim_pw = &player->weapon[PW_PRIMARY];
2005 player_weapon *sec_pw = &player->weapon[PW_SECONDARY];
2006 int prim_wb_index = prim_pw->index;
2007 int sec_wb_index = sec_pw->index;
2008 otype_wb_info *prim_wb = &ship->static_wb[prim_wb_index];
2009 otype_wb_info *sec_wb = &ship->static_wb[sec_wb_index];
2010 dynamic_wb_info *prim_dyn_wb = &pobj->dynamic_wb[prim_wb_index];
2011
2012 int cx = Ret_x_off + (FIXED_SCREEN_WIDTH >> 1);
2013 int cy = Ret_y_off + (FIXED_SCREEN_HEIGHT >> 1) + 6;
2014 int rw = RET_IMAGE_WIDTH;
2015 int rh = RET_IMAGE_HEIGHT;
2016
2017 // quad weapon check hack (any weapon states that change should be noted here.)
2018 if (prim_dyn_wb->flags & DWBF_QUAD) {
2019 if (!quad_primary_last_frame || primary_index_last_frame != prim_wb_index) {
2020 ResetReticle();
2021 }
2022 quad_primary_last_frame = true;
2023 } else {
2024 if (quad_primary_last_frame) {
2025 ResetReticle();
2026 }
2027 quad_primary_last_frame = false;
2028 }
2029
2030 primary_index_last_frame = prim_wb_index;
2031
2032 // determine which primary batteries are open.
2033 draw_reticle_sub(cx, cy, rw, rh, reticle_mask(pobj, prim_wb, prim_wb_index), Ret_prim_mask, Ret_prim_wb);
2034 draw_reticle_sub(cx, cy, rw, rh, reticle_mask(pobj, sec_wb, sec_wb_index), Ret_sec_mask, Ret_sec_wb);
2035
2036 if (Reticle_elem_array[RET_LGUNSIGHT].bmp_off > -1)
2037 RenderHUDQuad(cx - rw, cy - rh / 2, rw, rh, 0, 0, 1, 1, Reticle_elem_array[RET_LGUNSIGHT].bmp_off, 192);
2038
2039 if (Reticle_elem_array[RET_RGUNSIGHT].bmp_off > -1)
2040 RenderHUDQuad(cx, cy - rh / 2, rw, rh, 0, 0, 1, 1, Reticle_elem_array[RET_RGUNSIGHT].bmp_off, 192);
2041 }
2042
2043 // renders missile reticle
2044 void RenderMissileReticle() {
2045 // Crosshair reticle
2046 int cx = Game_window_w / 2;
2047 int cy = Game_window_h / 2;
2048
2049 RenderHUDTextFlags(HUDTEXT_CENTERED, GR_RED, HUD_ALPHA, 0, 10, cy - 50, TXT_HUD_GUIDED);
2050 grtext_Flush();
2051
2052 rend_SetZBufferState(0);
2053 rend_SetFlatColor(GR_GREEN);
2054
2055 rend_DrawLine(cx - 6, cy, cx + 6, cy);
2056 rend_DrawLine(cx, cy - 6, cx, cy + 6);
2057 rend_SetZBufferState(1);
2058 }
2059
2060 // renders missile reticle
2061 void RenderZoomReticle() {
2062 // Crosshair reticle
2063 int cx = Game_window_w / 2;
2064 int cy = Game_window_h / 2;
2065 int text_height = grfont_GetHeight(HUD_FONT);
2066 char str[255];
2067
2068 RenderHUDTextFlags(HUDTEXT_CENTERED, GR_RED, HUD_ALPHA, 0, 10, cy - 50, TXT_HUD_ZOOM);
2069
2070 snprintf(str, sizeof(str), TXT_HUD_ZOOM_UNITS, Players[Player_num].zoom_distance);
2071
2072 RenderHUDTextFlags(HUDTEXT_CENTERED, GR_RED, HUD_ALPHA, 0, 10, cy - 50 + text_height, str);
2073 grtext_Flush();
2074
2075 rend_SetZBufferState(0);
2076
2077 if (Players[Player_num].flags & PLAYER_FLAGS_BULLSEYE)
2078 rend_SetFlatColor(GR_RED);
2079 else
2080 rend_SetFlatColor(GR_GREEN);
2081
2082 rend_DrawLine(cx - 8, cy, cx + 8, cy);
2083 rend_DrawLine(cx, cy - 8, cx, cy + 8);
2084 }
2085
2086 /*
2087 // HUD FILE FUNCTIONS
2088 #define HUDCMD_NUM 22
2089 #define HUDCMD_TYPE 0
2090 #define HUDCMD_RED 1
2091 #define HUDCMD_GREEN 2
2092 #define HUDCMD_BLUE 3
2093 #define HUDCMD_X 4
2094 #define HUDCMD_Y 5
2095 #define HUDCMD_TX 6
2096 #define HUDCMD_TY 7
2097 #define HUDCMD_CREATE 8
2098 #define HUDCMD_SAT 9
2099 #define HUDCMD_SPECIAL 10
2100 #define HUDCMD_CKPTMODEL 11
2101 #define HUDCMD_AFTERBURN 12
2102 #define HUDCMD_ENERGY 13
2103 #define HUDCMD_INVPULSE 14
2104 #define HUDCMD_SHIP 15
2105 #define HUDCMD_SHIELDIMG0 16
2106 #define HUDCMD_SHIELDIMG1 17
2107 #define HUDCMD_SHIELDIMG2 18
2108 #define HUDCMD_SHIELDIMG3 19
2109 #define HUDCMD_SHIELDIMG4 20
2110 #define HUDCMD_ALPHA 21
2111
2112 const char *HUDCommands[HUDCMD_NUM] = {
2113 "type",
2114 "r",
2115 "g",
2116 "b",
2117 "x",
2118 "y",
2119 "tx",
2120 "ty",
2121 "create",
2122 "sat",
2123 "special",
2124 "ckptmodel",
2125 "afterburnimg",
2126 "energyimg",
2127 "invpulseimg",
2128 "shipimg",
2129 "shieldimg0",
2130 "shieldimg1",
2131 "shieldimg2",
2132 "shieldimg3",
2133 "shieldimg4",
2134 "alpha"
2135 };
2136
2137
2138 int HUDLex(const char *command)
2139 {
2140 for (int i = 0; i < HUDCMD_NUM; i++)
2141 if (strcmp(HUDCommands[i], command) == 0)
2142 return i;
2143
2144 return INFFILE_ERROR;
2145 }
2146
2147
2148 // takes a filename containing oms data.
2149 void LoadHudConfig(const char *filename, bool (*fn)(const char*, const char *, void*), void *ext_data)
2150 {
2151 InfFile inf;
2152 tHUDItem hud_item;
2153 char operand[INFFILE_LINELEN]; // operand
2154 bool txpos = false, typos = false;
2155 uint8_t r=GR_COLOR_RED(HUD_COLOR);
2156 uint8_t g=GR_COLOR_GREEN(HUD_COLOR);
2157 uint8_t b=GR_COLOR_BLUE(HUD_COLOR);
2158
2159 // start over.
2160 ResetHud();
2161
2162 memset(&hud_item, 0, sizeof(hud_item));
2163 hud_item.alpha = HUD_ALPHA;
2164
2165 // open file
2166 if (!inf.Open(file, "[hud file]", HUDLex)) {
2167 Warning("Unable to find requested theme %s or bad file.\n", file);
2168 return false;
2169 }
2170
2171 // check if valid cockpit file
2172 while (inf.ReadLine())
2173 {
2174 int cmd;
2175
2176 while ((cmd = inf.ParseLine(operand, INFFILE_LINELEN)) > INFFILE_ERROR)
2177 {
2178 switch (cmd)
2179 {
2180 case HUDCMD_TYPE: hud_item.type = atoi(operand); break;
2181 case HUDCMD_RED: r=(uint8_t)atoi(operand); break;
2182 case HUDCMD_GREEN: g=(uint8_t)atoi(operand); break;
2183 case HUDCMD_BLUE: b=(uint8_t)atoi(operand); break;
2184 case HUDCMD_X: hud_item.x = atoi(operand); break;
2185 case HUDCMD_Y: hud_item.y = atoi(operand); break;
2186 case HUDCMD_TX: hud_item.tx = atoi(operand); txpos = true; break;
2187 case HUDCMD_TY: hud_item.ty = atoi(operand); typos = true; break;
2188 case HUDCMD_SAT: hud_item.saturation_count = atoi(operand); break;
2189 case HUDCMD_SPECIAL: hud_item.stat |= STAT_SPECIAL; break;
2190 case HUDCMD_ALPHA: hud_item.alpha = atoi(operand); break;
2191 case HUDCMD_CREATE:
2192 hud_item.color = GR_RGB(r,g,b);
2193 if (!txpos) hud_item.tx = hud_item.x;
2194 if (!typos) hud_item.ty = hud_item.y;
2195 hud_item.render_fn = HudDisplayRouter;
2196 AddHudItem(&hud_item);
2197
2198 memset(&hud_item, 0, sizeof(hud_item));
2199 hud_item.alpha = HUD_ALPHA;
2200 r=GR_COLOR_RED(HUD_COLOR);
2201 g=GR_COLOR_GREEN(HUD_COLOR);
2202 b=GR_COLOR_BLUE(HUD_COLOR);
2203 txpos = false;
2204 typos = false;
2205 break;
2206 case HUDCMD_AFTERBURN:
2207 case HUDCMD_ENERGY:
2208 case HUDCMD_INVPULSE:
2209 case HUDCMD_SHIP:
2210 case HUDCMD_SHIELDIMG0:
2211 case HUDCMD_SHIELDIMG1:
2212 case HUDCMD_SHIELDIMG2:
2213 case HUDCMD_SHIELDIMG3:
2214 case HUDCMD_SHIELDIMG4:
2215 case HUDCMD_CKPTMODEL:
2216 default:
2217 if (fn && !(*fn)(HUDCommands[cmd], operand, ext_data)) {
2218 goto force_error;
2219 }
2220 }
2221 }
2222
2223 force_error:
2224 if (cmd == INFFILE_ERROR)
2225 Warning("Error in hud file %s line %d.\n", file, inf.line());
2226 }
2227
2228 inf.Close();
2229
2230 return true;
2231 }
2232
2233 */