Debian Codegraph @

Descent3/TelComAutoMap.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/TelComAutoMap.cpp $
21 * $Revision: 37 $
22 * $Date: 7/20/99 4:59p $
23 * $Author: Samir $
24 *
25 * TelCom Automap
26 *
27 * $Log: /DescentIII/main/TelComAutoMap.cpp $
28 *
29 * 37 7/20/99 4:59p Samir
30 * automap key will close automap.
31 *
32 * 36 5/13/99 3:42p Ardussi
33 * changes for compiling on the Mac
34 *
35 * 35 4/24/99 6:46p Jeff
36 * added functions for theif so he can steal things other than weapons
37 *
38 * 34 4/24/99 5:45p Matt
39 * Made the marker message use a localizable string.
40 *
41 * 33 4/24/99 1:54a Matt
42 * Changed to use briefing font for labels at bottom, and HUD font for
43 * name at top.
44 *
45 * 32 4/14/99 11:44a Jason
46 * fixes for secret rooms
47 *
48 * 31 4/14/99 3:57a Jeff
49 * fixed case mismatch in #includes
50 *
51 * 30 4/11/99 2:24p Kevin
52 * made AM_rotated_points dynamically allocated so it's only used if you
53 * go into the automap. Should help dedicated servers quite a bit.
54 *
55 * 29 4/02/99 5:42p Jason
56 * display level info name instead of current level name. Confused?
57 * Yeah, so am I.
58 *
59 * 28 4/01/99 5:58p Jason
60 * automap now tells you exactly where you haven't gone yet...dunno if
61 * this is a good thing. If enough people bitch then I will change it.
62 *
63 * 27 3/31/99 5:29p Jeff
64 * new way of key processesing...can capture printscreen now
65 *
66 * 26 3/29/99 7:30p Jason
67 * added fading doors
68 *
69 * 25 2/25/99 11:02p Jeff
70 * fixed automap rendering
71 *
72 * 24 2/24/99 6:23p Samir
73 * poll controls if in automap, not suspend and resume per frame.
74 *
75 * 23 2/22/99 3:37p Jason
76 * fixed markers in telcom
77 *
78 * 22 2/15/99 5:32p Jason
79 * made ship blink in automap
80 *
81 * 21 2/01/99 4:35p Jeff
82 * tab exits the automap
83 *
84 * 20 1/29/99 7:13p Jeff
85 * localization
86 *
87 * 19 1/29/99 11:29a Jason
88 * added misc bug fixes/features
89 *
90 * 18 1/21/99 11:15p Jeff
91 * pulled out some structs and defines from header files and moved them
92 * into seperate header files so that multiplayer dlls don't require major
93 * game headers, just those new headers. Side effect is a shorter build
94 * time. Also cleaned up some header file #includes that weren't needed.
95 * This affected polymodel.h, object.h, player.h, vecmat.h, room.h,
96 * manage.h and multi.h
97 *
98 * 17 12/23/98 3:08p Jason
99 * added new player ship
100 *
101 * 16 12/16/98 4:17p Jason
102 * draw external rooms no matter what
103 *
104 * 15 12/15/98 4:39p Jason
105 * added some more telcom functions
106 *
107 * 14 12/14/98 11:57a Jason
108 * changes for visibile automap
109 *
110 * 13 12/14/98 11:06a Jason
111 * changes for 1.1
112 *
113 * 12 12/11/98 11:37a Jason
114 *
115 * 11 12/09/98 2:52p Jason
116 * fixed automap problem on terrain
117 *
118 * 10 12/09/98 2:36p Jeff
119 * added function to enable/disable telcom system keys and disabled most
120 * system keys while in Automap
121 *
122 * 9 12/09/98 1:09p Jason
123 * second draft of automap
124 *
125 * 8 12/07/98 5:37p Jason
126 * first pass at automap
127 *
128 * 7 8/28/98 12:57p Jeff
129 * added sounds and some key functionality
130 *
131 * 6 8/27/98 2:51p Jeff
132 * New TelCom finally checked in
133 *
134 * 5 7/28/98 12:02p Jeff
135 * got file prepared for Matt to implement Automap
136 *
137 * 4 7/11/98 9:16p Jeff
138 * moved automatically drawing monitor overlay graphics from update() to a
139 * function of it's own, that way the TelCom API can be avoided if needed
140 *
141 * 3 6/16/98 10:54a Jeff
142 *
143 * 2 5/18/98 2:23p Jeff
144 * Automap displays stand-in art right now
145 *
146 * $NoKeywords: $
147 */
148
149 #include "TelComAutoMap.h"
150 #include <stdlib.h>
151 #include <string.h>
152 #include <ctype.h>
153
154 #include "cfile.h"
155 #include "pserror.h"
156 #include "ddio.h"
157 #include "bitmap.h"
158 #include "room.h"
159
160 #include "TelCom.h"
161 #include "TelComEffects.h"
162 #include "renderer.h"
163 #include "game.h"
164 #include "mem.h"
165 #include "stringtable.h"
166 #include "lightmap_info.h"
167 #include "lightmap.h"
168 #include "controls.h"
169 #include "terrain.h"
170 #include "config.h"
171 #include "gameloop.h"
172 #include "multi.h"
173 #include "fireball.h"
174 #include "gamesequence.h"
175 #include "Mission.h"
176 #include "polymodel.h"
177 #include "player.h"
178 #include "marker.h"
179 #include "hlsoundlib.h"
180
181 // Variables needed for automap
182 static vector AM_view_pos = {0, 0, 0};
183 static matrix AM_view_orient;
184 static tTelComInfo *AM_tcs;
185 static int AM_ship_model_handle = -1;
186
187 uint8_t AutomapVisMap[MAX_ROOMS];
188
189 static float AM_heading;
190 static float AM_pitch;
191
192 int AM_terrain = 0, AM_realign = 0, AM_center_on_player = 0, AM_current_marker;
193
194 static int Num_AM_rooms;
195 static uint16_t AM_room_list[MAX_ROOMS];
196 static uint8_t AM_rooms_seen[MAX_ROOMS];
197 static g3Point *AM_rotated_points = NULL; //[MAX_VERTS_PER_ROOM];
198
199 static void TCAMCallback(void);
200
201 static uint8_t *Small_faces[MAX_ROOMS];
202
203 // clears out the list of visible rooms that we've seen
204 void AutomapClearVisMap() { memset(AutomapVisMap, 0, MAX_ROOMS); }
205
206 void ClassifyAMFaces() {
207 int i = 0;
208 for (i = 0; i <= Highest_room_index; i++) {
209 if (Rooms[i].used) {
210 Small_faces[i] = (uint8_t *)mem_malloc(Rooms[i].num_faces);
211 ASSERT(Small_faces[i]);
212
213 memset(Small_faces[i], 0, Rooms[i].num_faces);
214
215 room *rp = &Rooms[i];
216
217 for (int t = 0; t < rp->num_faces; t++) {
218 face *fp = &rp->faces[t];
219
220 vector verts[MAX_VERTS_PER_FACE];
221 vector center;
222 for (int k = 0; k < fp->num_verts; k++)
223 verts[k] = rp->verts[fp->face_verts[k]];
224
225 float size = vm_GetCentroidFast(&center, verts, fp->num_verts);
226
227 if (size < 120)
228 Small_faces[i][t] = 1;
229 if (size < 60)
230 Small_faces[i][t] = 2;
231 }
232 }
233 }
234 }
235
236 void FreeAMFaces() {
237 for (int i = 0; i <= Highest_room_index; i++) {
238 if (Rooms[i].used) {
239 mem_free(Small_faces[i]);
240 Small_faces[i] = NULL;
241 }
242 }
243 }
244
245 // Returns the camera position to the player
246 void TCAMCenterOnPlayer() {
247
248 vm_MakeZero(&AM_view_pos);
249 vm_MakeIdentity(&AM_view_orient);
250
251 matrix newmat;
252 angvec heading;
253 AM_view_pos = Viewer_object->pos - (Viewer_object->orient.fvec * 10);
254 vm_ExtractAnglesFromMatrix(&heading, &Player_object->orient);
255
256 vm_AnglesToMatrix(&newmat, 0, heading.h, 0);
257 AM_view_orient = newmat;
258
259 AM_heading = heading.h;
260 AM_pitch = heading.p;
261 }
262
263 // This is the function called by TelCom
264 // return true if TelCom should exit to TelCom Main Menu
265 // return false if you should exit out of TelCom completly
266 // mmonitor = main monitor class
267 // lmonitor = local monitor class (the monitor at the top of the screen)
268 bool TelComAutoMap(tTelComInfo *tcs) {
269 bool done = false;
270
271 if (!AM_rotated_points) {
272 AM_rotated_points = (g3Point *)mem_malloc(sizeof(g3Point) * MAX_VERTS_PER_ROOM);
273 }
274 AM_tcs = tcs;
275 AM_current_marker = -1;
276 TelComEnableSystemKey(TCSYS_MAXKEYS, false); // disable all telcom system keys
277 TelComEnableSystemKey(TCSYS_F1, true); // enable F1 and enter, those are all we may need in automap
278 TelComEnableSystemKey(TCSYS_F2, true); // enable F2 and enter, those are all we may need in automap
279 TelComEnableSystemKey(TCSYS_F3, true); // enable F3 and enter, those are all we may need in automap
280 TelComEnableSystemKey(TCSYS_1, true); // enable marker key
281 TelComEnableSystemKey(TCSYS_2, true); // enable marker key
282 TelComEnableSystemKey(TCSYS_3, true); // enable marker key
283 TelComEnableSystemKey(TCSYS_4, true); // enable marker key
284 TelComEnableSystemKey(TCSYS_5, true); // enable marker key
285 TelComEnableSystemKey(TCSYS_6, true); // enable marker key
286 TelComEnableSystemKey(TCSYS_7, true); // enable marker key
287 TelComEnableSystemKey(TCSYS_8, true); // enable marker key
288 TelComEnableSystemKey(TCSYS_ENTER, true); // processing other keys is a waste of cpu
289 TelComEnableSystemKey(TCSYS_PRINTSCRN, true);
290
291 // Classify faces
292 ClassifyAMFaces();
293
294 // Load ship model
295 AM_ship_model_handle = LoadPolyModel("automapship.oof", 0);
296
297 // Setup intial pos/orient
298 TCAMCenterOnPlayer();
299 if (OBJECT_OUTSIDE(Viewer_object)) {
300 AM_terrain = 1;
301 }
302
303 TelcomStartScreen(0);
304
305 // setup general background, plain color
306 TCBKGDESC backg;
307 backg.color = BACKGROUND_COLOR;
308 backg.caps = TCBGD_COLOR;
309 backg.type = TC_BACK_STATIC;
310
311 /*//load up the "fake automap" <----Start Remove---->
312 TCBMPDESC bmpdesc;
313 bmpdesc.type = TC_BMP_STATIC;
314 bmpdesc.flags = 0;
315 bmpdesc.caps=TCBD_XY;
316 bmpdesc.x = 0; bmpdesc.y = 0;
317 strcpy(bmpdesc.filename,"TCMap.ogf");
318 // <----End Remove ---->*/
319
320 // setup text for the top monitor "Automap"
321 TCTEXTDESC textdesc;
322 textdesc.type = TC_TEXT_STATIC;
323 textdesc.font = BBRIEF_FONT_INDEX;
324 textdesc.caps = TCTD_TEXTBOX | TCTD_COLOR | TCTD_FONT;
325 textdesc.textbox.left = 65;
326 textdesc.textbox.right = 380;
327 textdesc.textbox.top = 2;
328 textdesc.textbox.bottom = 50;
329 textdesc.color = GR_RGB(255, 255, 255);
330
331 // Setup Main Monitor
332 // CreateBitmapEffect(&bmpdesc,MONITOR_MAIN,0);
333 CreateBackgroundEffect(&backg, MONITOR_MAIN, 0); //<---- Replace above line with this line to get a background
334
335 // Setup Location Monitor (small window at top)
336 CreateBackgroundEffect(&backg, MONITOR_TOP, 0);
337 CreateTextEffect(&textdesc, TXT_TCAUTOMAP, MONITOR_TOP, 0);
338 TelcomEndScreen();
339 TelcomRenderSetScreen(0);
340 TelcomRenderSetCallback(TCAMCallback);
341
342 ResumeControls(); // need to do because we're most likely coming from game.
343
344 while (!done) {
345 ct_packet automap_key;
346
347 Sound_system.BeginSoundFrame(Telcom_called_from_game);
348
349 if (Telcom_system.state != TCS_POWERON || tcs->current_status != TS_MAP) {
350 // we're done with the loop
351 done = true;
352 }
353
354 // Process all waiting events for the TelCom (we may only want to handle this once a frame!)
355 TelComHandleAllEvents(tcs);
356
357 TelcomRenderScreen();
358 Descent->defer();
359 if (KEY_STATE(KEY_ESC)) {
360 AM_tcs->state = TCS_POWEROFF;
361 }
362 // if(KEY_STATE(KEY_TAB)){
363 // AM_tcs->state = TCS_POWEROFF;
364 // }
365
366 // read controls
367 Controller->get_packet(ctfAUTOMAP_KEY, &automap_key);
368 if (automap_key.value > 0.0f) {
369 AM_tcs->state = TCS_POWEROFF;
370 }
371
372 Sound_system.EndSoundFrame();
373 }
374
375 SuspendControls();
376
377 DestroyAllScreens();
378 TelcomRenderSetScreen(DUMMY_SCREEN);
379 TelcomRenderSetCallback(NULL);
380
381 FreeAMFaces();
382
383 if (AM_ship_model_handle != -1) {
384 FreePolyModel(AM_ship_model_handle);
385 }
386
387 TelComEnableSystemKey(TCSYS_MAXKEYS, true); // re-enable all telcom keys
388 TelComEnableSystemKey(TCSYS_F1, false); // disable the T key, not needed outside of automap
389 if (AM_rotated_points) {
390 mem_free(AM_rotated_points);
391 AM_rotated_points = NULL;
392 }
393 return true;
394 }
395
396 // Builds a list of rooms to draw for the automap
397 void TCAMBuildRoomList(int startroom) {
398 memset(AM_rooms_seen, 0, MAX_ROOMS);
399 Num_AM_rooms = 0;
400
401 if (startroom > 0) {
402 AM_room_list[Num_AM_rooms++] = startroom;
403 AM_rooms_seen[startroom] = 1;
404 }
405
406 int i = 0;
407 for (i = 0; i <= Highest_room_index; i++) {
408 if (Rooms[i].used && !AM_rooms_seen[i] && (AutomapVisMap[i] == 1 || (Rooms[i].flags & RF_EXTERNAL))) {
409 AM_room_list[Num_AM_rooms++] = i;
410 AM_rooms_seen[i] = 1;
411 }
412 }
413 }
414
415 // Takes a min,max vector and makes a surrounding cube from it
416 void MakePointsFromMinMax(vector *corners, vector *minp, vector *maxp);
417 // Returns true if the external room is in the view cone
418 // Else returns false
419 bool IsRoomVisible(room *rp, float *nearz) {
420 g3Point pnt;
421 uint8_t ccode;
422
423 vector corners[8];
424
425 MakePointsFromMinMax(corners, &rp->min_xyz, &rp->max_xyz);
426
427 *nearz = 90000000;
428 uint8_t andbyte = 0xff;
429 for (int t = 0; t < 8; t++) {
430 g3_RotatePoint(&pnt, &corners[t]);
431
432 if (pnt.p3_z < *nearz)
433 *nearz = pnt.p3_z;
434
435 ccode = g3_CodePoint(&pnt);
436 if (!ccode)
437 return true;
438 andbyte &= ccode;
439 }
440
441 if (andbyte)
442 return false;
443
444 return true;
445 }
446
447 void TCAMRenderRoom(int roomnum) {
448 ASSERT(Rooms[roomnum].used);
449 room *rp = &Rooms[roomnum];
450 static int first = 1;
451 static float lm_red[32], lm_green[32], lm_blue[32];
452 float nearz;
453 int i;
454
455 if (first) {
456 first = 0;
457 for (int i = 0; i < 32; i++) {
458 lm_red[i] = ((float)i / 31.0);
459 lm_green[i] = ((float)i / 31.0);
460 lm_blue[i] = ((float)i / 31.0);
461 }
462 }
463
464 if ((rp->flags & RF_EXTERNAL) && !AM_terrain)
465 return;
466
467 if (!IsRoomVisible(rp, &nearz))
468 return;
469
470 // rotate all the points for this room
471 for (i = 0; i < rp->num_verts; i++) {
472 g3_RotatePoint(&AM_rotated_points[i], &rp->verts[i]);
473 g3_ProjectPoint(&AM_rotated_points[i]);
474 }
475
476 for (i = 0; i < rp->num_faces; i++) {
477 g3Point *pointlist[MAX_VERTS_PER_FACE];
478 g3Point pointbuffer[MAX_VERTS_PER_FACE];
479
480 face *fp = &rp->faces[i];
481
482 // See if this face is backfaced
483 vector subvec = rp->verts[fp->face_verts[0]] - AM_view_pos;
484 if (subvec * fp->normal > 0)
485 continue; // backfaced
486
487 int black_face = 0, wacky_face = 0;
488
489 if (fp->portal_num != -1) {
490 if (!AutomapVisMap[rp->portals[fp->portal_num].croom]) {
491 // Don't give away secret rooms
492 if (Rooms[rp->portals[fp->portal_num].croom].flags & RF_SECRET)
493 black_face = 1;
494 else
495 wacky_face = 1;
496 } else
497 continue;
498 }
499
500 if (nearz > 600) {
501 if (Small_faces[roomnum][i] != 0)
502 continue;
503 } else if (nearz > 300) {
504 if (Small_faces[roomnum][i] == 2)
505 continue;
506 }
507
508 // Color this face from the lightmaps
509 if (!black_face && !wacky_face && (fp->flags & FF_LIGHTMAP)) {
510 int lm_handle = LightmapInfo[fp->lmi_handle].lm_handle;
511 uint16_t *data = (uint16_t *)lm_data(lm_handle);
512 int w = lm_w(lm_handle);
513 int h = lm_h(lm_handle);
514
515 for (int t = 0; t < fp->num_verts; t++) {
516 pointbuffer[t] = AM_rotated_points[fp->face_verts[t]];
517 g3Point *p = &pointbuffer[t];
518 pointlist[t] = p;
519
520 float u = fp->face_uvls[t].u2 * w;
521 float v = fp->face_uvls[t].v2 * h;
522
523 int int_u = u;
524 int int_v = v;
525
526 uint16_t texel = data[int_v * w + int_u];
527
528 int r = (texel >> 10) & 0x1f;
529 int g = (texel >> 5) & 0x1f;
530 int b = (texel) & 0x1f;
531
532 p->p3_r = lm_red[r];
533 p->p3_g = lm_green[g];
534 p->p3_b = lm_blue[b];
535 p->p3_a = 1.0;
536 p->p3_flags |= PF_RGBA;
537 }
538
539 g3_DrawPoly(fp->num_verts, pointlist, 0);
540 } else {
541 for (int t = 0; t < fp->num_verts; t++) {
542 pointbuffer[t] = AM_rotated_points[fp->face_verts[t]];
543 g3Point *p = &pointbuffer[t];
544 pointlist[t] = p;
545
546 p->p3_flags |= PF_RGBA;
547 p->p3_r = 0.0;
548 p->p3_g = 0.0;
549 p->p3_b = 0.0;
550 p->p3_a = 1.0;
551
552 if (wacky_face) {
553 float curtime = timer_GetTime();
554 int val = curtime;
555 float fval = curtime - val;
556 p->p3_r = fval;
557 p->p3_g = fval;
558 p->p3_b = fval;
559 p->p3_a = 1.0;
560 }
561 }
562 g3_DrawPoly(fp->num_verts, pointlist, 0);
563 }
564 }
565 }
566
567 #define AM_TRANSLATION_SCALAR 200.0f
568 #define AM_ROTATIONAL_SCALAR 90
569
570 // Reads the controls for the automap, and adjusts viewpoint accordingly
571 void TCAMReadControls() {
572 Frametime = last_frametime;
573 int save_mode = Game_interface_mode;
574 game_controls controls;
575
576 controls.toggle_slide = 0;
577 controls.toggle_bank = 0;
578 Game_interface_mode = GAME_INTERFACE;
579
580 PollControls();
581 DoMovement(&controls);
582
583 // Do translational movement
584 AM_view_pos += (controls.forward_thrust * last_frametime * AM_TRANSLATION_SCALAR) * AM_view_orient.fvec;
585 AM_view_pos += (controls.vertical_thrust * last_frametime * AM_TRANSLATION_SCALAR) * AM_view_orient.uvec;
586 AM_view_pos += (controls.sideways_thrust * last_frametime * AM_TRANSLATION_SCALAR) * AM_view_orient.rvec;
587
588 // Do rotational movement
589
590 matrix newmat;
591 float norm = ((65536 / 360) * AM_ROTATIONAL_SCALAR) * last_frametime;
592
593 AM_pitch += (norm * controls.pitch_thrust);
594 AM_heading += (norm * controls.heading_thrust);
595
596 if (AM_pitch < 0)
597 AM_pitch += 65536;
598 if (AM_pitch >= 65536)
599 AM_pitch -= 65536;
600
601 if (AM_heading < 0)
602 AM_heading += 65536;
603 if (AM_heading >= 65536)
604 AM_heading -= 65536;
605
606 vm_AnglesToMatrix(&newmat, (uint16_t)AM_pitch, (uint16_t)AM_heading, 0);
607 AM_view_orient = newmat;
608
609 vm_Orthogonalize(&AM_view_orient);
610 Game_interface_mode = save_mode;
611 }
612
613 // Renders the low-res terrain for the automap
614 void TCAMRenderTerrain() {
615 int nt;
616 int render_width, render_height;
617 float w2, h2;
618
619 int save_check = Terrain_occlusion_checksum;
620 int save_pix = Detail_settings.Pixel_error;
621 float save_dist = Detail_settings.Terrain_render_distance;
622
623 Detail_settings.Pixel_error = 31;
624 Detail_settings.Terrain_render_distance = 300 * TERRAIN_SIZE;
625 Terrain_occlusion_checksum = -1;
626
627 // Get the size of the current render window
628 rend_GetProjectionParameters(&render_width, &render_height);
629 w2 = ((float)render_width - 1) / 2.0;
630 h2 = ((float)render_height - 1) / 2.0;
631
632 // Set up vars for (psuedo-)clipping window
633 Check_terrain_portal = 0;
634
635 Clip_scale_left = 0;
636 Clip_scale_right = render_width - 1;
637 Clip_scale_top = 0;
638 Clip_scale_bot = render_height - 1;
639
640 Terrain_from_mine = 0;
641
642 VisibleTerrainZ = (Detail_settings.Terrain_render_distance) * Matrix_scale.z;
643
644 // Set up our z wall
645 g3_SetFarClipZ(VisibleTerrainZ);
646
647 vector viewer_eye;
648 matrix viewer_orient;
649 // Get scaled matrix
650 g3_GetViewPosition(&viewer_eye);
651 g3_GetViewMatrix(&viewer_orient);
652
653 // Get all of the cells visible to us
654 nt = GetVisibleTerrain(&viewer_eye, &viewer_orient);
655
656 // And display!
657 if (nt > 0)
658 DisplayTerrainList(nt, 1);
659
660 Detail_settings.Pixel_error = save_pix;
661 Detail_settings.Terrain_render_distance = save_dist;
662 Terrain_occlusion_checksum = save_check;
663 }
664
665 #define AM_BLINK_TIME .25f
666
667 // Draws all the relevant objects for automap
668 void TCAMDrawObjects() {
669 int i;
670 int drawit = (timer_GetTime() * 4);
671 drawit = (drawit % 2);
672
673 if (Game_mode & GM_MULTI) {
674 for (i = 0; i < MAX_PLAYERS; i++) {
675 if (i == Player_num) {
676 object *obj = &Objects[Players[Player_num].objnum];
677 if (AM_ship_model_handle != -1 && drawit)
678 DrawPolygonModel(&obj->pos, &obj->orient, AM_ship_model_handle, NULL, 0, 1, 1, 1);
679 } else if (NetPlayers[i].flags & NPF_CONNECTED) {
680 object *obj = &Objects[Players[i].objnum];
681 if ((obj->type == OBJ_PLAYER && obj->render_type == RT_POLYOBJ) || obj->type == OBJ_OBSERVER)
682 DrawColoredDisk(&Objects[Players[i].objnum].pos, 1, 1, .5f, 1.0, .3f, 3.0);
683 }
684 }
685 } else {
686 object *obj = &Objects[Players[Player_num].objnum];
687
688 if (AM_ship_model_handle != -1 && drawit)
689 DrawPolygonModel(&obj->pos, &obj->orient, AM_ship_model_handle, NULL, 0, 1, 1, 1);
690 }
691
692 float norm = timer_GetTime();
693 int int_norm = norm;
694 norm -= int_norm;
695 for (i = 0; i <= Highest_object_index; i++) {
696 object *obj = &Objects[i];
697
698 if (obj->type == OBJ_MARKER && obj->parent_handle == Player_object->handle) {
699 float size = 2.5 + (norm * 2.5);
700 float r = 1.0;
701 float g = 0;
702 float b = 1.0;
703
704 if (AM_current_marker != -1) {
705 int index = 0;
706
707 if (Game_mode & GM_MULTI)
708 index = obj->id - (Player_num * 2);
709 else
710 index = obj->id;
711
712 if (AM_current_marker == index) {
713 size = 9.0 + (norm * 9.0);
714 r = 0;
715 g = 1.0;
716 b = 1.0;
717 }
718 }
719
720 DrawColoredDisk(&obj->pos, r, g, b, 1.0, .3f, size);
721 }
722 }
723 }
724
725 #include "hud.h"
726
727 void TCAMDrawMenu() {
728 char str[255];
729 g3Point *pntlist[4], points[4];
730 grtext_SetFont(BRIEFING_FONT);
731 int fontheight = grfont_GetHeight(BRIEFING_FONT);
732
733 points[0].p3_sx = AM_tcs->Monitor_coords[MONITOR_MAIN].left;
734 points[0].p3_sy = AM_tcs->Monitor_coords[MONITOR_MAIN].bottom - (fontheight * 3);
735
736 points[1].p3_sx = AM_tcs->Monitor_coords[MONITOR_MAIN].right;
737 points[1].p3_sy = AM_tcs->Monitor_coords[MONITOR_MAIN].bottom - (fontheight * 3);
738
739 points[2].p3_sx = AM_tcs->Monitor_coords[MONITOR_MAIN].right;
740 points[2].p3_sy = AM_tcs->Monitor_coords[MONITOR_MAIN].bottom;
741
742 points[3].p3_sx = AM_tcs->Monitor_coords[MONITOR_MAIN].left;
743 points[3].p3_sy = AM_tcs->Monitor_coords[MONITOR_MAIN].bottom;
744
745 for (int i = 0; i < 4; i++) {
746 points[i].p3_z = 0;
747 points[i].p3_flags = PF_PROJECTED;
748 pntlist[i] = &points[i];
749 }
750
751 rend_SetZBufferState(0);
752 rend_SetTextureType(TT_FLAT);
753 rend_SetAlphaType(AT_CONSTANT);
754 rend_SetLighting(LS_NONE);
755 rend_SetFlatColor(GR_BLACK);
756 rend_SetAlphaValue(192);
757 rend_DrawPolygon2D(0, pntlist, 4);
758
759 grtext_SetAlpha(250);
760 grtext_SetColor(GR_RGB(255, 255, 255));
761
762 snprintf(str, sizeof(str), TXT_TCAM_TERRAIN, AM_terrain ? TXT_STRING_OFF : TXT_STRING_ON);
763 grtext_CenteredPrintf(0, AM_tcs->Monitor_coords[MONITOR_MAIN].bottom - (fontheight * 3) + (fontheight / 2), str);
764 snprintf(str, sizeof(str), "%s", TXT_TCAM_INSTRUCTIONS);
765 grtext_CenteredPrintf(0, AM_tcs->Monitor_coords[MONITOR_MAIN].bottom - (fontheight * 2) + (fontheight / 2), str);
766
767 // Use HUD font for part that overlays the 3D
768 fontheight = grfont_GetHeight(HUD_FONT);
769 grtext_SetFont(HUD_FONT);
770 grtext_SetColor(HUD_COLOR);
771
772 snprintf(str, sizeof(str), "%s", Level_info.name);
773 grtext_CenteredPrintf(0, AM_tcs->Monitor_coords[MONITOR_MAIN].top + (fontheight / 2), str);
774
775 if (AM_current_marker != -1) {
776 int markernum = (Game_mode & GM_MULTI) ? (Player_num * 2 + AM_current_marker) : AM_current_marker;
777 snprintf(str, sizeof(str), TXT_VIEW_MARKER, AM_current_marker + 1);
778 strncat(str, ": ", sizeof(str) - strlen(str) - 1);
779 strncat(str, MarkerMessages[markernum], sizeof(str) - strlen(str) - 1);
780 grtext_CenteredPrintf(0, AM_tcs->Monitor_coords[MONITOR_MAIN].top + (fontheight / 2) + fontheight, str);
781 }
782
783 grtext_Flush();
784 }
785
786 // The callback function that the telcom calls every frame
787 void TCAMCallback(void) {
788 StartFrame(Telcom_system.Monitor_coords[MONITOR_MAIN].left, Telcom_system.Monitor_coords[MONITOR_MAIN].top,
789 Telcom_system.Monitor_coords[MONITOR_MAIN].right, Telcom_system.Monitor_coords[MONITOR_MAIN].bottom);
790
791 // Start a 3d frame
792 g3_StartFrame(&AM_view_pos, &AM_view_orient, Render_zoom);
793
794 if (AM_center_on_player) {
795 TCAMCenterOnPlayer();
796 AM_center_on_player = 0;
797 }
798
799 if (AM_realign) {
800 AM_pitch = 0;
801 AM_realign = 0;
802 }
803
804 rend_SetFiltering(1);
805 rend_SetAlphaType(AT_VERTEX);
806 rend_SetTextureType(TT_FLAT);
807 rend_SetLighting(LS_GOURAUD);
808 rend_SetColorModel(CM_RGB);
809 rend_SetOverlayType(OT_NONE);
810 rend_SetZBufferState(1);
811
812 if (AM_terrain)
813 rend_SetZValues(0, VisibleTerrainZ);
814
815 TCAMBuildRoomList(Viewer_object->roomnum);
816 // Render all rooms in view
817 for (int i = 0; i < Num_AM_rooms; i++) {
818 TCAMRenderRoom(AM_room_list[i]);
819 }
820
821 // Render terrain
822 if (AM_terrain)
823 TCAMRenderTerrain();
824
825 g3_EndFrame();
826
827 rend_SetFiltering(1);
828
829 TCAMDrawObjects();
830 EndFrame();
831
832 rend_SetFiltering(0);
833
834 TCAMDrawMenu();
835
836 TCAMReadControls();
837 }