]> icculus.org git repositories - btb/d2x.git/blob - main/collide.c
more header cleanup
[btb/d2x.git] / main / collide.c
1 /*
2 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
4 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
10 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
11 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
12 */
13
14 /*
15  *
16  * Routines to handle collisions
17  *
18  */
19
20 #ifdef HAVE_CONFIG_H
21 #include <conf.h>
22 #endif
23
24 #include <stdlib.h>
25 #include <stdio.h>
26
27 #include "inferno.h"
28 #include "gr.h"
29 #include "stdlib.h"
30 #include "mono.h"
31 #include "3d.h"
32 #include "key.h"
33 #include "error.h"
34 #ifdef TACTILE
35 #include "tactile.h"
36 #endif 
37 #ifdef EDITOR
38 #include "editor/editor.h"
39 #endif
40
41
42 #define STANDARD_EXPL_DELAY (f1_0/4)
43
44 //##void collide_fireball_and_wall(object *fireball,fix hitspeed, short hitseg, short hitwall, vms_vector * hitpt)      {
45 //##    return; 
46 //##}
47
48 //      -------------------------------------------------------------------------------------------------------------
49 //      The only reason this routine is called (as of 10/12/94) is so Brain guys can open doors.
50 void collide_robot_and_wall( object * robot, fix hitspeed, short hitseg, short hitwall, vms_vector * hitpt)
51 {
52         ai_local *ailp = &Ai_local_info[OBJECT_NUMBER(robot)];
53
54         if ((robot->id == ROBOT_BRAIN) || (robot->ctype.ai_info.behavior == AIB_RUN_FROM) || (Robot_info[robot->id].companion == 1) || (robot->ctype.ai_info.behavior == AIB_SNIPE)) {
55                 int     wall_num = Segments[hitseg].sides[hitwall].wall_num;
56                 if (wall_num != -1) {
57                         if ((Walls[wall_num].type == WALL_DOOR) && (Walls[wall_num].keys == KEY_NONE) && (Walls[wall_num].state == WALL_DOOR_CLOSED) && !(Walls[wall_num].flags & WALL_DOOR_LOCKED)) {
58                                 // -- mprintf((0, "Trying to open door at segment %i, side %i\n", hitseg, hitwall));
59                                 wall_open_door(&Segments[hitseg], hitwall);
60                         // -- Changed from this, 10/19/95, MK: Don't want buddy getting stranded from player
61                         //-- } else if ((Robot_info[robot->id].companion == 1) && (Walls[wall_num].type == WALL_DOOR) && (Walls[wall_num].keys != KEY_NONE) && (Walls[wall_num].state == WALL_DOOR_CLOSED) && !(Walls[wall_num].flags & WALL_DOOR_LOCKED)) {
62                         } else if ((Robot_info[robot->id].companion == 1) && (Walls[wall_num].type == WALL_DOOR)) {
63                                 if ((ailp->mode == AIM_GOTO_PLAYER) || (Escort_special_goal == ESCORT_GOAL_SCRAM)) {
64                                         if (Walls[wall_num].keys != KEY_NONE) {
65                                                 if (Walls[wall_num].keys & Players[Player_num].flags)
66                                                         wall_open_door(&Segments[hitseg], hitwall);
67                                         } else if (!(Walls[wall_num].flags & WALL_DOOR_LOCKED))
68                                                 wall_open_door(&Segments[hitseg], hitwall);
69                                 }
70                         } else if (Robot_info[robot->id].thief) {               //      Thief allowed to go through doors to which player has key.
71                                 if (Walls[wall_num].keys != KEY_NONE)
72                                         if (Walls[wall_num].keys & Players[Player_num].flags)
73                                                 wall_open_door(&Segments[hitseg], hitwall);
74                         }
75                 }
76         }
77
78         return;
79 }
80
81 //##void collide_hostage_and_wall( object * hostage, fix hitspeed, short hitseg, short hitwall, vms_vector * hitpt)     {
82 //##    return;
83 //##}
84
85 //      -------------------------------------------------------------------------------------------------------------
86
87 int apply_damage_to_clutter(object *clutter, fix damage)
88 {
89         if ( clutter->flags&OF_EXPLODING) return 0;
90
91         if (clutter->shields < 0 ) return 0;    //clutter already dead...
92
93         clutter->shields -= damage;
94
95         if (clutter->shields < 0) {
96                 explode_object(clutter,0);
97                 return 1;
98         } else
99                 return 0;
100 }
101
102 char    Monster_mode = 0;               //      A cheat.  Do massive damage when collide.
103
104 //given the specified force, apply damage from that force to an object
105 void apply_force_damage(object *obj,fix force,object *other_obj)
106 {
107         int     result;
108         fix damage;
109
110         if (obj->flags & (OF_EXPLODING|OF_SHOULD_BE_DEAD))
111                 return;         //already exploding or dead
112
113         damage = fixdiv(force,obj->mtype.phys_info.mass) / 8;
114
115         if ((other_obj->type == OBJ_PLAYER) && Monster_mode)
116                 damage = 0x7fffffff;
117
118 //mprintf((0,"obj %d, damage=%x\n",OBJECT_NUMBER(obj),damage));
119
120         switch (obj->type) {
121
122                 case OBJ_ROBOT:
123
124                         if (Robot_info[obj->id].attack_type == 1) {
125                                 if (other_obj->type == OBJ_WEAPON)
126                                         result = apply_damage_to_robot(obj,damage/4, other_obj->ctype.laser_info.parent_num);
127                                 else
128                                         result = apply_damage_to_robot(obj,damage/4, OBJECT_NUMBER(other_obj));
129                         }
130                         else {
131                                 if (other_obj->type == OBJ_WEAPON)
132                                         result = apply_damage_to_robot(obj,damage/2, other_obj->ctype.laser_info.parent_num);
133                                 else
134                                         result = apply_damage_to_robot(obj,damage/2, OBJECT_NUMBER(other_obj));
135                         }               
136
137                         if (result && (other_obj->ctype.laser_info.parent_signature == ConsoleObject->signature))
138                                 add_points_to_score(Robot_info[obj->id].score_value);
139                         break;
140
141                 case OBJ_PLAYER:
142
143                         //      If colliding with a claw type robot, do damage proportional to FrameTime because you can collide with those
144                         //      bots every frame since they don't move.
145                         if ( (other_obj->type == OBJ_ROBOT) && (Robot_info[other_obj->id].attack_type) )
146                                 damage = fixmul(damage, FrameTime*2);
147
148                         //      Make trainee easier.
149                         if (Difficulty_level == 0)
150                                 damage /= 2;
151
152                         apply_damage_to_player(obj,other_obj,damage);
153                         break;
154
155                 case OBJ_CLUTTER:
156
157                         apply_damage_to_clutter(obj,damage);
158                         break;
159
160                 case OBJ_CNTRLCEN:
161
162                         apply_damage_to_controlcen(obj, damage, OBJECT_NUMBER(other_obj));
163                         break;
164
165                 case OBJ_WEAPON:
166
167                         break;          //weapons don't take damage
168
169                 default:
170
171                         Int3();
172
173         }
174 }
175
176 //      -----------------------------------------------------------------------------
177 void bump_this_object(object *objp, object *other_objp, vms_vector *force, int damage_flag)
178 {
179         fix force_mag;
180
181         if (! (objp->mtype.phys_info.flags & PF_PERSISTENT))
182         {
183                 if (objp->type == OBJ_PLAYER) {
184                         vms_vector force2;
185                         force2.x = force->x/4;
186                         force2.y = force->y/4;
187                         force2.z = force->z/4;
188                         phys_apply_force(objp,&force2);
189                         if (damage_flag && ((other_objp->type != OBJ_ROBOT) || !Robot_info[other_objp->id].companion)) {
190                                 force_mag = vm_vec_mag_quick(&force2);
191                                 apply_force_damage(objp, force_mag, other_objp);
192                         }
193                 } else if ((objp->type == OBJ_ROBOT) || (objp->type == OBJ_CLUTTER) || (objp->type == OBJ_CNTRLCEN)) {
194                         if (!Robot_info[objp->id].boss_flag) {
195                                 vms_vector force2;
196                                 force2.x = force->x/(4 + Difficulty_level);
197                                 force2.y = force->y/(4 + Difficulty_level);
198                                 force2.z = force->z/(4 + Difficulty_level);
199
200                                 phys_apply_force(objp, force);
201                                 phys_apply_rot(objp, &force2);
202                                 if (damage_flag) {
203                                         force_mag = vm_vec_mag_quick(force);
204                                         apply_force_damage(objp, force_mag, other_objp);
205                                 }
206                         }
207                 }
208         }
209 }
210
211 //      -----------------------------------------------------------------------------
212 //deal with two objects bumping into each other.  Apply force from collision
213 //to each robot.  The flags tells whether the objects should take damage from
214 //the collision.
215 void bump_two_objects(object *obj0,object *obj1,int damage_flag)
216 {
217         vms_vector      force;
218         object          *t=NULL;
219
220         if (obj0->movement_type != MT_PHYSICS)
221                 t=obj1;
222         else if (obj1->movement_type != MT_PHYSICS)
223                 t=obj0;
224
225         if (t) {
226                 Assert(t->movement_type == MT_PHYSICS);
227                 vm_vec_copy_scale(&force,&t->mtype.phys_info.velocity,-t->mtype.phys_info.mass);
228                 phys_apply_force(t,&force);
229                 return;
230         }
231
232         vm_vec_sub(&force,&obj0->mtype.phys_info.velocity,&obj1->mtype.phys_info.velocity);
233         vm_vec_scale2(&force,2*fixmul(obj0->mtype.phys_info.mass,obj1->mtype.phys_info.mass),(obj0->mtype.phys_info.mass+obj1->mtype.phys_info.mass));
234
235         bump_this_object(obj1, obj0, &force, damage_flag);
236         vm_vec_negate(&force);
237         bump_this_object(obj0, obj1, &force, damage_flag);
238
239 }
240
241 void bump_one_object(object *obj0, vms_vector *hit_dir, fix damage)
242 {
243         vms_vector      hit_vec;
244
245         hit_vec = *hit_dir;
246         vm_vec_scale(&hit_vec, damage);
247
248         phys_apply_force(obj0,&hit_vec);
249
250 }
251
252 #define DAMAGE_SCALE            128     //      Was 32 before 8:55 am on Thursday, September 15, changed by MK, walls were hurting me more than robots!
253 #define DAMAGE_THRESHOLD        (F1_0/3)
254 #define WALL_LOUDNESS_SCALE (20)
255
256 fix force_force = i2f(50);
257
258 void collide_player_and_wall( object * playerobj, fix hitspeed, short hitseg, short hitwall, vms_vector * hitpt)
259 {
260         fix damage;
261         char ForceFieldHit=0;
262         int tmap_num,tmap_num2;
263
264         if (playerobj->id != Player_num) // Execute only for local player
265                 return;
266
267         tmap_num = Segments[hitseg].sides[hitwall].tmap_num;
268
269         //      If this wall does damage, don't make *BONK* sound, we'll be making another sound.
270         if (TmapInfo[tmap_num].damage > 0)
271                 return;
272
273         if (TmapInfo[tmap_num].flags & TMI_FORCE_FIELD) {
274                 vms_vector force;
275
276                 PALETTE_FLASH_ADD(0, 0, 60);    //flash blue
277
278                 //knock player around
279                 force.x = 40*(d_rand() - 16384);
280                 force.y = 40*(d_rand() - 16384);
281                 force.z = 40*(d_rand() - 16384);
282                 phys_apply_rot(playerobj, &force);
283
284 #ifdef TACTILE
285                 if (TactileStick)
286                  Tactile_apply_force (&force,&playerobj->orient);
287 #endif
288
289                 //make sound
290                 digi_link_sound_to_pos( SOUND_FORCEFIELD_BOUNCE_PLAYER, hitseg, 0, hitpt, 0, f1_0 );
291 #ifdef NETWORK
292                 if (Game_mode & GM_MULTI)
293                         multi_send_play_sound(SOUND_FORCEFIELD_BOUNCE_PLAYER, f1_0);
294 #endif
295                 ForceFieldHit=1;
296         } 
297         else {
298
299         #ifdef TACTILE
300                 vms_vector force;
301                 if (TactileStick) {
302                         force.x = -playerobj->mtype.phys_info.velocity.x;
303                         force.y = -playerobj->mtype.phys_info.velocity.y;
304                         force.z = -playerobj->mtype.phys_info.velocity.z;
305                         Tactile_do_collide(&force, &playerobj->orient);
306                 }
307         #endif
308
309         wall_hit_process( &Segments[hitseg], hitwall, 20, playerobj->id, playerobj );
310         }
311
312         //      ** Damage from hitting wall **
313         //      If the player has less than 10% shields, don't take damage from bump
314         // Note: Does quad damage if hit a force field - JL
315         damage = (hitspeed / DAMAGE_SCALE) * (ForceFieldHit*8 + 1);
316
317         tmap_num2 = Segments[hitseg].sides[hitwall].tmap_num2;
318
319         //don't do wall damage and sound if hit lava or water
320         if ((TmapInfo[tmap_num].flags & (TMI_WATER|TMI_VOLATILE)) || (tmap_num2 && (TmapInfo[tmap_num2&0x3fff].flags & (TMI_WATER|TMI_VOLATILE))))
321                 damage = 0;
322
323         if (damage >= DAMAGE_THRESHOLD) {
324                 int     volume;
325                 volume = (hitspeed-(DAMAGE_SCALE*DAMAGE_THRESHOLD)) / WALL_LOUDNESS_SCALE ;
326
327                 create_awareness_event(playerobj, PA_WEAPON_WALL_COLLISION);
328
329                 if ( volume > F1_0 )
330                         volume = F1_0;
331                 if (volume > 0 && !ForceFieldHit) {  // uhhhgly hack
332                         digi_link_sound_to_pos( SOUND_PLAYER_HIT_WALL, hitseg, 0, hitpt, 0, volume );
333                         #ifdef NETWORK
334                         if (Game_mode & GM_MULTI)
335                                 multi_send_play_sound(SOUND_PLAYER_HIT_WALL, volume);   
336                         #endif
337                 }
338
339                 if (!(Players[Player_num].flags & PLAYER_FLAGS_INVULNERABLE))
340                         if ( Players[Player_num].shields > f1_0*10 || ForceFieldHit)
341                                 apply_damage_to_player( playerobj, playerobj, damage );
342
343                 // -- No point in doing this unless we compute a reasonable hitpt.  Currently it is just the player's position. --MK, 01/18/96
344                 // -- if (!(TmapInfo[Segments[hitseg].sides[hitwall].tmap_num].flags & TMI_FORCE_FIELD)) {
345                 // --   vms_vector      hitpt1;
346                 // --   int                     hitseg1;
347                 // --
348                 // --           vm_vec_avg(&hitpt1, hitpt, &Objects[Players[Player_num].objnum].pos);
349                 // --   hitseg1 = find_point_seg(&hitpt1, Objects[Players[Player_num].objnum].segnum);
350                 // --   if (hitseg1 != -1)
351                 // --           object_create_explosion( hitseg, hitpt, Weapon_info[0].impact_size, Weapon_info[0].wall_hit_vclip );
352                 // -- }
353
354         }
355
356         return;
357 }
358
359 fix     Last_volatile_scrape_sound_time = 0;
360
361 void collide_weapon_and_wall( object * weapon, fix hitspeed, short hitseg, short hitwall, vms_vector * hitpt);
362 void collide_debris_and_wall( object * debris, fix hitspeed, short hitseg, short hitwall, vms_vector * hitpt);
363
364 //see if wall is volatile or water
365 //if volatile, cause damage to player  
366 //returns 1=lava, 2=water
367 int check_volatile_wall(object *obj,int segnum,int sidenum,vms_vector *hitpt)
368 {
369         fix tmap_num,d,water;
370
371         Assert(obj->type==OBJ_PLAYER);
372
373         tmap_num = Segments[segnum].sides[sidenum].tmap_num;
374
375         d = TmapInfo[tmap_num].damage;
376         water = (TmapInfo[tmap_num].flags & TMI_WATER);
377
378         if (d > 0 || water) {
379
380                 if (obj->id == Player_num) {
381
382                         if (d > 0) {
383                                 fix damage = fixmul(d,FrameTime);
384
385                                 if (Difficulty_level == 0)
386                                         damage /= 2;
387
388                                 if (!(Players[Player_num].flags & PLAYER_FLAGS_INVULNERABLE))
389                                         apply_damage_to_player( obj, obj, damage );
390
391 #ifdef TACTILE
392                                 if (TactileStick)
393                                  Tactile_Xvibrate (50,25);
394 #endif
395
396                                 PALETTE_FLASH_ADD(f2i(damage*4), 0, 0); //flash red
397                         }
398
399                         obj->mtype.phys_info.rotvel.x = (d_rand() - 16384)/2;
400                         obj->mtype.phys_info.rotvel.z = (d_rand() - 16384)/2;
401                 }
402
403                 return (d>0)?1:2;
404         }
405         else
406          {
407 #ifdef TACTILE
408                 if (TactileStick && !(FrameCount & 15))
409                  Tactile_Xvibrate_clear ();
410 #endif
411
412                 return 0;
413          }
414 }
415
416 //this gets called when an object is scraping along the wall
417 void scrape_object_on_wall(object *obj, short hitseg, short hitside, vms_vector * hitpt )
418 {
419         switch (obj->type) {
420
421                 case OBJ_PLAYER:
422
423                         if (obj->id==Player_num) {
424                                 int type;
425
426                                 //mprintf((0, "Scraped segment #%3i, side #%i\n", hitseg, hitside));
427
428                                 if ((type=check_volatile_wall(obj,hitseg,hitside,hitpt))!=0) {
429                                         vms_vector      hit_dir, rand_vec;
430
431                                         if ((GameTime > Last_volatile_scrape_sound_time + F1_0/4) || (GameTime < Last_volatile_scrape_sound_time)) {
432                                                 int sound = (type==1)?SOUND_VOLATILE_WALL_HISS:SOUND_SHIP_IN_WATER;
433
434                                                 Last_volatile_scrape_sound_time = GameTime;
435
436                                                 digi_link_sound_to_pos( sound, hitseg, 0, hitpt, 0, F1_0 );
437 #ifdef NETWORK
438                                                 if (Game_mode & GM_MULTI)
439                                                         multi_send_play_sound(sound, F1_0);
440 #endif
441                                         }
442
443                                         #ifdef COMPACT_SEGS
444                                                 get_side_normal(&Segments[hitseg], higside, 0, &hit_dir );      
445                                         #else
446                                                 hit_dir = Segments[hitseg].sides[hitside].normals[0];
447                                         #endif
448                         
449                                         make_random_vector(&rand_vec);
450                                         vm_vec_scale_add2(&hit_dir, &rand_vec, F1_0/8);
451                                         vm_vec_normalize_quick(&hit_dir);
452                                         bump_one_object(obj, &hit_dir, F1_0*8);
453                                 }
454
455                                 //@@} else {
456                                 //@@    //what scrape sound
457                                 //@@    //PLAY_SOUND( SOUND_PLAYER_SCRAPE_WALL );
458                                 //@@}
459                 
460                         }
461
462                         break;
463
464                 //these two kinds of objects below shouldn't really slide, so
465                 //if this scrape routine gets called (which it might if the
466                 //object (such as a fusion blob) was created already poking
467                 //through the wall) call the collide routine.
468
469                 case OBJ_WEAPON:
470                         collide_weapon_and_wall(obj,0,hitseg,hitside,hitpt); 
471                         break;
472
473                 case OBJ_DEBRIS:                
474                         collide_debris_and_wall(obj,0,hitseg,hitside,hitpt); 
475                         break;
476         }
477
478 }
479
480 //if an effect is hit, and it can blow up, then blow it up
481 //returns true if it blew up
482 int check_effect_blowup(segment *seg,int side,vms_vector *pnt, object *blower, int force_blowup_flag)
483 {
484         int tm,tmf,ec,db;
485
486         db=0;
487
488         //      If this wall has a trigger and the blower-upper is not the player or the buddy, abort!
489         {
490                 int     ok_to_blow = 0;
491
492                 if (blower->ctype.laser_info.parent_type == OBJ_ROBOT)
493                         if (Robot_info[Objects[blower->ctype.laser_info.parent_num].id].companion)
494                                 ok_to_blow = 1;
495
496                 if (!(ok_to_blow || (blower->ctype.laser_info.parent_type == OBJ_PLAYER))) {
497                         int     trigger_num, wall_num;
498
499                         wall_num = seg->sides[side].wall_num;
500                         if ( wall_num != -1 ) {
501                                 trigger_num = Walls[wall_num].trigger;
502
503                                 if (trigger_num != -1)
504                                         return 0;
505                         }
506                 }
507         }
508
509
510         if ((tm=seg->sides[side].tmap_num2) != 0) {
511
512                 tmf = tm&0xc000;                //tm flags
513                 tm &= 0x3fff;                   //tm without flags
514
515                 //check if it's an animation (monitor) or casts light
516                 if ((((ec=TmapInfo[tm].eclip_num)!=-1) && ((db=Effects[ec].dest_bm_num)!=-1 && !(Effects[ec].flags&EF_ONE_SHOT))) ||    (ec==-1 && (TmapInfo[tm].destroyed!=-1))) {
517                         fix u,v;
518                         grs_bitmap *bm = &GameBitmaps[Textures[tm].index];
519                         int x=0,y=0,t;
520
521                         PIGGY_PAGE_IN(Textures[tm]);
522
523                         //this can be blown up...did we hit it?
524
525                         if (!force_blowup_flag) {
526                                 find_hitpoint_uv(&u,&v,NULL,pnt,seg,side,0);    //evil: always say face zero
527
528                                 x = ((unsigned) f2i(u*bm->bm_w)) % bm->bm_w;
529                                 y = ((unsigned) f2i(v*bm->bm_h)) % bm->bm_h;
530
531                                 switch (tmf) {          //adjust for orientation of paste-on
532                                         case 0x0000:    break;
533                                         case 0x4000:    t=y; y=x; x=bm->bm_w-t-1; break;
534                                         case 0x8000:    y=bm->bm_h-y-1; x=bm->bm_w-x-1; break;
535                                         case 0xc000:    t=x; x=y; y=bm->bm_h-t-1; break;
536                                 }
537
538                                 //mprintf((0,"u,v = %x,%x   x,y=%x,%x",u,v,x,y));
539                         
540                                 if (bm->bm_flags & BM_FLAG_RLE)
541                                         bm = rle_expand_texture(bm);
542                         }
543
544                         if (force_blowup_flag || (bm->bm_data[y*bm->bm_w+x] != TRANSPARENCY_COLOR)) {           //not trans, thus on effect
545                                 int vc,sound_num;
546                                 fix dest_size;
547
548
549 #ifdef NETWORK
550                                 if ((Game_mode & GM_MULTI) && Netgame.AlwaysLighting)
551                                 if (!(ec!=-1 && db!=-1 && !(Effects[ec].flags&EF_ONE_SHOT)))
552                                         return(0);
553 #endif
554
555                                 //mprintf((0,"  HIT!\n"));
556
557                                 //note: this must get called before the texture changes, 
558                                 //because we use the light value of the texture to change
559                                 //the static light in the segment
560                                 subtract_light(SEGMENT_NUMBER(seg), side);
561
562                                 if (Newdemo_state == ND_STATE_RECORDING)
563                                         newdemo_record_effect_blowup( SEGMENT_NUMBER(seg), side, pnt );
564
565                                 if (ec!=-1) {
566                                         dest_size = Effects[ec].dest_size;
567                                         vc = Effects[ec].dest_vclip;
568                                 } else {
569                                         dest_size = i2f(20);
570                                         vc = 3;
571                                 }
572
573                                 object_create_explosion( SEGMENT_NUMBER(seg), pnt, dest_size, vc );
574
575                                 if (ec!=-1 && db!=-1 && !(Effects[ec].flags&EF_ONE_SHOT)) {
576
577                                         if ((sound_num = Vclip[vc].sound_num) != -1)
578                                                 digi_link_sound_to_pos( sound_num, SEGMENT_NUMBER(seg), 0, pnt, 0, F1_0 );
579
580                                         if ((sound_num=Effects[ec].sound_num)!=-1)              //kill sound
581                                                 digi_kill_sound_linked_to_segment(SEGMENT_NUMBER(seg), side, sound_num);
582
583                                         if (Effects[ec].dest_eclip!=-1 && Effects[Effects[ec].dest_eclip].segnum==-1) {
584                                                 int bm_num;
585                                                 eclip *new_ec;
586                                         
587                                                 new_ec = &Effects[Effects[ec].dest_eclip];
588                                                 bm_num = new_ec->changing_wall_texture;
589
590                                                 mprintf((0,"bm_num = %d\n",bm_num));
591
592                                                 new_ec->time_left = new_ec->vc.frame_time;
593                                                 new_ec->frame_count = 0;
594                                                 new_ec->segnum = SEGMENT_NUMBER(seg);
595                                                 new_ec->sidenum = side;
596                                                 new_ec->flags |= EF_ONE_SHOT;
597                                                 new_ec->dest_bm_num = Effects[ec].dest_bm_num;
598
599                                                 Assert(bm_num!=0 && seg->sides[side].tmap_num2!=0);
600                                                 seg->sides[side].tmap_num2 = bm_num | tmf;              //replace with destoyed
601
602                                         }
603                                         else {
604                                                 Assert(db!=0 && seg->sides[side].tmap_num2!=0);
605                                                 seg->sides[side].tmap_num2 = db | tmf;          //replace with destoyed
606                                         }
607                                 }
608                                 else {
609                                         seg->sides[side].tmap_num2 = TmapInfo[tm].destroyed | tmf;
610
611                                         //assume this is a light, and play light sound
612                                         digi_link_sound_to_pos( SOUND_LIGHT_BLOWNUP, SEGMENT_NUMBER(seg), 0, pnt, 0, F1_0 );
613                                 }
614
615
616                                 return 1;               //blew up!
617                         }
618                 }
619         }
620
621         return 0;               //didn't blow up
622 }
623
624 //      Copied from laser.c!
625 #define MIN_OMEGA_BLOBS         3                               //      No matter how close the obstruction, at this many blobs created.
626 #define MIN_OMEGA_DIST                  (F1_0*3)                //      At least this distance between blobs, unless doing so would violate MIN_OMEGA_BLOBS
627 #define DESIRED_OMEGA_DIST      (F1_0*5)                //      This is the desired distance between blobs.  For distances > MIN_OMEGA_BLOBS*DESIRED_OMEGA_DIST, but not very large, this will apply.
628 #define MAX_OMEGA_BLOBS         16                              //      No matter how far away the obstruction, this is the maximum number of blobs.
629 #define MAX_OMEGA_DIST                  (MAX_OMEGA_BLOBS * DESIRED_OMEGA_DIST)          //      Maximum extent of lightning blobs.
630
631 //      -------------------------------------------------
632 //      Return true if ok to do Omega damage.
633 int ok_to_do_omega_damage(object *weapon)
634 {
635         int     parent_sig = weapon->ctype.laser_info.parent_signature;
636         int     parent_num = weapon->ctype.laser_info.parent_num;
637
638         if (!(Game_mode & GM_MULTI))
639                 return 1;
640
641         if (Objects[parent_num].signature != parent_sig)
642                 mprintf((0, "Parent of omega blob not consistent with object information.\n"));
643         else {
644                 fix     dist = vm_vec_dist_quick(&Objects[parent_num].pos, &weapon->pos);
645
646                 if (dist > MAX_OMEGA_DIST) {
647                         // -- mprintf((0, "Not doing damage in frame %i, too far away.\n", FrameCount));
648                         return 0;
649                 } else
650                         ; // -- mprintf((0, "*** Doing damage in frame %i ***\n", FrameCount));
651         }
652
653         return 1;
654 }
655
656 //these gets added to the weapon's values when the weapon hits a volitle wall
657 #define VOLATILE_WALL_EXPL_STRENGTH i2f(10)
658 #define VOLATILE_WALL_IMPACT_SIZE       i2f(3)
659 #define VOLATILE_WALL_DAMAGE_FORCE      i2f(5)
660 #define VOLATILE_WALL_DAMAGE_RADIUS     i2f(30)
661
662 // int Show_seg_and_side = 0;
663
664 void collide_weapon_and_wall( object * weapon, fix hitspeed, short hitseg, short hitwall, vms_vector * hitpt)
665 {
666         segment *seg = &Segments[hitseg];
667         int blew_up;
668         int wall_type;
669         int playernum;
670         int     robot_escort;
671
672         if (weapon->id == OMEGA_ID)
673                 if (!ok_to_do_omega_damage(weapon))
674                         return;
675
676         //      If this is a guided missile and it strikes fairly directly, clear bounce flag.
677         if (weapon->id == GUIDEDMISS_ID) {
678                 fix     dot;
679
680                 dot = vm_vec_dot(&weapon->orient.fvec, &Segments[hitseg].sides[hitwall].normals[0]);
681                 mprintf((0, "Guided missile dot = %7.3f\n", f2fl(dot)));
682                 if (dot < -F1_0/6) {
683                         mprintf((0, "Guided missile loses bounciness.\n"));
684                         weapon->mtype.phys_info.flags &= ~PF_BOUNCE;
685                 }
686         }
687
688         //if an energy weapon hits a forcefield, let it bounce
689         if ((TmapInfo[seg->sides[hitwall].tmap_num].flags & TMI_FORCE_FIELD) &&
690                  !(weapon->type == OBJ_WEAPON && Weapon_info[weapon->id].energy_usage==0)) {
691
692                 //make sound
693                 digi_link_sound_to_pos( SOUND_FORCEFIELD_BOUNCE_WEAPON, hitseg, 0, hitpt, 0, f1_0 );
694 #ifdef NETWORK
695                 if (Game_mode & GM_MULTI)
696                         multi_send_play_sound(SOUND_FORCEFIELD_BOUNCE_WEAPON, f1_0);
697 #endif
698
699                 return; //bail here. physics code will bounce this object
700         }
701
702         #ifndef NDEBUG
703         if (keyd_pressed[KEY_LAPOSTRO])
704                 if (weapon->ctype.laser_info.parent_num == Players[Player_num].objnum) {
705                         //      MK: Real pain when you need to know a seg:side and you've got quad lasers.
706                         mprintf((0, "Your laser hit at segment = %i, side = %i\n", hitseg, hitwall));
707                         HUD_init_message("Hit at segment = %i, side = %i", hitseg, hitwall);
708                         if (weapon->id < 4)
709                                 subtract_light(hitseg, hitwall);
710                         else if (weapon->id == FLARE_ID)
711                                 add_light(hitseg, hitwall);
712                 }
713
714                 //@@#ifdef EDITOR
715                 //@@Cursegp = &Segments[hitseg];
716                 //@@Curside = hitwall;
717                 //@@#endif
718         #endif
719
720         if ((weapon->mtype.phys_info.velocity.x == 0) && (weapon->mtype.phys_info.velocity.y == 0) && (weapon->mtype.phys_info.velocity.z == 0)) {
721                 Int3(); //      Contact Matt: This is impossible.  A weapon with 0 velocity hit a wall, which doesn't move.
722                 return;
723         }
724
725         blew_up = check_effect_blowup(seg,hitwall,hitpt, weapon, 0);
726
727         //if ((seg->sides[hitwall].tmap_num2==0) && (TmapInfo[seg->sides[hitwall].tmap_num].flags & TMI_VOLATILE)) {
728
729         if ((weapon->ctype.laser_info.parent_type == OBJ_ROBOT) && (Robot_info[Objects[weapon->ctype.laser_info.parent_num].id].companion==1)) {
730                 robot_escort = 1;
731
732                 if (Game_mode & GM_MULTI)
733                  {
734                          Int3();  // Get Jason!
735                     return;
736             }   
737
738
739                 playernum = Player_num;         //if single player, he's the player's buddy
740         }
741         else {
742                 robot_escort = 0;
743
744                 if (Objects[weapon->ctype.laser_info.parent_num].type == OBJ_PLAYER)
745                         playernum = Objects[weapon->ctype.laser_info.parent_num].id;
746                 else
747                         playernum = -1;         //not a player (thus a robot)
748         }
749
750         if (blew_up) {          //could be a wall switch
751                 //for wall triggers, always say that the player shot it out.  This is
752                 //because robots can shoot out wall triggers, and so the trigger better
753                 //take effect  
754                 //      NO -- Changed by MK, 10/18/95.  We don't want robots blowing puzzles.  Only player or buddy can open!
755                 check_trigger(seg,hitwall,weapon->ctype.laser_info.parent_num,1);
756         }
757
758         if (weapon->id == EARTHSHAKER_ID)
759                 smega_rock_stuff();
760
761         wall_type = wall_hit_process( seg, hitwall, weapon->shields, playernum, weapon );
762
763         // Wall is volatile if either tmap 1 or 2 is volatile
764         if ((TmapInfo[seg->sides[hitwall].tmap_num].flags & TMI_VOLATILE) || (seg->sides[hitwall].tmap_num2 && (TmapInfo[seg->sides[hitwall].tmap_num2&0x3fff].flags & TMI_VOLATILE))) {
765                 weapon_info *wi = &Weapon_info[weapon->id];
766                 int vclip;
767
768                 //we've hit a volatile wall
769
770                 digi_link_sound_to_pos( SOUND_VOLATILE_WALL_HIT,hitseg, 0, hitpt, 0, F1_0 );
771
772                 //for most weapons, use volatile wall hit.  For mega, use its special vclip
773                 vclip = (weapon->id == MEGA_ID)?Weapon_info[weapon->id].robot_hit_vclip:VCLIP_VOLATILE_WALL_HIT;
774
775                 //      New by MK: If powerful badass, explode as badass, not due to lava, fixes megas being wimpy in lava.
776                 if (wi->damage_radius >= VOLATILE_WALL_DAMAGE_RADIUS/2) {
777                         // -- mprintf((0, "Big weapon doing badass in lava instead.\n"));
778                         explode_badass_weapon(weapon,hitpt);
779                 } else {
780                         object_create_badass_explosion( weapon, hitseg, hitpt, 
781                                 wi->impact_size + VOLATILE_WALL_IMPACT_SIZE,
782                                 vclip,
783                                 wi->strength[Difficulty_level]/4+VOLATILE_WALL_EXPL_STRENGTH,   //      diminished by mk on 12/08/94, i was doing 70 damage hitting lava on lvl 1.
784                                 wi->damage_radius+VOLATILE_WALL_DAMAGE_RADIUS,
785                                 wi->strength[Difficulty_level]/2+VOLATILE_WALL_DAMAGE_FORCE,
786                                 weapon->ctype.laser_info.parent_num );
787                 }
788
789                 weapon->flags |= OF_SHOULD_BE_DEAD;             //make flares die in lava
790
791         }
792         else if ((TmapInfo[seg->sides[hitwall].tmap_num].flags & TMI_WATER) || (seg->sides[hitwall].tmap_num2 && (TmapInfo[seg->sides[hitwall].tmap_num2&0x3fff].flags & TMI_WATER))) {
793                 weapon_info *wi = &Weapon_info[weapon->id];
794
795                 //we've hit water
796
797                 //      MK: 09/13/95: Badass in water is 1/2 normal intensity.
798                 if ( Weapon_info[weapon->id].matter ) {
799
800                         digi_link_sound_to_pos( SOUND_MISSILE_HIT_WATER,hitseg, 0, hitpt, 0, F1_0 );
801
802                         if ( Weapon_info[weapon->id].damage_radius ) {
803
804                                 digi_link_sound_to_object(SOUND_BADASS_EXPLOSION, OBJECT_NUMBER(weapon), 0, F1_0);
805
806                                 //      MK: 09/13/95: Badass in water is 1/2 normal intensity.
807                                 object_create_badass_explosion( weapon, hitseg, hitpt, 
808                                         wi->impact_size/2,
809                                         wi->robot_hit_vclip, 
810                                         wi->strength[Difficulty_level]/4,
811                                         wi->damage_radius,
812                                         wi->strength[Difficulty_level]/2,
813                                         weapon->ctype.laser_info.parent_num );
814                         }
815                         else
816                                 object_create_explosion( weapon->segnum, &weapon->pos, Weapon_info[weapon->id].impact_size, Weapon_info[weapon->id].wall_hit_vclip );
817
818                 } else {
819                         digi_link_sound_to_pos( SOUND_LASER_HIT_WATER,hitseg, 0, hitpt, 0, F1_0 );
820                         object_create_explosion( weapon->segnum, &weapon->pos, Weapon_info[weapon->id].impact_size, VCLIP_WATER_HIT );
821                 }
822
823                 weapon->flags |= OF_SHOULD_BE_DEAD;             //make flares die in water
824
825         }
826         else {
827
828                 if (weapon->mtype.phys_info.flags & PF_BOUNCE) {
829
830                         //do special bound sound & effect
831
832                 }
833                 else {
834
835                         //if it's not the player's weapon, or it is the player's and there
836                         //is no wall, and no blowing up monitor, then play sound
837                         if ((weapon->ctype.laser_info.parent_type != OBJ_PLAYER) ||     ((seg->sides[hitwall].wall_num == -1 || wall_type==WHP_NOT_SPECIAL) && !blew_up))
838                                 if ((Weapon_info[weapon->id].wall_hit_sound > -1 ) && (!(weapon->flags & OF_SILENT)))
839                                 digi_link_sound_to_pos( Weapon_info[weapon->id].wall_hit_sound,weapon->segnum, 0, &weapon->pos, 0, F1_0 );
840                 
841                         if ( Weapon_info[weapon->id].wall_hit_vclip > -1 )      {
842                                 if ( Weapon_info[weapon->id].damage_radius )
843                                         explode_badass_weapon(weapon,hitpt);
844                                 else
845                                         object_create_explosion( weapon->segnum, &weapon->pos, Weapon_info[weapon->id].impact_size, Weapon_info[weapon->id].wall_hit_vclip );
846                         }
847                 }
848         }
849
850         //      If weapon fired by player or companion...
851         if (( weapon->ctype.laser_info.parent_type== OBJ_PLAYER ) || robot_escort) {
852
853                 if (!(weapon->flags & OF_SILENT) && (weapon->ctype.laser_info.parent_num == Players[Player_num].objnum))
854                         create_awareness_event(weapon, PA_WEAPON_WALL_COLLISION);                       // object "weapon" can attract attention to player
855         
856 //              if (weapon->id != FLARE_ID) {
857 //      We now allow flares to open doors.
858                 {
859
860                         if (((weapon->id != FLARE_ID) || (weapon->ctype.laser_info.parent_type != OBJ_PLAYER)) && !(weapon->mtype.phys_info.flags & PF_BOUNCE))
861                                 weapon->flags |= OF_SHOULD_BE_DEAD;
862
863                         //don't let flares stick in force fields
864                         if ((weapon->id == FLARE_ID) && (TmapInfo[seg->sides[hitwall].tmap_num].flags & TMI_FORCE_FIELD))
865                                 weapon->flags |= OF_SHOULD_BE_DEAD;
866
867                         if (!(weapon->flags & OF_SILENT)) {
868                                 switch (wall_type) {
869
870                                         case WHP_NOT_SPECIAL:
871                                                 //should be handled above
872                                                 //digi_link_sound_to_pos( Weapon_info[weapon->id].wall_hit_sound, weapon->segnum, 0, &weapon->pos, 0, F1_0 );
873                                                 break;
874
875                                         case WHP_NO_KEY:
876                                                 //play special hit door sound (if/when we get it)
877                                                 digi_link_sound_to_pos( SOUND_WEAPON_HIT_DOOR, weapon->segnum, 0, &weapon->pos, 0, F1_0 );
878 #ifdef NETWORK
879                                  if (Game_mode & GM_MULTI)
880                                                         multi_send_play_sound( SOUND_WEAPON_HIT_DOOR, F1_0 );
881 #endif
882
883                                                 break;
884
885                                         case WHP_BLASTABLE:
886                                                 //play special blastable wall sound (if/when we get it)
887                                                 if ((Weapon_info[weapon->id].wall_hit_sound > -1 ) && (!(weapon->flags & OF_SILENT)))
888                                                         digi_link_sound_to_pos( SOUND_WEAPON_HIT_BLASTABLE, weapon->segnum, 0, &weapon->pos, 0, F1_0 );
889                                                 break;
890
891                                         case WHP_DOOR:
892                                                 //don't play anything, since door open sound will play
893                                                 break;
894                                 }
895                         } // else
896                                 //mprintf((0, "Weapon %i hits wall, but has silent bit set.\n", OBJECT_NUMBER(weapon)));
897                 } // else {
898                         //      if (weapon->lifeleft <= 0)
899                         //      weapon->flags |= OF_SHOULD_BE_DEAD;
900                 // }
901
902         } else {
903                 // This is a robot's laser
904                 if (!(weapon->mtype.phys_info.flags & PF_BOUNCE))
905                         weapon->flags |= OF_SHOULD_BE_DEAD;
906         }
907
908         return;
909 }
910
911 //##void collide_camera_and_wall( object * camera, fix hitspeed, short hitseg, short hitwall, vms_vector * hitpt)       {
912 //##    return;
913 //##}
914
915 //##void collide_powerup_and_wall( object * powerup, fix hitspeed, short hitseg, short hitwall, vms_vector * hitpt)     {
916 //##    return;
917 //##}
918
919 void collide_debris_and_wall( object * debris, fix hitspeed, short hitseg, short hitwall, vms_vector * hitpt)   {       
920         explode_object(debris,0);
921         return;
922 }
923
924 //##void collide_fireball_and_fireball( object * fireball1, object * fireball2, vms_vector *collision_point ) {
925 //##    return; 
926 //##}
927
928 //##void collide_fireball_and_robot( object * fireball, object * robot, vms_vector *collision_point ) {
929 //##    return; 
930 //##}
931
932 //##void collide_fireball_and_hostage( object * fireball, object * hostage, vms_vector *collision_point ) {
933 //##    return; 
934 //##}
935
936 //##void collide_fireball_and_player( object * fireball, object * player, vms_vector *collision_point ) {
937 //##    return; 
938 //##}
939
940 //##void collide_fireball_and_weapon( object * fireball, object * weapon, vms_vector *collision_point ) { 
941 //##    //weapon->flags |= OF_SHOULD_BE_DEAD;
942 //##    return; 
943 //##}
944
945 //##void collide_fireball_and_camera( object * fireball, object * camera, vms_vector *collision_point ) { 
946 //##    return; 
947 //##}
948
949 //##void collide_fireball_and_powerup( object * fireball, object * powerup, vms_vector *collision_point ) { 
950 //##    return; 
951 //##}
952
953 //##void collide_fireball_and_debris( object * fireball, object * debris, vms_vector *collision_point ) { 
954 //##    return; 
955 //##}
956
957 //      -------------------------------------------------------------------------------------------------------------------
958 void collide_robot_and_robot( object * robot1, object * robot2, vms_vector *collision_point ) { 
959 //      mprintf((0, "Coll: [%2i %4i %4i %4i] [%2i %4i %4i %4i] at [%4i %4i %4i]", 
960 //              OBJECT_NUMBER(robot1), f2i(robot1->pos.x), f2i(robot1->pos.y), f2i(robot1->pos.z),
961 //              OBJECT_NUMBER(robot2), f2i(robot2->pos.x), f2i(robot2->pos.y), f2i(robot2->pos.z),
962 //              f2i(collision_point->x), f2i(collision_point->y), f2i(collision_point->z)));
963
964         bump_two_objects(robot1, robot2, 1);
965         return; 
966 }
967
968 void collide_robot_and_controlcen( object * obj1, object * obj2, vms_vector *collision_point )
969 {
970
971         if (obj1->type == OBJ_ROBOT) {
972                 vms_vector      hitvec;
973                 vm_vec_normalize_quick(vm_vec_sub(&hitvec, &obj2->pos, &obj1->pos));
974                 bump_one_object(obj1, &hitvec, 0);
975         } else {
976                 vms_vector      hitvec;
977                 vm_vec_normalize_quick(vm_vec_sub(&hitvec, &obj1->pos, &obj2->pos));
978                 bump_one_object(obj2, &hitvec, 0);
979         }
980
981 }
982
983 //##void collide_robot_and_hostage( object * robot, object * hostage, vms_vector *collision_point ) { 
984 //##    return; 
985 //##}
986
987 fix Last_thief_hit_time;
988
989 void collide_robot_and_player( object * robot, object * playerobj, vms_vector *collision_point )
990
991         int     steal_attempt = 0;
992         int     collision_seg;
993
994         if (robot->flags&OF_EXPLODING)
995                 return;
996
997         collision_seg = find_point_seg(collision_point, playerobj->segnum);
998         if (collision_seg != -1)
999                 object_create_explosion( collision_seg, collision_point, Weapon_info[0].impact_size, Weapon_info[0].wall_hit_vclip );
1000
1001         if (playerobj->id == Player_num) {
1002                 if (Robot_info[robot->id].companion)    //      Player and companion don't collide.
1003                         return;
1004                 if (Robot_info[robot->id].kamikaze) {
1005                         apply_damage_to_robot(robot, robot->shields+1, OBJECT_NUMBER(playerobj));
1006                         if (playerobj == ConsoleObject)
1007                                 add_points_to_score(Robot_info[robot->id].score_value);
1008                 }
1009
1010                 if (Robot_info[robot->id].thief) {
1011                         if (Ai_local_info[OBJECT_NUMBER(robot)].mode == AIM_THIEF_ATTACK) {
1012                                 Last_thief_hit_time = GameTime;
1013                                 attempt_to_steal_item(robot, playerobj->id);
1014                                 steal_attempt = 1;
1015                         } else if (GameTime - Last_thief_hit_time < F1_0*2)
1016                                 return;         //      ZOUNDS!  BRILLIANT!  Thief not collide with player if not stealing!
1017                                                                 // NO!  VERY DUMB!  makes thief look very stupid if player hits him while cloaked! -AP
1018                         else
1019                                 Last_thief_hit_time = GameTime;
1020                 }
1021
1022                 create_awareness_event(playerobj, PA_PLAYER_COLLISION);                 // object robot can attract attention to player
1023                 do_ai_robot_hit_attack(robot, playerobj, collision_point);
1024                 do_ai_robot_hit(robot, PA_WEAPON_ROBOT_COLLISION);
1025         } 
1026 #ifdef NETWORK
1027         else
1028                 multi_robot_request_change(robot, playerobj->id);
1029 #endif
1030
1031         // added this if to remove the bump sound if it's the thief.
1032         // A "steal" sound was added and it was getting obscured by the bump. -AP 10/3/95
1033         //      Changed by MK to make this sound unless the robot stole.
1034         if ((!steal_attempt) && !Robot_info[robot->id].energy_drain)
1035                 digi_link_sound_to_pos( SOUND_ROBOT_HIT_PLAYER, playerobj->segnum, 0, collision_point, 0, F1_0 );
1036
1037         bump_two_objects(robot, playerobj, 1);
1038         return; 
1039 }
1040
1041 // Provide a way for network message to instantly destroy the control center
1042 // without awarding points or anything.
1043
1044 //      if controlcen == NULL, that means don't do the explosion because the control center
1045 //      was actually in another object.
1046 void net_destroy_controlcen(object *controlcen)
1047 {
1048         if (Control_center_destroyed != 1) {
1049
1050                 do_controlcen_destroyed_stuff(controlcen);
1051
1052                 if ((controlcen != NULL) && !(controlcen->flags&(OF_EXPLODING|OF_DESTROYED))) {
1053                         digi_link_sound_to_pos( SOUND_CONTROL_CENTER_DESTROYED, controlcen->segnum, 0, &controlcen->pos, 0, F1_0 );
1054                         explode_object(controlcen,0);
1055                 }
1056         }
1057
1058 }
1059
1060 //      -----------------------------------------------------------------------------
1061 void apply_damage_to_controlcen(object *controlcen, fix damage, short who)
1062 {
1063         int     whotype;
1064
1065         //      Only allow a player to damage the control center.
1066
1067         if ((who < 0) || (who > Highest_object_index))
1068                 return;
1069
1070         whotype = Objects[who].type;
1071         if (whotype != OBJ_PLAYER) {
1072                 mprintf((0, "Damage to control center by object of type %i prevented by MK!\n", whotype));
1073                 return;
1074         }
1075
1076         #ifdef NETWORK
1077         if ((Game_mode & GM_MULTI) && !(Game_mode & GM_MULTI_COOP) && (Players[Player_num].time_level < Netgame.control_invul_time))
1078         {
1079                 if (Objects[who].id == Player_num) {
1080                         int secs = f2i(Netgame.control_invul_time-Players[Player_num].time_level) % 60;
1081                         int mins = f2i(Netgame.control_invul_time-Players[Player_num].time_level) / 60;
1082                         HUD_init_message("%s %d:%02d.", TXT_CNTRLCEN_INVUL, mins, secs);
1083                 }
1084                 return;
1085         }
1086         #endif
1087
1088         if (Objects[who].id == Player_num) {
1089                 Control_center_been_hit = 1;
1090                 ai_do_cloak_stuff();
1091         }
1092
1093         if ( controlcen->shields >= 0 )
1094                 controlcen->shields -= damage;
1095
1096         if ( (controlcen->shields < 0) && !(controlcen->flags&(OF_EXPLODING|OF_DESTROYED)) ) {
1097
1098                 do_controlcen_destroyed_stuff(controlcen);
1099
1100                 #ifdef NETWORK
1101                 if (Game_mode & GM_MULTI) {
1102                         if (who == Players[Player_num].objnum)
1103                                 add_points_to_score(CONTROL_CEN_SCORE);
1104                         multi_send_destroy_controlcen( (ushort)(OBJECT_NUMBER(controlcen)), Objects[who].id );
1105                 }
1106                 #endif
1107
1108                 if (!(Game_mode & GM_MULTI))
1109                         add_points_to_score(CONTROL_CEN_SCORE);
1110
1111                 digi_link_sound_to_pos( SOUND_CONTROL_CENTER_DESTROYED, controlcen->segnum, 0, &controlcen->pos, 0, F1_0 );
1112
1113                 explode_object(controlcen,0);
1114         }
1115 }
1116
1117 void collide_player_and_controlcen( object * controlcen, object * playerobj, vms_vector *collision_point )
1118
1119         if (playerobj->id == Player_num) {
1120                 Control_center_been_hit = 1;
1121                 ai_do_cloak_stuff();                            //      In case player cloaked, make control center know where he is.
1122         }
1123
1124         digi_link_sound_to_pos( SOUND_ROBOT_HIT_PLAYER, playerobj->segnum, 0, collision_point, 0, F1_0 );
1125         bump_two_objects(controlcen, playerobj, 1);
1126
1127         return; 
1128 }
1129
1130 void collide_player_and_marker( object * marker, object * playerobj, vms_vector *collision_point )
1131
1132    mprintf ((0,"Collided with marker %d!\n",marker->id));
1133
1134         if (playerobj->id==Player_num) {
1135                 int drawn;
1136
1137                 if (Game_mode & GM_MULTI)
1138                 {
1139                         drawn = HUD_init_message ("MARKER %s: %s",Players[marker->id/2].callsign,MarkerMessage[marker->id]);
1140                 }
1141                 else
1142                 {
1143                         if (MarkerMessage[marker->id][0])
1144                                 drawn = HUD_init_message("MARKER %d: %s", marker->id+1,MarkerMessage[marker->id]);
1145                         else
1146                                 drawn = HUD_init_message("MARKER %d", marker->id+1);
1147            }
1148
1149                 if (drawn)
1150                         digi_play_sample( SOUND_MARKER_HIT, F1_0 );
1151
1152                 detect_escort_goal_accomplished(OBJECT_NUMBER(marker));
1153    }
1154 }
1155
1156 //      If a persistent weapon and other object is not a weapon, weaken it, else kill it.
1157 //      If both objects are weapons, weaken the weapon.
1158 void maybe_kill_weapon(object *weapon, object *other_obj)
1159 {
1160         if ((weapon->id == PROXIMITY_ID) || (weapon->id == SUPERPROX_ID) || (weapon->id == PMINE_ID)) {
1161                 weapon->flags |= OF_SHOULD_BE_DEAD;
1162                 return;
1163         }
1164
1165         //      Changed, 10/12/95, MK: Make weapon-weapon collisions always kill both weapons if not persistent.
1166         //      Reason: Otherwise you can't use proxbombs to detonate incoming homing missiles (or mega missiles).
1167         if (weapon->mtype.phys_info.flags & PF_PERSISTENT) {
1168                 //      Weapons do a lot of damage to weapons, other objects do much less.
1169                 if (!(weapon->mtype.phys_info.flags & PF_PERSISTENT)) {
1170                         if (other_obj->type == OBJ_WEAPON)
1171                                 weapon->shields -= other_obj->shields/2;
1172                         else
1173                                 weapon->shields -= other_obj->shields/4;
1174
1175                         if (weapon->shields <= 0) {
1176                                 weapon->shields = 0;
1177                                 weapon->flags |= OF_SHOULD_BE_DEAD;     // weapon->lifeleft = 1;
1178                         }
1179                 }
1180         } else
1181                 weapon->flags |= OF_SHOULD_BE_DEAD;     // weapon->lifeleft = 1;
1182
1183 // --   if ((weapon->mtype.phys_info.flags & PF_PERSISTENT) || (other_obj->type == OBJ_WEAPON)) {
1184 // --           //      Weapons do a lot of damage to weapons, other objects do much less.
1185 // --           if (!(weapon->mtype.phys_info.flags & PF_PERSISTENT)) {
1186 // --                   if (other_obj->type == OBJ_WEAPON)
1187 // --                           weapon->shields -= other_obj->shields/2;
1188 // --                   else
1189 // --                           weapon->shields -= other_obj->shields/4;
1190 // -- 
1191 // --                   if (weapon->shields <= 0) {
1192 // --                           weapon->shields = 0;
1193 // --                           weapon->flags |= OF_SHOULD_BE_DEAD;
1194 // --                   }
1195 // --           }
1196 // --   } else
1197 // --           weapon->flags |= OF_SHOULD_BE_DEAD;
1198 }
1199
1200 void collide_weapon_and_controlcen( object * weapon, object *controlcen, vms_vector *collision_point  )
1201 {
1202
1203         if (weapon->id == OMEGA_ID)
1204                 if (!ok_to_do_omega_damage(weapon))
1205                         return;
1206
1207         if (weapon->ctype.laser_info.parent_type == OBJ_PLAYER) {
1208                 fix     damage = weapon->shields;
1209
1210                 if (Objects[weapon->ctype.laser_info.parent_num].id == Player_num)
1211                         Control_center_been_hit = 1;
1212
1213                 if ( Weapon_info[weapon->id].damage_radius )
1214                         explode_badass_weapon(weapon,collision_point);
1215                 else
1216                         object_create_explosion( controlcen->segnum, collision_point, controlcen->size*3/20, VCLIP_SMALL_EXPLOSION );
1217
1218                 digi_link_sound_to_pos( SOUND_CONTROL_CENTER_HIT, controlcen->segnum, 0, collision_point, 0, F1_0 );
1219
1220                 damage = fixmul(damage, weapon->ctype.laser_info.multiplier);
1221
1222                 apply_damage_to_controlcen(controlcen, damage, weapon->ctype.laser_info.parent_num);
1223
1224                 maybe_kill_weapon(weapon,controlcen);
1225         } else {        //      If robot weapon hits control center, blow it up, make it go away, but do no damage to control center.
1226                 object_create_explosion( controlcen->segnum, collision_point, controlcen->size*3/20, VCLIP_SMALL_EXPLOSION );
1227                 maybe_kill_weapon(weapon,controlcen);
1228         }
1229
1230 }
1231
1232 void collide_weapon_and_clutter( object * weapon, object *clutter, vms_vector *collision_point  )       {
1233         short exp_vclip = VCLIP_SMALL_EXPLOSION;
1234
1235         if ( clutter->shields >= 0 )
1236                 clutter->shields -= weapon->shields;
1237
1238         digi_link_sound_to_pos( SOUND_LASER_HIT_CLUTTER, weapon->segnum, 0, collision_point, 0, F1_0 );
1239  
1240         object_create_explosion( clutter->segnum, collision_point, ((clutter->size/3)*3)/4, exp_vclip );
1241
1242         if ( (clutter->shields < 0) && !(clutter->flags&(OF_EXPLODING|OF_DESTROYED)))
1243                 explode_object(clutter,STANDARD_EXPL_DELAY);
1244
1245         maybe_kill_weapon(weapon,clutter);
1246 }
1247
1248 //--mk, 121094 -- extern void spin_robot(object *robot, vms_vector *collision_point);
1249
1250 extern object *explode_badass_object(object *objp, fix damage, fix distance, fix force);
1251
1252 int     Final_boss_is_dead = 0;
1253 fix     Final_boss_countdown_time = 0;
1254
1255 //      ------------------------------------------------------------------------------------------------------
1256 void do_final_boss_frame(void)
1257 {
1258
1259         if (!Final_boss_is_dead)
1260                 return;
1261
1262         if (!Control_center_destroyed)
1263                 return;
1264
1265         if (Final_boss_countdown_time == 0)
1266                 Final_boss_countdown_time = F1_0*2;
1267
1268         Final_boss_countdown_time -= FrameTime;
1269         if (Final_boss_countdown_time > 0)
1270                 return;
1271
1272         gr_palette_fade_out( gr_palette, 256, 0 );
1273         start_endlevel_sequence();              //pretend we hit the exit trigger
1274
1275 }
1276
1277 //      ------------------------------------------------------------------------------------------------------
1278 //      This is all the ugly stuff we do when you kill the final boss so that you don't die or something
1279 //      which would ruin the logic of the cut sequence.
1280 void do_final_boss_hacks(void)
1281 {
1282         if (Player_is_dead) {
1283                 Int3();         //      Uh-oh, player is dead.  Try to rescue him.
1284                 Player_is_dead = 0;
1285         }
1286
1287         if (Players[Player_num].shields <= 0)
1288                 Players[Player_num].shields = 1;
1289
1290         //      If you're not invulnerable, get invulnerable!
1291         if (!(Players[Player_num].flags & PLAYER_FLAGS_INVULNERABLE)) {
1292                 Players[Player_num].invulnerable_time = GameTime;
1293                 Players[Player_num].flags |= PLAYER_FLAGS_INVULNERABLE;
1294         }
1295         if (!(Game_mode & GM_MULTI))
1296                 buddy_message("Nice job, %s!", Players[Player_num].callsign);
1297
1298         Final_boss_is_dead = 1;
1299 }
1300
1301 extern int Buddy_dude_cheat;
1302 extern int multi_all_players_alive();
1303 void multi_send_finish_game ();
1304
1305 //      ------------------------------------------------------------------------------------------------------
1306 //      Return 1 if robot died, else return 0
1307 int apply_damage_to_robot(object *robot, fix damage, int killer_objnum)
1308 {
1309 #ifdef NETWORK
1310    char isthief;
1311         char i,temp_stolen[MAX_STOLEN_ITEMS];   
1312 #endif
1313         
1314         if ( robot->flags&OF_EXPLODING) return 0;
1315
1316         if (robot->shields < 0 ) return 0;      //robot already dead...
1317
1318         if (Robot_info[robot->id].boss_flag)
1319                 Boss_hit_time = GameTime;
1320
1321         //      Buddy invulnerable on level 24 so he can give you his important messages.  Bah.
1322         //      Also invulnerable if his cheat for firing weapons is in effect.
1323         if (Robot_info[robot->id].companion) {
1324 //              if ((PLAYING_BUILTIN_MISSION && Current_level_num == Last_level) || Buddy_dude_cheat)
1325 #ifdef NETWORK
1326                 if (PLAYING_BUILTIN_MISSION && Current_level_num == Last_level)
1327                         return 0;
1328 #endif
1329         }
1330
1331 //      if (robot->control_type == CT_REMOTE)
1332 //              return 0; // Can't damange a robot controlled by another player
1333
1334 // -- MK, 10/21/95, unused! --  if (Robot_info[robot->id].boss_flag)
1335 //              Boss_been_hit = 1;
1336
1337         robot->shields -= damage;
1338
1339         //      Do unspeakable hacks to make sure player doesn't die after killing boss.  Or before, sort of.
1340         if (Robot_info[robot->id].boss_flag)
1341                 if (PLAYING_BUILTIN_MISSION && Current_level_num == Last_level)
1342                         if (robot->shields < 0)
1343                          {
1344 #ifdef NETWORK
1345                                 if (Game_mode & GM_MULTI)
1346                                   {
1347                                          if (!multi_all_players_alive()) // everyones gotta be alive
1348                                            robot->shields=1;
1349                                          else
1350                                           {
1351                                             multi_send_finish_game();
1352                                             do_final_boss_hacks();
1353                                           }             
1354                                   
1355                                         }               
1356                                 else
1357 #endif
1358                                   {     // NOTE LINK TO ABOVE!!!
1359                                         if ((Players[Player_num].shields < 0) || Player_is_dead)
1360                                                 robot->shields = 1;             //      Sorry, we can't allow you to kill the final boss after you've died.  Rough luck.
1361                                         else
1362                                                 do_final_boss_hacks();
1363                                   }
1364                           }
1365
1366         if (robot->shields < 0) {
1367 #ifdef NETWORK
1368                 if (Game_mode & GM_MULTI) {
1369                  if (Robot_info[robot->id].thief)       
1370                         isthief=1;
1371                  else
1372                         isthief=0;
1373
1374                  if (isthief)
1375                         for (i=0;i<MAX_STOLEN_ITEMS;i++)
1376                          temp_stolen[(int)i]=Stolen_items[(int)i];
1377                                 
1378                         if (multi_explode_robot_sub(OBJECT_NUMBER(robot), killer_objnum,Robot_info[robot->id].thief))
1379                         {
1380                          if (isthief)   
1381                         for (i=0;i<MAX_STOLEN_ITEMS;i++)
1382                                   Stolen_items[(int)i]=temp_stolen[(int)i];
1383                                         
1384                                 multi_send_robot_explode(OBJECT_NUMBER(robot), killer_objnum,Robot_info[robot->id].thief);
1385
1386                    if (isthief) 
1387                                 for (i=0;i<MAX_STOLEN_ITEMS;i++)
1388                                           Stolen_items[(int)i]=255;
1389
1390                                 return 1;
1391                         }
1392                         else
1393                                 return 0;
1394                 }
1395 #endif
1396
1397                 Players[Player_num].num_kills_level++;
1398                 Players[Player_num].num_kills_total++;
1399
1400                 if (Robot_info[robot->id].boss_flag) {
1401                         start_boss_death_sequence(robot);       //do_controlcen_destroyed_stuff(NULL);
1402                 } else if (Robot_info[robot->id].death_roll) {
1403                         start_robot_death_sequence(robot);      //do_controlcen_destroyed_stuff(NULL);
1404                 } else {
1405                         if (robot->id == SPECIAL_REACTOR_ROBOT)
1406                                 special_reactor_stuff();
1407                         //if (Robot_info[robot->id].smart_blobs)
1408                         //      create_smart_children(robot, Robot_info[robot->id].smart_blobs);
1409                         //if (Robot_info[robot->id].badass)
1410                         //      explode_badass_object(robot, F1_0*Robot_info[robot->id].badass, F1_0*40, F1_0*150);
1411                         if (Robot_info[robot->id].kamikaze)
1412                                 explode_object(robot,1);                //      Kamikaze, explode right away, IN YOUR FACE!
1413                         else
1414                                 explode_object(robot,STANDARD_EXPL_DELAY);
1415                 }
1416                 return 1;
1417         } else
1418                 return 0;
1419 }
1420
1421 extern int boss_spew_robot(object *objp, vms_vector *pos);
1422
1423 //--ubyte       Boss_teleports[NUM_D2_BOSSES] =                                 {1,1,1,1,1,1};          // Set byte if this boss can teleport
1424 //--ubyte       Boss_cloaks[NUM_D2_BOSSES] =                                    {1,1,1,1,1,1};          // Set byte if this boss can cloak
1425 //--ubyte       Boss_spews_bots_energy[NUM_D2_BOSSES] =         {1,1,0,0,1,1};          //      Set byte if boss spews bots when hit by energy weapon.
1426 //--ubyte       Boss_spews_bots_matter[NUM_D2_BOSSES] =         {0,0,1,0,1,1};          //      Set byte if boss spews bots when hit by matter weapon.
1427 //--ubyte       Boss_invulnerable_energy[NUM_D2_BOSSES] = {0,0,1,1,0,0};                //      Set byte if boss is invulnerable to energy weapons.
1428 //--ubyte       Boss_invulnerable_matter[NUM_D2_BOSSES] = {0,0,0,1,0,0};                //      Set byte if boss is invulnerable to matter weapons.
1429 //--ubyte       Boss_invulnerable_spot[NUM_D2_BOSSES] =         {0,0,0,0,1,1};          //      Set byte if boss is invulnerable in all but a certain spot.  (Dot product fvec|vec_to_collision < BOSS_INVULNERABLE_DOT)
1430
1431 //#define       BOSS_INVULNERABLE_DOT   0               //      If a boss is invulnerable over most of his body, fvec(dot)vec_to_collision must be less than this for damage to occur.
1432 int     Boss_invulnerable_dot = 0;
1433
1434 int     Buddy_gave_hint_count = 5;
1435 fix     Last_time_buddy_gave_hint = 0;
1436
1437 //      ------------------------------------------------------------------------------------------------------
1438 //      Return true if damage done to boss, else return false.
1439 int do_boss_weapon_collision(object *robot, object *weapon, vms_vector *collision_point)
1440 {
1441         int     d2_boss_index;
1442         int     damage_flag;
1443
1444         damage_flag = 1;
1445
1446         d2_boss_index = Robot_info[robot->id].boss_flag - BOSS_D2;
1447
1448         Assert((d2_boss_index >= 0) && (d2_boss_index < NUM_D2_BOSSES));
1449
1450         //      See if should spew a bot.
1451         if (weapon->ctype.laser_info.parent_type == OBJ_PLAYER)
1452                 if ((Weapon_info[weapon->id].matter && Boss_spews_bots_matter[d2_boss_index]) || (!Weapon_info[weapon->id].matter && Boss_spews_bots_energy[d2_boss_index])) {
1453                         if (Boss_spew_more[d2_boss_index])
1454                                 if (d_rand() > 16384) {
1455                                         if (boss_spew_robot(robot, collision_point) != -1)
1456                                                 Last_gate_time = GameTime - Gate_interval - 1;  //      Force allowing spew of another bot.
1457                                 }
1458                         boss_spew_robot(robot, collision_point);
1459                 }
1460
1461         if (Boss_invulnerable_spot[d2_boss_index]) {
1462                 fix                     dot;
1463                 vms_vector      tvec1;
1464
1465                 //      Boss only vulnerable in back.  See if hit there.
1466                 vm_vec_sub(&tvec1, collision_point, &robot->pos);
1467                 vm_vec_normalize_quick(&tvec1); //      Note, if BOSS_INVULNERABLE_DOT is close to F1_0 (in magnitude), then should probably use non-quick version.
1468                 dot = vm_vec_dot(&tvec1, &robot->orient.fvec);
1469                 mprintf((0, "Boss hit vec dot = %7.3f\n", f2fl(dot)));
1470
1471                 if (dot > Boss_invulnerable_dot) {
1472                         int     new_obj;
1473                         int     segnum;
1474
1475                         segnum = find_point_seg(collision_point, robot->segnum);
1476                         digi_link_sound_to_pos( SOUND_WEAPON_HIT_DOOR, segnum, 0, collision_point, 0, F1_0);
1477                         damage_flag = 0;
1478
1479                         if (Last_time_buddy_gave_hint == 0)
1480                                 Last_time_buddy_gave_hint = d_rand()*32 + F1_0*16;
1481
1482                         if (Buddy_gave_hint_count) {
1483                                 if (Last_time_buddy_gave_hint + F1_0*20 < GameTime) {
1484                                         int     sval;
1485
1486                                         Buddy_gave_hint_count--;
1487                                         Last_time_buddy_gave_hint = GameTime;
1488                                         sval = (d_rand()*4) >> 15;
1489                                         switch (sval) {
1490                                                 case 0: buddy_message("Hit him in the back!");  break;
1491                                                 case 1: buddy_message("He's invulnerable there!");      break;
1492                                                 case 2: buddy_message("Get behind him and fire!");      break;
1493                                                 case 3:
1494                                                 default:
1495                                                                         buddy_message("Hit the glowing spot!"); break;
1496                                         }
1497                                 }
1498                         }
1499
1500                         //      Cause weapon to bounce.
1501                         //      Make a copy of this weapon, because the physics wants to destroy it.
1502                         if (!Weapon_info[weapon->id].matter) {
1503                                 new_obj = obj_create(weapon->type, weapon->id, weapon->segnum, &weapon->pos,
1504                                         &weapon->orient, weapon->size, weapon->control_type, weapon->movement_type, weapon->render_type);
1505
1506                                 if (new_obj != -1) {
1507                                         vms_vector      vec_to_point;
1508                                         vms_vector      weap_vec;
1509                                         fix                     speed;
1510
1511                                         if (weapon->render_type == RT_POLYOBJ) {
1512                                                 Objects[new_obj].rtype.pobj_info.model_num = Weapon_info[Objects[new_obj].id].model_num;
1513                                                 Objects[new_obj].size = fixdiv(Polygon_models[Objects[new_obj].rtype.pobj_info.model_num].rad,Weapon_info[Objects[new_obj].id].po_len_to_width_ratio);
1514                                         }
1515
1516                                         Objects[new_obj].mtype.phys_info.mass = Weapon_info[weapon->type].mass;
1517                                         Objects[new_obj].mtype.phys_info.drag = Weapon_info[weapon->type].drag;
1518                                         vm_vec_zero(&Objects[new_obj].mtype.phys_info.thrust);
1519
1520                                         vm_vec_sub(&vec_to_point, collision_point, &robot->pos);
1521                                         vm_vec_normalize_quick(&vec_to_point);
1522                                         weap_vec = weapon->mtype.phys_info.velocity;
1523                                         speed = vm_vec_normalize_quick(&weap_vec);
1524                                         vm_vec_scale_add2(&vec_to_point, &weap_vec, -F1_0*2);
1525                                         vm_vec_scale(&vec_to_point, speed/4);
1526                                         Objects[new_obj].mtype.phys_info.velocity = vec_to_point;
1527                                 }
1528                         }
1529                 }
1530         } else if ((Weapon_info[weapon->id].matter && Boss_invulnerable_matter[d2_boss_index]) || (!Weapon_info[weapon->id].matter && Boss_invulnerable_energy[d2_boss_index])) {
1531                 int     segnum;
1532
1533                 segnum = find_point_seg(collision_point, robot->segnum);
1534                 digi_link_sound_to_pos( SOUND_WEAPON_HIT_DOOR, segnum, 0, collision_point, 0, F1_0);
1535                 damage_flag = 0;
1536         }
1537
1538         return damage_flag;
1539 }
1540
1541 extern int Robots_kill_robots_cheat;
1542
1543 //      ------------------------------------------------------------------------------------------------------
1544 void collide_robot_and_weapon( object * robot, object * weapon, vms_vector *collision_point )
1545
1546         int     damage_flag=1;
1547         int     boss_invul_flag=0;
1548
1549         if (weapon->id == OMEGA_ID)
1550                 if (!ok_to_do_omega_damage(weapon))
1551                         return;
1552
1553         if (Robot_info[robot->id].boss_flag) {
1554                 Boss_hit_time = GameTime;
1555                 if (Robot_info[robot->id].boss_flag >= BOSS_D2) {
1556                         damage_flag = do_boss_weapon_collision(robot, weapon, collision_point);
1557                         boss_invul_flag = !damage_flag;
1558                 }
1559         }
1560
1561         //      Put in at request of Jasen (and Adam) because the Buddy-Bot gets in their way.
1562         //      MK has so much fun whacking his butt around the mine he never cared...
1563         if ((Robot_info[robot->id].companion) && ((weapon->ctype.laser_info.parent_type != OBJ_ROBOT) && !Robots_kill_robots_cheat))
1564                 return;
1565
1566         if (weapon->id == EARTHSHAKER_ID)
1567                 smega_rock_stuff();
1568
1569         //      If a persistent weapon hit robot most recently, quick abort, else we cream the same robot many times,
1570         //      depending on frame rate.
1571         if (weapon->mtype.phys_info.flags & PF_PERSISTENT) {
1572                 if (weapon->ctype.laser_info.last_hitobj == OBJECT_NUMBER(robot))
1573                         return;
1574                 else
1575                         weapon->ctype.laser_info.last_hitobj = OBJECT_NUMBER(robot);
1576
1577                 // mprintf((0, "weapon #%i with power %i hits robot #%i.\n", OBJECT_NUMBER(weapon), f2i(weapon->shields), OBJECT_NUMBER(robot)));
1578         }
1579
1580         if (weapon->ctype.laser_info.parent_signature == robot->signature)
1581                 return;
1582
1583         //      Changed, 10/04/95, put out blobs based on skill level and power of weapon doing damage.
1584         //      Also, only a weapon hit from a player weapon causes smart blobs.
1585         if ((weapon->ctype.laser_info.parent_type == OBJ_PLAYER) && (Robot_info[robot->id].energy_blobs))
1586                 if ((robot->shields > 0) && Weapon_is_energy[weapon->id]) {
1587                         fix     probval;
1588                         int     num_blobs;
1589
1590                         probval = (Difficulty_level+2) * min(weapon->shields, robot->shields);
1591                         probval = Robot_info[robot->id].energy_blobs * probval/(NDL*32);
1592
1593                         num_blobs = probval >> 16;
1594                         if (2*d_rand() < (probval & 0xffff))
1595                                 num_blobs++;
1596
1597                         if (num_blobs)
1598                                 create_smart_children(robot, num_blobs);
1599                 }
1600
1601         //      Note: If weapon hits an invulnerable boss, it will still do badass damage, including to the boss,
1602         //      unless this is trapped elsewhere.
1603         if ( Weapon_info[weapon->id].damage_radius )
1604         {
1605                 if (boss_invul_flag) {                  //don't make badass sound
1606                         weapon_info *wi = &Weapon_info[weapon->id];
1607
1608                         //this code copied from explode_badass_weapon()
1609                 
1610                         object_create_badass_explosion( weapon, weapon->segnum, collision_point, 
1611                                                         wi->impact_size, 
1612                                                         wi->robot_hit_vclip, 
1613                                                         wi->strength[Difficulty_level], 
1614                                                         wi->damage_radius,wi->strength[Difficulty_level],
1615                                                         weapon->ctype.laser_info.parent_num );
1616                 
1617                 }
1618                 else            //normal badass explosion
1619                         explode_badass_weapon(weapon,collision_point);
1620         }
1621
1622         if ( ((weapon->ctype.laser_info.parent_type==OBJ_PLAYER) || Robots_kill_robots_cheat) && !(robot->flags & OF_EXPLODING) )       {       
1623                 object *expl_obj=NULL;
1624
1625                 if (weapon->ctype.laser_info.parent_num == Players[Player_num].objnum) {
1626                         create_awareness_event(weapon, PA_WEAPON_ROBOT_COLLISION);                      // object "weapon" can attract attention to player
1627                         do_ai_robot_hit(robot, PA_WEAPON_ROBOT_COLLISION);
1628                 }
1629 #ifdef NETWORK
1630                 else
1631                         multi_robot_request_change(robot, Objects[weapon->ctype.laser_info.parent_num].id);
1632 #endif
1633
1634                 if ( Robot_info[robot->id].exp1_vclip_num > -1 )
1635                         expl_obj = object_create_explosion( weapon->segnum, collision_point, (robot->size/2*3)/4, Robot_info[robot->id].exp1_vclip_num );
1636                 else if ( Weapon_info[weapon->id].robot_hit_vclip > -1 )
1637                         expl_obj = object_create_explosion( weapon->segnum, collision_point, Weapon_info[weapon->id].impact_size, Weapon_info[weapon->id].robot_hit_vclip );
1638
1639                 if (expl_obj)
1640                         obj_attach(robot,expl_obj);
1641
1642                 if ( damage_flag && (Robot_info[robot->id].exp1_sound_num > -1 ))
1643                         digi_link_sound_to_pos( Robot_info[robot->id].exp1_sound_num, robot->segnum, 0, collision_point, 0, F1_0 );
1644
1645                 if (!(weapon->flags & OF_HARMLESS)) {
1646                         fix     damage = weapon->shields;
1647
1648                         if (damage_flag)
1649                                 damage = fixmul(damage, weapon->ctype.laser_info.multiplier);
1650                         else
1651                                 damage = 0;
1652
1653                         //      Cut Gauss damage on bosses because it just breaks the game.  Bosses are so easy to
1654                         //      hit, and missing a robot is what prevents the Gauss from being game-breaking.
1655                         if (weapon->id == GAUSS_ID)
1656                                 if (Robot_info[robot->id].boss_flag)
1657                                         damage = damage * (2*NDL-Difficulty_level)/(2*NDL);
1658
1659                         if (! apply_damage_to_robot(robot, damage, weapon->ctype.laser_info.parent_num))
1660                                 bump_two_objects(robot, weapon, 0);             //only bump if not dead. no damage from bump
1661                         else if (weapon->ctype.laser_info.parent_signature == ConsoleObject->signature) {
1662                                 add_points_to_score(Robot_info[robot->id].score_value);
1663                                 detect_escort_goal_accomplished(OBJECT_NUMBER(robot));
1664                         }
1665                 }
1666
1667
1668                 //      If Gauss Cannon, spin robot.
1669                 if ((robot != NULL) && (!Robot_info[robot->id].companion) && (!Robot_info[robot->id].boss_flag) && (weapon->id == GAUSS_ID)) {
1670                         ai_static       *aip = &robot->ctype.ai_info;
1671
1672                         if (aip->SKIP_AI_COUNT * FrameTime < F1_0) {
1673                                 aip->SKIP_AI_COUNT++;
1674                                 robot->mtype.phys_info.rotthrust.x = fixmul((d_rand() - 16384), FrameTime * aip->SKIP_AI_COUNT);
1675                                 robot->mtype.phys_info.rotthrust.y = fixmul((d_rand() - 16384), FrameTime * aip->SKIP_AI_COUNT);
1676                                 robot->mtype.phys_info.rotthrust.z = fixmul((d_rand() - 16384), FrameTime * aip->SKIP_AI_COUNT);
1677                                 robot->mtype.phys_info.flags |= PF_USES_THRUST;
1678
1679                         }
1680                 }
1681
1682         }
1683
1684         maybe_kill_weapon(weapon,robot);
1685
1686         return; 
1687 }
1688
1689 //##void collide_robot_and_camera( object * robot, object * camera, vms_vector *collision_point ) { 
1690 //##    return; 
1691 //##}
1692
1693 //##void collide_robot_and_powerup( object * robot, object * powerup, vms_vector *collision_point ) { 
1694 //##    return; 
1695 //##}
1696
1697 //##void collide_robot_and_debris( object * robot, object * debris, vms_vector *collision_point ) { 
1698 //##    return; 
1699 //##}
1700
1701 //##void collide_hostage_and_hostage( object * hostage1, object * hostage2, vms_vector *collision_point ) { 
1702 //##    return; 
1703 //##}
1704
1705 void collide_hostage_and_player( object * hostage, object * player, vms_vector *collision_point ) { 
1706         // Give player points, etc.
1707         if ( player == ConsoleObject )  {
1708                 detect_escort_goal_accomplished(OBJECT_NUMBER(hostage));
1709                 add_points_to_score(HOSTAGE_SCORE);
1710
1711                 // Do effect
1712                 hostage_rescue(hostage->id);
1713
1714                 // Remove the hostage object.
1715                 hostage->flags |= OF_SHOULD_BE_DEAD;
1716
1717                 #ifdef NETWORK  
1718                 if (Game_mode & GM_MULTI)
1719                         multi_send_remobj(OBJECT_NUMBER(hostage));
1720                 #endif
1721         }
1722         return; 
1723 }
1724
1725 //--unused-- void collide_hostage_and_weapon( object * hostage, object * weapon, vms_vector *collision_point )
1726 //--unused-- { 
1727 //--unused--    //      Cannot kill hostages, as per Matt's edict!
1728 //--unused--    //      (A fine edict, but in contradiction to the milestone: "Robots attack hostages.")
1729 //--unused--    hostage->shields -= weapon->shields/2;
1730 //--unused-- 
1731 //--unused--    create_awareness_event(weapon, PA_WEAPON_ROBOT_COLLISION);                      // object "weapon" can attract attention to player
1732 //--unused-- 
1733 //--unused--    //PLAY_SOUND_3D( SOUND_HOSTAGE_KILLED, collision_point, hostage->segnum );
1734 //--unused--    digi_link_sound_to_pos( SOUND_HOSTAGE_KILLED, hostage->segnum , 0, collision_point, 0, F1_0 );
1735 //--unused-- 
1736 //--unused-- 
1737 //--unused--    if (hostage->shields <= 0) {
1738 //--unused--            explode_object(hostage,0);
1739 //--unused--            hostage->flags |= OF_SHOULD_BE_DEAD;
1740 //--unused--    }
1741 //--unused-- 
1742 //--unused--    if ( Weapon_info[weapon->id].damage_radius )
1743 //--unused--            explode_badass_weapon(weapon);
1744 //--unused-- 
1745 //--unused--    maybe_kill_weapon(weapon,hostage);
1746 //--unused-- 
1747 //--unused-- }
1748
1749 //##void collide_hostage_and_camera( object * hostage, object * camera, vms_vector *collision_point ) { 
1750 //##    return; 
1751 //##}
1752
1753 //##void collide_hostage_and_powerup( object * hostage, object * powerup, vms_vector *collision_point ) { 
1754 //##    return; 
1755 //##}
1756
1757 //##void collide_hostage_and_debris( object * hostage, object * debris, vms_vector *collision_point ) { 
1758 //##    return; 
1759 //##}
1760
1761 void collide_player_and_player( object * player1, object * player2, vms_vector *collision_point ) { 
1762         digi_link_sound_to_pos( SOUND_ROBOT_HIT_PLAYER, player1->segnum, 0, collision_point, 0, F1_0 );
1763         bump_two_objects(player1, player2, 1);
1764         return;
1765 }
1766
1767 int maybe_drop_primary_weapon_egg(object *playerobj, int weapon_index)
1768 {
1769         int weapon_flag = HAS_FLAG(weapon_index);
1770         int powerup_num;
1771
1772         powerup_num = Primary_weapon_to_powerup[weapon_index];
1773
1774         if (Players[playerobj->id].primary_weapon_flags & weapon_flag)
1775                 return call_object_create_egg(playerobj, 1, OBJ_POWERUP, powerup_num);
1776         else
1777                 return -1;
1778 }
1779
1780 void maybe_drop_secondary_weapon_egg(object *playerobj, int weapon_index, int count)
1781 {
1782         int weapon_flag = HAS_FLAG(weapon_index);
1783         int powerup_num;
1784
1785         powerup_num = Secondary_weapon_to_powerup[weapon_index];
1786
1787         if (Players[playerobj->id].secondary_weapon_flags & weapon_flag) {
1788                 int     i, max_count;
1789
1790                 max_count = min(count, 3);
1791                 for (i=0; i<max_count; i++)
1792                         call_object_create_egg(playerobj, 1, OBJ_POWERUP, powerup_num);
1793         }
1794 }
1795
1796 void drop_missile_1_or_4(object *playerobj,int missile_index)
1797 {
1798         int num_missiles,powerup_id;
1799
1800         num_missiles = Players[playerobj->id].secondary_ammo[missile_index];
1801         powerup_id = Secondary_weapon_to_powerup[missile_index];
1802
1803         if (num_missiles > 10)
1804                 num_missiles = 10;
1805
1806         call_object_create_egg(playerobj, num_missiles/4, OBJ_POWERUP, powerup_id+1);
1807         call_object_create_egg(playerobj, num_missiles%4, OBJ_POWERUP, powerup_id);
1808 }
1809
1810 // -- int       Items_destroyed = 0;
1811
1812 void drop_player_eggs(object *playerobj)
1813 {
1814 //      mprintf((0, "In drop_player_eggs...\n"));
1815
1816         if ((playerobj->type == OBJ_PLAYER) || (playerobj->type == OBJ_GHOST)) {
1817                 int     rthresh;
1818                 int     pnum = playerobj->id;
1819                 int     objnum;
1820                 int     vulcan_ammo=0;
1821                 vms_vector      randvec;
1822
1823                 // -- Items_destroyed = 0;
1824
1825                 // Seed the random number generator so in net play the eggs will always
1826                 // drop the same way
1827                 #ifdef NETWORK
1828                 if (Game_mode & GM_MULTI) 
1829                 {
1830                         Net_create_loc = 0;
1831                         d_srand(5483L);
1832                 }
1833                 #endif
1834
1835                 //      If the player had smart mines, maybe arm one of them.
1836                 rthresh = 30000;
1837                 while ((Players[playerobj->id].secondary_ammo[SMART_MINE_INDEX]%4==1) && (d_rand() < rthresh)) {
1838                         int                     newseg;
1839                         vms_vector      tvec;
1840
1841                         make_random_vector(&randvec);
1842                         rthresh /= 2;
1843                         vm_vec_add(&tvec, &playerobj->pos, &randvec);
1844                         newseg = find_point_seg(&tvec, playerobj->segnum);
1845                         if (newseg != -1)
1846                                 Laser_create_new(&randvec, &tvec, newseg, OBJECT_NUMBER(playerobj), SUPERPROX_ID, 0);
1847                 }
1848
1849                 //      If the player had proximity bombs, maybe arm one of them.
1850
1851                 if ((Game_mode & GM_MULTI) && !(Game_mode & GM_HOARD))
1852                 {
1853                         rthresh = 30000;
1854                         while ((Players[playerobj->id].secondary_ammo[PROXIMITY_INDEX]%4==1) && (d_rand() < rthresh)) {
1855                                 int                     newseg;
1856                                 vms_vector      tvec;
1857         
1858                                 make_random_vector(&randvec);
1859                                 rthresh /= 2;
1860                                 vm_vec_add(&tvec, &playerobj->pos, &randvec);
1861                                 newseg = find_point_seg(&tvec, playerobj->segnum);
1862                                 if (newseg != -1)
1863                                         Laser_create_new(&randvec, &tvec, newseg, OBJECT_NUMBER(playerobj), PROXIMITY_ID, 0);
1864         
1865                         }
1866                 }
1867
1868                 //      If the player dies and he has powerful lasers, create the powerups here.
1869
1870                 if (Players[pnum].laser_level > MAX_LASER_LEVEL)
1871                         call_object_create_egg(playerobj, Players[pnum].laser_level-MAX_LASER_LEVEL, OBJ_POWERUP, POW_SUPER_LASER);
1872                 else if (Players[pnum].laser_level >= 1)
1873                         call_object_create_egg(playerobj, Players[pnum].laser_level, OBJ_POWERUP, POW_LASER);   // Note: laser_level = 0 for laser level 1.
1874
1875                 //      Drop quad laser if appropos
1876                 if (Players[pnum].flags & PLAYER_FLAGS_QUAD_LASERS)
1877                         call_object_create_egg(playerobj, 1, OBJ_POWERUP, POW_QUAD_FIRE);
1878
1879                 if (Players[pnum].flags & PLAYER_FLAGS_CLOAKED)
1880                         call_object_create_egg(playerobj, 1, OBJ_POWERUP, POW_CLOAK);
1881
1882                 if (Players[pnum].flags & PLAYER_FLAGS_MAP_ALL)
1883                         call_object_create_egg(playerobj, 1, OBJ_POWERUP, POW_FULL_MAP);
1884
1885                 if (Players[pnum].flags & PLAYER_FLAGS_AFTERBURNER)
1886                         call_object_create_egg(playerobj, 1, OBJ_POWERUP, POW_AFTERBURNER);
1887
1888                 if (Players[pnum].flags & PLAYER_FLAGS_AMMO_RACK)
1889                         call_object_create_egg(playerobj, 1, OBJ_POWERUP, POW_AMMO_RACK);
1890
1891                 if (Players[pnum].flags & PLAYER_FLAGS_CONVERTER)
1892                         call_object_create_egg(playerobj, 1, OBJ_POWERUP, POW_CONVERTER);
1893
1894                 if (Players[pnum].flags & PLAYER_FLAGS_HEADLIGHT)
1895                         call_object_create_egg(playerobj, 1, OBJ_POWERUP, POW_HEADLIGHT);
1896
1897                 // drop the other enemies flag if you have it
1898
1899 #ifdef NETWORK
1900                 if ((Game_mode & GM_CAPTURE) && (Players[pnum].flags & PLAYER_FLAGS_FLAG))
1901                 {
1902                  if ((get_team (pnum)==TEAM_RED))
1903                         call_object_create_egg(playerobj, 1, OBJ_POWERUP, POW_FLAG_BLUE);
1904                  else
1905                         call_object_create_egg(playerobj, 1, OBJ_POWERUP, POW_FLAG_RED);
1906                 }
1907
1908         
1909                 if (Game_mode & GM_HOARD)
1910                 {
1911                         // Drop hoard orbs
1912                         
1913                         int max_count,i;
1914
1915                         mprintf ((0,"HOARD MODE: Dropping %d orbs\n",Players[pnum].secondary_ammo[PROXIMITY_INDEX]));
1916         
1917                         max_count = min(Players[pnum].secondary_ammo[PROXIMITY_INDEX], 12);
1918                         for (i=0; i<max_count; i++)
1919                                 call_object_create_egg(playerobj, 1, OBJ_POWERUP, POW_HOARD_ORB);
1920                 }
1921 #endif
1922
1923                 //Drop the vulcan, gauss, and ammo
1924                 vulcan_ammo = Players[pnum].primary_ammo[VULCAN_INDEX];
1925                 if ((Players[pnum].primary_weapon_flags & HAS_FLAG(VULCAN_INDEX)) && (Players[pnum].primary_weapon_flags & HAS_FLAG(GAUSS_INDEX)))
1926                         vulcan_ammo /= 2;               //if both vulcan & gauss, each gets half
1927                 if (vulcan_ammo < VULCAN_AMMO_AMOUNT)
1928                         vulcan_ammo = VULCAN_AMMO_AMOUNT;       //make sure gun has at least as much as a powerup
1929                 objnum = maybe_drop_primary_weapon_egg(playerobj, VULCAN_INDEX);
1930                 if (objnum!=-1)
1931                         Objects[objnum].ctype.powerup_info.count = vulcan_ammo;
1932                 objnum = maybe_drop_primary_weapon_egg(playerobj, GAUSS_INDEX);
1933                 if (objnum!=-1)
1934                         Objects[objnum].ctype.powerup_info.count = vulcan_ammo;
1935
1936                 //      Drop the rest of the primary weapons
1937                 maybe_drop_primary_weapon_egg(playerobj, SPREADFIRE_INDEX);
1938                 maybe_drop_primary_weapon_egg(playerobj, PLASMA_INDEX);
1939                 maybe_drop_primary_weapon_egg(playerobj, FUSION_INDEX);
1940
1941                 maybe_drop_primary_weapon_egg(playerobj, HELIX_INDEX);
1942                 maybe_drop_primary_weapon_egg(playerobj, PHOENIX_INDEX);
1943
1944                 objnum = maybe_drop_primary_weapon_egg(playerobj, OMEGA_INDEX);
1945                 if (objnum!=-1)
1946                         Objects[objnum].ctype.powerup_info.count = (playerobj->id==Player_num)?Omega_charge:MAX_OMEGA_CHARGE;
1947
1948                 //      Drop the secondary weapons
1949                 //      Note, proximity weapon only comes in packets of 4.  So drop n/2, but a max of 3 (handled inside maybe_drop..)  Make sense?
1950                 
1951                 if (!(Game_mode & GM_HOARD))
1952                         maybe_drop_secondary_weapon_egg(playerobj, PROXIMITY_INDEX, (Players[playerobj->id].secondary_ammo[PROXIMITY_INDEX])/4);
1953
1954                 maybe_drop_secondary_weapon_egg(playerobj, SMART_INDEX, Players[playerobj->id].secondary_ammo[SMART_INDEX]);
1955                 maybe_drop_secondary_weapon_egg(playerobj, MEGA_INDEX, Players[playerobj->id].secondary_ammo[MEGA_INDEX]);
1956
1957                 maybe_drop_secondary_weapon_egg(playerobj, SMART_MINE_INDEX,(Players[playerobj->id].secondary_ammo[SMART_MINE_INDEX])/4);
1958                 maybe_drop_secondary_weapon_egg(playerobj, SMISSILE5_INDEX, Players[playerobj->id].secondary_ammo[SMISSILE5_INDEX]);
1959
1960                 //      Drop the player's missiles in packs of 1 and/or 4
1961                 drop_missile_1_or_4(playerobj,HOMING_INDEX);
1962                 drop_missile_1_or_4(playerobj,GUIDED_INDEX);
1963                 drop_missile_1_or_4(playerobj,CONCUSSION_INDEX);
1964                 drop_missile_1_or_4(playerobj,SMISSILE1_INDEX);
1965                 drop_missile_1_or_4(playerobj,SMISSILE4_INDEX);
1966
1967                 //      If player has vulcan ammo, but no vulcan cannon, drop the ammo.
1968                 if (!(Players[playerobj->id].primary_weapon_flags & HAS_VULCAN_FLAG)) {
1969                         int     amount = Players[playerobj->id].primary_ammo[VULCAN_INDEX];
1970                         if (amount > 200) {
1971                                 mprintf((0, "Surprising amount of vulcan ammo: %i bullets.\n", amount));
1972                                 amount = 200;
1973                         }
1974                         while (amount > 0) {
1975                                 call_object_create_egg(playerobj, 1, OBJ_POWERUP, POW_VULCAN_AMMO);
1976                                 amount -= VULCAN_AMMO_AMOUNT;
1977                         }
1978                 }
1979
1980                 //      Always drop a shield and energy powerup.
1981                 if (Game_mode & GM_MULTI) {
1982                         call_object_create_egg(playerobj, 1, OBJ_POWERUP, POW_SHIELD_BOOST);
1983                         call_object_create_egg(playerobj, 1, OBJ_POWERUP, POW_ENERGY);
1984                 }
1985
1986 //--            //      Drop all the keys.
1987 //--            if (Players[Player_num].flags & PLAYER_FLAGS_BLUE_KEY) {
1988 //--                    playerobj->contains_count = 1;
1989 //--                    playerobj->contains_type = OBJ_POWERUP;
1990 //--                    playerobj->contains_id = POW_KEY_BLUE;
1991 //--                    object_create_egg(playerobj);
1992 //--            }
1993 //--            if (Players[Player_num].flags & PLAYER_FLAGS_RED_KEY) {
1994 //--                    playerobj->contains_count = 1;
1995 //--                    playerobj->contains_type = OBJ_POWERUP;
1996 //--                    playerobj->contains_id = POW_KEY_RED;
1997 //--                    object_create_egg(playerobj);
1998 //--            }
1999 //--            if (Players[Player_num].flags & PLAYER_FLAGS_GOLD_KEY) {
2000 //--                    playerobj->contains_count = 1;
2001 //--                    playerobj->contains_type = OBJ_POWERUP;
2002 //--                    playerobj->contains_id = POW_KEY_GOLD;
2003 //--                    object_create_egg(playerobj);
2004 //--            }
2005
2006 // --           if (Items_destroyed) {
2007 // --                   if (Items_destroyed == 1)
2008 // --                           HUD_init_message("%i item was destroyed.", Items_destroyed);
2009 // --                   else
2010 // --                           HUD_init_message("%i items were destroyed.", Items_destroyed);
2011 // --                   Items_destroyed = 0;
2012 // --           }
2013         }
2014
2015 }
2016
2017 // -- removed, 09/06/95, MK -- void destroy_primary_weapon(int weapon_index)
2018 // -- removed, 09/06/95, MK -- {
2019 // -- removed, 09/06/95, MK --  if (weapon_index == MAX_PRIMARY_WEAPONS) {
2020 // -- removed, 09/06/95, MK --          HUD_init_message("Quad lasers destroyed!");
2021 // -- removed, 09/06/95, MK --          Players[Player_num].flags &= ~PLAYER_FLAGS_QUAD_LASERS;
2022 // -- removed, 09/06/95, MK --          update_laser_weapon_info();
2023 // -- removed, 09/06/95, MK --  } else if (weapon_index == 0) {
2024 // -- removed, 09/06/95, MK --          Assert(Players[Player_num].laser_level > 0);
2025 // -- removed, 09/06/95, MK --          HUD_init_message("%s degraded!", Text_string[104+weapon_index]);                //      Danger! Danger! Use of literal!  Danger!
2026 // -- removed, 09/06/95, MK --          Players[Player_num].laser_level--;
2027 // -- removed, 09/06/95, MK --          update_laser_weapon_info();
2028 // -- removed, 09/06/95, MK --  } else {
2029 // -- removed, 09/06/95, MK --          HUD_init_message("%s destroyed!", Text_string[104+weapon_index]);               //      Danger! Danger! Use of literal!  Danger!
2030 // -- removed, 09/06/95, MK --          Players[Player_num].primary_weapon_flags &= ~(1 << weapon_index);
2031 // -- removed, 09/06/95, MK --          auto_select_weapon(0);
2032 // -- removed, 09/06/95, MK --  }
2033 // -- removed, 09/06/95, MK -- 
2034 // -- removed, 09/06/95, MK -- }
2035 // -- removed, 09/06/95, MK -- 
2036 // -- removed, 09/06/95, MK -- void destroy_secondary_weapon(int weapon_index)
2037 // -- removed, 09/06/95, MK -- {
2038 // -- removed, 09/06/95, MK --  if (Players[Player_num].secondary_ammo <= 0)
2039 // -- removed, 09/06/95, MK --          return;
2040 // -- removed, 09/06/95, MK -- 
2041 // -- removed, 09/06/95, MK --  HUD_init_message("%s destroyed!", Text_string[114+weapon_index]);               //      Danger! Danger! Use of literal!  Danger!
2042 // -- removed, 09/06/95, MK --  if (--Players[Player_num].secondary_ammo[weapon_index] == 0)
2043 // -- removed, 09/06/95, MK --          auto_select_weapon(1);
2044 // -- removed, 09/06/95, MK -- 
2045 // -- removed, 09/06/95, MK -- }
2046 // -- removed, 09/06/95, MK -- 
2047 // -- removed, 09/06/95, MK -- #define  LOSE_WEAPON_THRESHOLD   (F1_0*30)
2048
2049 extern fix Buddy_sorry_time;
2050
2051 void apply_damage_to_player(object *playerobj, object *killer, fix damage)
2052 {
2053         if (Player_is_dead)
2054                 return;
2055
2056         if (Players[Player_num].flags & PLAYER_FLAGS_INVULNERABLE)
2057                 return;
2058
2059         if (Endlevel_sequence)
2060                 return;
2061
2062         //for the player, the 'real' shields are maintained in the Players[]
2063         //array.  The shields value in the player's object are, I think, not
2064         //used anywhere.  This routine, however, sets the objects shields to
2065         //be a mirror of the value in the Player structure. 
2066
2067         if (playerobj->id == Player_num) {              //is this the local player?
2068
2069                 //      MK: 08/14/95: This code can never be reached.  See the return about 12 lines up.
2070 // --           if (Players[Player_num].flags & PLAYER_FLAGS_INVULNERABLE) {
2071 // -- 
2072 // --                   //invincible, so just do blue flash
2073 // -- 
2074 // --                   PALETTE_FLASH_ADD(0,0,f2i(damage)*4);   //flash blue
2075 // -- 
2076 // --           } 
2077 // --           else {          //take damage, do red flash
2078
2079                         Players[Player_num].shields -= damage;
2080
2081                         PALETTE_FLASH_ADD(f2i(damage)*4,-f2i(damage/2),-f2i(damage/2)); //flash red
2082
2083 // --           }
2084
2085                 if (Players[Player_num].shields < 0)    {
2086
2087                         Players[Player_num].killer_objnum = OBJECT_NUMBER(killer);
2088                         
2089 //                      if ( killer && (killer->type == OBJ_PLAYER))
2090 //                              Players[Player_num].killer_objnum = OBJECT_NUMBER(killer);
2091
2092                         playerobj->flags |= OF_SHOULD_BE_DEAD;
2093
2094                         if (Buddy_objnum != -1)
2095                                 if (killer && (killer->type == OBJ_ROBOT) && (Robot_info[killer->id].companion))
2096                                         Buddy_sorry_time = GameTime;
2097                 }
2098 // -- removed, 09/06/95, MK --  else if (Players[Player_num].shields < LOSE_WEAPON_THRESHOLD) {
2099 // -- removed, 09/06/95, MK --                  int     randnum = d_rand();
2100 // -- removed, 09/06/95, MK -- 
2101 // -- removed, 09/06/95, MK --                  if (fixmul(Players[Player_num].shields, randnum) < damage/4) {
2102 // -- removed, 09/06/95, MK --                          if (d_rand() > 20000) {
2103 // -- removed, 09/06/95, MK --                                  destroy_secondary_weapon(Secondary_weapon);
2104 // -- removed, 09/06/95, MK --                          } else if (Primary_weapon == 0) {
2105 // -- removed, 09/06/95, MK --                                  if (Players[Player_num].flags & PLAYER_FLAGS_QUAD_LASERS)
2106 // -- removed, 09/06/95, MK --                                          destroy_primary_weapon(MAX_PRIMARY_WEAPONS);    //      This means to destroy quad laser.
2107 // -- removed, 09/06/95, MK --                                  else if (Players[Player_num].laser_level > 0)
2108 // -- removed, 09/06/95, MK --                                          destroy_primary_weapon(Primary_weapon);
2109 // -- removed, 09/06/95, MK --                          } else
2110 // -- removed, 09/06/95, MK --                                  destroy_primary_weapon(Primary_weapon);
2111 // -- removed, 09/06/95, MK --                  } else
2112 // -- removed, 09/06/95, MK --                          ; // mprintf((0, "%8x > %8x, so don't lose weapon.\n", fixmul(Players[Player_num].shields, randnum), damage/4));
2113 // -- removed, 09/06/95, MK --          }
2114
2115                 playerobj->shields = Players[Player_num].shields;               //mirror
2116
2117         }
2118 }
2119
2120 void collide_player_and_weapon( object * playerobj, object * weapon, vms_vector *collision_point )
2121 {
2122         fix             damage = weapon->shields;
2123         object * killer=NULL;
2124
2125         //      In multiplayer games, only do damage to another player if in first frame.
2126         //      This is necessary because in multiplayer, due to varying framerates, omega blobs actually
2127         //      have a bit of a lifetime.  But they start out with a lifetime of ONE_FRAME_TIME, and this
2128         //      gets bashed to 1/4 second in laser_do_weapon_sequence.  This bashing occurs for visual purposes only.
2129         if (weapon->id == OMEGA_ID)
2130                 if (!ok_to_do_omega_damage(weapon))
2131                         return;
2132
2133         //      Don't collide own smart mines unless direct hit.
2134         if (weapon->id == SUPERPROX_ID)
2135                 if (OBJECT_NUMBER(playerobj) == weapon->ctype.laser_info.parent_num)
2136                         if (vm_vec_dist_quick(collision_point, &playerobj->pos) > playerobj->size)
2137                                 return;
2138
2139         if (weapon->id == EARTHSHAKER_ID)
2140                 smega_rock_stuff();
2141
2142         damage = fixmul(damage, weapon->ctype.laser_info.multiplier);
2143 #ifndef SHAREWARE
2144         if (Game_mode & GM_MULTI)
2145                 damage = fixmul(damage, Weapon_info[weapon->id].multi_damage_scale);
2146 #endif
2147
2148         if (weapon->mtype.phys_info.flags & PF_PERSISTENT)
2149         {
2150                 if (weapon->ctype.laser_info.last_hitobj == OBJECT_NUMBER(playerobj))
2151                         return;
2152                 else
2153                         weapon->ctype.laser_info.last_hitobj = OBJECT_NUMBER(playerobj);
2154         }
2155
2156         if (playerobj->id == Player_num)
2157         {
2158                 if (!(Players[Player_num].flags & PLAYER_FLAGS_INVULNERABLE))
2159                 {
2160                         digi_link_sound_to_pos( SOUND_PLAYER_GOT_HIT, playerobj->segnum, 0, collision_point, 0, F1_0 );
2161                         #ifdef NETWORK
2162                         if (Game_mode & GM_MULTI)
2163                                 multi_send_play_sound(SOUND_PLAYER_GOT_HIT, F1_0);
2164                         #endif
2165                 }
2166                 else
2167                 {
2168                         digi_link_sound_to_pos( SOUND_WEAPON_HIT_DOOR, playerobj->segnum, 0, collision_point, 0, F1_0);
2169                         #ifdef NETWORK
2170                         if (Game_mode & GM_MULTI)
2171                                 multi_send_play_sound(SOUND_WEAPON_HIT_DOOR, F1_0);
2172                         #endif
2173                 }
2174         }
2175
2176         object_create_explosion( playerobj->segnum, collision_point, i2f(10)/2, VCLIP_PLAYER_HIT );
2177         if ( Weapon_info[weapon->id].damage_radius )
2178                 explode_badass_weapon(weapon,collision_point);
2179
2180         maybe_kill_weapon(weapon,playerobj);
2181
2182         bump_two_objects(playerobj, weapon, 0); //no damage from bump
2183
2184         if ( !Weapon_info[weapon->id].damage_radius ) {
2185                 if ( weapon->ctype.laser_info.parent_num > -1 )
2186                         killer = &Objects[weapon->ctype.laser_info.parent_num];
2187
2188 //              if (weapon->id == SMART_HOMING_ID)
2189 //                      damage /= 4;
2190
2191                 if (!(weapon->flags & OF_HARMLESS))
2192                         apply_damage_to_player( playerobj, killer, damage);
2193         }
2194
2195         //      Robots become aware of you if you get hit.
2196         ai_do_cloak_stuff();
2197
2198         return; 
2199 }
2200
2201 //      Nasty robots are the ones that attack you by running into you and doing lots of damage.
2202 void collide_player_and_nasty_robot( object * playerobj, object * robot, vms_vector *collision_point )
2203 {
2204 //      if (!(Robot_info[robot->id].energy_drain && Players[playerobj->id].energy))
2205                 digi_link_sound_to_pos( Robot_info[robot->id].claw_sound, playerobj->segnum, 0, collision_point, 0, F1_0 );
2206
2207         object_create_explosion( playerobj->segnum, collision_point, i2f(10)/2, VCLIP_PLAYER_HIT );
2208
2209         bump_two_objects(playerobj, robot, 0);  //no damage from bump
2210
2211         apply_damage_to_player( playerobj, robot, F1_0*(Difficulty_level+1));
2212
2213         return; 
2214 }
2215
2216 void collide_player_and_materialization_center(object *objp)
2217 {
2218         int     side;
2219         vms_vector      exit_dir;
2220         segment *segp = &Segments[objp->segnum];
2221
2222         digi_link_sound_to_pos(SOUND_PLAYER_GOT_HIT, objp->segnum, 0, &objp->pos, 0, F1_0);
2223 //      digi_play_sample( SOUND_PLAYER_GOT_HIT, F1_0 );
2224
2225         object_create_explosion( objp->segnum, &objp->pos, i2f(10)/2, VCLIP_PLAYER_HIT );
2226
2227         if (objp->id != Player_num)
2228                 return;
2229
2230         for (side=0; side<MAX_SIDES_PER_SEGMENT; side++)
2231                 if (WALL_IS_DOORWAY(segp, side) & WID_FLY_FLAG) {
2232                         vms_vector      exit_point, rand_vec;
2233
2234                         compute_center_point_on_side(&exit_point, segp, side);
2235                         vm_vec_sub(&exit_dir, &exit_point, &objp->pos);
2236                         vm_vec_normalize_quick(&exit_dir);
2237                         make_random_vector(&rand_vec);
2238                         rand_vec.x /= 4;        rand_vec.y /= 4;        rand_vec.z /= 4;
2239                         vm_vec_add2(&exit_dir, &rand_vec);
2240                         vm_vec_normalize_quick(&exit_dir);
2241                 }
2242
2243         bump_one_object(objp, &exit_dir, 64*F1_0);
2244
2245         apply_damage_to_player( objp, objp, 4*F1_0);    //      Changed, MK, 2/19/96, make killer the player, so if you die in matcen, will say you killed yourself
2246
2247         return; 
2248
2249 }
2250
2251 void collide_robot_and_materialization_center(object *objp)
2252 {
2253         int     side;
2254         vms_vector      exit_dir;
2255         segment *segp=&Segments[objp->segnum];
2256
2257         digi_link_sound_to_pos(SOUND_ROBOT_HIT, objp->segnum, 0, &objp->pos, 0, F1_0);
2258 //      digi_play_sample( SOUND_ROBOT_HIT, F1_0 );
2259
2260         if ( Robot_info[objp->id].exp1_vclip_num > -1 )
2261                 object_create_explosion( objp->segnum, &objp->pos, (objp->size/2*3)/4, Robot_info[objp->id].exp1_vclip_num );
2262
2263         for (side=0; side<MAX_SIDES_PER_SEGMENT; side++)
2264                 if (WALL_IS_DOORWAY(segp, side) & WID_FLY_FLAG) {
2265                         vms_vector      exit_point;
2266
2267                         compute_center_point_on_side(&exit_point, segp, side);
2268                         vm_vec_sub(&exit_dir, &exit_point, &objp->pos);
2269                         vm_vec_normalize_quick(&exit_dir);
2270                 }
2271
2272         bump_one_object(objp, &exit_dir, 8*F1_0);
2273
2274         apply_damage_to_robot( objp, F1_0, -1);
2275
2276         return; 
2277
2278 }
2279
2280 //##void collide_player_and_camera( object * playerobj, object * camera, vms_vector *collision_point ) { 
2281 //##    return; 
2282 //##}
2283
2284 extern int Network_got_powerup; // HACK!!!
2285
2286 void collide_player_and_powerup( object * playerobj, object * powerup, vms_vector *collision_point ) { 
2287         if (!Endlevel_sequence && !Player_is_dead && (playerobj->id == Player_num )) {
2288                 int powerup_used;
2289
2290                 powerup_used = do_powerup(powerup);
2291                 
2292                 if (powerup_used)       {
2293                         powerup->flags |= OF_SHOULD_BE_DEAD;
2294                         #ifdef NETWORK
2295                         if (Game_mode & GM_MULTI)
2296                                 multi_send_remobj(OBJECT_NUMBER(powerup));
2297                         #endif
2298                 }
2299         }
2300 #ifndef SHAREWARE
2301         else if ((Game_mode & GM_MULTI_COOP) && (playerobj->id != Player_num))
2302         {
2303                 switch (powerup->id) {
2304                         case POW_KEY_BLUE:      
2305                                 Players[playerobj->id].flags |= PLAYER_FLAGS_BLUE_KEY;
2306                                 break;
2307                         case POW_KEY_RED:       
2308                                 Players[playerobj->id].flags |= PLAYER_FLAGS_RED_KEY;
2309                                 break;
2310                         case POW_KEY_GOLD:      
2311                                 Players[playerobj->id].flags |= PLAYER_FLAGS_GOLD_KEY;
2312                                 break;
2313                         default:
2314                                 break;
2315                 }
2316         }
2317 #endif
2318         return; 
2319 }
2320
2321 //##void collide_player_and_debris( object * playerobj, object * debris, vms_vector *collision_point ) { 
2322 //##    return; 
2323 //##}
2324
2325 void collide_player_and_clutter( object * playerobj, object * clutter, vms_vector *collision_point ) { 
2326         digi_link_sound_to_pos( SOUND_ROBOT_HIT_PLAYER, playerobj->segnum, 0, collision_point, 0, F1_0 );
2327         bump_two_objects(clutter, playerobj, 1);
2328         return; 
2329 }
2330
2331 //      See if weapon1 creates a badass explosion.  If so, create the explosion
2332 //      Return true if weapon does proximity (as opposed to only contact) damage when it explodes.
2333 int maybe_detonate_weapon(object *weapon1, object *weapon2, vms_vector *collision_point)
2334 {
2335         if ( Weapon_info[weapon1->id].damage_radius ) {
2336                 fix     dist;
2337
2338                 dist = vm_vec_dist_quick(&weapon1->pos, &weapon2->pos);
2339                 if (dist < F1_0*5) {
2340                         maybe_kill_weapon(weapon1,weapon2);
2341                         if (weapon1->flags & OF_SHOULD_BE_DEAD) {
2342                                 explode_badass_weapon(weapon1,collision_point);
2343                                 digi_link_sound_to_pos( Weapon_info[weapon1->id].robot_hit_sound, weapon1->segnum , 0, collision_point, 0, F1_0 );
2344                         }
2345                         return 1;
2346                 } else {
2347                         weapon1->lifeleft = min(dist/64, F1_0);
2348                         return 1;
2349                 }
2350         } else
2351                 return 0;
2352 }
2353
2354 void collide_weapon_and_weapon( object * weapon1, object * weapon2, vms_vector *collision_point )
2355
2356         // -- Does this look buggy??:  if (weapon1->id == PMINE_ID && weapon1->id == PMINE_ID)
2357         if (weapon1->id == PMINE_ID && weapon2->id == PMINE_ID)
2358                 return;         //these can't blow each other up  
2359
2360         if (weapon1->id == OMEGA_ID) {
2361                 if (!ok_to_do_omega_damage(weapon1))
2362                         return;
2363         } else if (weapon2->id == OMEGA_ID) {
2364                 if (!ok_to_do_omega_damage(weapon2))
2365                         return;
2366         }
2367
2368         if ((Weapon_info[weapon1->id].destroyable) || (Weapon_info[weapon2->id].destroyable)) {
2369
2370                 //      Bug reported by Adam Q. Pletcher on September 9, 1994, smart bomb homing missiles were toasting each other.
2371                 if ((weapon1->id == weapon2->id) && (weapon1->ctype.laser_info.parent_num == weapon2->ctype.laser_info.parent_num))
2372                         return;
2373
2374                 if (Weapon_info[weapon1->id].destroyable)
2375                         if (maybe_detonate_weapon(weapon1, weapon2, collision_point))
2376                                 maybe_detonate_weapon(weapon2,weapon1, collision_point);
2377
2378                 if (Weapon_info[weapon2->id].destroyable)
2379                         if (maybe_detonate_weapon(weapon2, weapon1, collision_point))
2380                                 maybe_detonate_weapon(weapon1,weapon2, collision_point);
2381
2382         }
2383
2384 }
2385
2386 //##void collide_weapon_and_camera( object * weapon, object * camera, vms_vector *collision_point ) { 
2387 //##    return; 
2388 //##}
2389
2390 //##void collide_weapon_and_powerup( object * weapon, object * powerup, vms_vector *collision_point ) { 
2391 //##    return; 
2392 //##}
2393
2394 void collide_weapon_and_debris( object * weapon, object * debris, vms_vector *collision_point ) { 
2395
2396         //      Hack!  Prevent debris from causing bombs spewed at player death to detonate!
2397         if ((weapon->id == PROXIMITY_ID) || (weapon->id == SUPERPROX_ID)) {
2398                 if (weapon->ctype.laser_info.creation_time + F1_0/2 > GameTime)
2399                         return;
2400         }
2401
2402         if ( (weapon->ctype.laser_info.parent_type==OBJ_PLAYER) && !(debris->flags & OF_EXPLODING) )    {       
2403                 digi_link_sound_to_pos( SOUND_ROBOT_HIT, weapon->segnum , 0, collision_point, 0, F1_0 );
2404
2405                 explode_object(debris,0);
2406                 if ( Weapon_info[weapon->id].damage_radius )
2407                         explode_badass_weapon(weapon,collision_point);
2408                 maybe_kill_weapon(weapon,debris);
2409                 weapon->flags |= OF_SHOULD_BE_DEAD;
2410         }
2411         return; 
2412 }
2413
2414 //##void collide_camera_and_camera( object * camera1, object * camera2, vms_vector *collision_point ) { 
2415 //##    return; 
2416 //##}
2417
2418 //##void collide_camera_and_powerup( object * camera, object * powerup, vms_vector *collision_point ) { 
2419 //##    return; 
2420 //##}
2421
2422 //##void collide_camera_and_debris( object * camera, object * debris, vms_vector *collision_point ) { 
2423 //##    return; 
2424 //##}
2425
2426 //##void collide_powerup_and_powerup( object * powerup1, object * powerup2, vms_vector *collision_point ) { 
2427 //##    return; 
2428 //##}
2429
2430 //##void collide_powerup_and_debris( object * powerup, object * debris, vms_vector *collision_point ) { 
2431 //##    return; 
2432 //##}
2433
2434 //##void collide_debris_and_debris( object * debris1, object * debris2, vms_vector *collision_point ) { 
2435 //##    return; 
2436 //##}
2437
2438
2439 /* DPH: Put these macros on one long line to avoid CR/LF problems on linux */
2440 #define COLLISION_OF(a,b) (((a)<<8) + (b))
2441
2442 #define DO_COLLISION(type1,type2,collision_function)    case COLLISION_OF( (type1), (type2) ):  (collision_function)( (A), (B), collision_point ); break;   case COLLISION_OF( (type2), (type1) ):  (collision_function)( (B), (A), collision_point );  break;
2443
2444 #define DO_SAME_COLLISION(type1,type2,collision_function)    case COLLISION_OF( (type1), (type1) ):  (collision_function)( (A), (B), collision_point ); break;
2445
2446 //these next two macros define a case that does nothing
2447 #define NO_COLLISION(type1,type2,collision_function)    case COLLISION_OF( (type1), (type2) ):  break;  case COLLISION_OF( (type2), (type1) ):  break;
2448
2449 #define NO_SAME_COLLISION(type1,type2,collision_function)    case COLLISION_OF( (type1), (type1) ):    break;
2450
2451 /* DPH: These ones are never used so I'm not going to bother */
2452 #ifndef __GNUC__
2453 #define IGNORE_COLLISION(type1,type2,collision_function)                                        \
2454         case COLLISION_OF( (type1), (type2) ):                                                                          \
2455                 break;                                                                                                                                                  \
2456         case COLLISION_OF( (type2), (type1) ):                                                                          \
2457                 break;
2458
2459 #define ERROR_COLLISION(type1,type2,collision_function)                                 \
2460         case COLLISION_OF( (type1), (type2) ):                                                                          \
2461                 Error( "Error in collision type!" );                                                                    \
2462                 break;                                                                                                                                                  \
2463         case COLLISION_OF( (type2), (type1) ):                                                                          \
2464                 Error( "Error in collision type!" );                                                                    \
2465                 break;
2466 #endif
2467
2468 void collide_two_objects( object * A, object * B, vms_vector *collision_point )
2469 {
2470         int collision_type;     
2471                 
2472         collision_type = COLLISION_OF(A->type,B->type);
2473
2474         //mprintf( (0, "Object %d of type %d collided with object %d of type %d\n", OBJECT_NUMBER(A), A->type, OBJECT_NUMBER(B), B->type) );
2475
2476         switch( collision_type )        {
2477         NO_SAME_COLLISION( OBJ_FIREBALL, OBJ_FIREBALL,   collide_fireball_and_fireball )
2478         DO_SAME_COLLISION( OBJ_ROBOT, OBJ_ROBOT, collide_robot_and_robot )
2479         NO_SAME_COLLISION( OBJ_HOSTAGE, OBJ_HOSTAGE,  collide_hostage_and_hostage )
2480         DO_SAME_COLLISION( OBJ_PLAYER, OBJ_PLAYER,  collide_player_and_player )
2481         DO_SAME_COLLISION( OBJ_WEAPON, OBJ_WEAPON,  collide_weapon_and_weapon )
2482         NO_SAME_COLLISION( OBJ_CAMERA, OBJ_CAMERA, collide_camera_and_camera )
2483         NO_SAME_COLLISION( OBJ_POWERUP, OBJ_POWERUP,  collide_powerup_and_powerup )
2484         NO_SAME_COLLISION( OBJ_DEBRIS, OBJ_DEBRIS,  collide_debris_and_debris )
2485         NO_SAME_COLLISION( OBJ_MARKER, OBJ_MARKER,  NULL )
2486         NO_COLLISION( OBJ_FIREBALL, OBJ_ROBOT,   collide_fireball_and_robot )
2487         NO_COLLISION( OBJ_FIREBALL, OBJ_HOSTAGE, collide_fireball_and_hostage )
2488         NO_COLLISION( OBJ_FIREBALL, OBJ_PLAYER,  collide_fireball_and_player )
2489         NO_COLLISION( OBJ_FIREBALL, OBJ_WEAPON,  collide_fireball_and_weapon )
2490         NO_COLLISION( OBJ_FIREBALL, OBJ_CAMERA,  collide_fireball_and_camera )
2491         NO_COLLISION( OBJ_FIREBALL, OBJ_POWERUP, collide_fireball_and_powerup )
2492         NO_COLLISION( OBJ_FIREBALL, OBJ_DEBRIS,  collide_fireball_and_debris )
2493         NO_COLLISION( OBJ_ROBOT, OBJ_HOSTAGE, collide_robot_and_hostage )
2494         DO_COLLISION( OBJ_ROBOT, OBJ_PLAYER,  collide_robot_and_player )
2495         DO_COLLISION( OBJ_ROBOT, OBJ_WEAPON,  collide_robot_and_weapon )
2496         NO_COLLISION( OBJ_ROBOT, OBJ_CAMERA,  collide_robot_and_camera )
2497         NO_COLLISION( OBJ_ROBOT, OBJ_POWERUP, collide_robot_and_powerup )
2498         NO_COLLISION( OBJ_ROBOT, OBJ_DEBRIS,  collide_robot_and_debris )
2499         DO_COLLISION( OBJ_HOSTAGE, OBJ_PLAYER,  collide_hostage_and_player )
2500         NO_COLLISION( OBJ_HOSTAGE, OBJ_WEAPON,  collide_hostage_and_weapon )
2501         NO_COLLISION( OBJ_HOSTAGE, OBJ_CAMERA,  collide_hostage_and_camera )
2502         NO_COLLISION( OBJ_HOSTAGE, OBJ_POWERUP, collide_hostage_and_powerup )
2503         NO_COLLISION( OBJ_HOSTAGE, OBJ_DEBRIS,  collide_hostage_and_debris )
2504         DO_COLLISION( OBJ_PLAYER, OBJ_WEAPON,  collide_player_and_weapon )
2505         NO_COLLISION( OBJ_PLAYER, OBJ_CAMERA,  collide_player_and_camera )
2506         DO_COLLISION( OBJ_PLAYER, OBJ_POWERUP, collide_player_and_powerup )
2507         NO_COLLISION( OBJ_PLAYER, OBJ_DEBRIS,  collide_player_and_debris )
2508         DO_COLLISION( OBJ_PLAYER, OBJ_CNTRLCEN, collide_player_and_controlcen )
2509         DO_COLLISION( OBJ_PLAYER, OBJ_CLUTTER, collide_player_and_clutter )
2510         NO_COLLISION( OBJ_WEAPON, OBJ_CAMERA,  collide_weapon_and_camera )
2511         NO_COLLISION( OBJ_WEAPON, OBJ_POWERUP, collide_weapon_and_powerup )
2512         DO_COLLISION( OBJ_WEAPON, OBJ_DEBRIS,  collide_weapon_and_debris )
2513         NO_COLLISION( OBJ_CAMERA, OBJ_POWERUP, collide_camera_and_powerup )
2514         NO_COLLISION( OBJ_CAMERA, OBJ_DEBRIS,  collide_camera_and_debris )
2515         NO_COLLISION( OBJ_POWERUP, OBJ_DEBRIS,  collide_powerup_and_debris )
2516         DO_COLLISION( OBJ_WEAPON, OBJ_CNTRLCEN, collide_weapon_and_controlcen )
2517         DO_COLLISION( OBJ_ROBOT, OBJ_CNTRLCEN, collide_robot_and_controlcen )
2518         DO_COLLISION( OBJ_WEAPON, OBJ_CLUTTER, collide_weapon_and_clutter )
2519
2520         DO_COLLISION( OBJ_MARKER, OBJ_PLAYER,  collide_player_and_marker)
2521         NO_COLLISION( OBJ_MARKER, OBJ_ROBOT,   NULL)
2522         NO_COLLISION( OBJ_MARKER, OBJ_HOSTAGE, NULL)
2523         NO_COLLISION( OBJ_MARKER, OBJ_WEAPON,  NULL)
2524         NO_COLLISION( OBJ_MARKER, OBJ_CAMERA,  NULL)
2525         NO_COLLISION( OBJ_MARKER, OBJ_POWERUP, NULL)
2526         NO_COLLISION( OBJ_MARKER, OBJ_DEBRIS,  NULL)
2527
2528         default:
2529                 Int3(); //Error( "Unhandled collision_type in collide.c!\n" );
2530         }
2531 }
2532
2533 #define ENABLE_COLLISION(type1,type2)                                   \
2534         CollisionResult[type1][type2] = RESULT_CHECK;   \
2535         CollisionResult[type2][type1] = RESULT_CHECK;
2536
2537 #define DISABLE_COLLISION(type1,type2)                                  \
2538         CollisionResult[type1][type2] = RESULT_NOTHING; \
2539         CollisionResult[type2][type1] = RESULT_NOTHING;
2540
2541 void collide_init()     {
2542         int i, j;
2543
2544         for (i=0; i < MAX_OBJECT_TYPES; i++ )
2545                 for (j=0; j < MAX_OBJECT_TYPES; j++ )
2546                         CollisionResult[i][j] = RESULT_NOTHING;
2547
2548         ENABLE_COLLISION( OBJ_WALL, OBJ_ROBOT );
2549         ENABLE_COLLISION( OBJ_WALL, OBJ_WEAPON );
2550         ENABLE_COLLISION( OBJ_WALL, OBJ_PLAYER  );
2551         DISABLE_COLLISION( OBJ_FIREBALL, OBJ_FIREBALL );
2552
2553         ENABLE_COLLISION( OBJ_ROBOT, OBJ_ROBOT );
2554 //      DISABLE_COLLISION( OBJ_ROBOT, OBJ_ROBOT );      //      ALERT: WARNING: HACK: MK = RESPONSIBLE! TESTING!!
2555
2556         DISABLE_COLLISION( OBJ_HOSTAGE, OBJ_HOSTAGE );
2557         ENABLE_COLLISION( OBJ_PLAYER, OBJ_PLAYER );
2558         ENABLE_COLLISION( OBJ_WEAPON, OBJ_WEAPON );
2559         DISABLE_COLLISION( OBJ_CAMERA, OBJ_CAMERA );
2560         DISABLE_COLLISION( OBJ_POWERUP, OBJ_POWERUP );
2561         DISABLE_COLLISION( OBJ_DEBRIS, OBJ_DEBRIS );
2562         DISABLE_COLLISION( OBJ_FIREBALL, OBJ_ROBOT );
2563         DISABLE_COLLISION( OBJ_FIREBALL, OBJ_HOSTAGE );
2564         DISABLE_COLLISION( OBJ_FIREBALL, OBJ_PLAYER );
2565         DISABLE_COLLISION( OBJ_FIREBALL, OBJ_WEAPON );
2566         DISABLE_COLLISION( OBJ_FIREBALL, OBJ_CAMERA );
2567         DISABLE_COLLISION( OBJ_FIREBALL, OBJ_POWERUP );
2568         DISABLE_COLLISION( OBJ_FIREBALL, OBJ_DEBRIS );
2569         DISABLE_COLLISION( OBJ_ROBOT, OBJ_HOSTAGE );
2570         ENABLE_COLLISION( OBJ_ROBOT, OBJ_PLAYER );
2571         ENABLE_COLLISION( OBJ_ROBOT, OBJ_WEAPON );
2572         DISABLE_COLLISION( OBJ_ROBOT, OBJ_CAMERA );
2573         DISABLE_COLLISION( OBJ_ROBOT, OBJ_POWERUP );
2574         DISABLE_COLLISION( OBJ_ROBOT, OBJ_DEBRIS );
2575         ENABLE_COLLISION( OBJ_HOSTAGE, OBJ_PLAYER );
2576         ENABLE_COLLISION( OBJ_HOSTAGE, OBJ_WEAPON );
2577         DISABLE_COLLISION( OBJ_HOSTAGE, OBJ_CAMERA );
2578         DISABLE_COLLISION( OBJ_HOSTAGE, OBJ_POWERUP );
2579         DISABLE_COLLISION( OBJ_HOSTAGE, OBJ_DEBRIS );
2580         ENABLE_COLLISION( OBJ_PLAYER, OBJ_WEAPON );
2581         DISABLE_COLLISION( OBJ_PLAYER, OBJ_CAMERA );
2582         ENABLE_COLLISION( OBJ_PLAYER, OBJ_POWERUP );
2583         DISABLE_COLLISION( OBJ_PLAYER, OBJ_DEBRIS );
2584         DISABLE_COLLISION( OBJ_WEAPON, OBJ_CAMERA );
2585         DISABLE_COLLISION( OBJ_WEAPON, OBJ_POWERUP );
2586         ENABLE_COLLISION( OBJ_WEAPON, OBJ_DEBRIS );
2587         DISABLE_COLLISION( OBJ_CAMERA, OBJ_POWERUP );
2588         DISABLE_COLLISION( OBJ_CAMERA, OBJ_DEBRIS );
2589         DISABLE_COLLISION( OBJ_POWERUP, OBJ_DEBRIS );
2590         ENABLE_COLLISION( OBJ_POWERUP, OBJ_WALL );
2591         ENABLE_COLLISION( OBJ_WEAPON, OBJ_CNTRLCEN )
2592         ENABLE_COLLISION( OBJ_WEAPON, OBJ_CLUTTER )
2593         ENABLE_COLLISION( OBJ_PLAYER, OBJ_CNTRLCEN )
2594         ENABLE_COLLISION( OBJ_ROBOT, OBJ_CNTRLCEN )
2595         ENABLE_COLLISION( OBJ_PLAYER, OBJ_CLUTTER )
2596
2597         ENABLE_COLLISION( OBJ_PLAYER, OBJ_MARKER );
2598
2599 }
2600
2601 void collide_object_with_wall( object * A, fix hitspeed, short hitseg, short hitwall, vms_vector * hitpt )
2602 {
2603
2604         switch( A->type )       {
2605         case OBJ_NONE:
2606                 Error( "A object of type NONE hit a wall!\n");
2607                 break;
2608         case OBJ_PLAYER:                collide_player_and_wall(A,hitspeed,hitseg,hitwall,hitpt); break;
2609         case OBJ_WEAPON:                collide_weapon_and_wall(A,hitspeed,hitseg,hitwall,hitpt); break;
2610         case OBJ_DEBRIS:                collide_debris_and_wall(A,hitspeed,hitseg,hitwall,hitpt); break;
2611
2612         case OBJ_FIREBALL:      break;          //collide_fireball_and_wall(A,hitspeed,hitseg,hitwall,hitpt); 
2613         case OBJ_ROBOT:         collide_robot_and_wall(A,hitspeed,hitseg,hitwall,hitpt); break;
2614         case OBJ_HOSTAGE:               break;          //collide_hostage_and_wall(A,hitspeed,hitseg,hitwall,hitpt); 
2615         case OBJ_CAMERA:                break;          //collide_camera_and_wall(A,hitspeed,hitseg,hitwall,hitpt); 
2616         case OBJ_POWERUP:               break;          //collide_powerup_and_wall(A,hitspeed,hitseg,hitwall,hitpt); 
2617         case OBJ_GHOST:         break;  //do nothing
2618
2619         default:
2620                 Error( "Unhandled object type hit wall in collide.c\n" );
2621         }
2622 }
2623
2624