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