1 /* $Id: automap.c,v 1.19 2004-10-09 15:59:28 schaffner 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.
33 #include "pa_enabl.h" //$$POLY_ACC
83 #define AUTOMAP_DIRECT_RENDER
86 #define EF_USED 1 // This edge is used
87 #define EF_DEFINING 2 // A structure defining edge that should always draw.
88 #define EF_FRONTIER 4 // An edge between the known and the unknown.
89 #define EF_SECRET 8 // An edge that is part of a secret wall.
90 #define EF_GRATE 16 // A grate... draw it all the time.
91 #define EF_NO_FADE 32 // An edge that doesn't fade with distance
92 #define EF_TOO_FAR 64 // An edge that is too far away
94 void modex_printf(int x,int y,char *s,grs_font *font,int color);
96 typedef struct Edge_info {
97 short verts[2]; // 4 bytes
98 ubyte sides[4]; // 4 bytes
99 short segnum[4]; // 8 bytes // This might not need to be stored... If you can access the normals of a side.
100 ubyte flags; // 1 bytes // See the EF_??? defines above.
101 ubyte color; // 1 bytes
102 ubyte num_faces; // 1 bytes // 19 bytes...
105 // OLD BUT GOOD -- #define MAX_EDGES_FROM_VERTS(v) ((v*5)/2)
106 // THE following was determined by John by loading levels 1-14 and recording
107 // numbers on 10/26/94.
108 //#define MAX_EDGES_FROM_VERTS(v) (((v)*21)/10)
109 #define MAX_EDGES_FROM_VERTS(v) ((v)*4)
110 //#define MAX_EDGES (MAX_EDGES_FROM_VERTS(MAX_VERTICES))
112 #define MAX_EDGES 6000 // Determined by loading all the levels by John & Mike, Feb 9, 1995
114 #define K_WALL_NORMAL_COLOR BM_XRGB(29, 29, 29 )
115 #define K_WALL_DOOR_COLOR BM_XRGB(5, 27, 5 )
116 #define K_WALL_DOOR_BLUE BM_XRGB(0, 0, 31)
117 #define K_WALL_DOOR_GOLD BM_XRGB(31, 31, 0)
118 #define K_WALL_DOOR_RED BM_XRGB(31, 0, 0)
119 #define K_WALL_REVEALED_COLOR BM_XRGB(0, 0, 25 ) //what you see when you have the full map powerup
120 #define K_HOSTAGE_COLOR BM_XRGB(0, 31, 0 )
121 #define K_FONT_COLOR_20 BM_XRGB(20, 20, 20 )
122 #define K_GREEN_31 BM_XRGB(0, 31, 0)
124 int Wall_normal_color;
129 int Wall_revealed_color;
137 void init_automap_colors(void)
139 Wall_normal_color = K_WALL_NORMAL_COLOR;
140 Wall_door_color = K_WALL_DOOR_COLOR;
141 Wall_door_blue = K_WALL_DOOR_BLUE;
142 Wall_door_gold = K_WALL_DOOR_GOLD;
143 Wall_door_red = K_WALL_DOOR_RED;
144 Wall_revealed_color = K_WALL_REVEALED_COLOR;
145 Hostage_color = K_HOSTAGE_COLOR;
146 Font_color_20 = K_FONT_COLOR_20;
147 Green_31 = K_GREEN_31;
149 White_63 = gr_find_closest_color_current(63,63,63);
150 Blue_48 = gr_find_closest_color_current(0,0,48);
151 Red_48 = gr_find_closest_color_current(48,0,0);
154 // Segment visited list
155 ubyte Automap_visited[MAX_SEGMENTS];
157 // Edge list variables
158 static int Num_edges=0;
159 static int Max_edges; //set each frame
160 static int Highest_edge_index = -1;
161 static Edge_info Edges[MAX_EDGES];
162 static short DrawingListBright[MAX_EDGES];
164 //static short DrawingListBright[MAX_EDGES];
165 //static short Edge_used_list[MAX_EDGES]; //which entries in edge_list have been used
167 // Map movement defines
168 #define PITCH_DEFAULT 9000
169 #define ZOOM_DEFAULT i2f(20*10)
170 #define ZOOM_MIN_VALUE i2f(20*5)
171 #define ZOOM_MAX_VALUE i2f(20*100)
173 #define SLIDE_SPEED (350)
174 #define ZOOM_SPEED_FACTOR 500 //(1500)
175 #define ROT_SPEED_DIVISOR (115000)
177 #ifndef AUTOMAP_DIRECT_RENDER
178 // Screen anvas variables
179 static int current_page=0;
181 static dd_grs_canvas ddPages[2];
182 static dd_grs_canvas ddDrawingPages[2];
184 #define ddPage ddPages[0]
185 #define ddDrawingPage ddDrawingPages[0]
189 #if defined(MACINTOSH) && defined(POLY_ACC)
190 grs_canvas Pages[2]; // non static under rave so the backbuffer callback function can get at them
191 grs_canvas DrawingPages[2]; // non static under rave so the backbuffer callback function can get at them
193 static grs_canvas Pages[2];
194 static grs_canvas DrawingPages[2];
196 #endif /* AUTOMAP_DIRECT_RENDER */
198 #define Page Pages[0]
199 #define DrawingPage DrawingPages[0]
202 static int Automap_cheat = 0; // If set, show everything
204 // Rendering variables
205 static fix Automap_zoom = 0x9000;
206 static vms_vector view_target;
207 static fix Automap_farthest_dist = (F1_0 * 20 * 50); // 50 segments away
208 static vms_matrix ViewMatrix;
209 static fix ViewDist=0;
211 // Function Prototypes
212 void adjust_segment_limit(int SegmentLimit);
213 void draw_all_edges(void);
214 void automap_build_edge_list(void);
216 #define MAX_DROP_MULTI 2
217 #define MAX_DROP_SINGLE 9
219 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
220 int HighlightMarker=-1;
221 char MarkerMessage[NUM_MARKERS][MARKER_MESSAGE_LEN];
222 char MarkerOwner[NUM_MARKERS][CALLSIGN_LEN+1];
223 float MarkerScale=2.0;
224 int MarkerObject[NUM_MARKERS];
226 extern vms_vector Matrix_scale; //how the matrix is currently scaled
229 #if defined(MACINTOSH) && defined(POLY_ACC)
230 // icky hack. automap draw context is no longer valid when this is called.
231 // so we can not use the pa_draw_line function for rave
232 bool automap_draw_line(g3s_point *p0, g3s_point *p1)
234 int savePAEnabledState = PAEnabled;
237 g3_draw_line(&FromPoint, &ToPoint);
238 PAEnabled = savePAEnabledState;
241 # define automap_draw_line g3_draw_line
245 // -------------------------------------------------------------
247 void DrawMarkerNumber (int num)
250 g3s_point BasePoint,FromPoint,ToPoint;
252 float ArrayX[10][20]={ {-.25, 0.0, 0.0, 0.0, -1.0, 1.0},
253 {-1.0, 1.0, 1.0, 1.0, -1.0, 1.0, -1.0, -1.0, -1.0, 1.0},
254 {-1.0, 1.0, 1.0, 1.0, -1.0, 1.0, 0.0, 1.0},
255 {-1.0, -1.0, -1.0, 1.0, 1.0, 1.0},
256 {-1.0, 1.0, -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, -1.0, 1.0},
257 {-1.0, 1.0, -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, -1.0, 1.0},
258 {-1.0, 1.0, 1.0, 1.0},
259 {-1.0, 1.0, 1.0, 1.0, -1.0, 1.0, -1.0, -1.0, -1.0, 1.0},
260 {-1.0, 1.0, 1.0, 1.0, -1.0, 1.0, -1.0, -1.0}
263 float ArrayY[10][20]={ {.75, 1.0, 1.0, -1.0, -1.0, -1.0},
264 {1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, -1.0, -1.0, -1.0},
265 {1.0, 1.0, 1.0, -1.0, -1.0, -1.0, 0.0, 0.0},
266 {1.0, 0.0, 0.0, 0.0, 1.0, -1.0},
267 {1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, -1.0, -1.0, -1.0},
268 {1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, 0.0, 0.0, 0.0},
269 {1.0, 1.0, 1.0, -1.0},
270 {1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, 1.0, 0.0, 0.0},
271 {1.0, 1.0, 1.0, -1.0, 0.0, 0.0, 0.0, 1.0}
273 int NumOfPoints[]={6,10,8,6,10,10,4,10,8};
275 for (i=0;i<NumOfPoints[num];i++)
277 ArrayX[num][i]*=MarkerScale;
278 ArrayY[num][i]*=MarkerScale;
281 if (num==HighlightMarker)
282 gr_setcolor (White_63);
284 gr_setcolor (Blue_48);
287 g3_rotate_point(&BasePoint,&Objects[MarkerObject[(Player_num*2)+num]].pos);
289 for (i=0;i<NumOfPoints[num];i+=2)
295 FromPoint.p3_x+=fixmul ((fl2f (ArrayX[num][i])),Matrix_scale.x);
296 FromPoint.p3_y+=fixmul ((fl2f (ArrayY[num][i])),Matrix_scale.y);
297 g3_code_point (&FromPoint);
298 g3_project_point (&FromPoint);
300 ToPoint.p3_x+=fixmul ((fl2f (ArrayX[num][i+1])),Matrix_scale.x);
301 ToPoint.p3_y+=fixmul ((fl2f (ArrayY[num][i+1])),Matrix_scale.y);
302 g3_code_point (&ToPoint);
303 g3_project_point (&ToPoint);
305 automap_draw_line(&FromPoint, &ToPoint);
309 void DropMarker (int player_marker_num)
311 int marker_num = (Player_num*2)+player_marker_num;
312 object *playerp = &Objects[Players[Player_num].objnum];
314 MarkerPoint[marker_num] = playerp->pos;
316 if (MarkerObject[marker_num] != -1)
317 obj_delete(MarkerObject[marker_num]);
319 MarkerObject[marker_num] = drop_marker_object(&playerp->pos,playerp->segnum,&playerp->orient,marker_num);
322 if (Game_mode & GM_MULTI)
323 multi_send_drop_marker (Player_num,playerp->pos,player_marker_num,MarkerMessage[marker_num]);
328 extern char guidebot_name[];
330 void DropBuddyMarker(object *objp)
334 // 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?
335 marker_num = MAX_DROP_SINGLE+1;
336 if (marker_num > NUM_MARKERS-1)
337 marker_num = NUM_MARKERS-1;
339 sprintf(MarkerMessage[marker_num], "RIP: %s",guidebot_name);
341 MarkerPoint[marker_num] = objp->pos;
343 if (MarkerObject[marker_num] != -1 && MarkerObject[marker_num] !=0)
344 obj_delete(MarkerObject[marker_num]);
346 MarkerObject[marker_num] = drop_marker_object(&objp->pos, objp->segnum, &objp->orient, marker_num);
350 #define MARKER_SPHERE_SIZE 0x58000
355 static int cyc=10,cycdir=1;
356 g3s_point sphere_point;
358 if (Game_mode & GM_MULTI)
363 for (i=0;i<maxdrop;i++)
364 if (MarkerObject[(Player_num*2)+i] != -1) {
366 g3_rotate_point(&sphere_point,&Objects[MarkerObject[(Player_num*2)+i]].pos);
368 gr_setcolor (gr_find_closest_color_current(cyc,0,0));
369 g3_draw_sphere(&sphere_point,MARKER_SPHERE_SIZE);
370 gr_setcolor (gr_find_closest_color_current(cyc+10,0,0));
371 g3_draw_sphere(&sphere_point,MARKER_SPHERE_SIZE/2);
372 gr_setcolor (gr_find_closest_color_current(cyc+20,0,0));
373 g3_draw_sphere(&sphere_point,MARKER_SPHERE_SIZE/4);
375 DrawMarkerNumber (i);
400 for (i=0;i<NUM_MARKERS;i++) {
401 MarkerMessage[i][0]=0;
406 void automap_clear_visited()
409 for (i=0; i<MAX_SEGMENTS; i++ )
410 Automap_visited[i] = 0;
414 grs_canvas *name_canv_left,*name_canv_right;
416 void draw_player( object * obj )
418 vms_vector arrow_pos, head_pos;
419 g3s_point sphere_point, arrow_point, head_point;
421 // Draw Console player -- shaped like a ellipse with an arrow.
422 g3_rotate_point(&sphere_point,&obj->pos);
423 g3_draw_sphere(&sphere_point,obj->size);
425 // Draw shaft of arrow
426 vm_vec_scale_add( &arrow_pos, &obj->pos, &obj->orient.fvec, obj->size*3 );
427 g3_rotate_point(&arrow_point,&arrow_pos);
428 automap_draw_line(&sphere_point, &arrow_point);
430 // Draw right head of arrow
431 vm_vec_scale_add( &head_pos, &obj->pos, &obj->orient.fvec, obj->size*2 );
432 vm_vec_scale_add2( &head_pos, &obj->orient.rvec, obj->size*1 );
433 g3_rotate_point(&head_point,&head_pos);
434 automap_draw_line(&arrow_point, &head_point);
436 // Draw left head of arrow
437 vm_vec_scale_add( &head_pos, &obj->pos, &obj->orient.fvec, obj->size*2 );
438 vm_vec_scale_add2( &head_pos, &obj->orient.rvec, obj->size*(-1) );
439 g3_rotate_point(&head_point,&head_pos);
440 automap_draw_line(&arrow_point, &head_point);
442 // Draw player's up vector
443 vm_vec_scale_add( &arrow_pos, &obj->pos, &obj->orient.uvec, obj->size*2 );
444 g3_rotate_point(&arrow_point,&arrow_pos);
445 automap_draw_line(&sphere_point, &arrow_point);
449 #if defined(MACINTOSH) && defined(POLY_ACC)
451 void pa_mac_draw_automap_extras(void)
456 g3s_point sphere_point;
458 AutomapHires = 1; // always on the mac
462 if (Game_mode & GM_TEAM)
463 color = get_team(Player_num);
466 color = Player_num; // Note link to above if!
468 gr_setcolor(gr_getcolor(player_rgb[color].r,player_rgb[color].g,player_rgb[color].b));
469 draw_player(&Objects[Players[Player_num].objnum]);
473 if (HighlightMarker>-1 && MarkerMessage[HighlightMarker][0]!=0)
475 char msg[10+MARKER_MESSAGE_LEN+1];
477 sprintf(msg,"Marker %d: %s",HighlightMarker+1,MarkerMessage[(Player_num*2)+HighlightMarker]);
479 gr_setcolor (Red_48);
481 modex_printf(5,20,msg,SMALL_FONT,Font_color_20);
486 if ( (Game_mode & (GM_TEAM | GM_MULTI_COOP)) || (Netgame.game_flags & NETGAME_FLAG_SHOW_MAP) )
488 for (i=0; i<N_players; i++)
490 if ((i != Player_num) &&
491 ((Game_mode & GM_MULTI_COOP) || (get_team(Player_num) == get_team(i)) || (Netgame.game_flags & NETGAME_FLAG_SHOW_MAP)) )
493 if ( Objects[Players[i].objnum].type == OBJ_PLAYER )
495 if (Game_mode & GM_TEAM)
499 gr_setcolor(gr_getcolor(player_rgb[color].r,player_rgb[color].g,player_rgb[color].b));
500 draw_player(&Objects[Players[i].objnum]);
508 for (i=0;i<=Highest_object_index;i++,objp++)
513 gr_setcolor(Hostage_color);
514 g3_rotate_point(&sphere_point,&objp->pos);
515 g3_draw_sphere(&sphere_point,objp->size);
518 if ( Automap_visited[objp->segnum] )
520 if ( (objp->id==POW_KEY_RED) || (objp->id==POW_KEY_BLUE) || (objp->id==POW_KEY_GOLD) )
524 case POW_KEY_RED: gr_setcolor(gr_getcolor(63, 5, 5)); break;
525 case POW_KEY_BLUE: gr_setcolor(gr_getcolor(5, 5, 63)); break;
526 case POW_KEY_GOLD: gr_setcolor(gr_getcolor(63, 63, 10)); break;
528 Error("Illegal key type: %i", objp->id);
530 g3_rotate_point(&sphere_point,&objp->pos);
531 g3_draw_sphere(&sphere_point,objp->size*4);
538 gr_bitmapm(AutomapHires?10:5, AutomapHires?10:5, &name_canv_left->cv_bitmap);
539 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);
542 void pa_mac_draw_automap(void)
544 vms_vector viewer_position;
547 render_start_frame();
548 pa_set_context(kAutoMapDrawContextID, NULL);
551 vm_vec_scale_add(&viewer_position,&view_target,&ViewMatrix.fvec,-ViewDist );
552 g3_set_view_matrix(&viewer_position,&ViewMatrix,Automap_zoom);
566 vms_vector viewer_position;
567 g3s_point sphere_point;
573 pa_mac_draw_automap();
579 #ifndef AUTOMAP_DIRECT_RENDER
581 WIN(mprintf((1, "Can't do lores automap in Windows!\n")));
584 gr_set_current_canvas(&DrawingPages[current_page]);
588 dd_gr_set_current_canvas(&ddDrawingPage),
589 gr_set_current_canvas(&DrawingPage)
594 #if defined(POLY_ACC)
599 dd_gr_clear_canvas(BM_XRGB(0,0,0)),
600 gr_clear_canvas(BM_XRGB(0,0,0))
603 WIN(DDGRLOCK(dd_grd_curcanv));
606 render_start_frame();
608 vm_vec_scale_add(&viewer_position,&view_target,&ViewMatrix.fvec,-ViewDist );
610 g3_set_view_matrix(&viewer_position,&ViewMatrix,Automap_zoom);
612 // mprintf((0, "dd_grd_curcanv->canvas.cv_bitmap.bm_data= %x\n", dd_grd_curcanv->canvas.cv_bitmap.bm_data));
613 // mprintf((0, "grd_curcanv->cv_bitmap.bm_data= %x\n", grd_curcanv->cv_bitmap.bm_data));
619 if (Game_mode & GM_TEAM)
620 color = get_team(Player_num);
623 color = Player_num; // Note link to above if!
625 gr_setcolor(gr_getcolor(player_rgb[color].r,player_rgb[color].g,player_rgb[color].b));
626 draw_player(&Objects[Players[Player_num].objnum]);
630 if (HighlightMarker>-1 && MarkerMessage[HighlightMarker][0]!=0)
632 char msg[10+MARKER_MESSAGE_LEN+1];
634 sprintf(msg,"Marker %d: %s",HighlightMarker+1,MarkerMessage[(Player_num*2)+HighlightMarker]);
636 gr_setcolor (Red_48);
638 modex_printf(5,20,msg,SMALL_FONT,Font_color_20);
643 if ( (Game_mode & (GM_TEAM | GM_MULTI_COOP)) || (Netgame.game_flags & NETGAME_FLAG_SHOW_MAP) ) {
644 for (i=0; i<N_players; i++) {
645 if ( (i != Player_num) && ((Game_mode & GM_MULTI_COOP) || (get_team(Player_num) == get_team(i)) || (Netgame.game_flags & NETGAME_FLAG_SHOW_MAP)) ) {
646 if ( Objects[Players[i].objnum].type == OBJ_PLAYER ) {
647 if (Game_mode & GM_TEAM)
651 gr_setcolor(gr_getcolor(player_rgb[color].r,player_rgb[color].g,player_rgb[color].b));
652 draw_player(&Objects[Players[i].objnum]);
660 for (i=0;i<=Highest_object_index;i++,objp++) {
661 switch( objp->type ) {
663 gr_setcolor(Hostage_color);
664 g3_rotate_point(&sphere_point,&objp->pos);
665 g3_draw_sphere(&sphere_point,objp->size);
668 if ( Automap_visited[objp->segnum] ) {
669 if ( (objp->id==POW_KEY_RED) || (objp->id==POW_KEY_BLUE) || (objp->id==POW_KEY_GOLD) ) {
671 case POW_KEY_RED: gr_setcolor(gr_getcolor(63, 5, 5)); break;
672 case POW_KEY_BLUE: gr_setcolor(gr_getcolor(5, 5, 63)); break;
673 case POW_KEY_GOLD: gr_setcolor(gr_getcolor(63, 63, 10)); break;
675 Error("Illegal key type: %i", objp->id);
677 g3_rotate_point(&sphere_point,&objp->pos);
678 g3_draw_sphere(&sphere_point,objp->size*4);
687 gr_bitmapm(AutomapHires?10:5, AutomapHires?10:5, &name_canv_left->cv_bitmap);
688 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);
690 WIN(DDGRUNLOCK(dd_grd_curcanv));
695 #ifndef AUTOMAP_DIRECT_RENDER
697 gr_show_canvas( &Pages[current_page] );
700 //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 );
701 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 );
703 dd_gr_blt_screen(&ddPage, 0,0,0,0,0,0,0,0);
712 #define LEAVE_TIME 0x00010000
714 #define LEAVE_TIME 0x4000
717 #define WINDOW_WIDTH 288
720 //print to canvas & double height
721 grs_canvas *print_to_canvas(char *s,grs_font *font, int fc, int bc, int double_flag)
726 grs_canvas *temp_canv;
731 dd_grs_canvas *save_canv,
732 grs_canvas *save_canv
736 save_canv = dd_grd_curcanv,
737 save_canv = grd_curcanv
740 save_font = grd_curcanv->cv_font;
741 gr_set_curfont(font); //set the font we're going to use
742 gr_get_string_size(s,&w,&h,&aw); //now get the string size
743 gr_set_curfont(save_font); //restore real font
745 //temp_canv = gr_create_canvas(font->ft_w*strlen(s),font->ft_h*2);
746 temp_canv = gr_create_canvas(w,font->ft_h*2);
748 gr_set_current_canvas(temp_canv);
749 gr_set_curfont(font);
750 gr_clear_canvas(TRANSPARENCY_COLOR); //trans color
751 gr_set_fontcolor(fc,bc);
754 //now double it, since we're drawing to 400-line modex screen
757 data = temp_canv->cv_bitmap.bm_data;
758 rs = temp_canv->cv_bitmap.bm_rowsize;
760 for (y=temp_canv->cv_bitmap.bm_h/2;y--;) {
761 memcpy(data+(rs*y*2),data+(rs*y),temp_canv->cv_bitmap.bm_w);
762 memcpy(data+(rs*(y*2+1)),data+(rs*y),temp_canv->cv_bitmap.bm_w);
767 dd_gr_set_current_canvas(save_canv),
768 gr_set_current_canvas(save_canv)
774 //print to buffer, double heights, and blit bitmap to screen
775 void modex_printf(int x,int y,char *s,grs_font *font,int color)
777 grs_canvas *temp_canv;
779 temp_canv = print_to_canvas(s, font, color, -1, !AutomapHires);
781 gr_bitmapm(x,y,&temp_canv->cv_bitmap);
783 gr_free_canvas(temp_canv);
786 //name for each group. maybe move somewhere else
787 char *system_name[] = {
795 void create_name_canv()
797 char name_level_left[128],name_level_right[128];
799 if (Current_level_num > 0)
800 sprintf(name_level_left, "%s %i",TXT_LEVEL, Current_level_num);
802 sprintf(name_level_left, "Secret Level %i",-Current_level_num);
804 if (PLAYING_BUILTIN_MISSION && Current_level_num > 0)
805 sprintf(name_level_right,"%s %d: ",system_name[(Current_level_num-1)/4],((Current_level_num-1)%4)+1);
807 strcpy(name_level_right, " ");
809 strcat(name_level_right, Current_level_name);
811 gr_set_fontcolor(Green_31,-1);
812 name_canv_left = print_to_canvas(name_level_left, SMALL_FONT, Green_31, -1, !AutomapHires);
813 name_canv_right = print_to_canvas(name_level_right,SMALL_FONT, Green_31, -1, !AutomapHires);
818 extern void GameLoop(int, int );
819 extern int set_segment_depths(int start_seg, ubyte *segbuf);
821 int Automap_active = 0;
824 #define MAP_BACKGROUND_FILENAME (AutomapHires?"\x01MAPB.PCX":"\x01MAP.PCX") //load only from hog file
826 #define MAP_BACKGROUND_FILENAME ((AutomapHires && cfexist("mapb.pcx"))?"MAPB.PCX":"MAP.PCX")
829 int Automap_always_hires=0;
830 extern int MenuHiresAvailable;
832 extern int Current_display_mode;
834 u_int32_t automap_mode = SM(640,480);
835 int automap_width = 640;
836 int automap_height = 480;
837 int automap_use_game_res=0;
838 int nice_automap = 0;
840 #define RESCALE_X(x) ((x) * automap_width / 640)
841 #define RESCALE_Y(y) ((y) * automap_height / 480)
843 void do_automap( int key_code ) {
850 #if !defined(AUTOMAP_DIRECT_RENDER) || !defined(NDEBUG)
855 int pause_game=1; // Set to 1 if everything is paused during automap...No pause during net.
857 control_info saved_control_info;
858 grs_bitmap Automap_background;
859 int Max_segments_away = 0;
860 int SegmentLimit = 1;
863 int must_free_canvas=0;
865 WIN(int dd_VR_screen_mode_save);
866 WIN(int redraw_screen=0);
870 init_automap_colors();
872 key_code = key_code; // disable warning...
874 if ((Game_mode & GM_MULTI) && (Function_mode == FMODE_GAME) && (!Endlevel_sequence))
879 digi_pause_digi_sounds();
882 Max_edges = min(MAX_EDGES_FROM_VERTS(Num_vertices),MAX_EDGES); //make maybe smaller than max
884 mprintf( (0, "Num_vertices=%d, Max_edges=%d, (MAX:%d)\n", Num_vertices, Max_edges, MAX_EDGES ));
885 mprintf( (0, "Allocated %d K for automap edge list\n", (sizeof(Edge_info)+sizeof(short))*Max_edges/1024 ));
887 #if !defined (WINDOWS) && !defined(MACINTOSH)
888 if ((Current_display_mode!=0 && Current_display_mode!=2) || (Automap_always_hires && MenuHiresAvailable)) {
889 #if !defined(POLY_ACC)
890 //edit 4/23/99 Matt Mueller - don't switch res unless we need to
891 if (grd_curscreen->sc_mode != AUTOMAP_MODE)
892 gr_set_mode( AUTOMAP_MODE );
894 gr_set_current_canvas(NULL);
896 automap_width=grd_curscreen->sc_canvas.cv_bitmap.bm_w;
897 automap_height=grd_curscreen->sc_canvas.cv_bitmap.bm_h;
899 PA_DFX (pa_set_frontbuffer_current());
903 gr_set_mode( SM(320, 400));
907 AutomapHires = 1; //Mac & Windows(?) always in hires
911 dd_VR_screen_mode_save = VR_screen_mode;
912 VR_screen_mode = SM95_640x480x8; // HACK! Forcing reinit of 640x480
913 set_screen_mode(SCREEN_GAME);
916 FontHires = FontHiresAvailable && AutomapHires;
925 #ifndef AUTOMAP_DIRECT_RENDER
926 gr_init_sub_canvas(&Pages[0],grd_curcanv,0,0,320,400);
927 gr_init_sub_canvas(&Pages[1],grd_curcanv,0,401,320,400);
928 gr_init_sub_canvas(&DrawingPages[0],&Pages[0],16,69,WINDOW_WIDTH,272);
929 gr_init_sub_canvas(&DrawingPages[1],&Pages[1],16,69,WINDOW_WIDTH,272);
932 gr_init_bitmap_data (&Automap_background);
933 pcx_error = pcx_read_bitmap(MAP_BACKGROUND_FILENAME, &Automap_background, BM_LINEAR, pal);
934 if (pcx_error != PCX_ERROR_NONE)
935 Error("File %s - PCX error: %s", MAP_BACKGROUND_FILENAME, pcx_errormsg(pcx_error));
936 gr_remap_bitmap_good(&Automap_background, pal, -1, -1);
938 #ifndef AUTOMAP_DIRECT_RENDER
941 gr_set_current_canvas(&Pages[i]);
942 gr_bitmap(0, 0, &Automap_background );
943 modex_printf(40, 22, TXT_AUTOMAP, HUGE_FONT, Font_color_20);
944 modex_printf(30, 353, TXT_TURN_SHIP, SMALL_FONT, Font_color_20);
945 modex_printf(30, 369, TXT_SLIDE_UPDOWN, SMALL_FONT, Font_color_20);
946 modex_printf(30, 385, TXT_VIEWING_DISTANCE, SMALL_FONT, Font_color_20);
948 gr_free_bitmap_data(&Automap_background);
949 gr_set_current_canvas(&DrawingPages[current_page]);
950 #endif /* AUTOMAP_DIRECT_RENDER */
951 #endif /* MACINTOSH */
954 #ifndef AUTOMAP_DIRECT_RENDER
955 if (VR_render_buffer[0].cv_w >= automap_width && VR_render_buffer[0].cv_h >= automap_height)
957 WIN(dd_gr_init_sub_canvas(&ddPage, &dd_VR_render_buffer[0], 0, 0, automap_width,automap_height));
959 #if defined(MACINTOSH) && defined(POLY_ACC)
962 // we want all the automap border stuff to be drawn straight to the screen
963 gr_init_sub_canvas(&Page,&(grd_curscreen->sc_canvas),0, 0, automap_width, automap_height);
967 gr_init_sub_canvas(&Page,&VR_render_buffer[0],0, 0, automap_width, automap_height);
970 gr_init_sub_canvas(&Page,&VR_render_buffer[0],0, 0, automap_width, automap_height);
977 MALLOC(raw_data,ubyte,automap_width*automap_height);
978 gr_init_canvas(&Page,raw_data,BM_LINEAR,automap_width,automap_height);
980 dd_gr_init_canvas(&ddPage, BM_LINEAR, automap_width,automap_height);
981 gr_init_canvas(&Page,NULL,BM_LINEAR,automap_width,automap_height);
983 must_free_canvas = 1;
986 WIN(dd_gr_init_sub_canvas(&ddDrawingPage, &ddPage, RESCALE_X(27), RESCALE_Y(80), RESCALE_X(582), RESCALE_Y(334)));
987 gr_init_sub_canvas(&DrawingPage, &Page, RESCALE_X(27), RESCALE_Y(80), RESCALE_X(582), RESCALE_Y(334));
990 dd_gr_set_current_canvas(&ddPage),
991 gr_set_current_canvas(&Page)
995 #if defined(POLY_ACC)
998 pcx_error = pcx_read_bitmap(MAP_BACKGROUND_FILENAME,&(grd_curcanv->cv_bitmap),BM_LINEAR15,pal);
1002 pcx_error = pcx_read_bitmap(MAP_BACKGROUND_FILENAME,&(grd_curcanv->cv_bitmap),BM_LINEAR15,pal);
1003 if ( pcx_error != PCX_ERROR_NONE )
1005 Error("File %s - PCX error: %s",MAP_BACKGROUND_FILENAME,pcx_errormsg(pcx_error));
1011 pcx_error = pcx_read_bitmap(MAP_BACKGROUND_FILENAME,&(grd_curcanv->cv_bitmap),BM_LINEAR,pal);
1012 if ( pcx_error != PCX_ERROR_NONE )
1014 Error("File %s - PCX error: %s",MAP_BACKGROUND_FILENAME,pcx_errormsg(pcx_error));
1018 gr_remap_bitmap_good( &(grd_curcanv->cv_bitmap), pal, -1, -1 );
1023 WIN(DDGRLOCK(dd_grd_curcanv));
1024 pcx_error = pcx_read_fullscr(MAP_BACKGROUND_FILENAME, pal);
1025 if ( pcx_error != PCX_ERROR_NONE ) {
1026 //printf("File %s - PCX error: %s",MAP_BACKGROUND_FILENAME,pcx_errormsg(pcx_error));
1027 Error("File %s - PCX error: %s",MAP_BACKGROUND_FILENAME,pcx_errormsg(pcx_error));
1031 gr_remap_bitmap_good( &(grd_curcanv->cv_bitmap), pal, -1, -1 );
1034 gr_set_curfont(HUGE_FONT);
1035 gr_set_fontcolor(BM_XRGB(20, 20, 20), -1);
1036 gr_printf(RESCALE_X(80), RESCALE_Y(36), TXT_AUTOMAP, HUGE_FONT);
1037 gr_set_curfont(SMALL_FONT);
1038 gr_set_fontcolor(BM_XRGB(20, 20, 20), -1);
1039 gr_printf(RESCALE_X(60), RESCALE_Y(426), TXT_TURN_SHIP);
1040 gr_printf(RESCALE_X(60), RESCALE_Y(443), TXT_SLIDE_UPDOWN);
1041 gr_printf(RESCALE_X(60), RESCALE_Y(460), TXT_VIEWING_DISTANCE);
1042 WIN(DDGRUNLOCK(dd_grd_curcanv));
1044 #ifndef AUTOMAP_DIRECT_RENDER
1046 dd_gr_set_current_canvas(&ddDrawingPage),
1047 gr_set_current_canvas(&DrawingPage)
1053 WIN(if (!redraw_screen) {)
1054 automap_build_edge_list();
1057 ViewDist = ZOOM_DEFAULT;
1058 ViewMatrix = Objects[Players[Player_num].objnum].orient;
1060 tangles.p = PITCH_DEFAULT;
1066 view_target = Objects[Players[Player_num].objnum].pos;
1068 t1 = entry_time = timer_get_fixed_seconds();
1071 //Fill in Automap_visited from Objects[Players[Player_num].objnum].segnum
1072 Max_segments_away = set_segment_depths(Objects[Players[Player_num].objnum].segnum, Automap_visited);
1073 SegmentLimit = Max_segments_away;
1075 adjust_segment_limit(SegmentLimit);
1078 WIN(if (redraw_screen) redraw_screen = 0);
1081 if ( leave_mode==0 && Controls.automap_state && (timer_get_fixed_seconds()-entry_time)>LEAVE_TIME)
1084 if ( !Controls.automap_state && (leave_mode==1) )
1089 saved_control_info = Controls; // Save controls so we can zero them
1090 memset(&Controls,0,sizeof(control_info)); // Clear everything...
1091 old_wiggle = ConsoleObject->mtype.phys_info.flags & PF_WIGGLE; // Save old wiggle
1092 ConsoleObject->mtype.phys_info.flags &= ~PF_WIGGLE; // Turn off wiggle
1094 if (multi_menu_poll())
1097 // GameLoop( 0, 0 ); // Do game loop with no rendering and no reading controls.
1098 ConsoleObject->mtype.phys_info.flags |= old_wiggle; // Restore wiggle
1099 Controls = saved_control_info;
1103 controls_read_all();
1105 controls_read_all_win();
1108 if ( Controls.automap_down_count ) {
1114 //see if redbook song needs to be restarted
1115 songs_check_redbook_repeat();
1120 DoMessageStuff(&msg);
1121 if (_RedrawScreen) {
1122 _RedrawScreen = FALSE;
1127 if (msg.message == WM_QUIT) exit(1);
1134 while( (c=key_inkey()) ) {
1137 case KEY_BACKSP: Int3(); break;
1140 case KEY_PRINT_SCREEN: {
1143 dd_gr_set_current_canvas(NULL),
1144 gr_set_current_canvas(NULL)
1147 #ifndef AUTOMAP_DIRECT_RENDER
1149 gr_set_current_canvas(&Pages[current_page]);
1151 save_screen_shot(1);
1161 case KEY_DEBUGGED+KEY_F: {
1162 for (i=0; i<=Highest_segment_index; i++ )
1163 Automap_visited[i] = 1;
1164 automap_build_edge_list();
1165 Max_segments_away = set_segment_depths(Objects[Players[Player_num].objnum].segnum, Automap_visited);
1166 SegmentLimit = Max_segments_away;
1167 adjust_segment_limit(SegmentLimit);
1173 if (SegmentLimit > 1) {
1175 adjust_segment_limit(SegmentLimit);
1179 if (SegmentLimit < Max_segments_away) {
1181 adjust_segment_limit(SegmentLimit);
1194 if (Game_mode & GM_MULTI)
1200 marker_num = c-KEY_1;
1202 switch(c) { // god this is stupid.....
1203 case KEY_1: marker_num = 0; break;
1204 case KEY_2: marker_num = 1; break;
1205 case KEY_3: marker_num = 2; break;
1206 case KEY_4: marker_num = 3; break;
1207 case KEY_5: marker_num = 4; break;
1208 case KEY_6: marker_num = 5; break;
1209 case KEY_7: marker_num = 6; break;
1210 case KEY_8: marker_num = 7; break;
1211 case KEY_9: marker_num = 8; break;
1212 case KEY_0: marker_num = 9; break;
1215 if (marker_num<=maxdrop)
1217 if (MarkerObject[marker_num] != -1)
1218 HighlightMarker=marker_num;
1222 case KEY_D+KEY_CTRLED:
1223 #ifndef AUTOMAP_DIRECT_RENDER
1224 if (current_page) //menu will only work on page 0
1225 draw_automap(); //..so switch from 1 to 0
1228 if (HighlightMarker > -1 && MarkerObject[HighlightMarker] != -1) {
1229 #ifndef AUTOMAP_DIRECT_RENDER
1231 dd_gr_set_current_canvas(&ddPages[current_page]),
1232 gr_set_current_canvas(&Pages[current_page])
1236 if (nm_messagebox( NULL, 2, TXT_YES, TXT_NO, "Delete Marker?" ) == 0) {
1237 obj_delete(MarkerObject[HighlightMarker]);
1238 MarkerObject[HighlightMarker]=-1;
1239 MarkerMessage[HighlightMarker][0]=0;
1240 HighlightMarker = -1;
1251 if (MarkerScale<30.0)
1256 //added 8/23/99 by Matt Mueller for hot key res/fullscreen changing, and menu access
1258 case KEY_CTRLED+KEY_SHIFTED+KEY_PADDIVIDE:
1259 case KEY_ALTED+KEY_CTRLED+KEY_PADDIVIDE:
1260 case KEY_ALTED+KEY_SHIFTED+KEY_PADDIVIDE:
1263 case KEY_CTRLED+KEY_SHIFTED+KEY_PADMULTIPLY:
1264 case KEY_ALTED+KEY_CTRLED+KEY_PADMULTIPLY:
1265 case KEY_ALTED+KEY_SHIFTED+KEY_PADMULTIPLY:
1268 case KEY_CTRLED+KEY_SHIFTED+KEY_PADMINUS:
1269 case KEY_ALTED+KEY_CTRLED+KEY_PADMINUS:
1270 case KEY_ALTED+KEY_SHIFTED+KEY_PADMINUS:
1272 //should we just cycle through the list that is displayed in the res change menu?
1273 // what if their card/X/etc can't handle that mode? hrm.
1274 //well, the quick access to the menu is good enough for now.
1276 case KEY_CTRLED+KEY_SHIFTED+KEY_PADPLUS:
1277 case KEY_ALTED+KEY_CTRLED+KEY_PADPLUS:
1278 case KEY_ALTED+KEY_SHIFTED+KEY_PADPLUS:
1282 case KEY_ALTED+KEY_ENTER:
1283 case KEY_ALTED+KEY_PADENTER:
1284 gr_toggle_fullscreen_game();
1291 if ( Controls.fire_primary_down_count ) {
1292 // Reset orientation
1293 ViewDist = ZOOM_DEFAULT;
1294 tangles.p = PITCH_DEFAULT;
1297 view_target = Objects[Players[Player_num].objnum].pos;
1300 ViewDist -= Controls.forward_thrust_time*ZOOM_SPEED_FACTOR;
1302 tangles.p += fixdiv( Controls.pitch_time, ROT_SPEED_DIVISOR );
1303 tangles.h += fixdiv( Controls.heading_time, ROT_SPEED_DIVISOR );
1304 tangles.b += fixdiv( Controls.bank_time, ROT_SPEED_DIVISOR*2 );
1306 if ( Controls.vertical_thrust_time || Controls.sideways_thrust_time ) {
1307 vms_angvec tangles1;
1309 old_vt = view_target;
1311 vm_angles_2_matrix(&tempm,&tangles1);
1312 vm_matrix_x_matrix(&ViewMatrix,&Objects[Players[Player_num].objnum].orient,&tempm);
1313 vm_vec_scale_add2( &view_target, &ViewMatrix.uvec, Controls.vertical_thrust_time*SLIDE_SPEED );
1314 vm_vec_scale_add2( &view_target, &ViewMatrix.rvec, Controls.sideways_thrust_time*SLIDE_SPEED );
1315 if ( vm_vec_dist_quick( &view_target, &Objects[Players[Player_num].objnum].pos) > i2f(1000) ) {
1316 view_target = old_vt;
1320 vm_angles_2_matrix(&tempm,&tangles);
1321 vm_matrix_x_matrix(&ViewMatrix,&Objects[Players[Player_num].objnum].orient,&tempm);
1323 if ( ViewDist < ZOOM_MIN_VALUE ) ViewDist = ZOOM_MIN_VALUE;
1324 if ( ViewDist > ZOOM_MAX_VALUE ) ViewDist = ZOOM_MAX_VALUE;
1330 gr_palette_load( gr_palette );
1333 t2 = timer_get_fixed_seconds();
1334 while (t2 - t1 < F1_0 / 100) // ogl is fast enough that the automap can read the input too fast and you start to turn really slow. So delay a bit (and free up some cpu :)
1339 t2 = timer_get_fixed_seconds();
1347 //d_free(DrawingListBright);
1349 gr_free_canvas(name_canv_left); name_canv_left=NULL;
1350 gr_free_canvas(name_canv_right); name_canv_right=NULL;
1352 if (must_free_canvas) {
1353 #ifndef AUTOMAP_DIRECT_RENDER
1355 DDFreeSurface(ddPages[0].lpdds),
1356 d_free(Page.cv_bitmap.bm_data)
1361 mprintf( (0, "Automap memory freed\n" ));
1363 game_flush_inputs();
1365 #if defined(POLY_ACC) && defined(MACINTOSH)
1368 pa_set_context(kGamePlayDrawContextID, NULL);
1375 digi_resume_digi_sounds();
1379 VR_screen_mode = dd_VR_screen_mode_save;
1385 void adjust_segment_limit(int SegmentLimit)
1390 mprintf(( 0, "Seglimit: %d\n", SegmentLimit ));
1392 for (i=0; i<=Highest_edge_index; i++ ) {
1394 e->flags |= EF_TOO_FAR;
1395 for (e1=0; e1<e->num_faces; e1++ ) {
1396 if ( Automap_visited[e->segnum[e1]] <= SegmentLimit ) {
1397 e->flags &= (~EF_TOO_FAR);
1405 void draw_all_edges()
1409 ubyte nfacing,nnfacing;
1413 fix min_distance = 0x7fffffff;
1419 for (i=0; i<=Highest_edge_index; i++ ) {
1420 //e = &Edges[Edge_used_list[i]];
1422 if (!(e->flags & EF_USED)) continue;
1424 if ( e->flags & EF_TOO_FAR) continue;
1426 if (e->flags&EF_FRONTIER) { // A line that is between what we have seen and what we haven't
1427 if ( (!(e->flags&EF_SECRET))&&(e->color==Wall_normal_color))
1428 continue; // If a line isn't secret and is normal color, then don't draw it
1431 cc=rotate_list(2,e->verts);
1432 distance = Segment_points[e->verts[1]].p3_z;
1434 if (min_distance>distance )
1435 min_distance = distance;
1437 if (!cc.and) { //all off screen?
1438 nfacing = nnfacing = 0;
1439 tv1 = &Vertices[e->verts[0]];
1441 while( j<e->num_faces && (nfacing==0 || nnfacing==0) ) {
1444 get_side_normal(&Segments[e->segnum[j]], e->sides[j], 0, &temp_v );
1445 if (!g3_check_normal_facing( tv1, &temp_v ) )
1447 if (!g3_check_normal_facing( tv1, &Segments[e->segnum[j]].sides[e->sides[j]].normals[0] ) )
1455 if ( nfacing && nnfacing ) {
1457 DrawingListBright[nbright++] = e-Edges;
1458 } else if ( e->flags&(EF_DEFINING|EF_GRATE) ) {
1459 if ( nfacing == 0 ) {
1460 if ( e->flags & EF_NO_FADE )
1461 gr_setcolor( e->color );
1463 gr_setcolor( gr_fade_table[e->color+256*8] );
1464 g3_draw_line( &Segment_points[e->verts[0]], &Segment_points[e->verts[1]] );
1466 DrawingListBright[nbright++] = e-Edges;
1472 /// mprintf( (0, "Min distance=%.2f, ViewDist=%.2f, Delta=%.2f\n", f2fl(min_distance), f2fl(ViewDist), f2fl(min_distance)- f2fl(ViewDist) ));
1474 if ( min_distance < 0 ) min_distance = 0;
1476 // Sort the bright ones using a shell sort
1479 int i, j, incr, v1, v2;
1483 for (i=incr; i<nbright; i++ ) {
1486 // compare element j and j+incr
1487 v1 = Edges[DrawingListBright[j]].verts[0];
1488 v2 = Edges[DrawingListBright[j+incr]].verts[0];
1490 if (Segment_points[v1].p3_z < Segment_points[v2].p3_z) {
1491 // If not in correct order, them swap 'em
1492 t=DrawingListBright[j+incr];
1493 DrawingListBright[j+incr]=DrawingListBright[j];
1494 DrawingListBright[j]=t;
1505 // Draw the bright ones
1506 for (i=0; i<nbright; i++ ) {
1509 e = &Edges[DrawingListBright[i]];
1510 p1 = &Segment_points[e->verts[0]];
1511 p2 = &Segment_points[e->verts[1]];
1512 dist = p1->p3_z - min_distance;
1513 // Make distance be 1.0 to 0.0, where 0.0 is 10 segments away;
1514 if ( dist < 0 ) dist=0;
1515 if ( dist >= Automap_farthest_dist ) continue;
1517 if ( e->flags & EF_NO_FADE ) {
1518 gr_setcolor( e->color );
1520 dist = F1_0 - fixdiv( dist, Automap_farthest_dist );
1521 color = f2i( dist*31 );
1522 gr_setcolor( gr_fade_table[e->color+color*256] );
1524 g3_draw_line( p1, p2 );
1530 //==================================================================
1532 // All routines below here are used to build the Edge list
1534 //==================================================================
1537 //finds edge, filling in edge_ptr. if found old edge, returns index, else return -1
1538 static int automap_find_edge(int v0,int v1,Edge_info **edge_ptr)
1546 oldhash = hash = ((v0*5+v1) % Max_edges);
1551 ev0 = (int)(Edges[hash].verts[0]);
1552 ev1 = (int)(Edges[hash].verts[1]);
1553 evv = (ev1<<16)+ev0;
1554 if (Edges[hash].num_faces == 0 ) ret=0;
1555 else if (evv == vv) ret=1;
1557 if (++hash==Max_edges) hash=0;
1558 if (hash==oldhash) Error("Edge list full!");
1562 *edge_ptr = &Edges[hash];
1572 void add_one_edge( short va, short vb, ubyte color, ubyte side, short segnum, int hidden, int grate, int no_fade ) {
1577 if ( Num_edges >= Max_edges) {
1578 // GET JOHN! (And tell him that his
1579 // MAX_EDGES_FROM_VERTS formula is hosed.)
1580 // If he's not around, save the mine,
1581 // and send him mail so he can look
1582 // at the mine later. Don't modify it.
1583 // This is important if this happens.
1584 Int3(); // LOOK ABOVE!!!!!!
1594 found = automap_find_edge(va,vb,&e);
1601 e->flags = EF_USED | EF_DEFINING; // Assume a normal line
1603 e->segnum[0] = segnum;
1604 //Edge_used_list[Num_edges] = e-Edges;
1605 if ( (e-Edges) > Highest_edge_index )
1606 Highest_edge_index = e - Edges;
1609 //Assert(e->num_faces < 8 );
1611 if ( color != Wall_normal_color )
1612 if (color != Wall_revealed_color)
1615 if ( e->num_faces < 4 ) {
1616 e->sides[e->num_faces] = side;
1617 e->segnum[e->num_faces] = segnum;
1623 e->flags |= EF_GRATE;
1626 e->flags|=EF_SECRET; // Mark this as a hidden edge
1628 e->flags |= EF_NO_FADE;
1631 void add_one_unknown_edge( short va, short vb ) {
1642 found = automap_find_edge(va,vb,&e);
1644 e->flags|=EF_FRONTIER; // Mark as a border edge
1648 extern obj_position Player_init[];
1651 void add_segment_edges(segment *seg)
1653 int is_grate, no_fade;
1656 int segnum = seg-Segments;
1658 int ttype,trigger_num;
1660 for (sn=0;sn<MAX_SIDES_PER_SEGMENT;sn++) {
1661 short vertex_list[4];
1669 if (seg->children[sn] == -1) {
1670 color = Wall_normal_color;
1673 switch( Segment2s[segnum].special ) {
1674 case SEGMENT_IS_FUELCEN:
1675 color = BM_XRGB( 29, 27, 13 );
1677 case SEGMENT_IS_CONTROLCEN:
1678 if (Control_center_present)
1679 color = BM_XRGB( 29, 0, 0 );
1681 case SEGMENT_IS_ROBOTMAKER:
1682 color = BM_XRGB( 29, 0, 31 );
1686 if (seg->sides[sn].wall_num > -1) {
1688 trigger_num = Walls[seg->sides[sn].wall_num].trigger;
1689 ttype = Triggers[trigger_num].type;
1690 if (ttype==TT_SECRET_EXIT)
1692 color = BM_XRGB( 29, 0, 31 );
1697 switch( Walls[seg->sides[sn].wall_num].type ) {
1699 if (Walls[seg->sides[sn].wall_num].keys == KEY_BLUE) {
1701 color = Wall_door_blue;
1702 //mprintf((0, "Seg %i, side %i has BLUE wall\n", segnum, sn));
1703 } else if (Walls[seg->sides[sn].wall_num].keys == KEY_GOLD) {
1705 color = Wall_door_gold;
1706 //mprintf((0, "Seg %i, side %i has GOLD wall\n", segnum, sn));
1707 } else if (Walls[seg->sides[sn].wall_num].keys == KEY_RED) {
1709 color = Wall_door_red;
1710 //mprintf((0, "Seg %i, side %i has RED wall\n", segnum, sn));
1711 } else if (!(WallAnims[Walls[seg->sides[sn].wall_num].clip_num].flags & WCF_HIDDEN)) {
1712 int connected_seg = seg->children[sn];
1713 if (connected_seg != -1) {
1714 int connected_side = find_connect_side(seg, &Segments[connected_seg]);
1715 int keytype = Walls[Segments[connected_seg].sides[connected_side].wall_num].keys;
1716 if ((keytype != KEY_BLUE) && (keytype != KEY_GOLD) && (keytype != KEY_RED))
1717 color = Wall_door_color;
1719 switch (Walls[Segments[connected_seg].sides[connected_side].wall_num].keys) {
1720 case KEY_BLUE: color = Wall_door_blue; no_fade = 1; break;
1721 case KEY_GOLD: color = Wall_door_gold; no_fade = 1; break;
1722 case KEY_RED: color = Wall_door_red; no_fade = 1; break;
1723 default: Error("Inconsistent data. Supposed to be a colored wall, but not blue, gold or red.\n");
1725 //mprintf((0, "Seg %i, side %i has a colored door on the other side.\n", segnum, sn));
1730 color = Wall_normal_color;
1732 //mprintf((0, "Wall at seg:side %i:%i is hidden.\n", seg-Segments, sn));
1736 // Make grates draw properly
1737 if (WALL_IS_DOORWAY(seg,sn) & WID_RENDPAST_FLAG)
1741 color = Wall_normal_color;
1743 case WALL_BLASTABLE:
1745 color = Wall_door_color;
1750 if (segnum==Player_init[Player_num].segnum)
1751 color = BM_XRGB(31,0,31);
1753 if ( color != 255 ) {
1754 // If they have a map powerup, draw unvisited areas in dark blue.
1755 if (Players[Player_num].flags & PLAYER_FLAGS_MAP_ALL && (!Automap_visited[segnum]))
1756 color = Wall_revealed_color;
1761 get_side_verts(vertex_list,segnum,sn);
1762 add_one_edge( vertex_list[0], vertex_list[1], color, sn, segnum, hidden_flag, 0, no_fade );
1763 add_one_edge( vertex_list[1], vertex_list[2], color, sn, segnum, hidden_flag, 0, no_fade );
1764 add_one_edge( vertex_list[2], vertex_list[3], color, sn, segnum, hidden_flag, 0, no_fade );
1765 add_one_edge( vertex_list[3], vertex_list[0], color, sn, segnum, hidden_flag, 0, no_fade );
1768 add_one_edge( vertex_list[0], vertex_list[2], color, sn, segnum, hidden_flag, 1, no_fade );
1769 add_one_edge( vertex_list[1], vertex_list[3], color, sn, segnum, hidden_flag, 1, no_fade );
1777 // Adds all the edges from a segment we haven't visited yet.
1779 void add_unknown_segment_edges(segment *seg)
1782 int segnum = seg-Segments;
1784 for (sn=0;sn<MAX_SIDES_PER_SEGMENT;sn++) {
1785 short vertex_list[4];
1787 // Only add edges that have no children
1788 if (seg->children[sn] == -1) {
1789 get_side_verts(vertex_list,segnum,sn);
1791 add_one_unknown_edge( vertex_list[0], vertex_list[1] );
1792 add_one_unknown_edge( vertex_list[1], vertex_list[2] );
1793 add_one_unknown_edge( vertex_list[2], vertex_list[3] );
1794 add_one_unknown_edge( vertex_list[3], vertex_list[0] );
1802 void automap_build_edge_list()
1809 if ( Players[Player_num].flags & PLAYER_FLAGS_MAP_ALL_CHEAT )
1810 Automap_cheat = 1; // Damn cheaters...
1813 for (i=0; i<Max_edges; i++) {
1814 Edges[i].num_faces = 0;
1818 Highest_edge_index = -1;
1820 if (Automap_cheat || (Players[Player_num].flags & PLAYER_FLAGS_MAP_ALL) ) {
1821 // Cheating, add all edges as visited
1822 for (s=0; s<=Highest_segment_index; s++)
1824 if (Segments[s].segnum != -1)
1827 add_segment_edges(&Segments[s]);
1830 // Not cheating, add visited edges, and then unvisited edges
1831 for (s=0; s<=Highest_segment_index; s++)
1833 if (Segments[s].segnum != -1)
1835 if (Automap_visited[s]) {
1836 add_segment_edges(&Segments[s]);
1839 for (s=0; s<=Highest_segment_index; s++)
1841 if (Segments[s].segnum != -1)
1843 if (!Automap_visited[s]) {
1844 add_unknown_segment_edges(&Segments[s]);
1848 // Find unnecessary lines (These are lines that don't have to be drawn because they have small curvature)
1849 for (i=0; i<=Highest_edge_index; i++ ) {
1851 if (!(e->flags&EF_USED)) continue;
1853 for (e1=0; e1<e->num_faces; e1++ ) {
1854 for (e2=1; e2<e->num_faces; e2++ ) {
1855 if ( (e1 != e2) && (e->segnum[e1] != e->segnum[e2]) ) {
1858 get_side_normal(&Segments[e->segnum[e1]], e->sides[e1], 0, &v1 );
1859 get_side_normal(&Segments[e->segnum[e2]], e->sides[e2], 0, &v2 );
1860 if ( vm_vec_dot(&v1,&v2) > (F1_0-(F1_0/10)) ) {
1862 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)) ) {
1864 e->flags &= (~EF_DEFINING);
1869 if (!(e->flags & EF_DEFINING))
1874 mprintf( (0, "Automap used %d / %d edges\n", Num_edges, Max_edges ));
1878 char Marker_input [40];
1880 ubyte DefiningMarkerMessage=0;
1881 ubyte MarkerBeingDefined;
1882 ubyte LastMarkerDropped;
1884 void InitMarkerInput ()
1888 //find free marker slot
1890 if (Game_mode & GM_MULTI)
1891 maxdrop=MAX_DROP_MULTI;
1893 maxdrop=MAX_DROP_SINGLE;
1895 for (i=0;i<maxdrop;i++)
1896 if (MarkerObject[(Player_num*2)+i] == -1) //found free slot!
1899 if (i==maxdrop) //no free slot
1901 if (Game_mode & GM_MULTI)
1902 i = !LastMarkerDropped; //in multi, replace older of two
1904 HUD_init_message("No free marker slots");
1909 //got a free slot. start inputting marker message
1913 DefiningMarkerMessage=1;
1914 MarkerBeingDefined = i;
1917 void MarkerInputMessage (int key)
1922 DefiningMarkerMessage = 0;
1923 game_flush_inputs();
1928 if (Marker_index > 0)
1930 Marker_input[Marker_index] = 0;
1933 strcpy (MarkerMessage[(Player_num*2)+MarkerBeingDefined],Marker_input);
1934 if (Game_mode & GM_MULTI)
1935 strcpy (MarkerOwner[(Player_num*2)+MarkerBeingDefined],Players[Player_num].callsign);
1936 DropMarker(MarkerBeingDefined);
1937 LastMarkerDropped = MarkerBeingDefined;
1938 game_flush_inputs();
1939 DefiningMarkerMessage = 0;
1944 int ascii = key_to_ascii(key);
1946 if (Marker_index < 38 )
1948 Marker_input[Marker_index++] = ascii;
1949 Marker_input[Marker_index] = 0;