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