]> icculus.org git repositories - taylor/freespace2.git/blob - src/ship/shield.cpp
Initial revision
[taylor/freespace2.git] / src / ship / shield.cpp
1 /*
2  * $Logfile: /Freespace2/code/Ship/Shield.cpp $
3  * $Revision$
4  * $Date$
5  * $Author$
6  *
7  *      Stuff pertaining to shield graphical effects, etc.
8  *
9  * $Log$
10  * Revision 1.1  2002/05/03 03:28:10  root
11  * Initial revision
12  *
13  * 
14  * 11    8/03/99 1:46p Dave
15  * Make opacity higher.
16  * 
17  * 10    8/03/99 11:28a Dave
18  * Fixed shield problem.
19  * 
20  * 9     8/02/99 10:42p Dave
21  * Make shields less opaque in the nebula.
22  * 
23  * 8     8/02/99 10:39p Dave
24  * Added colored shields. OoOoOoooOoo
25  * 
26  * 7     7/15/99 9:20a Andsager
27  * FS2_DEMO initial checkin
28  * 
29  * 6     3/10/99 6:50p Dave
30  * Changed the way we buffer packets for all clients. Optimized turret
31  * fired packets. Did some weapon firing optimizations.
32  * 
33  * 5     1/12/99 5:45p Dave
34  * Moved weapon pipeline in multiplayer to almost exclusively client side.
35  * Very good results. Bandwidth goes down, playability goes up for crappy
36  * connections. Fixed object update problem for ship subsystems.
37  * 
38  * 4     12/01/98 8:06a Dave
39  * Temporary checkin to fix some texture transparency problems in d3d.
40  * 
41  * 3     11/05/98 5:55p Dave
42  * Big pass at reducing #includes
43  * 
44  * 2     10/07/98 10:53a Dave
45  * Initial checkin.
46  * 
47  * 1     10/07/98 10:51a Dave
48  * 
49  * 65    5/25/98 12:12a Mike
50  * Make shield effect less CPU-intensive in software.  Always use lower
51  * detail versions.
52  * 
53  * 64    4/22/98 8:37p Mike
54  * Recover gracefully from exhausted MAX_GLOBAL_TRIS asserts.
55  * 
56  * 63    4/09/98 7:58p John
57  * Cleaned up tmapper code a bit.   Put NDEBUG around some ndebug stuff.
58  * Took out XPARENT flag settings in all the alpha-blended texture stuff.
59  * 
60  * 62    4/02/98 6:28p Lawrance
61  * remove shield code from demo build
62  * 
63  * 61    4/02/98 11:40a Lawrance
64  * check for #ifdef DEMO instead of #ifdef DEMO_RELEASE
65  * 
66  * 60    3/31/98 5:32p Mike
67  * Reduce size of some buffers.
68  * 
69  * 59    3/31/98 5:19p John
70  * Removed demo/save/restore.  Made NDEBUG defined compile.  Removed a
71  * bunch of debug stuff out of player file.  Made model code be able to
72  * unload models and malloc out only however many models are needed.
73  *  
74  * 
75  * 58    3/30/98 4:02p John
76  * Made machines with < 32 MB of RAM use every other frame of certain
77  * bitmaps.   Put in code to keep track of how much RAM we've malloc'd.
78  * 
79  * 57    3/30/98 12:18a Lawrance
80  * change some DEMO_RELEASE code to not compile code rather than return
81  * early
82  * 
83  * 56    3/29/98 11:33p Mike
84  * Speedup sheidl hit effect at detail levels 1, 3 (in 0..4).
85  * 
86  * 55    3/29/98 5:02p Adam
87  * changed ANIs referenced for shieldhit effect to all be
88  * shieldhit01a.ani.  There won't be different ones for different species
89  * like I once thought.
90  * 
91  * 54    3/29/98 4:05p John
92  * New paging code that loads everything necessary at level startup.
93  * 
94  * 53    3/27/98 9:06p Mike
95  * Make shield effect larger in lower detail levels (to match size in
96  * higher detail level) and handle changing detail level whiel shield
97  * effect playing.
98  * 
99  * 52    3/27/98 8:35p Mike
100  * Detail level support in shield effect system.
101  * 
102  * 51    3/16/98 4:07p Sandeep
103  * 
104  * 50    3/12/98 1:24p Mike
105  * When weapons linked, increase firing delay.
106  * Free up weapon slots for AI ships, if necessary.
107  * Backside render shield effect.
108  * Remove shield hit triangle if offscreen.
109  * 
110  * 49    3/02/98 5:42p John
111  * Removed WinAVI stuff from Freespace.  Made all HUD gauges wriggle from
112  * afterburner.  Made gr_set_clip work good with negative x &y.  Made
113  * model_caching be on by default.  Made each cached model have it's own
114  * bitmap id.  Made asteroids not rotate when model_caching is on.  
115  * 
116  * 48    2/22/98 4:17p John
117  * More string externalization classification... 190 left to go!
118  * 
119  * 47    2/14/98 11:13p Mike
120  * Optimize a bit by making old ones go away if Poly_count high.
121  * 
122  * 46    2/06/98 9:10a Allender
123  * removed an Assert for multiplayer clients
124  * 
125  * 45    2/05/98 9:21p John
126  * Some new Direct3D code.   Added code to monitor a ton of stuff in the
127  * game.
128  * 
129  * 44    1/28/98 11:15p Allender
130  * work on getting shield effect to show correctly in client side
131  * multiplayer
132  * 
133  * 43    12/30/97 4:26p Lawrance
134  * Remove .ani from shield animations, avoids bmpman warning
135  * 
136  * $NoKeywords: $
137  */
138
139 //      Detail level effects (Detail.shield_effects)
140 //              0               Nothing rendered
141 //              1               An animating bitmap rendered per hit, not shrink-wrapped.  Lasts half time.  One per ship.
142 //              2               Animating bitmap per hit, not shrink-wrapped.  Lasts full time.  Unlimited.
143 //              3               Shrink-wrapped texture.  Lasts half-time.
144 //              4               Shrink-wrapped texture.  Lasts full-time.
145
146 #include <math.h>
147
148 #include "2d.h"
149 #include "3d.h"
150 #include "model.h"
151 #include "tmapper.h"
152 #include "floating.h"
153 #include "fvi.h"
154 #include "lighting.h"
155 #include "fireballs.h"
156 #include "fix.h"
157 #include "bmpman.h"
158 #include        "object.h"
159 #include "player.h"             //      #include of "player.h" is only for debugging!
160 #include "timer.h"
161 #include "freespace.h"
162 #include "packunpack.h"
163 #include "animplay.h"
164 #include "shiphit.h"
165 #include "missionparse.h"
166 #include "multimsgs.h"
167 #include "multi.h"
168
169 int     New_shield_system = 1;
170 int     Show_shield_mesh = 0;
171
172 #ifndef DEMO // not for FS2_DEMO
173
174 //      One unit in 3d means this in the shield hit texture map.
175 //#define       SHIELD_HIT_SCALE        0.075f                  //      Scale decreased by MK on 12/18/97, made about 1/4x as large. Note, larger constant means smaller effect
176 #define SHIELD_HIT_SCALE        0.15f                   //      Doubled on 12/23/97 by MK.  Was overflowing.  See todo item #924.
177 //#define       MAX_SHIELD_HITS 20
178 #define MAX_TRIS_PER_HIT        40                                      //      Number of triangles per shield hit, maximum.
179 #define MAX_SHIELD_HITS 20                                      //      Maximum number of active shield hits.
180 #define MAX_SHIELD_TRI_BUFFER   (MAX_SHIELD_HITS*20) // Persistent buffer of triangle comprising all active shield hits.
181 #define SHIELD_HIT_DURATION     (3*F1_0/4)      //      Duration, in milliseconds, of shield hit effect
182
183 #define SH_UNUSED                       -1                                      //      Indicates an unused record in Shield_hits
184 #define SH_TYPE_1                       1                                       //      Indicates Shield_hits record is of type 1.
185
186 #define UV_MAX                          (63.95f/64.0f)  //      max allowed value until tmapper bugs fixed, 1/24/97
187
188 float   Shield_scale = SHIELD_HIT_SCALE;
189
190 //      Structure which mimics the shield_tri structure in model.h.  Since the global shield triangle
191 // array needs the vertex information, we will acutally store the information in this
192 // structure instead of the indices into the vertex list
193 typedef struct gshield_tri {
194         int                             used;                                                   //      Set if this triangle is currently in use.
195         int                             trinum;                                         //      a debug parameter
196         fix                             creation_time;                          //      time at which created.
197         shield_vertex   verts[4];                                       //      Triangles, but at lower detail level, a square.
198 } gshield_tri;
199
200 typedef struct shield_hit {
201         int     start_time;                                                             //      start time of this object
202         int     type;                                                                           //      type, probably the weapon type, to indicate the bitmap to use
203         int     objnum;                                                                 //      Object index, needed to get current orientation, position.
204         int     num_tris;                                                               //      Number of Shield_tris comprising this shield.
205         int     tri_list[MAX_TRIS_PER_HIT];             //      Indices into Shield_tris, triangles for this shield hit.
206         ubyte rgb[3];                                                                   // rgb colors
207 } shield_hit;
208
209 //      Stores point at which shield was hit.
210 //      Gets processed in frame interval.
211 typedef struct shield_point {
212         int             objnum;                                                         //      Object that was hit.
213         int             shield_tri;                                                     //      Triangle in shield mesh that took hit.
214         vector  hit_point;                                                      //      Point in global 3-space of hit.
215 } shield_point;
216
217 #define MAX_SHIELD_POINTS       100
218 shield_point    Shield_points[MAX_SHIELD_POINTS];
219 int             Num_shield_points;
220 int             Num_multi_shield_points;                                        // used by multiplayer clients
221
222 gshield_tri     Global_tris[MAX_SHIELD_TRI_BUFFER];     //      The persistent triangles, part of shield hits.
223 int     Num_tris;                                                               //      Number of triangles in current shield.  Would be a local, but needed in numerous routines.
224
225 shield_hit      Shield_hits[MAX_SHIELD_HITS];
226
227 typedef struct shield_ani {
228         char            *filename;
229         int             first_frame;
230         int             nframes;
231 } shield_ani;
232
233 //XSTR:OFF
234 #define MAX_SHIELD_ANIMS MAX_SPECIES_NAMES
235 shield_ani Sheild_ani[MAX_SHIELD_ANIMS] = {
236         { "shieldhit01a", -1, -1 },
237         { "shieldhit01a", -1, -1 },
238         { "shieldhit01a", -1, -1 },
239 };
240 //XSTR:ON
241
242 int Shield_bitmaps_loaded = 0;
243
244 //      This is a recursive function, so prototype it.
245 extern void create_shield_from_triangle(int trinum, matrix *orient, shield_info *shieldp, vector *tcp, vector *centerp, float radius, vector *rvec, vector *uvec);
246
247 void load_shield_hit_bitmap()
248 {
249         #ifndef DEMO // not for FS2_DEMO
250
251         int i;
252         // Check if we've already allocated the shield effect bitmaps
253         if ( Shield_bitmaps_loaded )
254                 return;
255
256         Shield_bitmaps_loaded = 1;
257
258         for (i=0; i<MAX_SHIELD_ANIMS; i++ )     {
259                 Sheild_ani[i].first_frame = bm_load_animation(Sheild_ani[i].filename, &Sheild_ani[i].nframes,NULL, 1);
260                 if ( Sheild_ani[i].first_frame < 0 )
261                         Int3();
262         }
263
264         #endif
265 }
266
267 void shield_hit_page_in()
268 {
269         int i;
270
271         if ( !Shield_bitmaps_loaded )   {
272                 load_shield_hit_bitmap();
273         }
274
275         for (i=0; i<MAX_SHIELD_ANIMS; i++ )     {
276                 bm_page_in_xparent_texture( Sheild_ani[i].first_frame, Sheild_ani[i].nframes );
277         }
278 }
279
280
281 //      Initialize shield hit system.  Called from game_level_init()
282 void shield_hit_init()
283 {
284         int     i;
285
286         for (i=0; i<MAX_SHIELD_HITS; i++)
287                 Shield_hits[i].type = SH_UNUSED;
288
289         for (i=0; i<MAX_SHIELD_TRI_BUFFER; i++) {
290                 Global_tris[i].used = 0;
291                 Global_tris[i].creation_time = Missiontime;
292         }
293
294         Num_multi_shield_points = 0;
295
296         load_shield_hit_bitmap();
297 }
298
299 // ---------------------------------------------------------------------
300 // release_shield_hit_bitmap()
301 //
302 // Release the storage allocated to store the shield effect.
303 //
304 void release_shield_hit_bitmap()
305 {
306         if ( !Shield_bitmaps_loaded )
307                 return;
308
309         // This doesn't need to do anything; the bitmap manager will
310         // release everything.
311 }
312
313 int     Poly_count = 0;
314
315 // ---------------------------------------------------------------------
316 // shield_hit_close()
317 //
318 // De-initalize the shield hit system.  Called from game_level_close().
319 //
320 // TODO: We should probably not bother releasing the shield hit bitmaps every level.
321 //
322 void shield_hit_close()
323 {
324         release_shield_hit_bitmap();
325 }
326
327 void shield_frame_init()
328 {
329         //nprintf(("AI", "Frame %i: Number of shield hits: %i, polycount = %i\n", Framecount, Num_shield_points, Poly_count));
330
331         Poly_count = 0;
332
333         Num_shield_points = 0;
334 }
335
336 void create_low_detail_poly(int global_index, vector *tcp, vector *rightv, vector *upv)
337 {
338         float           scale;
339         gshield_tri     *trip;
340
341         trip = &Global_tris[global_index];
342
343         scale = vm_vec_mag(tcp) * 2.0f;
344
345         vm_vec_scale_add(&trip->verts[0].pos, tcp, rightv, -scale/2.0f);
346         vm_vec_scale_add2(&trip->verts[0].pos, upv, scale/2.0f);
347
348         vm_vec_scale_add(&trip->verts[1].pos, &trip->verts[0].pos, rightv, scale);
349
350         vm_vec_scale_add(&trip->verts[2].pos, &trip->verts[1].pos, upv, -scale);
351
352         vm_vec_scale_add(&trip->verts[3].pos, &trip->verts[2].pos, rightv, -scale);
353
354         //      Set u, v coordinates.
355         //      Note, this need only be done once, as it's common for all explosions.
356         trip->verts[0].u = 0.0f;
357         trip->verts[0].v = 0.0f;
358
359         trip->verts[1].u = 1.0f;
360         trip->verts[1].v = 0.0f;
361
362         trip->verts[2].u = 1.0f;
363         trip->verts[2].v = 1.0f;
364
365         trip->verts[3].u = 0.0f;
366         trip->verts[3].v = 1.0f;
367
368 }
369
370 //      ----------------------------------------------------------------------------------------------------
371 //      Given a shield triangle, compute the uv coordinates at its vertices given
372 //      the center point of the explosion texture, distance to center of shield and
373 //      right and up vectors.
374 //      For small distances (relative to radius), coordinates can be computed using
375 //      distance.  For larger values, should comptue angle.
376 void rs_compute_uvs(shield_tri *stp, shield_vertex *verts, vector *tcp, float radius, vector *rightv, vector *upv)
377 {
378         int     i;
379         shield_vertex *sv;
380
381         for (i=0; i<3; i++) {
382                 vector  v2cp;
383
384                 sv = &verts[stp->verts[i]];
385
386                 vm_vec_sub(&v2cp, &sv->pos, tcp);
387                 sv->u = vm_vec_dot(&v2cp, rightv) * Shield_scale + 0.5f;
388                 sv->v = - vm_vec_dot(&v2cp, upv) * Shield_scale + 0.5f;
389
390                 if (sv->u > UV_MAX){
391                         sv->u = UV_MAX;
392                 }
393
394                 if (sv->u < 0.0f){
395                         sv->u = 0.0f;
396                 }
397
398                 if (sv->v > UV_MAX){
399                         sv->v = UV_MAX;
400                 }
401
402                 if (sv->v < 0.0f){
403                         sv->v = 0.0f;
404                 }
405
406                 // mprintf(("u, v = %7.3f %7.3f\n", stp->verts[i].u, stp->verts[i].v));
407         }
408
409         // mprintf(("\n"));
410 }
411
412 //      ----------------------------------------------------------------------------------------------------
413 //      Free records in Global_tris previously used by Shield_hits[shnum].tri_list
414 void free_global_tri_records(int shnum)
415 {
416         int     i;
417
418         Assert((shnum >= 0) && (shnum < MAX_SHIELD_HITS));
419
420         //mprintf(("Freeing up %i global records.\n", Shield_hits[shnum].num_tris));
421
422         for (i=0; i<Shield_hits[shnum].num_tris; i++){
423                 Global_tris[Shield_hits[shnum].tri_list[i]].used = 0;
424         }
425 }
426
427 void render_low_detail_shield_bitmap(gshield_tri *trip, matrix *orient, vector *pos, ubyte r, ubyte g, ubyte b)
428 {
429         matrix  m;
430         int             j;
431         vector  pnt;
432         vertex  verts[4];
433
434         vm_copy_transpose_matrix(&m,orient);
435
436         for (j=0; j<4; j++ )    {
437                 // Rotate point into world coordinates
438                 vm_vec_rotate(&pnt, &trip->verts[j].pos, &m);
439                 vm_vec_add2(&pnt, pos);
440
441                 // Pnt is now the x,y,z world coordinates of this vert.
442                 g3_rotate_vertex(&verts[j], &pnt);
443                 verts[j].u = trip->verts[j].u;
444                 verts[j].v = trip->verts[j].v;
445         }       
446
447         verts[0].r = r;
448         verts[0].g = g;
449         verts[0].b = b;
450         verts[1].r = r;
451         verts[1].g = g;
452         verts[1].b = b;
453         verts[2].r = r;
454         verts[2].g = g;
455         verts[2].b = b;
456         verts[3].r = r;
457         verts[3].g = g;
458         verts[3].b = b;
459
460         vector  norm;
461         vm_vec_perp(&norm, &trip->verts[0].pos, &trip->verts[1].pos, &trip->verts[2].pos);
462         vertex  *vertlist[4];
463         if ( vm_vec_dot(&norm, &trip->verts[1].pos ) < 0.0 )    {
464                 vertlist[0] = &verts[3]; 
465                 vertlist[1] = &verts[2];
466                 vertlist[2] = &verts[1]; 
467                 vertlist[3] = &verts[0]; 
468                 g3_draw_poly( 4, vertlist, TMAP_FLAG_TEXTURED | TMAP_FLAG_RGB | TMAP_FLAG_GOURAUD);
469         } else {
470                 vertlist[0] = &verts[0]; 
471                 vertlist[1] = &verts[1];
472                 vertlist[2] = &verts[2]; 
473                 vertlist[3] = &verts[3]; 
474                 g3_draw_poly( 4, vertlist, TMAP_FLAG_TEXTURED | TMAP_FLAG_RGB | TMAP_FLAG_GOURAUD);
475         }
476 }
477
478 //      Render one triangle of a shield hit effect on one ship.
479 //      Each frame, the triangle needs to be rotated into global coords.
480 //      trip            pointer to triangle in global array
481 //      orient  orientation of object shield is associated with
482 //      pos             center point of object
483 void render_shield_triangle(gshield_tri *trip, matrix *orient, vector *pos, ubyte r, ubyte g, ubyte b)
484 {
485         matrix  m;
486         int             j;
487         vector  pnt;
488         vertex  *verts[3];
489         vertex  points[3];
490
491         if (trip->trinum == -1)
492                 return; //      Means this is a quad, must have switched detail_level.
493
494         vm_copy_transpose_matrix(&m,orient);
495
496         for (j=0; j<3; j++ )    {
497                 // Rotate point into world coordinates
498                 vm_vec_rotate(&pnt, &trip->verts[j].pos, &m);
499                 vm_vec_add2(&pnt, pos);
500
501                 // Pnt is now the x,y,z world coordinates of this vert.
502                 // For this example, I am just drawing a sphere at that point.
503                 g3_rotate_vertex(&points[j], &pnt);
504                 points[j].u = trip->verts[j].u;
505                 points[j].v = trip->verts[j].v;
506                 Assert((trip->verts[j].u >= 0.0f) && (trip->verts[j].u <= UV_MAX));
507                 Assert((trip->verts[j].v >= 0.0f) && (trip->verts[j].v <= UV_MAX));
508                 verts[j] = &points[j];
509         }
510
511         verts[0]->r = r;
512         verts[0]->g = g;
513         verts[0]->b = b;
514         verts[1]->r = r;
515         verts[1]->g = g;
516         verts[1]->b = b;
517         verts[2]->r = r;
518         verts[2]->g = g;
519         verts[2]->b = b;
520
521         vector  norm;
522         Poly_count++;
523         vm_vec_perp(&norm,(vector *)&verts[0]->x,(vector *)&verts[1]->x,(vector*)&verts[2]->x);
524         if ( vm_vec_dot(&norm,(vector *)&verts[1]->x ) >= 0.0 ) {
525                 vertex  *vertlist[3];
526                 vertlist[0] = verts[2]; 
527                 vertlist[1] = verts[1]; 
528                 vertlist[2] = verts[0]; 
529                 g3_draw_poly( 3, vertlist, TMAP_FLAG_TEXTURED | TMAP_FLAG_RGB | TMAP_FLAG_GOURAUD);
530         } else {
531                 g3_draw_poly( 3, verts, TMAP_FLAG_TEXTURED | TMAP_FLAG_RGB | TMAP_FLAG_GOURAUD);
532         }
533 }
534
535 MONITOR(NumShieldRend);
536
537 //      Render a shield mesh in the global array Shield_hits[]
538 void render_shield(int shield_num) //, matrix *orient, vector *centerp)
539 {
540         int             i;
541         vector  *centerp;
542         matrix  *orient;
543         object  *objp;
544         ship            *shipp;
545         ship_info       *si;
546
547         if (Shield_hits[shield_num].type == SH_UNUSED)  {
548                 return;
549         }
550
551         Assert(Shield_hits[shield_num].objnum >= 0);
552
553         objp = &Objects[Shield_hits[shield_num].objnum];
554
555         if (objp->flags & OF_NO_SHIELDS)        {
556                 return;
557         }
558
559         //      If this object didn't get rendered, don't render its shields.  In fact, make the shield hit go away.
560         if (!(objp->flags & OF_WAS_RENDERED)) {
561                 Shield_hits[shield_num].type = SH_UNUSED;
562                 return;
563         }
564
565         //      At detail levels 1, 3, animations play at double speed to reduce load.
566         if (!D3D_enabled || (Detail.shield_effects == 1) || (Detail.shield_effects == 3)) {
567                 Shield_hits[shield_num].start_time -= Frametime;
568         }
569
570         MONITOR_INC(NumShieldRend,1);
571
572         shipp = &Ships[objp->instance];
573         si = &Ship_info[shipp->ship_info_index];
574
575         // objp, shipp, and si are now setup correctly
576
577         //      If this ship is in its deathroll, make the shield hit effects go away faster.
578         if (shipp->flags & SF_DYING)    {
579                 Shield_hits[shield_num].start_time -= fl2f(2*flFrametime);
580         }
581
582         //      Detail level stuff.  When lots of shield hits, maybe make them go away faster.
583         if (Poly_count > 50) {
584                 if (Shield_hits[shield_num].start_time + (SHIELD_HIT_DURATION*50)/Poly_count < Missiontime) {
585                         Shield_hits[shield_num].type = SH_UNUSED;
586                         free_global_tri_records(shield_num);
587                         // nprintf(("AI", "* "));
588                         return;
589                 }
590         } else if ((Shield_hits[shield_num].start_time + SHIELD_HIT_DURATION) < Missiontime) {
591                 Shield_hits[shield_num].type = SH_UNUSED;
592                 free_global_tri_records(shield_num);
593                 return;
594         }
595
596         orient = &objp->orient;
597         centerp = &objp->pos;
598
599         int bitmap_id, frame_num, n;
600
601         // mprintf(("Percent = %7.3f\n", f2fl(Missiontime - Shield_hits[shield_num].start_time)));
602
603         n = si->species;                
604         // Do some sanity checking
605         Assert( (n >=0) && (n<MAX_SPECIES_NAMES));
606         Assert( (n >=0) && (n<MAX_SHIELD_ANIMS));
607
608         frame_num = fl2i( f2fl(Missiontime - Shield_hits[shield_num].start_time) * Sheild_ani[n].nframes);
609         if ( frame_num >= Sheild_ani[n].nframes )       {
610                 frame_num = Sheild_ani[n].nframes - 1;
611         } else if ( frame_num < 0 )     {
612                 mprintf(( "HEY! Missiontime went backwards! (Shield.cpp)\n" ));
613                 frame_num = 0;
614         }
615         bitmap_id = Sheild_ani[n].first_frame + frame_num;
616
617         float alpha = 0.9999f;
618         if(The_mission.flags & MISSION_FLAG_FULLNEB){
619                 alpha *= 0.85f;
620         }
621         gr_set_bitmap(bitmap_id, GR_ALPHABLEND_FILTER, GR_BITBLT_MODE_NORMAL, alpha );
622
623         if (!D3D_enabled || (Detail.shield_effects == 1) || (Detail.shield_effects == 2)) {
624                 if ( bitmap_id != - 1 ) {
625                         render_low_detail_shield_bitmap(&Global_tris[Shield_hits[shield_num].tri_list[0]], orient, centerp, Shield_hits[shield_num].rgb[0], Shield_hits[shield_num].rgb[1], Shield_hits[shield_num].rgb[2]);
626                 }
627         } else {
628
629                 // AL 06/01/97 don't use Assert() until issue with Missiontime being reset to 0 are worked out
630                 if ( bitmap_id != - 1 ) {
631                         for (i=0; i<Shield_hits[shield_num].num_tris; i++) {
632                                 //if (Missiontime == Shield_hits[shield_num].start_time)
633                                 //      nprintf(("AI", "Frame %i: Render triangle %i.\n", Framecount, Global_tris[Shield_hits[shield_num].tri_list[i]].trinum));
634                                 render_shield_triangle(&Global_tris[Shield_hits[shield_num].tri_list[i]], orient, centerp, Shield_hits[shield_num].rgb[0], Shield_hits[shield_num].rgb[1], Shield_hits[shield_num].rgb[2]);
635                         }
636                 }
637         }
638 }
639
640 //      Render all the shield hits  in the global array Shield_hits[]
641 //      This is a temporary function.  Shield hit rendering will at least have to
642 // occur with the ship, perhaps even internal to the ship.
643 void render_shields()
644 {
645         int     i;
646
647         if (Detail.shield_effects == 0){
648                 return; //      No shield effect rendered at lowest detail level.
649         }
650
651         if (!New_shield_system){
652                 return;
653         }
654
655         for (i=0; i<MAX_SHIELD_HITS; i++){
656                 if (Shield_hits[i].type != SH_UNUSED){
657                         render_shield(i);
658                 }
659         }
660 }
661
662
663 // -----------------------------------------------------------------------------------------------------
664 void create_tris_containing(vector *vp, matrix *orient, shield_info *shieldp, vector *tcp, vector *centerp, float radius, vector *rvec, vector *uvec)
665 {
666         int     i, j;
667         shield_vertex *verts;
668
669         verts = shieldp->verts;
670
671         for (i=0; i<Num_tris; i++) {
672                 if ( !shieldp->tris[i].used ) {
673                         for (j=0; j<3; j++) {
674                                 vector v;
675
676                                 v = verts[shieldp->tris[i].verts[j]].pos;
677                                 if ((vp->x == v.x) && (vp->y == v.y) && (vp->z == v.z))
678                                         create_shield_from_triangle(i, orient, shieldp, tcp, centerp, radius, rvec, uvec);
679                         }
680                 }
681         }
682 }
683
684 void visit_children(int trinum, int vertex_index, matrix *orient, shield_info *shieldp, vector *tcp, vector *centerp, float radius, vector *rvec, vector *uvec)
685 {
686         shield_vertex *sv;
687
688         sv = &(shieldp->verts[shieldp->tris[trinum].verts[vertex_index]]);
689
690         if ( (sv->u > 0.0f) && (sv->u < UV_MAX) && (sv->v > 0.0f) && (sv->v < UV_MAX))
691                         create_tris_containing(&sv->pos, orient, shieldp, tcp, centerp, radius, rvec, uvec);
692 }
693
694 int     Gi_max = 0;
695
696 int get_free_global_shield_index()
697 {
698         int     gi = 0;
699
700         while ((gi < MAX_SHIELD_TRI_BUFFER) && (Global_tris[gi].used) && (Global_tris[gi].creation_time + SHIELD_HIT_DURATION > Missiontime)) {
701                 gi++;
702         }
703
704         //      If couldn't find one, choose a random one.
705         if (gi == MAX_SHIELD_TRI_BUFFER)
706                 gi = (int) (frand() * MAX_SHIELD_TRI_BUFFER);
707
708         return gi;
709 }
710
711 int get_global_shield_tri()
712 {
713         int     shnum;
714
715         //      Find unused shield hit buffer
716         for (shnum=0; shnum<MAX_SHIELD_HITS; shnum++)
717                 if (Shield_hits[shnum].type == SH_UNUSED)
718                         break;
719
720         if (shnum == MAX_SHIELD_HITS) {
721                 //nprintf(("AI", "Warning: Shield_hit buffer full!  Stealing an old one!\n"));
722                 shnum = myrand() % MAX_SHIELD_HITS;
723         }
724
725         Assert((shnum >= 0) && (shnum < MAX_SHIELD_HITS));
726
727         return shnum;
728 }
729
730 void create_shield_from_triangle(int trinum, matrix *orient, shield_info *shieldp, vector *tcp, vector *centerp, float radius, vector *rvec, vector *uvec)
731 {
732         //nprintf(("AI", "[%3i] ", trinum));
733
734         rs_compute_uvs( &shieldp->tris[trinum], shieldp->verts, tcp, radius, rvec, uvec);
735
736         //Assert(trinum < MAX_SHIELD_HITS);
737         shieldp->tris[trinum].used = 1;
738
739 //mprintf(("%i ", trinum));
740         visit_children(trinum, 0, orient, shieldp, tcp, centerp, radius, rvec, uvec);
741         visit_children(trinum, 1, orient, shieldp, tcp, centerp, radius, rvec, uvec);
742         visit_children(trinum, 2, orient, shieldp, tcp, centerp, radius, rvec, uvec);
743 }
744
745 //      Copy information from Current_tris to Global_tris, stuffing information
746 //      in a slot in Shield_hits.  The Global_tris array is not a shield_tri structure.
747 // We need to store vertex information in the global array since the vertex list
748 // will not be available to us when we actually use the array.
749 void copy_shield_to_globals( int objnum, shield_info *shieldp )
750 {
751         int     i, j;
752         int     gi = 0;
753         int     count = 0;                      //      Number of triangles in this shield hit.
754         int     shnum;                          //      shield hit number, index in Shield_hits.
755
756         shnum = get_global_shield_tri();
757         
758         Shield_hits[shnum].type = SH_TYPE_1;
759         // mprintf(("Creating hit #%i at time = %7.3f\n", shnum, f2fl(Missiontime)));
760
761         for (i = 0; i < shieldp->ntris; i++ ) {
762                 if ( shieldp->tris[i].used ) {
763                         while ( (gi < MAX_SHIELD_TRI_BUFFER) && (Global_tris[gi].used) && (Global_tris[gi].creation_time + SHIELD_HIT_DURATION > Missiontime)) {
764                                 gi++;
765                         }
766                         
767                         //      If couldn't find one, choose a random one.
768                         if (gi == MAX_SHIELD_TRI_BUFFER)
769                                 gi = (int) (frand() * MAX_SHIELD_TRI_BUFFER);
770
771                         Global_tris[gi].used = shieldp->tris[i].used;
772                         Global_tris[gi].trinum = i;
773                         Global_tris[gi].creation_time = Missiontime;
774
775                         // copy the pos/u/v elements of the shield_vertex structure into the shield vertex structure for this global triangle.
776                         for (j = 0; j < 3; j++)
777                                 Global_tris[gi].verts[j] = shieldp->verts[shieldp->tris[i].verts[j]];
778                         Shield_hits[shnum].tri_list[count++] = gi;
779
780                         if (count >= MAX_TRIS_PER_HIT) {
781                                 mprintf(("Warning: Too many triangles in shield hit.\n"));
782                                 break;
783                         }
784                 }
785         }
786
787         Shield_hits[shnum].num_tris = count;
788         Shield_hits[shnum].start_time = Missiontime;
789         Shield_hits[shnum].objnum = objnum;
790
791         Shield_hits[shnum].rgb[0] = 255;
792         Shield_hits[shnum].rgb[1] = 255;
793         Shield_hits[shnum].rgb[2] = 255;
794         if((objnum >= 0) && (objnum < MAX_OBJECTS) && (Objects[objnum].type == OBJ_SHIP) && (Objects[objnum].instance >= 0) && (Objects[objnum].instance < MAX_SHIPS) && (Ships[Objects[objnum].instance].ship_info_index >= 0) && (Ships[Objects[objnum].instance].ship_info_index < Num_ship_types)){
795                 ship_info *sip = &Ship_info[Ships[Objects[objnum].instance].ship_info_index];
796                 
797                 Shield_hits[shnum].rgb[0] = sip->shield_color[0];
798                 Shield_hits[shnum].rgb[1] = sip->shield_color[1];
799                 Shield_hits[shnum].rgb[2] = sip->shield_color[2];
800         }
801 }
802
803 //      ***** This is the version that works on a quadrant basis.
804 //      Return absolute amount of damage not applied.
805 float apply_damage_to_shield(object *objp, int shield_quadrant, float damage)
806 {
807         ai_info *aip;
808
809         // multiplayer clients bail here if nodamage
810         // if(MULTIPLAYER_CLIENT && (Netgame.debug_flags & NETD_FLAG_CLIENT_NODAMAGE)){
811         if(MULTIPLAYER_CLIENT){
812                 return damage;
813         }
814
815         if ( (shield_quadrant < 0)  || (shield_quadrant > 3) ) return damage;   
816         
817         Assert(objp->type == OBJ_SHIP);
818         aip = &Ai_info[Ships[objp->instance].ai_index];
819         aip->last_hit_quadrant = shield_quadrant;
820
821         objp->shields[shield_quadrant] -= damage;
822
823         if (objp->shields[shield_quadrant] < 0.0f) {
824                 float   remaining_damage;
825
826                 remaining_damage = -objp->shields[shield_quadrant];
827                 objp->shields[shield_quadrant] = 0.0f;
828                 //nprintf(("AI", "Applied %7.3f damage to quadrant #%i, %7.3f passes through\n", damage - remaining_damage, quadrant_num, remaining_damage));
829                 return remaining_damage;
830         } else {
831                 //nprintf(("AI", "Applied %7.3f damage to quadrant #%i\n", damage, quadrant_num));
832                 return 0.0f;
833         }
834                 
835 }
836
837 //      At lower detail levels, shield hit effects are a single texture, applied to one enlarged triangle.
838 void create_shield_low_detail(int objnum, int model_num, matrix *orient, vector *centerp, vector *tcp, int tr0, shield_info *shieldp)
839 {
840         matrix  tom;
841         int             gi;
842         int             shnum;
843
844         shnum = get_global_shield_tri();
845         Shield_hits[shnum].type = SH_TYPE_1;
846
847         gi = get_free_global_shield_index();
848
849         Global_tris[gi].used = 1;
850         Global_tris[gi].trinum = -1;            //      This tells triangle renderer to not render in case detail_level was switched.
851         Global_tris[gi].creation_time = Missiontime;
852
853         Shield_hits[shnum].tri_list[0] = gi;
854         Shield_hits[shnum].num_tris = 1;
855         Shield_hits[shnum].start_time = Missiontime;
856         Shield_hits[shnum].objnum = objnum;
857
858         Shield_hits[shnum].rgb[0] = 255;
859         Shield_hits[shnum].rgb[1] = 255;
860         Shield_hits[shnum].rgb[2] = 255;
861         if((objnum >= 0) && (objnum < MAX_OBJECTS) && (Objects[objnum].type == OBJ_SHIP) && (Objects[objnum].instance >= 0) && (Objects[objnum].instance < MAX_SHIPS) && (Ships[Objects[objnum].instance].ship_info_index >= 0) && (Ships[Objects[objnum].instance].ship_info_index < Num_ship_types)){
862                 ship_info *sip = &Ship_info[Ships[Objects[objnum].instance].ship_info_index];
863                 
864                 Shield_hits[shnum].rgb[0] = sip->shield_color[0];
865                 Shield_hits[shnum].rgb[1] = sip->shield_color[1];
866                 Shield_hits[shnum].rgb[2] = sip->shield_color[2];
867         }
868
869         vm_vector_2_matrix(&tom, &shieldp->tris[tr0].norm, NULL, NULL);
870         //rs_compute_uvs( &shieldp->tris[tr0], shieldp->verts, tcp, Objects[objnum].radius, &tom.rvec, &tom.uvec);
871
872         create_low_detail_poly(gi, tcp, &tom.rvec, &tom.uvec);
873
874 }
875
876 // Algorithm for shrink-wrapping a texture across a triangular mesh.
877 // 
878 // - Given a point of intersection, tcp (local to objnum)
879 // - Vector to center of shield from tcp is v2c.
880 // - Using v2c, compute right and down vectors.  These are the vectors of
881 //   increasing u and v, respectively.
882 // - Triangle of intersection of tcp is tr0.
883 // - For 3 points in tr0, compute u,v coordinates using up and down vectors
884 //   from center point, tcp.  Need to know size of explosion texture.  N units
885 //   along right vector corresponds to O units in explosion texture space.
886 // - For each edge, if either endpoint was outside texture bounds, recursively
887 //   apply previous and current step.
888 // 
889 // Output of above is a list of triangles with u,v coordinates.  These u,v
890 // coordinates will have to be clipped against the explosion texture bounds.
891
892 void create_shield_explosion(int objnum, int model_num, matrix *orient, vector *centerp, vector *tcp, int tr0)
893 {
894 //      vector  v2c;            //      Vector to center from point tcp
895         matrix  tom;            //      Texture Orientation Matrix
896 //      float           radius; // Radius of shield, computed as distance from tcp to objp->pos.
897         shield_info     *shieldp;
898         polymodel       *pm;
899         int             i;
900
901         if (!New_shield_system)
902                 return;
903
904         if (Objects[objnum].flags & OF_NO_SHIELDS)
905                 return;
906
907         pm = model_get(model_num);
908         Num_tris = pm->shield.ntris;
909         //Assert(Num_tris < MAX_SHIELD_HITS);
910         shieldp = &pm->shield;
911
912         if (Num_tris == 0)
913                 return;
914
915         //nprintf(("AI", "Frame %i: Creating explosion on %i.\n", Framecount, objnum));
916
917         if (!D3D_enabled || (Detail.shield_effects == 1) || (Detail.shield_effects == 2)) {
918                 create_shield_low_detail(objnum, model_num, orient, centerp, tcp, tr0, shieldp);
919                 return;
920         }
921
922         for (i=0; i<Num_tris; i++)
923                 shieldp->tris[i].used = 0;
924
925         //      Compute orientation matrix from normal of surface hit.
926         //      Note, this will cause the shape of the bitmap to change abruptly
927         //      as the impact point moves to another triangle.  To prevent this,
928         //      you could average the normals at the vertices, then interpolate the
929         //      normals from the vertices to get a smoothly changing normal across the face.
930         //      I had tried using the vector from the impact point to the center, which
931         //      changes smoothly, but this looked surprisingly bad.
932         vm_vector_2_matrix(&tom, &shieldp->tris[tr0].norm, NULL, NULL);
933         //vm_vec_sub(&v2c, tcp, &Objects[objnum].pos);
934
935         //      Create the shield from the current triangle, as well as its neighbors.
936         create_shield_from_triangle(tr0, orient, shieldp, tcp, centerp, Objects[objnum].radius, &tom.rvec, &tom.uvec);
937         //nprintf(("AI", "\n"));
938         for (i=0; i<3; i++)
939                 create_shield_from_triangle(shieldp->tris[tr0].neighbors[i], orient, shieldp, tcp, centerp, Objects[objnum].radius, &tom.rvec, &tom.uvec);
940         
941         copy_shield_to_globals(objnum, shieldp);
942         // render_shield(orient, centerp);
943 }
944
945 MONITOR(NumShieldHits);
946
947 //      Add data for a shield hit.
948 void add_shield_point(int objnum, int tri_num, vector *hit_pos)
949 {
950         //Assert(Num_shield_points < MAX_SHIELD_POINTS);
951         if (Num_shield_points >= MAX_SHIELD_POINTS)
952                 return;
953
954         MONITOR_INC(NumShieldHits,1);
955
956         Shield_points[Num_shield_points].objnum = objnum;
957         Shield_points[Num_shield_points].shield_tri = tri_num;
958         Shield_points[Num_shield_points].hit_point = *hit_pos;
959
960         Num_shield_points++;
961
962         // in multiplayer -- send the shield hit data to the clients
963         // if ( MULTIPLAYER_MASTER && !(Netgame.debug_flags & NETD_FLAG_CLIENT_NODAMAGE)){
964                 // send_shield_explosion_packet( objnum, tri_num, *hit_pos );
965         // }
966
967         Ships[Objects[objnum].instance].shield_hits++;
968 }
969
970 // ugh!  I wrote a special routine to store shield points for clients in multiplayer
971 // games.  Problem is initilization and flow control of normal gameplay make this problem
972 // more than trivial to solve.  Turns out that I think I can just keep track of the
973 // shield_points for multiplayer in a separate count -- then assign the multi count to
974 // the normal count at the correct time.
975 void add_shield_point_multi(int objnum, int tri_num, vector *hit_pos)
976 {
977         //Assert(Num_multi_shield_points < MAX_SHIELD_POINTS);
978
979         if (Num_multi_shield_points >= MAX_SHIELD_POINTS)
980                 return;
981
982         Shield_points[Num_shield_points].objnum = objnum;
983         Shield_points[Num_shield_points].shield_tri = tri_num;
984         Shield_points[Num_shield_points].hit_point = *hit_pos;
985
986         Num_multi_shield_points++;
987 }
988
989 // sets up the shield point hit information for multiplayer clients
990 void shield_point_multi_setup()
991 {
992         int i;
993
994         Assert( MULTIPLAYER_CLIENT );
995
996         if ( Num_multi_shield_points == 0 )
997                 return;
998
999         Num_shield_points = Num_multi_shield_points;
1000         for (i = 0; i < Num_shield_points; i++ ){
1001                 Ships[Objects[Shield_points[i].objnum].instance].shield_hits++;
1002         }
1003
1004         Num_multi_shield_points = 0;
1005 }
1006
1007
1008 //      Create all the shield explosions that occurred on object *objp this frame.
1009 void create_shield_explosion_all(object *objp)
1010 {
1011         int     i;
1012         int     num;
1013         int     count;
1014         int     objnum;
1015         ship    *shipp;
1016
1017         if (Detail.shield_effects == 0){
1018                 return; 
1019         }
1020
1021         num = objp->instance;
1022         shipp = &Ships[num];
1023
1024         count = shipp->shield_hits;
1025         objnum = objp-Objects;
1026
1027         for (i=0; i<Num_shield_points; i++) {
1028                 if (Shield_points[i].objnum == objnum) {
1029                         create_shield_explosion(objnum, shipp->modelnum, &objp->orient, &objp->pos, &Shield_points[i].hit_point, Shield_points[i].shield_tri);
1030                         count--;
1031                         if (count <= 0){
1032                                 break;
1033                         }
1034                 }
1035         }
1036
1037         //mprintf(("Creating %i explosions took %7.3f seconds\n", shipp->shield_hits, (float) (timer_get_milliseconds() - start_time)/1000.0f));
1038
1039         // some some reason, clients seem to have a bogus count valud on occation.  I"ll chalk it up
1040         // to missed packets :-)  MWA 2/6/98
1041         if ( !MULTIPLAYER_CLIENT ){
1042                 Assert(count == 0);     //      Couldn't find all the alleged shield hits.  Bogus!
1043         }
1044 }
1045
1046 int     Break_value = -1;
1047
1048 //      This is a debug function.
1049 //      Draw the whole shield as a wireframe mesh, not looking at the current
1050 //      integrity.
1051 #ifndef NDEBUG
1052 void ship_draw_shield( object *objp)
1053 {
1054         int             model_num;
1055         matrix  m;
1056         int             i;
1057         vector  pnt;
1058         polymodel * pm; 
1059
1060         if (!New_shield_system)
1061                 return;
1062
1063         if (objp->flags & OF_NO_SHIELDS)
1064                 return;
1065
1066         Assert(objp->instance >= 0);
1067
1068         model_num = Ships[objp->instance].modelnum;
1069
1070         if ( Fred_running ) return;
1071
1072         pm = model_get(model_num);
1073
1074         if (pm->shield.ntris<1) return;
1075
1076         vm_copy_transpose_matrix(&m, &objp->orient);
1077
1078         //      Scan all the triangles in the mesh.
1079         for (i=0; i<pm->shield.ntris; i++ )     {
1080                 int             j;
1081                 vector  gnorm, v2f, tri_point;
1082                 vertex prev_pnt, pnt0;
1083                 shield_tri *tri;
1084
1085                 tri = &pm->shield.tris[i];
1086
1087                 if (i == Break_value)
1088                         Int3();
1089
1090                 //      Hack! Only works for object in identity orientation.
1091                 //      Need to rotate eye position into object's reference frame.
1092                 //      Only draw facing triangles.
1093                 vm_vec_rotate(&tri_point, &pm->shield.verts[tri->verts[0]].pos, &Eye_matrix);
1094                 vm_vec_add2(&tri_point, &objp->pos);
1095
1096                 vm_vec_sub(&v2f, &tri_point, &Eye_position);
1097                 vm_vec_rotate(&gnorm, &tri->norm, &m);
1098
1099                 if (vm_vec_dot(&gnorm, &v2f) < 0.0f) {
1100                         int     intensity;
1101
1102                         intensity = (int) (Ships[objp->instance].shield_integrity[i] * 255);
1103
1104                         if (intensity < 0)
1105                                 intensity = 0;
1106                         else if (intensity > 255)
1107                                 intensity = 255;
1108                         
1109                         gr_set_color(0, 0, intensity);
1110
1111                         //      Process the vertices.
1112                         //      Note this rotates each vertex each time it's needed, very dumb.
1113                         for (j=0; j<3; j++ )    {
1114                                 vertex tmp;
1115
1116                                 // Rotate point into world coordinates
1117                                 vm_vec_rotate(&pnt, &pm->shield.verts[tri->verts[j]].pos, &m);
1118                                 //vm_vec_rotate(&pnt,&pm->shield[i].pnt[j],&m);
1119                                 vm_vec_add2(&pnt, &objp->pos);
1120
1121                                 // Pnt is now the x,y,z world coordinates of this vert.
1122                                 // For this example, I am just drawing a sphere at that
1123                                 // point.
1124                                 g3_rotate_vertex(&tmp, &pnt);
1125
1126                                 if (j)
1127                                         g3_draw_line(&prev_pnt, &tmp);
1128                                 else
1129                                         pnt0 = tmp;
1130                                 prev_pnt = tmp;
1131                         }
1132
1133                         g3_draw_line(&pnt0, &prev_pnt);
1134                 }
1135         }
1136 }
1137 #endif
1138
1139 // Returns true if the shield presents any opposition to something 
1140 // trying to force through it.
1141 // If quadrant is -1, looks at entire shield, otherwise
1142 // just one quadrant
1143 int ship_is_shield_up( object *obj, int quadrant )
1144 {
1145         if ( (quadrant>=0) && (quadrant<=3))    {
1146                 // Just check one quadrant
1147                 if (obj->shields[quadrant] > max(2.0f, 0.1f * Ship_info[Ships[obj->instance].ship_info_index].shields/4.0f))    {
1148                         return 1;
1149                 }
1150         } else {
1151                 // Check all quadrants
1152                 float strength = get_shield_strength(obj);
1153
1154                 if ( strength > max(2.0f*4.0f, 0.1f * Ship_info[Ships[obj->instance].ship_info_index].shields ))        {
1155                         return 1;
1156                 }
1157         }
1158         return 0;       // no shield strength
1159 }
1160
1161
1162 /*
1163 //-- CODE TO "BOUNCE" AN ARRAY FROM A GIVEN POINT.
1164 //-- LIKE A MATTRESS.
1165 #define BOUNCE_SIZE ???
1166
1167 byte Bouncer1[BOUNCE_SIZE];
1168 byte Bouncer2[BOUNCE_SIZE];
1169
1170 byte * Bouncer = Bouncer1;
1171 byte * OldBouncer = Bouncer2;
1172
1173 // To wiggle, add value to Bouncer[] 
1174
1175 void bounce_it()
1176 {
1177         int i, tmp;
1178
1179
1180         for (i=0; i<BOUNCE_SIZE; i++ )  {
1181                 int t = 0;
1182
1183                 t += OldBouncer[ LEFT ];
1184                 t += OldBouncer[ RIGHT ];
1185                 t += OldBouncer[ UP ];
1186                 t += OldBouncer[ DOWN ];
1187
1188                 t = (t/2) - Bouncer[i];
1189                 tmp = t - t/16;         // 8
1190                 
1191                 if ( tmp < -127 ) tmp = -127;
1192                 if ( tmp > 127 ) tmp = 127;
1193                 Bouncer[i] = tmp;
1194         }
1195
1196         if ( Bouncer == Bouncer1 )      {
1197                 OldBouncer = Bouncer1;
1198                 Bouncer = Bouncer2;
1199         } else {
1200                 OldBouncer = Bouncer2;
1201                 Bouncer = Bouncer1;
1202         }
1203 }
1204 */
1205
1206 #else 
1207
1208 // stub out shield functions for the demo
1209 void shield_hit_init() {}
1210 void create_shield_explosion_all(object *objp) {}
1211 void shield_frame_init() {}
1212 void add_shield_point(int objnum, int tri_num, vector *hit_pos) {}
1213 void add_shield_point_multi(int objnum, int tri_num, vector *hit_pos) {}
1214 void shield_point_multi_setup() {}
1215 void shield_hit_close() {}
1216 void ship_draw_shield( object *objp) {}
1217 void shield_hit_page_in() {}
1218 void render_shields() {}
1219 float apply_damage_to_shield(object *objp, int shield_quadrant, float damage) {return damage;} 
1220 int ship_is_shield_up( object *obj, int quadrant ) {return 0;}
1221
1222 #endif // DEMO
1223
1224
1225 //      return quadrant containing hit_pnt.
1226 //      \  1  /.
1227 //      3 \ / 0
1228 //        / \.
1229 //      /  2  \.
1230 //      Note: This is in the object's local reference frame.  Do _not_ pass a vector in the world frame.
1231 int get_quadrant(vector *hit_pnt)
1232 {
1233         int     result = 0;
1234
1235         if (hit_pnt->x < hit_pnt->z)
1236                 result |= 1;
1237
1238         if (hit_pnt->x < -hit_pnt->z)
1239                 result |= 2;
1240
1241         return result;
1242 }