1 /* $Id: automap.c,v 1.16 2003-11-15 00:37:48 btb Exp $ */
3 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
4 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
5 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
6 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
7 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
8 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
9 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
10 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
11 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
12 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
17 * Routines for displaying the auto-map.
20 * Revision 1.8 1995/10/31 10:24:54 allender
23 * Revision 1.7 1995/10/21 16:18:20 allender
24 * blit pcx background directly to Page canvas instead of creating
25 * seperate bitmap for it -- hope to solve VM bug on some macs
27 * Revision 1.6 1995/10/20 00:49:16 allender
28 * added redbook check during automap
30 * Revision 1.5 1995/09/13 08:44:07 allender
31 * Dave Denhart's changes to speed up the automap
33 * Revision 1.4 1995/08/18 15:46:00 allender
34 * put text all on upper bar -- and fixed background since
35 * changing xparency color
37 * Revision 1.3 1995/08/03 15:15:18 allender
38 * fixed edge hashing problem causing automap to crash
40 * Revision 1.2 1995/07/12 12:49:27 allender
41 * works in 640x480 mode
43 * Revision 1.1 1995/05/16 15:22:59 allender
46 * Revision 2.2 1995/03/21 14:41:26 john
47 * Ifdef'd out the NETWORK code.
49 * Revision 2.1 1995/03/20 18:16:06 john
50 * Added code to not store the normals in the segment structure.
52 * Revision 2.0 1995/02/27 11:32:55 john
53 * New version 2.0, which has no anonymous unions, builds with
54 * Watcom 10.0, and doesn't require parsing BITMAPS.TBL.
56 * Revision 1.117 1995/02/22 14:11:31 allender
57 * remove anonymous unions from object structure
59 * Revision 1.116 1995/02/22 13:24:39 john
60 * Removed the vecmat anonymous unions.
62 * Revision 1.115 1995/02/09 14:57:02 john
63 * Reduced mem usage. Made automap slide farther.
65 * Revision 1.114 1995/02/07 20:40:44 rob
66 * Allow for anarchy automap of player pos by option.
68 * Revision 1.113 1995/02/07 15:45:33 john
69 * Made automap memory be static.
71 * Revision 1.112 1995/02/02 12:24:00 adam
72 * played with automap labels
74 * Revision 1.111 1995/02/02 01:52:52 john
75 * Made the automap use small font.
77 * Revision 1.110 1995/02/02 01:34:34 john
78 * Made Reset in automap not change segmentlimit.
80 * Revision 1.109 1995/02/02 01:23:11 john
81 * Finalized the new automap partial viewer.
83 * Revision 1.108 1995/02/02 00:49:45 mike
84 * new automap segment-depth functionality.
86 * Revision 1.107 1995/02/02 00:23:04 john
87 * Half of the code for new connected distance stuff in automap.
89 * Revision 1.106 1995/02/01 22:54:00 john
90 * Made colored doors not fade in automap. Made default
91 * viewing area be maxxed.
93 * Revision 1.105 1995/02/01 13:16:13 john
96 * Revision 1.104 1995/01/31 12:47:06 john
97 * Made Alt+F only work with cheats enabled.
99 * Revision 1.103 1995/01/31 12:41:23 john
100 * Working with new controls.
102 * Revision 1.102 1995/01/31 12:04:19 john
103 * Version 2 of new key control.
105 * Revision 1.101 1995/01/31 11:32:00 john
106 * First version of new automap system.
108 * Revision 1.100 1995/01/28 16:55:48 john
109 * Made keys draw in automap in the segments that you have
112 * Revision 1.99 1995/01/28 14:44:51 john
113 * Made hostage doors show up on automap.
115 * Revision 1.98 1995/01/22 17:03:49 rob
116 * Fixed problem drawing playerships in automap coop/team mode
118 * Revision 1.97 1995/01/21 17:23:11 john
119 * Limited S movement in map. Made map bitmap load from disk
122 * Revision 1.96 1995/01/19 18:55:38 john
123 * Don't draw players in automap if not obj_player.
125 * Revision 1.95 1995/01/19 18:48:13 john
126 * Made player colors better in automap.
128 * Revision 1.94 1995/01/19 17:34:52 rob
129 * Added team colorizations in automap.
131 * Revision 1.93 1995/01/19 17:15:36 rob
132 * Trying to add player ships into map for coop and team mode.
134 * Revision 1.92 1995/01/19 17:11:09 john
135 * Added code for Rob to draw Multiplayer ships in automap.
137 * Revision 1.91 1995/01/12 13:35:20 john
138 * Fixed bug with Segment 0 not getting displayed
139 * in automap if you have EDITOR compiled in.
141 * Revision 1.90 1995/01/08 16:17:14 john
142 * Added code to draw player's up vector while in automap.
144 * Revision 1.89 1995/01/08 16:09:41 john
145 * Fixed problems with grate.
147 * Revision 1.88 1994/12/14 22:54:17 john
148 * Fixed bug that didn't show hostages in automap.
150 * Revision 1.87 1994/12/09 00:41:03 mike
151 * fix hang in automap print screen
153 * Revision 1.86 1994/12/05 23:37:15 matt
154 * Took out calls to warning() function
156 * Revision 1.85 1994/12/03 22:35:28 yuan
159 * Revision 1.84 1994/12/02 15:05:45 matt
160 * Added new "official" cheats
162 * Revision 1.83 1994/11/30 12:10:49 adam
163 * added support for PCX titles/brief screens
165 * Revision 1.82 1994/11/27 23:15:12 matt
166 * Made changes for new mprintf calling convention
168 * Revision 1.81 1994/11/27 15:35:52 matt
169 * Enable screen shots even when debugging is turned off
171 * Revision 1.80 1994/11/26 22:51:43 matt
172 * Removed editor-only fields from segment structure when editor is compiled
173 * out, and padded segment structure to even multiple of 4 bytes.
175 * Revision 1.79 1994/11/26 16:22:48 matt
178 * Revision 1.78 1994/11/23 22:00:10 mike
181 * Revision 1.77 1994/11/21 11:40:33 rob
182 * Tweaked the game-loop for automap in multiplayer games.
184 * Revision 1.76 1994/11/18 16:42:06 adam
187 * Revision 1.75 1994/11/17 13:06:48 adam
190 * Revision 1.74 1994/11/14 20:47:17 john
191 * Attempted to strip out all the code in the game
192 * directory that uses any ui code.
205 #include "ogl_init.h"
208 #include "pa_enabl.h" //$$POLY_ACC
226 #include "textures.h"
229 #include "segpoint.h"
236 #include "gamefont.h"
244 #include "endlevel.h"
251 #include "cntrlcen.h"
253 #if defined(POLY_ACC)
254 #include "poly_acc.h"
258 #define AUTOMAP_DIRECT_RENDER
261 #define EF_USED 1 // This edge is used
262 #define EF_DEFINING 2 // A structure defining edge that should always draw.
263 #define EF_FRONTIER 4 // An edge between the known and the unknown.
264 #define EF_SECRET 8 // An edge that is part of a secret wall.
265 #define EF_GRATE 16 // A grate... draw it all the time.
266 #define EF_NO_FADE 32 // An edge that doesn't fade with distance
267 #define EF_TOO_FAR 64 // An edge that is too far away
269 void modex_printf(int x,int y,char *s,grs_font *font,int color);
271 typedef struct Edge_info {
272 short verts[2]; // 4 bytes
273 ubyte sides[4]; // 4 bytes
274 short segnum[4]; // 8 bytes // This might not need to be stored... If you can access the normals of a side.
275 ubyte flags; // 1 bytes // See the EF_??? defines above.
276 ubyte color; // 1 bytes
277 ubyte num_faces; // 1 bytes // 19 bytes...
280 // OLD BUT GOOD -- #define MAX_EDGES_FROM_VERTS(v) ((v*5)/2)
281 // THE following was determined by John by loading levels 1-14 and recording
282 // numbers on 10/26/94.
283 //#define MAX_EDGES_FROM_VERTS(v) (((v)*21)/10)
284 #define MAX_EDGES_FROM_VERTS(v) ((v)*4)
285 //#define MAX_EDGES (MAX_EDGES_FROM_VERTS(MAX_VERTICES))
287 #define MAX_EDGES 6000 // Determined by loading all the levels by John & Mike, Feb 9, 1995
289 #define K_WALL_NORMAL_COLOR BM_XRGB(29, 29, 29 )
290 #define K_WALL_DOOR_COLOR BM_XRGB(5, 27, 5 )
291 #define K_WALL_DOOR_BLUE BM_XRGB(0, 0, 31)
292 #define K_WALL_DOOR_GOLD BM_XRGB(31, 31, 0)
293 #define K_WALL_DOOR_RED BM_XRGB(31, 0, 0)
294 #define K_WALL_REVEALED_COLOR BM_XRGB(0, 0, 25 ) //what you see when you have the full map powerup
295 #define K_HOSTAGE_COLOR BM_XRGB(0, 31, 0 )
296 #define K_FONT_COLOR_20 BM_XRGB(20, 20, 20 )
297 #define K_GREEN_31 BM_XRGB(0, 31, 0)
299 int Wall_normal_color;
304 int Wall_revealed_color;
312 void init_automap_colors(void)
314 Wall_normal_color = K_WALL_NORMAL_COLOR;
315 Wall_door_color = K_WALL_DOOR_COLOR;
316 Wall_door_blue = K_WALL_DOOR_BLUE;
317 Wall_door_gold = K_WALL_DOOR_GOLD;
318 Wall_door_red = K_WALL_DOOR_RED;
319 Wall_revealed_color = K_WALL_REVEALED_COLOR;
320 Hostage_color = K_HOSTAGE_COLOR;
321 Font_color_20 = K_FONT_COLOR_20;
322 Green_31 = K_GREEN_31;
324 White_63 = gr_find_closest_color_current(63,63,63);
325 Blue_48 = gr_find_closest_color_current(0,0,48);
326 Red_48 = gr_find_closest_color_current(48,0,0);
329 // Segment visited list
330 ubyte Automap_visited[MAX_SEGMENTS];
332 // Edge list variables
333 static int Num_edges=0;
334 static int Max_edges; //set each frame
335 static int Highest_edge_index = -1;
336 static Edge_info Edges[MAX_EDGES];
337 static short DrawingListBright[MAX_EDGES];
339 //static short DrawingListBright[MAX_EDGES];
340 //static short Edge_used_list[MAX_EDGES]; //which entries in edge_list have been used
342 // Map movement defines
343 #define PITCH_DEFAULT 9000
344 #define ZOOM_DEFAULT i2f(20*10)
345 #define ZOOM_MIN_VALUE i2f(20*5)
346 #define ZOOM_MAX_VALUE i2f(20*100)
348 #define SLIDE_SPEED (350)
349 #define ZOOM_SPEED_FACTOR 500 //(1500)
350 #define ROT_SPEED_DIVISOR (115000)
352 #ifndef AUTOMAP_DIRECT_RENDER
353 // Screen anvas variables
354 static int current_page=0;
356 static dd_grs_canvas ddPages[2];
357 static dd_grs_canvas ddDrawingPages[2];
359 #define ddPage ddPages[0]
360 #define ddDrawingPage ddDrawingPages[0]
364 #if defined(MACINTOSH) && defined(POLY_ACC)
365 grs_canvas Pages[2]; // non static under rave so the backbuffer callback function can get at them
366 grs_canvas DrawingPages[2]; // non static under rave so the backbuffer callback function can get at them
368 static grs_canvas Pages[2];
369 static grs_canvas DrawingPages[2];
371 #endif /* AUTOMAP_DIRECT_RENDER */
373 #define Page Pages[0]
374 #define DrawingPage DrawingPages[0]
377 static int Automap_cheat = 0; // If set, show everything
379 // Rendering variables
380 static fix Automap_zoom = 0x9000;
381 static vms_vector view_target;
382 static fix Automap_farthest_dist = (F1_0 * 20 * 50); // 50 segments away
383 static vms_matrix ViewMatrix;
384 static fix ViewDist=0;
386 // Function Prototypes
387 void adjust_segment_limit(int SegmentLimit);
388 void draw_all_edges(void);
389 void automap_build_edge_list(void);
391 #define MAX_DROP_MULTI 2
392 #define MAX_DROP_SINGLE 9
394 vms_vector MarkerPoint[NUM_MARKERS]; //these are only used in multi.c, and I'd get rid of them there, but when I tried to do that once, I caused some horrible bug. -MT
395 int HighlightMarker=-1;
396 char MarkerMessage[NUM_MARKERS][MARKER_MESSAGE_LEN];
397 char MarkerOwner[NUM_MARKERS][CALLSIGN_LEN+1];
398 float MarkerScale=2.0;
399 int MarkerObject[NUM_MARKERS];
401 extern vms_vector Matrix_scale; //how the matrix is currently scaled
404 #if defined(MACINTOSH) && defined(POLY_ACC)
405 // icky hack. automap draw context is no longer valid when this is called.
406 // so we can not use the pa_draw_line function for rave
407 bool automap_draw_line(g3s_point *p0, g3s_point *p1)
409 int savePAEnabledState = PAEnabled;
412 g3_draw_line(&FromPoint, &ToPoint);
413 PAEnabled = savePAEnabledState;
416 # define automap_draw_line g3_draw_line
420 // -------------------------------------------------------------
422 void DrawMarkerNumber (int num)
425 g3s_point BasePoint,FromPoint,ToPoint;
427 float ArrayX[10][20]={ {-.25, 0.0, 0.0, 0.0, -1.0, 1.0},
428 {-1.0, 1.0, 1.0, 1.0, -1.0, 1.0, -1.0, -1.0, -1.0, 1.0},
429 {-1.0, 1.0, 1.0, 1.0, -1.0, 1.0, 0.0, 1.0},
430 {-1.0, -1.0, -1.0, 1.0, 1.0, 1.0},
431 {-1.0, 1.0, -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, -1.0, 1.0},
432 {-1.0, 1.0, -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, -1.0, 1.0},
433 {-1.0, 1.0, 1.0, 1.0},
434 {-1.0, 1.0, 1.0, 1.0, -1.0, 1.0, -1.0, -1.0, -1.0, 1.0},
435 {-1.0, 1.0, 1.0, 1.0, -1.0, 1.0, -1.0, -1.0}
438 float ArrayY[10][20]={ {.75, 1.0, 1.0, -1.0, -1.0, -1.0},
439 {1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, -1.0, -1.0, -1.0},
440 {1.0, 1.0, 1.0, -1.0, -1.0, -1.0, 0.0, 0.0},
441 {1.0, 0.0, 0.0, 0.0, 1.0, -1.0},
442 {1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, -1.0, -1.0, -1.0},
443 {1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, 0.0, 0.0, 0.0},
444 {1.0, 1.0, 1.0, -1.0},
445 {1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, 1.0, 0.0, 0.0},
446 {1.0, 1.0, 1.0, -1.0, 0.0, 0.0, 0.0, 1.0}
448 int NumOfPoints[]={6,10,8,6,10,10,4,10,8};
450 for (i=0;i<NumOfPoints[num];i++)
452 ArrayX[num][i]*=MarkerScale;
453 ArrayY[num][i]*=MarkerScale;
456 if (num==HighlightMarker)
457 gr_setcolor (White_63);
459 gr_setcolor (Blue_48);
462 g3_rotate_point(&BasePoint,&Objects[MarkerObject[(Player_num*2)+num]].pos);
464 for (i=0;i<NumOfPoints[num];i+=2)
470 FromPoint.p3_x+=fixmul ((fl2f (ArrayX[num][i])),Matrix_scale.x);
471 FromPoint.p3_y+=fixmul ((fl2f (ArrayY[num][i])),Matrix_scale.y);
472 g3_code_point (&FromPoint);
473 g3_project_point (&FromPoint);
475 ToPoint.p3_x+=fixmul ((fl2f (ArrayX[num][i+1])),Matrix_scale.x);
476 ToPoint.p3_y+=fixmul ((fl2f (ArrayY[num][i+1])),Matrix_scale.y);
477 g3_code_point (&ToPoint);
478 g3_project_point (&ToPoint);
480 automap_draw_line(&FromPoint, &ToPoint);
484 void DropMarker (int player_marker_num)
486 int marker_num = (Player_num*2)+player_marker_num;
487 object *playerp = &Objects[Players[Player_num].objnum];
489 MarkerPoint[marker_num] = playerp->pos;
491 if (MarkerObject[marker_num] != -1)
492 obj_delete(MarkerObject[marker_num]);
494 MarkerObject[marker_num] = drop_marker_object(&playerp->pos,playerp->segnum,&playerp->orient,marker_num);
497 if (Game_mode & GM_MULTI)
498 multi_send_drop_marker (Player_num,playerp->pos,player_marker_num,MarkerMessage[marker_num]);
503 extern char guidebot_name[];
505 void DropBuddyMarker(object *objp)
509 // Find spare marker slot. "if" code below should be an assert, but what if someone changes NUM_MARKERS or MAX_CROP_SINGLE and it never gets hit?
510 marker_num = MAX_DROP_SINGLE+1;
511 if (marker_num > NUM_MARKERS-1)
512 marker_num = NUM_MARKERS-1;
514 sprintf(MarkerMessage[marker_num], "RIP: %s",guidebot_name);
516 MarkerPoint[marker_num] = objp->pos;
518 if (MarkerObject[marker_num] != -1 && MarkerObject[marker_num] !=0)
519 obj_delete(MarkerObject[marker_num]);
521 MarkerObject[marker_num] = drop_marker_object(&objp->pos, objp->segnum, &objp->orient, marker_num);
525 #define MARKER_SPHERE_SIZE 0x58000
530 static int cyc=10,cycdir=1;
531 g3s_point sphere_point;
533 if (Game_mode & GM_MULTI)
538 for (i=0;i<maxdrop;i++)
539 if (MarkerObject[(Player_num*2)+i] != -1) {
541 g3_rotate_point(&sphere_point,&Objects[MarkerObject[(Player_num*2)+i]].pos);
543 gr_setcolor (gr_find_closest_color_current(cyc,0,0));
544 g3_draw_sphere(&sphere_point,MARKER_SPHERE_SIZE);
545 gr_setcolor (gr_find_closest_color_current(cyc+10,0,0));
546 g3_draw_sphere(&sphere_point,MARKER_SPHERE_SIZE/2);
547 gr_setcolor (gr_find_closest_color_current(cyc+20,0,0));
548 g3_draw_sphere(&sphere_point,MARKER_SPHERE_SIZE/4);
550 DrawMarkerNumber (i);
575 for (i=0;i<NUM_MARKERS;i++) {
576 MarkerMessage[i][0]=0;
581 void automap_clear_visited()
584 for (i=0; i<MAX_SEGMENTS; i++ )
585 Automap_visited[i] = 0;
589 grs_canvas *name_canv_left,*name_canv_right;
591 void draw_player( object * obj )
593 vms_vector arrow_pos, head_pos;
594 g3s_point sphere_point, arrow_point, head_point;
596 // Draw Console player -- shaped like a ellipse with an arrow.
597 g3_rotate_point(&sphere_point,&obj->pos);
598 g3_draw_sphere(&sphere_point,obj->size);
600 // Draw shaft of arrow
601 vm_vec_scale_add( &arrow_pos, &obj->pos, &obj->orient.fvec, obj->size*3 );
602 g3_rotate_point(&arrow_point,&arrow_pos);
603 automap_draw_line(&sphere_point, &arrow_point);
605 // Draw right head of arrow
606 vm_vec_scale_add( &head_pos, &obj->pos, &obj->orient.fvec, obj->size*2 );
607 vm_vec_scale_add2( &head_pos, &obj->orient.rvec, obj->size*1 );
608 g3_rotate_point(&head_point,&head_pos);
609 automap_draw_line(&arrow_point, &head_point);
611 // Draw left head of arrow
612 vm_vec_scale_add( &head_pos, &obj->pos, &obj->orient.fvec, obj->size*2 );
613 vm_vec_scale_add2( &head_pos, &obj->orient.rvec, obj->size*(-1) );
614 g3_rotate_point(&head_point,&head_pos);
615 automap_draw_line(&arrow_point, &head_point);
617 // Draw player's up vector
618 vm_vec_scale_add( &arrow_pos, &obj->pos, &obj->orient.uvec, obj->size*2 );
619 g3_rotate_point(&arrow_point,&arrow_pos);
620 automap_draw_line(&sphere_point, &arrow_point);
624 #if defined(MACINTOSH) && defined(POLY_ACC)
626 void pa_mac_draw_automap_extras(void)
631 g3s_point sphere_point;
633 AutomapHires = 1; // always on the mac
637 if (Game_mode & GM_TEAM)
638 color = get_team(Player_num);
641 color = Player_num; // Note link to above if!
643 gr_setcolor(gr_getcolor(player_rgb[color].r,player_rgb[color].g,player_rgb[color].b));
644 draw_player(&Objects[Players[Player_num].objnum]);
648 if (HighlightMarker>-1 && MarkerMessage[HighlightMarker][0]!=0)
650 char msg[10+MARKER_MESSAGE_LEN+1];
652 sprintf(msg,"Marker %d: %s",HighlightMarker+1,MarkerMessage[(Player_num*2)+HighlightMarker]);
654 gr_setcolor (Red_48);
656 modex_printf(5,20,msg,SMALL_FONT,Font_color_20);
661 if ( (Game_mode & (GM_TEAM | GM_MULTI_COOP)) || (Netgame.game_flags & NETGAME_FLAG_SHOW_MAP) )
663 for (i=0; i<N_players; i++)
665 if ((i != Player_num) &&
666 ((Game_mode & GM_MULTI_COOP) || (get_team(Player_num) == get_team(i)) || (Netgame.game_flags & NETGAME_FLAG_SHOW_MAP)) )
668 if ( Objects[Players[i].objnum].type == OBJ_PLAYER )
670 if (Game_mode & GM_TEAM)
674 gr_setcolor(gr_getcolor(player_rgb[color].r,player_rgb[color].g,player_rgb[color].b));
675 draw_player(&Objects[Players[i].objnum]);
683 for (i=0;i<=Highest_object_index;i++,objp++)
688 gr_setcolor(Hostage_color);
689 g3_rotate_point(&sphere_point,&objp->pos);
690 g3_draw_sphere(&sphere_point,objp->size);
693 if ( Automap_visited[objp->segnum] )
695 if ( (objp->id==POW_KEY_RED) || (objp->id==POW_KEY_BLUE) || (objp->id==POW_KEY_GOLD) )
699 case POW_KEY_RED: gr_setcolor(gr_getcolor(63, 5, 5)); break;
700 case POW_KEY_BLUE: gr_setcolor(gr_getcolor(5, 5, 63)); break;
701 case POW_KEY_GOLD: gr_setcolor(gr_getcolor(63, 63, 10)); break;
703 Error("Illegal key type: %i", objp->id);
705 g3_rotate_point(&sphere_point,&objp->pos);
706 g3_draw_sphere(&sphere_point,objp->size*4);
713 gr_bitmapm(AutomapHires?10:5, AutomapHires?10:5, &name_canv_left->cv_bitmap);
714 gr_bitmapm(grd_curcanv->cv_bitmap.bm_w-(AutomapHires?10:5)-name_canv_right->cv_bitmap.bm_w,AutomapHires?10:5,&name_canv_right->cv_bitmap);
717 void pa_mac_draw_automap(void)
719 vms_vector viewer_position;
722 render_start_frame();
723 pa_set_context(kAutoMapDrawContextID, NULL);
726 vm_vec_scale_add(&viewer_position,&view_target,&ViewMatrix.fvec,-ViewDist );
727 g3_set_view_matrix(&viewer_position,&ViewMatrix,Automap_zoom);
741 vms_vector viewer_position;
742 g3s_point sphere_point;
748 pa_mac_draw_automap();
754 #ifndef AUTOMAP_DIRECT_RENDER
756 WIN(mprintf((1, "Can't do lores automap in Windows!\n")));
759 gr_set_current_canvas(&DrawingPages[current_page]);
763 dd_gr_set_current_canvas(&ddDrawingPage),
764 gr_set_current_canvas(&DrawingPage)
769 #if defined(POLY_ACC)
774 dd_gr_clear_canvas(BM_XRGB(0,0,0)),
775 gr_clear_canvas(BM_XRGB(0,0,0))
778 WIN(DDGRLOCK(dd_grd_curcanv));
781 render_start_frame();
783 vm_vec_scale_add(&viewer_position,&view_target,&ViewMatrix.fvec,-ViewDist );
785 g3_set_view_matrix(&viewer_position,&ViewMatrix,Automap_zoom);
787 // mprintf((0, "dd_grd_curcanv->canvas.cv_bitmap.bm_data= %x\n", dd_grd_curcanv->canvas.cv_bitmap.bm_data));
788 // mprintf((0, "grd_curcanv->cv_bitmap.bm_data= %x\n", grd_curcanv->cv_bitmap.bm_data));
794 if (Game_mode & GM_TEAM)
795 color = get_team(Player_num);
798 color = Player_num; // Note link to above if!
800 gr_setcolor(gr_getcolor(player_rgb[color].r,player_rgb[color].g,player_rgb[color].b));
801 draw_player(&Objects[Players[Player_num].objnum]);
805 if (HighlightMarker>-1 && MarkerMessage[HighlightMarker][0]!=0)
807 char msg[10+MARKER_MESSAGE_LEN+1];
809 sprintf(msg,"Marker %d: %s",HighlightMarker+1,MarkerMessage[(Player_num*2)+HighlightMarker]);
811 gr_setcolor (Red_48);
813 modex_printf(5,20,msg,SMALL_FONT,Font_color_20);
818 if ( (Game_mode & (GM_TEAM | GM_MULTI_COOP)) || (Netgame.game_flags & NETGAME_FLAG_SHOW_MAP) ) {
819 for (i=0; i<N_players; i++) {
820 if ( (i != Player_num) && ((Game_mode & GM_MULTI_COOP) || (get_team(Player_num) == get_team(i)) || (Netgame.game_flags & NETGAME_FLAG_SHOW_MAP)) ) {
821 if ( Objects[Players[i].objnum].type == OBJ_PLAYER ) {
822 if (Game_mode & GM_TEAM)
826 gr_setcolor(gr_getcolor(player_rgb[color].r,player_rgb[color].g,player_rgb[color].b));
827 draw_player(&Objects[Players[i].objnum]);
835 for (i=0;i<=Highest_object_index;i++,objp++) {
836 switch( objp->type ) {
838 gr_setcolor(Hostage_color);
839 g3_rotate_point(&sphere_point,&objp->pos);
840 g3_draw_sphere(&sphere_point,objp->size);
843 if ( Automap_visited[objp->segnum] ) {
844 if ( (objp->id==POW_KEY_RED) || (objp->id==POW_KEY_BLUE) || (objp->id==POW_KEY_GOLD) ) {
846 case POW_KEY_RED: gr_setcolor(gr_getcolor(63, 5, 5)); break;
847 case POW_KEY_BLUE: gr_setcolor(gr_getcolor(5, 5, 63)); break;
848 case POW_KEY_GOLD: gr_setcolor(gr_getcolor(63, 63, 10)); break;
850 Error("Illegal key type: %i", objp->id);
852 g3_rotate_point(&sphere_point,&objp->pos);
853 g3_draw_sphere(&sphere_point,objp->size*4);
862 gr_bitmapm(AutomapHires?10:5, AutomapHires?10:5, &name_canv_left->cv_bitmap);
863 gr_bitmapm(grd_curcanv->cv_bitmap.bm_w-(AutomapHires?10:5)-name_canv_right->cv_bitmap.bm_w,AutomapHires?10:5,&name_canv_right->cv_bitmap);
865 WIN(DDGRUNLOCK(dd_grd_curcanv));
870 #ifndef AUTOMAP_DIRECT_RENDER
872 gr_show_canvas( &Pages[current_page] );
875 //gr_bm_ubitblt( Page.cv_bitmap.bm_w, Page.cv_bitmap.bm_h, Page.cv_bitmap.bm_x, Page.cv_bitmap.bm_y, 0, 0, &Page.cv_bitmap, &VR_screen_pages[0].cv_bitmap );
876 gr_bm_ubitblt( Page.cv_bitmap.bm_w, Page.cv_bitmap.bm_h, Page.cv_bitmap.bm_x, Page.cv_bitmap.bm_y, 0, 0, &Page.cv_bitmap, &grd_curscreen->sc_canvas.cv_bitmap );
878 dd_gr_blt_screen(&ddPage, 0,0,0,0,0,0,0,0);
887 #define LEAVE_TIME 0x00010000
889 #define LEAVE_TIME 0x4000
892 #define WINDOW_WIDTH 288
895 //print to canvas & double height
896 grs_canvas *print_to_canvas(char *s,grs_font *font, int fc, int bc, int double_flag)
901 grs_canvas *temp_canv;
906 dd_grs_canvas *save_canv,
907 grs_canvas *save_canv
911 save_canv = dd_grd_curcanv,
912 save_canv = grd_curcanv
915 save_font = grd_curcanv->cv_font;
916 gr_set_curfont(font); //set the font we're going to use
917 gr_get_string_size(s,&w,&h,&aw); //now get the string size
918 gr_set_curfont(save_font); //restore real font
920 //temp_canv = gr_create_canvas(font->ft_w*strlen(s),font->ft_h*2);
921 temp_canv = gr_create_canvas(w,font->ft_h*2);
923 gr_set_current_canvas(temp_canv);
924 gr_set_curfont(font);
925 gr_clear_canvas(TRANSPARENCY_COLOR); //trans color
926 gr_set_fontcolor(fc,bc);
929 //now double it, since we're drawing to 400-line modex screen
932 data = temp_canv->cv_bitmap.bm_data;
933 rs = temp_canv->cv_bitmap.bm_rowsize;
935 for (y=temp_canv->cv_bitmap.bm_h/2;y--;) {
936 memcpy(data+(rs*y*2),data+(rs*y),temp_canv->cv_bitmap.bm_w);
937 memcpy(data+(rs*(y*2+1)),data+(rs*y),temp_canv->cv_bitmap.bm_w);
942 dd_gr_set_current_canvas(save_canv),
943 gr_set_current_canvas(save_canv)
949 //print to buffer, double heights, and blit bitmap to screen
950 void modex_printf(int x,int y,char *s,grs_font *font,int color)
952 grs_canvas *temp_canv;
954 temp_canv = print_to_canvas(s, font, color, -1, !AutomapHires);
956 gr_bitmapm(x,y,&temp_canv->cv_bitmap);
958 gr_free_canvas(temp_canv);
961 //name for each group. maybe move somewhere else
962 char *system_name[] = {
970 void create_name_canv()
972 char name_level_left[128],name_level_right[128];
974 if (Current_level_num > 0)
975 sprintf(name_level_left, "%s %i",TXT_LEVEL, Current_level_num);
977 sprintf(name_level_left, "Secret Level %i",-Current_level_num);
979 if (Current_mission_num == Builtin_mission_num && Current_level_num>0) //built-in mission
980 sprintf(name_level_right,"%s %d: ",system_name[(Current_level_num-1)/4],((Current_level_num-1)%4)+1);
982 strcpy(name_level_right, " ");
984 strcat(name_level_right, Current_level_name);
986 gr_set_fontcolor(Green_31,-1);
987 name_canv_left = print_to_canvas(name_level_left, SMALL_FONT, Green_31, -1, !AutomapHires);
988 name_canv_right = print_to_canvas(name_level_right,SMALL_FONT, Green_31, -1, !AutomapHires);
993 extern void GameLoop(int, int );
994 extern int set_segment_depths(int start_seg, ubyte *segbuf);
996 int Automap_active = 0;
999 #define MAP_BACKGROUND_FILENAME (AutomapHires?"\x01MAPB.PCX":"\x01MAP.PCX") //load only from hog file
1001 #define MAP_BACKGROUND_FILENAME ((AutomapHires && cfexist("mapb.pcx"))?"MAPB.PCX":"MAP.PCX")
1004 int Automap_always_hires=0;
1005 extern int MenuHiresAvailable;
1007 extern int Current_display_mode;
1009 u_int32_t automap_mode = SM(640,480);
1010 int automap_width = 640;
1011 int automap_height = 480;
1012 int automap_use_game_res=0;
1014 #define RESCALE_X(x) ((x) * automap_width / 640)
1015 #define RESCALE_Y(y) ((y) * automap_height / 480)
1017 void do_automap( int key_code ) {
1024 #if !defined(AUTOMAP_DIRECT_RENDER) || !defined(NDEBUG)
1029 int pause_game=1; // Set to 1 if everything is paused during automap...No pause during net.
1031 control_info saved_control_info;
1032 grs_bitmap Automap_background;
1033 int Max_segments_away = 0;
1034 int SegmentLimit = 1;
1037 int must_free_canvas=0;
1039 WIN(int dd_VR_screen_mode_save);
1040 WIN(int redraw_screen=0);
1044 init_automap_colors();
1046 key_code = key_code; // disable warning...
1048 if ((Game_mode & GM_MULTI) && (Function_mode == FMODE_GAME) && (!Endlevel_sequence))
1053 digi_pause_digi_sounds();
1056 Max_edges = min(MAX_EDGES_FROM_VERTS(Num_vertices),MAX_EDGES); //make maybe smaller than max
1058 mprintf( (0, "Num_vertices=%d, Max_edges=%d, (MAX:%d)\n", Num_vertices, Max_edges, MAX_EDGES ));
1059 mprintf( (0, "Allocated %d K for automap edge list\n", (sizeof(Edge_info)+sizeof(short))*Max_edges/1024 ));
1061 #if !defined (WINDOWS) && !defined(MACINTOSH)
1062 if ((Current_display_mode!=0 && Current_display_mode!=2) || (Automap_always_hires && MenuHiresAvailable)) {
1063 #if !defined(POLY_ACC)
1064 //edit 4/23/99 Matt Mueller - don't switch res unless we need to
1065 if (grd_curscreen->sc_mode != AUTOMAP_MODE)
1066 gr_set_mode( AUTOMAP_MODE );
1068 gr_set_current_canvas(NULL);
1070 automap_width=grd_curscreen->sc_canvas.cv_bitmap.bm_w;
1071 automap_height=grd_curscreen->sc_canvas.cv_bitmap.bm_h;
1073 PA_DFX (pa_set_frontbuffer_current());
1077 gr_set_mode( SM(320, 400));
1081 AutomapHires = 1; //Mac & Windows(?) always in hires
1085 dd_VR_screen_mode_save = VR_screen_mode;
1086 VR_screen_mode = SM95_640x480x8; // HACK! Forcing reinit of 640x480
1087 set_screen_mode(SCREEN_GAME);
1090 FontHires = FontHiresAvailable && AutomapHires;
1097 if (!AutomapHires) {
1099 #ifndef AUTOMAP_DIRECT_RENDER
1100 gr_init_sub_canvas(&Pages[0],grd_curcanv,0,0,320,400);
1101 gr_init_sub_canvas(&Pages[1],grd_curcanv,0,401,320,400);
1102 gr_init_sub_canvas(&DrawingPages[0],&Pages[0],16,69,WINDOW_WIDTH,272);
1103 gr_init_sub_canvas(&DrawingPages[1],&Pages[1],16,69,WINDOW_WIDTH,272);
1106 gr_init_bitmap_data (&Automap_background);
1107 pcx_error = pcx_read_bitmap(MAP_BACKGROUND_FILENAME, &Automap_background, BM_LINEAR, pal);
1108 if (pcx_error != PCX_ERROR_NONE)
1109 Error("File %s - PCX error: %s", MAP_BACKGROUND_FILENAME, pcx_errormsg(pcx_error));
1110 gr_remap_bitmap_good(&Automap_background, pal, -1, -1);
1112 #ifndef AUTOMAP_DIRECT_RENDER
1115 gr_set_current_canvas(&Pages[i]);
1116 gr_bitmap(0, 0, &Automap_background );
1117 modex_printf(40, 22, TXT_AUTOMAP, HUGE_FONT, Font_color_20);
1118 modex_printf(30, 353, TXT_TURN_SHIP, SMALL_FONT, Font_color_20);
1119 modex_printf(30, 369, TXT_SLIDE_UPDOWN, SMALL_FONT, Font_color_20);
1120 modex_printf(30, 385, TXT_VIEWING_DISTANCE, SMALL_FONT, Font_color_20);
1122 gr_free_bitmap_data(&Automap_background);
1123 gr_set_current_canvas(&DrawingPages[current_page]);
1124 #endif /* AUTOMAP_DIRECT_RENDER */
1125 #endif /* MACINTOSH */
1128 #ifndef AUTOMAP_DIRECT_RENDER
1129 if (VR_render_buffer[0].cv_w >= automap_width && VR_render_buffer[0].cv_h >= automap_height)
1131 WIN(dd_gr_init_sub_canvas(&ddPage, &dd_VR_render_buffer[0], 0, 0, automap_width,automap_height));
1133 #if defined(MACINTOSH) && defined(POLY_ACC)
1136 // we want all the automap border stuff to be drawn straight to the screen
1137 gr_init_sub_canvas(&Page,&(grd_curscreen->sc_canvas),0, 0, automap_width, automap_height);
1141 gr_init_sub_canvas(&Page,&VR_render_buffer[0],0, 0, automap_width, automap_height);
1144 gr_init_sub_canvas(&Page,&VR_render_buffer[0],0, 0, automap_width, automap_height);
1151 MALLOC(raw_data,ubyte,automap_width*automap_height);
1152 gr_init_canvas(&Page,raw_data,BM_LINEAR,automap_width,automap_height);
1154 dd_gr_init_canvas(&ddPage, BM_LINEAR, automap_width,automap_height);
1155 gr_init_canvas(&Page,NULL,BM_LINEAR,automap_width,automap_height);
1157 must_free_canvas = 1;
1160 WIN(dd_gr_init_sub_canvas(&ddDrawingPage, &ddPage, RESCALE_X(27), RESCALE_Y(80), RESCALE_X(582), RESCALE_Y(334)));
1161 gr_init_sub_canvas(&DrawingPage, &Page, RESCALE_X(27), RESCALE_Y(80), RESCALE_X(582), RESCALE_Y(334));
1164 dd_gr_set_current_canvas(&ddPage),
1165 gr_set_current_canvas(&Page)
1169 #if defined(POLY_ACC)
1172 pcx_error = pcx_read_bitmap(MAP_BACKGROUND_FILENAME,&(grd_curcanv->cv_bitmap),BM_LINEAR15,pal);
1176 pcx_error = pcx_read_bitmap(MAP_BACKGROUND_FILENAME,&(grd_curcanv->cv_bitmap),BM_LINEAR15,pal);
1177 if ( pcx_error != PCX_ERROR_NONE )
1179 Error("File %s - PCX error: %s",MAP_BACKGROUND_FILENAME,pcx_errormsg(pcx_error));
1185 pcx_error = pcx_read_bitmap(MAP_BACKGROUND_FILENAME,&(grd_curcanv->cv_bitmap),BM_LINEAR,pal);
1186 if ( pcx_error != PCX_ERROR_NONE )
1188 Error("File %s - PCX error: %s",MAP_BACKGROUND_FILENAME,pcx_errormsg(pcx_error));
1192 gr_remap_bitmap_good( &(grd_curcanv->cv_bitmap), pal, -1, -1 );
1197 WIN(DDGRLOCK(dd_grd_curcanv));
1198 pcx_error = pcx_read_fullscr(MAP_BACKGROUND_FILENAME, pal);
1199 if ( pcx_error != PCX_ERROR_NONE ) {
1200 //printf("File %s - PCX error: %s",MAP_BACKGROUND_FILENAME,pcx_errormsg(pcx_error));
1201 Error("File %s - PCX error: %s",MAP_BACKGROUND_FILENAME,pcx_errormsg(pcx_error));
1205 gr_remap_bitmap_good( &(grd_curcanv->cv_bitmap), pal, -1, -1 );
1208 gr_set_curfont(HUGE_FONT);
1209 gr_set_fontcolor(BM_XRGB(20, 20, 20), -1);
1210 gr_printf(RESCALE_X(80), RESCALE_Y(36), TXT_AUTOMAP, HUGE_FONT);
1211 gr_set_curfont(SMALL_FONT);
1212 gr_set_fontcolor(BM_XRGB(20, 20, 20), -1);
1213 gr_printf(RESCALE_X(60), RESCALE_Y(426), TXT_TURN_SHIP);
1214 gr_printf(RESCALE_X(60), RESCALE_Y(443), TXT_SLIDE_UPDOWN);
1215 gr_printf(RESCALE_X(60), RESCALE_Y(460), TXT_VIEWING_DISTANCE);
1216 WIN(DDGRUNLOCK(dd_grd_curcanv));
1218 #ifndef AUTOMAP_DIRECT_RENDER
1220 dd_gr_set_current_canvas(&ddDrawingPage),
1221 gr_set_current_canvas(&DrawingPage)
1227 WIN(if (!redraw_screen) {)
1228 automap_build_edge_list();
1231 ViewDist = ZOOM_DEFAULT;
1232 ViewMatrix = Objects[Players[Player_num].objnum].orient;
1234 tangles.p = PITCH_DEFAULT;
1240 view_target = Objects[Players[Player_num].objnum].pos;
1242 t1 = entry_time = timer_get_fixed_seconds();
1245 //Fill in Automap_visited from Objects[Players[Player_num].objnum].segnum
1246 Max_segments_away = set_segment_depths(Objects[Players[Player_num].objnum].segnum, Automap_visited);
1247 SegmentLimit = Max_segments_away;
1249 adjust_segment_limit(SegmentLimit);
1252 WIN(if (redraw_screen) redraw_screen = 0);
1255 if ( leave_mode==0 && Controls.automap_state && (timer_get_fixed_seconds()-entry_time)>LEAVE_TIME)
1258 if ( !Controls.automap_state && (leave_mode==1) )
1263 saved_control_info = Controls; // Save controls so we can zero them
1264 memset(&Controls,0,sizeof(control_info)); // Clear everything...
1265 old_wiggle = ConsoleObject->mtype.phys_info.flags & PF_WIGGLE; // Save old wiggle
1266 ConsoleObject->mtype.phys_info.flags &= ~PF_WIGGLE; // Turn off wiggle
1268 if (multi_menu_poll())
1271 // GameLoop( 0, 0 ); // Do game loop with no rendering and no reading controls.
1272 ConsoleObject->mtype.phys_info.flags |= old_wiggle; // Restore wiggle
1273 Controls = saved_control_info;
1277 controls_read_all();
1279 controls_read_all_win();
1282 if ( Controls.automap_down_count ) {
1288 //see if redbook song needs to be restarted
1289 songs_check_redbook_repeat();
1294 DoMessageStuff(&msg);
1295 if (_RedrawScreen) {
1296 _RedrawScreen = FALSE;
1301 if (msg.message == WM_QUIT) exit(1);
1308 while( (c=key_inkey()) ) {
1311 case KEY_BACKSP: Int3(); break;
1314 case KEY_PRINT_SCREEN: {
1317 dd_gr_set_current_canvas(NULL),
1318 gr_set_current_canvas(NULL)
1321 #ifndef AUTOMAP_DIRECT_RENDER
1323 gr_set_current_canvas(&Pages[current_page]);
1325 save_screen_shot(1);
1335 case KEY_DEBUGGED+KEY_F: {
1336 for (i=0; i<=Highest_segment_index; i++ )
1337 Automap_visited[i] = 1;
1338 automap_build_edge_list();
1339 Max_segments_away = set_segment_depths(Objects[Players[Player_num].objnum].segnum, Automap_visited);
1340 SegmentLimit = Max_segments_away;
1341 adjust_segment_limit(SegmentLimit);
1347 if (SegmentLimit > 1) {
1349 adjust_segment_limit(SegmentLimit);
1353 if (SegmentLimit < Max_segments_away) {
1355 adjust_segment_limit(SegmentLimit);
1368 if (Game_mode & GM_MULTI)
1374 marker_num = c-KEY_1;
1376 switch(c) { // god this is stupid.....
1377 case KEY_1: marker_num = 0; break;
1378 case KEY_2: marker_num = 1; break;
1379 case KEY_3: marker_num = 2; break;
1380 case KEY_4: marker_num = 3; break;
1381 case KEY_5: marker_num = 4; break;
1382 case KEY_6: marker_num = 5; break;
1383 case KEY_7: marker_num = 6; break;
1384 case KEY_8: marker_num = 7; break;
1385 case KEY_9: marker_num = 8; break;
1386 case KEY_0: marker_num = 9; break;
1389 if (marker_num<=maxdrop)
1391 if (MarkerObject[marker_num] != -1)
1392 HighlightMarker=marker_num;
1396 case KEY_D+KEY_CTRLED:
1397 #ifndef AUTOMAP_DIRECT_RENDER
1398 if (current_page) //menu will only work on page 0
1399 draw_automap(); //..so switch from 1 to 0
1402 if (HighlightMarker > -1 && MarkerObject[HighlightMarker] != -1) {
1403 #ifndef AUTOMAP_DIRECT_RENDER
1405 dd_gr_set_current_canvas(&ddPages[current_page]),
1406 gr_set_current_canvas(&Pages[current_page])
1410 if (nm_messagebox( NULL, 2, TXT_YES, TXT_NO, "Delete Marker?" ) == 0) {
1411 obj_delete(MarkerObject[HighlightMarker]);
1412 MarkerObject[HighlightMarker]=-1;
1413 MarkerMessage[HighlightMarker][0]=0;
1414 HighlightMarker = -1;
1425 if (MarkerScale<30.0)
1430 //added 8/23/99 by Matt Mueller for hot key res/fullscreen changing, and menu access
1432 case KEY_CTRLED+KEY_SHIFTED+KEY_PADDIVIDE:
1433 case KEY_ALTED+KEY_CTRLED+KEY_PADDIVIDE:
1434 case KEY_ALTED+KEY_SHIFTED+KEY_PADDIVIDE:
1437 case KEY_CTRLED+KEY_SHIFTED+KEY_PADMULTIPLY:
1438 case KEY_ALTED+KEY_CTRLED+KEY_PADMULTIPLY:
1439 case KEY_ALTED+KEY_SHIFTED+KEY_PADMULTIPLY:
1442 case KEY_CTRLED+KEY_SHIFTED+KEY_PADMINUS:
1443 case KEY_ALTED+KEY_CTRLED+KEY_PADMINUS:
1444 case KEY_ALTED+KEY_SHIFTED+KEY_PADMINUS:
1446 //should we just cycle through the list that is displayed in the res change menu?
1447 // what if their card/X/etc can't handle that mode? hrm.
1448 //well, the quick access to the menu is good enough for now.
1450 case KEY_CTRLED+KEY_SHIFTED+KEY_PADPLUS:
1451 case KEY_ALTED+KEY_CTRLED+KEY_PADPLUS:
1452 case KEY_ALTED+KEY_SHIFTED+KEY_PADPLUS:
1456 case KEY_ALTED+KEY_ENTER:
1457 case KEY_ALTED+KEY_PADENTER:
1458 gr_toggle_fullscreen_game();
1465 if ( Controls.fire_primary_down_count ) {
1466 // Reset orientation
1467 ViewDist = ZOOM_DEFAULT;
1468 tangles.p = PITCH_DEFAULT;
1471 view_target = Objects[Players[Player_num].objnum].pos;
1474 ViewDist -= Controls.forward_thrust_time*ZOOM_SPEED_FACTOR;
1476 tangles.p += fixdiv( Controls.pitch_time, ROT_SPEED_DIVISOR );
1477 tangles.h += fixdiv( Controls.heading_time, ROT_SPEED_DIVISOR );
1478 tangles.b += fixdiv( Controls.bank_time, ROT_SPEED_DIVISOR*2 );
1480 if ( Controls.vertical_thrust_time || Controls.sideways_thrust_time ) {
1481 vms_angvec tangles1;
1483 old_vt = view_target;
1485 vm_angles_2_matrix(&tempm,&tangles1);
1486 vm_matrix_x_matrix(&ViewMatrix,&Objects[Players[Player_num].objnum].orient,&tempm);
1487 vm_vec_scale_add2( &view_target, &ViewMatrix.uvec, Controls.vertical_thrust_time*SLIDE_SPEED );
1488 vm_vec_scale_add2( &view_target, &ViewMatrix.rvec, Controls.sideways_thrust_time*SLIDE_SPEED );
1489 if ( vm_vec_dist_quick( &view_target, &Objects[Players[Player_num].objnum].pos) > i2f(1000) ) {
1490 view_target = old_vt;
1494 vm_angles_2_matrix(&tempm,&tangles);
1495 vm_matrix_x_matrix(&ViewMatrix,&Objects[Players[Player_num].objnum].orient,&tempm);
1497 if ( ViewDist < ZOOM_MIN_VALUE ) ViewDist = ZOOM_MIN_VALUE;
1498 if ( ViewDist > ZOOM_MAX_VALUE ) ViewDist = ZOOM_MAX_VALUE;
1504 gr_palette_load( gr_palette );
1507 t2 = timer_get_fixed_seconds();
1514 //d_free(DrawingListBright);
1516 gr_free_canvas(name_canv_left); name_canv_left=NULL;
1517 gr_free_canvas(name_canv_right); name_canv_right=NULL;
1519 if (must_free_canvas) {
1520 #ifndef AUTOMAP_DIRECT_RENDER
1522 DDFreeSurface(ddPages[0].lpdds),
1523 d_free(Page.cv_bitmap.bm_data)
1528 mprintf( (0, "Automap memory freed\n" ));
1530 game_flush_inputs();
1532 #if defined(POLY_ACC) && defined(MACINTOSH)
1535 pa_set_context(kGamePlayDrawContextID, NULL);
1542 digi_resume_digi_sounds();
1546 VR_screen_mode = dd_VR_screen_mode_save;
1552 void adjust_segment_limit(int SegmentLimit)
1557 mprintf(( 0, "Seglimit: %d\n", SegmentLimit ));
1559 for (i=0; i<=Highest_edge_index; i++ ) {
1561 e->flags |= EF_TOO_FAR;
1562 for (e1=0; e1<e->num_faces; e1++ ) {
1563 if ( Automap_visited[e->segnum[e1]] <= SegmentLimit ) {
1564 e->flags &= (~EF_TOO_FAR);
1572 void draw_all_edges()
1576 ubyte nfacing,nnfacing;
1580 fix min_distance = 0x7fffffff;
1586 for (i=0; i<=Highest_edge_index; i++ ) {
1587 //e = &Edges[Edge_used_list[i]];
1589 if (!(e->flags & EF_USED)) continue;
1591 if ( e->flags & EF_TOO_FAR) continue;
1593 if (e->flags&EF_FRONTIER) { // A line that is between what we have seen and what we haven't
1594 if ( (!(e->flags&EF_SECRET))&&(e->color==Wall_normal_color))
1595 continue; // If a line isn't secret and is normal color, then don't draw it
1598 cc=rotate_list(2,e->verts);
1599 distance = Segment_points[e->verts[1]].p3_z;
1601 if (min_distance>distance )
1602 min_distance = distance;
1604 if (!cc.and) { //all off screen?
1605 nfacing = nnfacing = 0;
1606 tv1 = &Vertices[e->verts[0]];
1608 while( j<e->num_faces && (nfacing==0 || nnfacing==0) ) {
1611 get_side_normal(&Segments[e->segnum[j]], e->sides[j], 0, &temp_v );
1612 if (!g3_check_normal_facing( tv1, &temp_v ) )
1614 if (!g3_check_normal_facing( tv1, &Segments[e->segnum[j]].sides[e->sides[j]].normals[0] ) )
1622 if ( nfacing && nnfacing ) {
1624 DrawingListBright[nbright++] = e-Edges;
1625 } else if ( e->flags&(EF_DEFINING|EF_GRATE) ) {
1626 if ( nfacing == 0 ) {
1627 if ( e->flags & EF_NO_FADE )
1628 gr_setcolor( e->color );
1630 gr_setcolor( gr_fade_table[e->color+256*8] );
1631 g3_draw_line( &Segment_points[e->verts[0]], &Segment_points[e->verts[1]] );
1633 DrawingListBright[nbright++] = e-Edges;
1639 /// mprintf( (0, "Min distance=%.2f, ViewDist=%.2f, Delta=%.2f\n", f2fl(min_distance), f2fl(ViewDist), f2fl(min_distance)- f2fl(ViewDist) ));
1641 if ( min_distance < 0 ) min_distance = 0;
1643 // Sort the bright ones using a shell sort
1646 int i, j, incr, v1, v2;
1650 for (i=incr; i<nbright; i++ ) {
1653 // compare element j and j+incr
1654 v1 = Edges[DrawingListBright[j]].verts[0];
1655 v2 = Edges[DrawingListBright[j+incr]].verts[0];
1657 if (Segment_points[v1].p3_z < Segment_points[v2].p3_z) {
1658 // If not in correct order, them swap 'em
1659 t=DrawingListBright[j+incr];
1660 DrawingListBright[j+incr]=DrawingListBright[j];
1661 DrawingListBright[j]=t;
1672 // Draw the bright ones
1673 for (i=0; i<nbright; i++ ) {
1676 e = &Edges[DrawingListBright[i]];
1677 p1 = &Segment_points[e->verts[0]];
1678 p2 = &Segment_points[e->verts[1]];
1679 dist = p1->p3_z - min_distance;
1680 // Make distance be 1.0 to 0.0, where 0.0 is 10 segments away;
1681 if ( dist < 0 ) dist=0;
1682 if ( dist >= Automap_farthest_dist ) continue;
1684 if ( e->flags & EF_NO_FADE ) {
1685 gr_setcolor( e->color );
1687 dist = F1_0 - fixdiv( dist, Automap_farthest_dist );
1688 color = f2i( dist*31 );
1689 gr_setcolor( gr_fade_table[e->color+color*256] );
1691 g3_draw_line( p1, p2 );
1697 //==================================================================
1699 // All routines below here are used to build the Edge list
1701 //==================================================================
1704 //finds edge, filling in edge_ptr. if found old edge, returns index, else return -1
1705 static int automap_find_edge(int v0,int v1,Edge_info **edge_ptr)
1713 oldhash = hash = ((v0*5+v1) % Max_edges);
1718 ev0 = (int)(Edges[hash].verts[0]);
1719 ev1 = (int)(Edges[hash].verts[1]);
1720 evv = (ev1<<16)+ev0;
1721 if (Edges[hash].num_faces == 0 ) ret=0;
1722 else if (evv == vv) ret=1;
1724 if (++hash==Max_edges) hash=0;
1725 if (hash==oldhash) Error("Edge list full!");
1729 *edge_ptr = &Edges[hash];
1739 void add_one_edge( short va, short vb, ubyte color, ubyte side, short segnum, int hidden, int grate, int no_fade ) {
1744 if ( Num_edges >= Max_edges) {
1745 // GET JOHN! (And tell him that his
1746 // MAX_EDGES_FROM_VERTS formula is hosed.)
1747 // If he's not around, save the mine,
1748 // and send him mail so he can look
1749 // at the mine later. Don't modify it.
1750 // This is important if this happens.
1751 Int3(); // LOOK ABOVE!!!!!!
1761 found = automap_find_edge(va,vb,&e);
1768 e->flags = EF_USED | EF_DEFINING; // Assume a normal line
1770 e->segnum[0] = segnum;
1771 //Edge_used_list[Num_edges] = e-Edges;
1772 if ( (e-Edges) > Highest_edge_index )
1773 Highest_edge_index = e - Edges;
1776 //Assert(e->num_faces < 8 );
1778 if ( color != Wall_normal_color )
1779 if (color != Wall_revealed_color)
1782 if ( e->num_faces < 4 ) {
1783 e->sides[e->num_faces] = side;
1784 e->segnum[e->num_faces] = segnum;
1790 e->flags |= EF_GRATE;
1793 e->flags|=EF_SECRET; // Mark this as a hidden edge
1795 e->flags |= EF_NO_FADE;
1798 void add_one_unknown_edge( short va, short vb ) {
1809 found = automap_find_edge(va,vb,&e);
1811 e->flags|=EF_FRONTIER; // Mark as a border edge
1815 extern obj_position Player_init[];
1818 void add_segment_edges(segment *seg)
1820 int is_grate, no_fade;
1823 int segnum = seg-Segments;
1825 int ttype,trigger_num;
1827 for (sn=0;sn<MAX_SIDES_PER_SEGMENT;sn++) {
1828 short vertex_list[4];
1836 if (seg->children[sn] == -1) {
1837 color = Wall_normal_color;
1840 switch( Segment2s[segnum].special ) {
1841 case SEGMENT_IS_FUELCEN:
1842 color = BM_XRGB( 29, 27, 13 );
1844 case SEGMENT_IS_CONTROLCEN:
1845 if (Control_center_present)
1846 color = BM_XRGB( 29, 0, 0 );
1848 case SEGMENT_IS_ROBOTMAKER:
1849 color = BM_XRGB( 29, 0, 31 );
1853 if (seg->sides[sn].wall_num > -1) {
1855 trigger_num = Walls[seg->sides[sn].wall_num].trigger;
1856 ttype = Triggers[trigger_num].type;
1857 if (ttype==TT_SECRET_EXIT)
1859 color = BM_XRGB( 29, 0, 31 );
1864 switch( Walls[seg->sides[sn].wall_num].type ) {
1866 if (Walls[seg->sides[sn].wall_num].keys == KEY_BLUE) {
1868 color = Wall_door_blue;
1869 //mprintf((0, "Seg %i, side %i has BLUE wall\n", segnum, sn));
1870 } else if (Walls[seg->sides[sn].wall_num].keys == KEY_GOLD) {
1872 color = Wall_door_gold;
1873 //mprintf((0, "Seg %i, side %i has GOLD wall\n", segnum, sn));
1874 } else if (Walls[seg->sides[sn].wall_num].keys == KEY_RED) {
1876 color = Wall_door_red;
1877 //mprintf((0, "Seg %i, side %i has RED wall\n", segnum, sn));
1878 } else if (!(WallAnims[Walls[seg->sides[sn].wall_num].clip_num].flags & WCF_HIDDEN)) {
1879 int connected_seg = seg->children[sn];
1880 if (connected_seg != -1) {
1881 int connected_side = find_connect_side(seg, &Segments[connected_seg]);
1882 int keytype = Walls[Segments[connected_seg].sides[connected_side].wall_num].keys;
1883 if ((keytype != KEY_BLUE) && (keytype != KEY_GOLD) && (keytype != KEY_RED))
1884 color = Wall_door_color;
1886 switch (Walls[Segments[connected_seg].sides[connected_side].wall_num].keys) {
1887 case KEY_BLUE: color = Wall_door_blue; no_fade = 1; break;
1888 case KEY_GOLD: color = Wall_door_gold; no_fade = 1; break;
1889 case KEY_RED: color = Wall_door_red; no_fade = 1; break;
1890 default: Error("Inconsistent data. Supposed to be a colored wall, but not blue, gold or red.\n");
1892 //mprintf((0, "Seg %i, side %i has a colored door on the other side.\n", segnum, sn));
1897 color = Wall_normal_color;
1899 //mprintf((0, "Wall at seg:side %i:%i is hidden.\n", seg-Segments, sn));
1903 // Make grates draw properly
1904 if (WALL_IS_DOORWAY(seg,sn) & WID_RENDPAST_FLAG)
1908 color = Wall_normal_color;
1910 case WALL_BLASTABLE:
1912 color = Wall_door_color;
1917 if (segnum==Player_init[Player_num].segnum)
1918 color = BM_XRGB(31,0,31);
1920 if ( color != 255 ) {
1921 // If they have a map powerup, draw unvisited areas in dark blue.
1922 if (Players[Player_num].flags & PLAYER_FLAGS_MAP_ALL && (!Automap_visited[segnum]))
1923 color = Wall_revealed_color;
1928 get_side_verts(vertex_list,segnum,sn);
1929 add_one_edge( vertex_list[0], vertex_list[1], color, sn, segnum, hidden_flag, 0, no_fade );
1930 add_one_edge( vertex_list[1], vertex_list[2], color, sn, segnum, hidden_flag, 0, no_fade );
1931 add_one_edge( vertex_list[2], vertex_list[3], color, sn, segnum, hidden_flag, 0, no_fade );
1932 add_one_edge( vertex_list[3], vertex_list[0], color, sn, segnum, hidden_flag, 0, no_fade );
1935 add_one_edge( vertex_list[0], vertex_list[2], color, sn, segnum, hidden_flag, 1, no_fade );
1936 add_one_edge( vertex_list[1], vertex_list[3], color, sn, segnum, hidden_flag, 1, no_fade );
1944 // Adds all the edges from a segment we haven't visited yet.
1946 void add_unknown_segment_edges(segment *seg)
1949 int segnum = seg-Segments;
1951 for (sn=0;sn<MAX_SIDES_PER_SEGMENT;sn++) {
1952 short vertex_list[4];
1954 // Only add edges that have no children
1955 if (seg->children[sn] == -1) {
1956 get_side_verts(vertex_list,segnum,sn);
1958 add_one_unknown_edge( vertex_list[0], vertex_list[1] );
1959 add_one_unknown_edge( vertex_list[1], vertex_list[2] );
1960 add_one_unknown_edge( vertex_list[2], vertex_list[3] );
1961 add_one_unknown_edge( vertex_list[3], vertex_list[0] );
1969 void automap_build_edge_list()
1976 if ( Players[Player_num].flags & PLAYER_FLAGS_MAP_ALL_CHEAT )
1977 Automap_cheat = 1; // Damn cheaters...
1980 for (i=0; i<Max_edges; i++) {
1981 Edges[i].num_faces = 0;
1985 Highest_edge_index = -1;
1987 if (Automap_cheat || (Players[Player_num].flags & PLAYER_FLAGS_MAP_ALL) ) {
1988 // Cheating, add all edges as visited
1989 for (s=0; s<=Highest_segment_index; s++)
1991 if (Segments[s].segnum != -1)
1994 add_segment_edges(&Segments[s]);
1997 // Not cheating, add visited edges, and then unvisited edges
1998 for (s=0; s<=Highest_segment_index; s++)
2000 if (Segments[s].segnum != -1)
2002 if (Automap_visited[s]) {
2003 add_segment_edges(&Segments[s]);
2006 for (s=0; s<=Highest_segment_index; s++)
2008 if (Segments[s].segnum != -1)
2010 if (!Automap_visited[s]) {
2011 add_unknown_segment_edges(&Segments[s]);
2015 // Find unnecessary lines (These are lines that don't have to be drawn because they have small curvature)
2016 for (i=0; i<=Highest_edge_index; i++ ) {
2018 if (!(e->flags&EF_USED)) continue;
2020 for (e1=0; e1<e->num_faces; e1++ ) {
2021 for (e2=1; e2<e->num_faces; e2++ ) {
2022 if ( (e1 != e2) && (e->segnum[e1] != e->segnum[e2]) ) {
2025 get_side_normal(&Segments[e->segnum[e1]], e->sides[e1], 0, &v1 );
2026 get_side_normal(&Segments[e->segnum[e2]], e->sides[e2], 0, &v2 );
2027 if ( vm_vec_dot(&v1,&v2) > (F1_0-(F1_0/10)) ) {
2029 if ( vm_vec_dot( &Segments[e->segnum[e1]].sides[e->sides[e1]].normals[0], &Segments[e->segnum[e2]].sides[e->sides[e2]].normals[0] ) > (F1_0-(F1_0/10)) ) {
2031 e->flags &= (~EF_DEFINING);
2036 if (!(e->flags & EF_DEFINING))
2041 mprintf( (0, "Automap used %d / %d edges\n", Num_edges, Max_edges ));
2045 char Marker_input [40];
2047 ubyte DefiningMarkerMessage=0;
2048 ubyte MarkerBeingDefined;
2049 ubyte LastMarkerDropped;
2051 void InitMarkerInput ()
2055 //find free marker slot
2057 if (Game_mode & GM_MULTI)
2058 maxdrop=MAX_DROP_MULTI;
2060 maxdrop=MAX_DROP_SINGLE;
2062 for (i=0;i<maxdrop;i++)
2063 if (MarkerObject[(Player_num*2)+i] == -1) //found free slot!
2066 if (i==maxdrop) //no free slot
2068 if (Game_mode & GM_MULTI)
2069 i = !LastMarkerDropped; //in multi, replace older of two
2071 HUD_init_message("No free marker slots");
2076 //got a free slot. start inputting marker message
2080 DefiningMarkerMessage=1;
2081 MarkerBeingDefined = i;
2084 void MarkerInputMessage (int key)
2089 DefiningMarkerMessage = 0;
2090 game_flush_inputs();
2095 if (Marker_index > 0)
2097 Marker_input[Marker_index] = 0;
2100 strcpy (MarkerMessage[(Player_num*2)+MarkerBeingDefined],Marker_input);
2101 if (Game_mode & GM_MULTI)
2102 strcpy (MarkerOwner[(Player_num*2)+MarkerBeingDefined],Players[Player_num].callsign);
2103 DropMarker(MarkerBeingDefined);
2104 LastMarkerDropped = MarkerBeingDefined;
2105 game_flush_inputs();
2106 DefiningMarkerMessage = 0;
2111 int ascii = key_to_ascii(key);
2113 if (Marker_index < 38 )
2115 Marker_input[Marker_index++] = ascii;
2116 Marker_input[Marker_index] = 0;