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