]> icculus.org git repositories - taylor/freespace2.git/blob - src/hud/hudbrackets.cpp
Initial revision
[taylor/freespace2.git] / src / hud / hudbrackets.cpp
1 /*
2  * $Logfile: /Freespace2/code/Hud/HUDbrackets.cpp $
3  * $Revision$
4  * $Date$
5  * $Author$
6  *
7  * C file that contains functions for drawing target brackets on the HUD
8  *
9  * $Log$
10  * Revision 1.1  2002/05/03 03:28:09  root
11  * Initial revision
12  *
13  * 
14  * 6     8/03/99 5:35p Andsager
15  * Dont draw target dot for instructor in training mission
16  * 
17  * 5     6/07/99 4:20p Andsager
18  * Add HUD color for tagged object.  Apply to target and radar.
19  * 
20  * 4     12/28/98 3:17p Dave
21  * Support for multiple hud bitmap filenames for hi-res mode.
22  * 
23  * 3     12/21/98 5:02p Dave
24  * Modified all hud elements to be multi-resolution friendly.
25  * 
26  * 2     10/07/98 10:53a Dave
27  * Initial checkin.
28  * 
29  * 1     10/07/98 10:49a Dave
30  * 
31  * 54    8/25/98 1:48p Dave
32  * First rev of EMP effect. Player side stuff basically done. Next comes
33  * AI code.
34  * 
35  * 53    6/01/98 11:43a John
36  * JAS & MK:  Classified all strings for localization.
37  * 
38  * 52    5/27/98 1:22p Allender
39  * make targeting dots work in multiplayer -- as well as many other minor
40  * targeting problems
41  * 
42  * 51    5/23/98 2:26a Lawrance
43  * Tweak brackets
44  * 
45  * 50    5/14/98 11:26a Lawrance
46  * ensure fighter bays are drawn with correct bracket color
47  * 
48  * 49    5/12/98 9:27a Mike
49  * num-ships-attacking: always showed an additional ship attacking
50  * asteroid or debris.  Fixed.
51  * 
52  * 48    5/08/98 10:16a Lawrance
53  * Add new "ship attacking count" gauge
54  * 
55  * 47    5/07/98 4:07p Mike
56  * Use smaller num-ships-attacking blip.
57  * 
58  * 46    5/06/98 5:30p John
59  * Removed unused cfilearchiver.  Removed/replaced some unused/little used
60  * graphics functions, namely gradient_h and _v and pixel_sp.   Put in new
61  * DirectX header files and libs that fixed the Direct3D alpha blending
62  * problems.
63  * 
64  * 45    5/06/98 2:46p Mike
65  * Modify num-ships-attacking system.
66  * 
67  * 44    5/03/98 1:07a Mike
68  * Show + for ships attacking your target, whether hostile or friendly.
69  * 
70  * 43    4/05/98 7:42p Lawrance
71  * fix inconsistent distance display on the HUD
72  * 
73  * 42    4/01/98 9:21p John
74  * Made NDEBUG, optimized build with no warnings or errors.
75  * 
76  * 41    3/30/98 12:20a Lawrance
77  * Draw subsystem targeting brackets gray if subsystem is destroyed.
78  * 
79  * 40    3/18/98 6:04p Lawrance
80  * Improve when brackets get drawn for large objects
81  * 
82  * 39    3/10/98 6:03p Lawrance
83  * Ensure proper bracket color gets drawn for traitors
84  * 
85  * 38    3/06/98 5:13p Johnson
86  * Put in a check for team traitor in hud_brackets_get_iff_color()
87  * 
88  * 37    3/02/98 11:32p Lawrance
89  * Allow asteroids about to impact ships to be bracketed
90  * 
91  * 36    2/21/98 2:49p Lawrance
92  * Don't do facing check for subsystems when deciding whether to draw
93  * brackets
94  * 
95  * 35    2/19/98 12:48a Lawrance
96  * Ensure subsystem brackets remain between HUD and target monitor
97  * 
98  * 34    2/09/98 8:05p Lawrance
99  * Add new gauges: cmeasure success, warp-out, and missiontime
100  * 
101  * 33    2/07/98 5:46p Lawrance
102  * Show target distance on brackets
103  * 
104  * 32    1/19/98 11:37p Lawrance
105  * Fixing Optimization build warnings
106  * 
107  * 31    1/18/98 5:09p Lawrance
108  * Added support for TEAM_TRAITOR
109  * 
110  * 30    1/02/98 10:01p Lawrance
111  * Ensure correct subsystem bracket color gets drawn once player goes
112  * traitor.
113  * 
114  * 29    1/02/98 9:10p Lawrance
115  * Big changes to how colors get set on the HUD.
116  * 
117  * 28    12/28/97 5:54p Lawrance
118  * Draw HUD brackets the correct IFF color.. taking into account that the
119  * player may be TEAM_NEUTRAL
120  * 
121  * 27    12/18/97 8:46p Lawrance
122  * Move IFF_color definitions from HUD->ship, so FRED can use them.
123  * 
124  * 26    12/17/97 11:14p Mike
125  * Change radar and hud color to red for all neutral.
126  * 
127  * 25    11/27/97 4:24p Lawrance
128  * change appearance of subsystem targeting brackets
129  * 
130  * 24    10/22/97 5:53p Lawrance
131  * change name of subsystem_in_sight() function
132  * 
133  * 23    9/06/97 2:13p Mike
134  * Replace support for TEAM_NEUTRAL
135  * 
136  * 22    7/24/97 10:45a Mike
137  * Fix hole in Unknown team support.
138  * 
139  * 21    7/24/97 10:24a Mike
140  * Restore support for Unknown team
141  * 
142  * 20    6/11/97 1:12p John
143  * Started fixing all the text colors in the game.
144  * 
145  * 19    5/21/97 11:12a Mike
146  * Move more stuff out of player struct, mainly subsys stuff.
147  * 
148  * 18    5/20/97 2:45p Mike
149  * Move current_target and a bunch of other stuff out of player struct.
150  * 
151  * 17    4/09/97 3:30p Lawrance
152  * let target brackets grow to bracket ship entirely
153  * 
154  * 16    4/08/97 1:28p Lawrance
155  * get brackets for targeting and messaging drawing right
156  * 
157  * 15    4/08/97 11:44a Lawrance
158  * get selection and target brackets drawing right at close and far
159  * distances
160  * 
161  * 14    4/08/97 10:55a Allender
162  * draw purple brackets on ship sending a message
163  * 
164  * 13    4/08/97 9:58a Lawrance
165  * center bracket on target center.  Give min and max dimensions to
166  * subsystem target brackets.
167  * 
168  * 12    4/07/97 6:03p Lawrance
169  * draw diamond brackets instead of dashed boxes
170  * 
171  * 11    4/07/97 3:50p Allender
172  * ability to assign > 1 ship to a hotkey.  Enabled use of hotkeys in
173  * squadmate messaging
174  * 
175  * 10    4/02/97 10:08a Lawrance
176  * fixed bracket drawing glitches 
177  * 
178  * 9     3/28/97 2:46p John
179  * added code to make debris chunks target properly.
180  * 
181  * 8     3/27/97 5:44p Lawrance
182  * drawing dashed lines for sub-object targeting box that is not in line
183  * of sight
184  * 
185  * 7     3/27/97 3:59p Lawrance
186  * made brackets draw even if center of target is offscreen
187  * 
188  * 6     3/27/97 9:29a Lawrance
189  * If reach maximum bounding box size, use radius targeting box method
190  * 
191  * 5     3/25/97 3:55p Lawrance
192  * allowing debris to be targeted and shown on radar
193  * 
194  * 4     3/23/97 11:55p Lawrance
195  * made max targeting bracket size of 200x200
196  * 
197  * 3     3/07/97 4:37p Mike
198  * Make rockeye missile home.
199  * Remove UNKNOWN and NEUTRAL teams.
200  * 
201  * 2     12/24/96 4:30p Lawrance
202  * Target bracket drawing code moved to separate files
203  *
204  * $NoKeywords: $
205  */
206
207 #include "hudbrackets.h"
208 #include "hud.h"
209 #include "player.h"
210 #include "hudtarget.h"
211 #include "3d.h"
212 #include "debris.h"
213 #include "ai.h"
214 #include "freespace.h"
215 #include "bmpman.h"
216 #include "linklist.h"
217 #include "emp.h"
218
219 #define FADE_FACTOR     2                       // how much the bounding brackets get faded
220 #define LOWEST_RED      50                      // lowest r value for bounding bracket
221 #define LOWEST_GREEN    50                      // lowest g value for bounding bracket
222 #define LOWEST_BLUE     50                      // lowest b value for bounding bracket
223
224 char Ships_attack_fname[GR_NUM_RESOLUTIONS][MAX_FILENAME_LEN] = {
225         "attacker",
226         "attacker"
227 };
228
229 // resolution adjust factors for the above defines
230 int Min_target_box_width[GR_NUM_RESOLUTIONS] = { 20, 30 };
231 int Min_target_box_height[GR_NUM_RESOLUTIONS] = { 20, 30 };
232 int Min_subtarget_box_width[GR_NUM_RESOLUTIONS] = { 12, 24 };
233 int Min_subtarget_box_height[GR_NUM_RESOLUTIONS] = { 12, 24 };
234
235 void hud_init_brackets()
236 {
237 }
238
239 // find IFF color index for brackets based on team
240 int hud_brackets_get_iff_color(int team)
241 {
242         int color=IFF_COLOR_FRIENDLY;
243
244         switch ( team ) {
245         case TEAM_FRIENDLY:
246         case TEAM_HOSTILE:
247         case TEAM_NEUTRAL:
248         case TEAM_TRAITOR:
249         case TEAM_UNKNOWN:
250                 if ( (team == Player_ship->team) && (team != TEAM_TRAITOR) ) {
251                         color = IFF_COLOR_FRIENDLY;
252                 } else {
253                         switch (team) {
254                         case TEAM_NEUTRAL:
255                                 color = IFF_COLOR_NEUTRAL;
256                                 break;
257                         case TEAM_UNKNOWN:
258                                 color = IFF_COLOR_UNKNOWN;
259                                 break;
260                         case TEAM_HOSTILE:
261                         case TEAM_FRIENDLY:
262                         case TEAM_TRAITOR:
263                                 color = IFF_COLOR_HOSTILE;
264                                 break;
265                         }
266                 }
267                 break;
268         case SELECTION_SET:
269                 color = IFF_COLOR_SELECTION;
270                 break;
271                 
272         case MESSAGE_SENDER:
273                 color = IFF_COLOR_MESSAGE;
274                 break;
275
276         default:
277                 color = IFF_COLOR_UNKNOWN;
278                 Int3();
279         } // end switch
280
281         return color;
282 }
283
284
285 //      Called by draw_bounding_brackets.  
286 void draw_brackets_square(int x1, int y1, int x2, int y2)
287 {
288         int     width, height;
289         
290         width = x2 - x1;
291         Assert( width > 0);
292         height = y2 - y1;
293         Assert( height > 0);
294
295         // make the brackets extend 25% of the way along the width or height
296         int bracket_width = width/4;
297         int bracket_height = height/4;
298
299         // horizontal lines
300         if ( (x1 + bracket_width > 0) && (x1 < gr_screen.clip_width) ){
301                 gr_gradient(x1,y1,x1+bracket_width-1,y1);       // top left
302                 gr_gradient(x1,y2,x1+bracket_width-1,y2);       // bottom left
303         }
304
305         if ( (x2 - bracket_width < gr_screen.clip_width) && (x2 > 0) )  {
306                 gr_gradient(x2, y1, x2-bracket_width+1,y1);     // top right
307                 gr_gradient(x2, y2, x2-bracket_width+1,y2);     // bottom right
308         }
309
310         // vertical lines
311         if ( (y1 + bracket_height > 0) && (y1 < gr_screen.clip_height) ) {
312                 gr_gradient(x1,y1,x1,y1+bracket_height-1);              // top left
313                 gr_gradient(x2,y1,x2,y1+bracket_height-1);              // top right
314         }
315
316         if ( (y2 - bracket_height < gr_screen.clip_height) && (y2 > 0) )        {
317                 gr_gradient(x1,y2,x1,y2-bracket_height+1);      // bottom left
318                 gr_gradient(x2,y2,x2,y2-bracket_height+1);      // bottom right
319         }
320 }
321
322 void draw_brackets_square_quick(int x1, int y1, int x2, int y2, int thick)
323 {
324         int     width, height;
325
326         width = x2 - x1;
327         height = y2 - y1;
328
329         // make the brackets extend 25% of the way along the width or height
330         int bracket_width = width/4;
331         int bracket_height = height/4;
332
333         // top line
334         gr_line(x1,y1,x1+bracket_width,y1);
335         gr_line(x2,y1,x2-bracket_width,y1);
336         if ( thick ) {
337                 gr_line(x1,y1+1,x1+bracket_width,y1+1);
338                 gr_line(x2,y1+1,x2-bracket_width,y1+1);
339         }
340
341         // bottom line
342         gr_line(x1,y2,x1+bracket_width,y2);
343         gr_line(x2,y2,x2-bracket_width,y2);
344         if ( thick ) {
345                 gr_line(x1,y2-1,x1+bracket_width,y2-1);
346                 gr_line(x2,y2-1,x2-bracket_width,y2-1);
347         }
348
349         // left line
350         if ( thick ) {
351                 gr_line(x1,y1+2,x1,y1+bracket_height);
352                 gr_line(x1,y2-2,x1,y2-bracket_height);
353                 gr_line(x1+1,y1+2,x1+1,y1+bracket_height);
354                 gr_line(x1+1,y2-2,x1+1,y2-bracket_height);
355         } else {
356                 gr_line(x1,y1+1,x1,y1+bracket_height);
357                 gr_line(x1,y2-1,x1,y2-bracket_height);
358         }
359
360         // right line
361         if ( thick ) {
362                 gr_line(x2,y1+2,x2,y1+bracket_height);
363                 gr_line(x2,y2-2,x2,y2-bracket_height);
364                 gr_line(x2-1,y1+2,x2-1,y1+bracket_height);
365                 gr_line(x2-1,y2-2,x2-1,y2-bracket_height);
366         } else {
367                 gr_line(x2,y1+1,x2,y1+bracket_height);
368                 gr_line(x2,y2-1,x2,y2-bracket_height);
369         }
370 }
371
372
373 #define NUM_DASHES      2
374 void draw_brackets_dashed_square_quick(int x1, int y1, int x2, int y2)
375 {
376         int     width, height, i;
377
378         width = x2 - x1;
379         height = y2 - y1;
380
381         // make the brackets extend 25% of the way along the width or height
382         float bracket_width = width/4.0f;
383         float bracket_height = height/4.0f;
384
385         int dash_width;
386         dash_width = fl2i(bracket_width / ( NUM_DASHES*2 - 1 ) + 0.5f);
387
388         if ( dash_width < 1 ) {
389                 draw_brackets_square_quick(x1, y1, x2, y2);
390                 return;
391         }
392
393         int dash_height;
394         dash_height = fl2i(bracket_height / ( NUM_DASHES*2 - 1 ) + 0.5f);
395
396         if ( dash_height < 1 ) {
397                 draw_brackets_square_quick(x1, y1, x2, y2);
398                 return;
399         }
400         
401         int dash_x1, dash_x2, dash_y1, dash_y2;
402
403         dash_x1 = x1;
404         dash_x2 = x2;
405         dash_y1 = y1;
406         dash_y2 = y2;
407
408         for ( i = 0; i < NUM_DASHES; i++ ) {
409                 // top line
410                 gr_line(dash_x1, y1, dash_x1+(dash_width-1), y1);
411                 gr_line(dash_x2, y1, dash_x2-(dash_width-1), y1);
412
413                 // bottom line
414                 gr_line(dash_x1, y2, dash_x1+(dash_width-1), y2);
415                 gr_line(dash_x2, y2, dash_x2-(dash_width-1), y2);
416                 
417                 dash_x1 += dash_width*2;
418                 dash_x2 -= dash_width*2;
419
420                 // left line
421                 gr_line(x1, dash_y1, x1, dash_y1+(dash_height-1));
422                 gr_line(x1, dash_y2, x1, dash_y2-(dash_height-1));
423
424                 // right line
425                 gr_line(x2, dash_y1, x2, dash_y1+(dash_height-1));
426                 gr_line(x2, dash_y2, x2, dash_y2-(dash_height-1));
427
428                 dash_y1 += dash_height*2;
429                 dash_y2 -= dash_height*2;
430         }
431
432 }
433
434
435
436 // draw_brackets_diamond()
437 //      Called by draw_bounding_brackets.  
438
439 void draw_brackets_diamond(int x1, int y1, int x2, int y2)
440 {
441         int width, height, half_width, half_height;
442         int center_x, center_y;
443         int x_delta, y_delta;
444
445         float side_len, bracket_len;
446
447         width = x2 - x1;
448         height = y2 - y1;
449
450         half_width = fl2i( width/2.0f + 0.5f );
451         half_height = fl2i( height/2.0f +0.5f );
452
453         side_len = (float)_hypot(half_width, half_height);
454         bracket_len = side_len / 8;
455         
456         x_delta = fl2i(bracket_len * width / side_len + 0.5f);
457         y_delta = fl2i(bracket_len * height / side_len + 0.5f);
458
459
460         center_x = x1 + half_width;
461         center_y = y1 + half_height;
462
463         // top left line
464         gr_gradient(center_x - x_delta, y1 + y_delta,center_x, y1);
465         gr_gradient(x1 + x_delta, center_y - y_delta, x1, center_y);
466
467         // top right line
468         gr_gradient(center_x + x_delta, y1 + y_delta,center_x, y1);
469         gr_gradient(x2 - x_delta, center_y - y_delta, x2, center_y);
470
471         // bottom left line
472         gr_gradient(x1 + x_delta, center_y + y_delta, x1, center_y);
473         gr_gradient(center_x - x_delta, y2 - y_delta, center_x, y2);
474
475         // bottom right line
476         gr_gradient(x2 - x_delta, center_y + y_delta, x2, center_y);
477         gr_gradient(center_x + x_delta, y2 - y_delta, center_x, y2);
478 }
479
480 void draw_brackets_diamond_quick(int x1, int y1, int x2, int y2, int thick)
481 {
482         int width, height, half_width, half_height;
483         int center_x, center_y;
484         int x_delta, y_delta;
485
486         float side_len, bracket_len;
487
488         width = x2 - x1;
489         height = y2 - y1;
490
491         half_width = fl2i( width/2.0f + 0.5f);
492         half_height = fl2i( height/2.0f + 0.5f);
493
494         side_len = (float)_hypot(half_width, half_height);
495         bracket_len = side_len / 8;
496         
497         x_delta = fl2i(bracket_len * width / side_len + 0.5f);
498         y_delta = fl2i(bracket_len * height / side_len + 0.5f);
499
500         center_x = x1 + half_width;
501         center_y = y1 + half_height;
502
503         // top left line
504         gr_line(center_x - x_delta, y1 + y_delta,center_x, y1);
505         gr_line(x1 + x_delta, center_y - y_delta, x1, center_y);
506
507         // top right line
508         gr_line(center_x + x_delta, y1 + y_delta,center_x, y1);
509         gr_line(x2 - x_delta, center_y - y_delta, x2, center_y);
510
511         // bottom left line
512         gr_line(x1 + x_delta, center_y + y_delta, x1, center_y);
513         gr_line(center_x - x_delta, y2 - y_delta, center_x, y2);
514
515         // bottom right line
516         gr_line(x2 - x_delta, center_y + y_delta, x2, center_y);
517         gr_line(center_x + x_delta, y2 - y_delta, center_x, y2);
518
519         // draw an 'X' in the middle of the brackets
520         gr_line(center_x-x_delta, center_y-y_delta, center_x+x_delta, center_y+y_delta);
521         gr_line(center_x-x_delta, center_y+y_delta, center_x+x_delta, center_y-y_delta);
522 }
523
524
525 int subsys_is_fighterbay(ship_subsys *ss)
526 {
527         if ( !strnicmp(NOX("fighter"), ss->system_info->name, 7) ) {
528                 return 1;
529         }
530
531         return 0;
532 }
533
534 //      Draw bounding brackets for a subobject.
535 void draw_bounding_brackets_subobject()
536 {
537         if (Player_ai->targeted_subsys_parent == Player_ai->target_objnum)
538                 if (Player_ai->targeted_subsys != NULL) {
539                         ship_subsys     *subsys;
540                         int             target_objnum;
541                         object* targetp;
542                         vertex subobj_vertex;
543                         vector  subobj_pos;
544                         int x1,x2,y1,y2;
545
546                         subsys = Player_ai->targeted_subsys;
547                         target_objnum = Player_ai->target_objnum;
548                         Assert(target_objnum != -1);
549                         targetp = &Objects[target_objnum];
550                         Assert( targetp->type == OBJ_SHIP );
551
552                         get_subsystem_world_pos(targetp, subsys, &subobj_pos);
553
554                         g3_rotate_vertex(&subobj_vertex,&subobj_pos);
555
556                         g3_project_vertex(&subobj_vertex);
557                         if (subobj_vertex.flags & PF_OVERFLOW)  // if overflow, no point in drawing brackets
558                                 return;
559
560                         int subobj_x = fl2i(subobj_vertex.sx + 0.5f);
561                         int subobj_y = fl2i(subobj_vertex.sy + 0.5f);
562                         int hud_subtarget_w, hud_subtarget_h, bound_rc;
563
564                         bound_rc = subobj_find_2d_bound(subsys->system_info->radius, &targetp->orient, &subobj_pos, &x1,&y1,&x2,&y2);
565                         if ( bound_rc != 0 )
566                                 return;
567
568                         hud_subtarget_w = x2-x1+1;
569                         if ( hud_subtarget_w > gr_screen.clip_width ) {
570                                 hud_subtarget_w = gr_screen.clip_width;
571                         }
572
573                         hud_subtarget_h = y2-y1+1;
574                         if ( hud_subtarget_h > gr_screen.clip_height ) {
575                                 hud_subtarget_h = gr_screen.clip_height;
576                         }
577
578                         if ( hud_subtarget_w > gr_screen.max_w ) {
579                                 x1 = subobj_x - (gr_screen.max_w>>1);
580                                 x2 = subobj_x + (gr_screen.max_w>>1);
581                         }
582                         if ( hud_subtarget_h > gr_screen.max_h ) {
583                                 y1 = subobj_y - (gr_screen.max_h>>1);
584                                 y2 = subobj_y + (gr_screen.max_h>>1);
585                         }
586
587                         if ( hud_subtarget_w < Min_subtarget_box_width[gr_screen.res] ) {
588                                 x1 = subobj_x - (Min_subtarget_box_width[gr_screen.res]>>1);
589                                 x2 = subobj_x + (Min_subtarget_box_width[gr_screen.res]>>1);
590                         }
591                         if ( hud_subtarget_h < Min_subtarget_box_height[gr_screen.res] ) {
592                                 y1 = subobj_y - (Min_subtarget_box_height[gr_screen.res]>>1);
593                                 y2 = subobj_y + (Min_subtarget_box_height[gr_screen.res]>>1);
594                         }
595
596                         // determine if subsystem is on far or near side of the ship
597                         Player->subsys_in_view = ship_subsystem_in_sight(targetp, subsys, &View_position, &subobj_pos, 0);
598
599                         // AL 29-3-98: If subsystem is destroyed, draw gray brackets                                    
600                         if ( (Player_ai->targeted_subsys->current_hits <= 0) && (!subsys_is_fighterbay(Player_ai->targeted_subsys)) ) {
601                                 gr_set_color_fast(&IFF_colors[IFF_COLOR_MESSAGE][1]);
602                         } else {
603                                 hud_set_iff_color( targetp, 1 );
604                         }
605
606                         if ( Player->subsys_in_view ) {
607                                 draw_brackets_square_quick(x1, y1, x2, y2);
608                         } else {
609                                 draw_brackets_diamond_quick(x1, y1, x2, y2);
610                         }
611                         // mprintf(("Drawing subobject brackets at %4i, %4i\n", sx, sy));
612                 }
613 }
614
615 extern int HUD_drew_selection_bracket_on_target;
616
617 // Display the current target distance, right justified at (x,y)
618 void hud_target_show_dist_on_bracket(int x, int y, float distance)
619 {
620         char    text_dist[64];
621         int     w,h;
622
623         if ( y < 0 || y > gr_screen.clip_height ) {
624                 return;
625         }
626
627         if ( x < 0 || x > gr_screen.clip_width ) {
628                 return;
629         }
630
631         sprintf(text_dist, "%d", fl2i(distance+0.5f));
632         hud_num_make_mono(text_dist);
633         gr_get_string_size(&w,&h,text_dist);
634
635         int y_delta = 4;
636         if ( HUD_drew_selection_bracket_on_target ) {
637                 y += 4;
638         }
639
640         gr_string(x - w+2, y+y_delta, text_dist);
641 }
642
643
644 // !!!!!!!!!!!!!!!
645 //      Given an object number, return the number of ships attacking it.
646 // MWA 5/26/98 -- copied from aicode num_attacking_ships()!!!
647 // !!!!!!!!!!!!!!!
648 int hud_bracket_num_ships_attacking(int objnum)
649 {
650         object  *objp;
651         ship_obj        *so;
652         int             count = 0;
653
654         for ( so = GET_FIRST(&Ship_obj_list); so != END_OF_LIST(&Ship_obj_list); so = GET_NEXT(so) ) {
655                 objp = &Objects[so->objnum];
656                 if (objp->instance != -1) {
657                         ai_info *aip;
658                         aip = &Ai_info[Ships[objp->instance].ai_index];
659
660                         // don't count instructor
661                         int is_training_mission();
662                         if ( is_training_mission() && stricmp(Ships[objp->instance].ship_name, "Instructor") == 0) {
663                                 break;
664                         }
665
666                         if ( ((Game_mode & GM_MULTIPLAYER) || (aip->mode == AIM_CHASE)) && (aip->target_objnum == objnum))
667                                 if (Ships[objp->instance].team != Ships[Objects[objnum].instance].team)
668                                         count++;
669                 }
670         }
671
672         return count;
673 }
674
675
676 int     Ships_attacking_bitmap = -1;
677
678 // draw_bounding_brackets() will draw the faded brackets that surround the current target
679 void draw_bounding_brackets(int x1, int y1, int x2, int y2, int w_correction, int h_correction, float distance, int target_objnum)
680 {
681         int width, height;
682
683         if ( ( x1 < 0 && x2 < 0 ) || ( y1 < 0 && y2 < 0 ) )
684                 return;
685
686         if ( ( x1 > gr_screen.clip_width && x2 > gr_screen.clip_width ) ||
687                   ( y1 > gr_screen.clip_height && y2 > gr_screen.clip_height ) )
688                 return;
689
690         width = x2-x1;
691         Assert(width>=0);
692
693         height = y2-y1;
694         Assert(height>=0);
695
696         if ( (width>(gr_screen.max_w - 1)) && (height>(gr_screen.max_h - 1)) ) {
697                 return;
698         }
699         if ( width > 1200 ) {
700                 return;
701
702         }
703         if ( height > 1200) {
704                 return;
705         }
706
707         if (width < Min_target_box_width[gr_screen.res]) {
708                 x1 = x1 - (Min_target_box_width[gr_screen.res]-width)/2;
709                 x2 = x2 + (Min_target_box_width[gr_screen.res]-width)/2;
710         }
711
712         if (height < Min_target_box_height[gr_screen.res]) {
713                 y1 = y1 - (Min_target_box_height[gr_screen.res]-height)/2;
714                 y2 = y2 + (Min_target_box_height[gr_screen.res]-height)/2;
715         }
716                 
717         draw_brackets_square(x1-w_correction, y1-h_correction, x2+w_correction, y2+h_correction);
718
719         // draw distance to target in lower right corner of box
720         if ( distance > 0 ) {
721                 hud_target_show_dist_on_bracket(x2+w_correction,y2+h_correction,distance);
722         }
723
724         //      Maybe show + for each additional fighter or bomber attacking target.
725         if ( (target_objnum != -1) && hud_gauge_active(HUD_ATTACKING_TARGET_COUNT) ) {
726                 int num_attacking = hud_bracket_num_ships_attacking(target_objnum);
727
728                 if (Ships_attacking_bitmap == -1){
729                         Ships_attacking_bitmap = bm_load(Ships_attack_fname[gr_screen.res]);
730                 }
731
732                 if (Ships_attacking_bitmap == -1) {
733                         Int3();
734                         return;
735                 }
736
737                 //      If a ship not on player's team, show one fewer plus since it is targeted and attacked by player.
738                 int     k=0;
739                 if (Objects[target_objnum].type == OBJ_SHIP) {
740                         if (Ships[Objects[target_objnum].instance].team != Player_ship->team){
741                                 k = 1;
742                         }
743                 } else {
744                         k = 1;
745                 }
746
747                 if (num_attacking > k) {
748                         int     i, num_blips;
749                         
750                         num_blips = num_attacking-k;
751                         if (num_blips > 4){
752                                 num_blips = 4;
753                         }
754
755                         //int   bitmap = get_blip_bitmap();
756
757                         if (Ships_attacking_bitmap > -1) {
758                                 if (num_blips > 3)
759                                         y1 -= 3;
760
761                                 for (i=0; i<num_blips; i++) {
762                                         GR_AABITMAP(Ships_attacking_bitmap, x2+3, y1+i*7);                                      
763                                 }
764                         }
765                 }
766         }
767 }