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