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