1 /* $Id: object.c,v 1.16 2004-08-28 23:17:45 schaffner Exp $ */
3 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
4 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
5 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
6 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
7 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
8 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
9 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
10 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
11 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
12 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
29 #include <string.h> // for memset
91 #include "editor/editor.h"
98 void obj_detach_all(object *parent);
99 void obj_detach_one(object *sub);
100 int free_object_slots(int num_used);
106 extern sbyte WasRecorded[MAX_OBJECTS];
108 ubyte CollisionResult[MAX_OBJECT_TYPES][MAX_OBJECT_TYPES];
110 object *ConsoleObject; //the object that is the player
112 static short free_obj_list[MAX_OBJECTS];
118 //info on the various types of objects
120 object Object_minus_one;
123 object Objects[MAX_OBJECTS];
125 int Highest_object_index=0;
126 int Highest_ever_object_index=0;
128 // grs_bitmap *robot_bms[MAX_ROBOT_BITMAPS]; //all bitmaps for all robots
130 // int robot_bm_nums[MAX_ROBOT_TYPES]; //starting bitmap num for each robot
131 // int robot_n_bitmaps[MAX_ROBOT_TYPES]; //how many bitmaps for each robot
133 // char *robot_names[MAX_ROBOT_TYPES]; //name of each robot
135 //--unused-- int Num_robot_types=0;
137 int print_object_info = 0;
138 //@@int Object_viewer = 0;
140 //object * Slew_object = NULL; // Object containing slew object info.
142 //--unused-- int Player_controller_type = 0;
144 window_rendered_data Window_rendered_data[MAX_RENDERED_WINDOWS];
147 char Object_type_names[MAX_OBJECT_TYPES][9] = {
168 //set viewer object to next object in array
169 void object_goto_next_viewer()
171 int i, start_obj = 0;
173 start_obj = Viewer - Objects; //get viewer object number
175 for (i=0;i<=Highest_object_index;i++) {
178 if (start_obj > Highest_object_index ) start_obj = 0;
180 if (Objects[start_obj].type != OBJ_NONE ) {
181 Viewer = &Objects[start_obj];
186 Error( "Couldn't find a viewer object!" );
190 //set viewer object to next object in array
191 void object_goto_prev_viewer()
193 int i, start_obj = 0;
195 start_obj = Viewer - Objects; //get viewer object number
197 for (i=0; i<=Highest_object_index; i++) {
200 if (start_obj < 0 ) start_obj = Highest_object_index;
202 if (Objects[start_obj].type != OBJ_NONE ) {
203 Viewer = &Objects[start_obj];
208 Error( "Couldn't find a viewer object!" );
213 object *obj_find_first_of_type (int type)
217 for (i=0;i<=Highest_object_index;i++)
218 if (Objects[i].type==type)
219 return (&Objects[i]);
220 return ((object *)NULL);
223 int obj_return_num_of_type (int type)
227 for (i=0;i<=Highest_object_index;i++)
228 if (Objects[i].type==type)
232 int obj_return_num_of_typeid (int type,int id)
236 for (i=0;i<=Highest_object_index;i++)
237 if (Objects[i].type==type && Objects[i].id==id)
242 int global_orientation = 0;
244 //draw an object that has one bitmap & doesn't rotate
245 void draw_object_blob(object *obj,bitmap_index bmi)
248 grs_bitmap * bm = &GameBitmaps[bmi.index];
251 if (obj->type == OBJ_FIREBALL)
252 orientation = (obj-Objects) & 7;
254 orientation = global_orientation;
257 //@@ if (obj->type == OBJ_POWERUP) {
258 //@@ if ( GameBitmaps[(bmi).index].bm_flags & BM_FLAG_PAGED_OUT)
259 //@@ piggy_bitmap_page_in_w( bmi,1 );
261 //@@ if (bm->bm_handle) {
262 //@@ DDGRUNLOCK(dd_grd_curcanv);
265 PIGGY_PAGE_IN( bmi );
268 if (bm->bm_w > bm->bm_h)
270 g3_draw_bitmap(&obj->pos,obj->size,fixmuldiv(obj->size,bm->bm_h,bm->bm_w),bm, orientation);
274 g3_draw_bitmap(&obj->pos,fixmuldiv(obj->size,bm->bm_w,bm->bm_h),obj->size,bm, orientation);
277 //@@ if (bm->bm_handle) {
278 //@@ DDGRLOCK(dd_grd_curcanv);
283 //draw an object that is a texture-mapped rod
284 void draw_object_tmap_rod(object *obj,bitmap_index bitmapi,int lighted)
286 grs_bitmap * bitmap = &GameBitmaps[bitmapi.index];
289 vms_vector delta,top_v,bot_v;
290 g3s_point top_p,bot_p;
292 PIGGY_PAGE_IN(bitmapi);
294 bitmap->bm_handle = bitmapi.index;
296 vm_vec_copy_scale(&delta,&obj->orient.uvec,obj->size);
298 vm_vec_add(&top_v,&obj->pos,&delta);
299 vm_vec_sub(&bot_v,&obj->pos,&delta);
301 g3_rotate_point(&top_p,&top_v);
302 g3_rotate_point(&bot_p,&bot_v);
305 light = compute_object_light(obj,&top_p.p3_vec);
310 _3dfx_rendering_poly_obj = 1;
313 #ifdef PA_3DFX_VOODOO
317 g3_draw_rod_tmap(bitmap,&bot_p,obj->size,&top_p,obj->size,light);
320 _3dfx_rendering_poly_obj = 0;
325 int Linear_tmap_polygon_objects = 1;
327 extern fix Max_thrust;
329 //used for robot engine glow
330 #define MAX_VELOCITY i2f(50)
332 //function that takes the same parms as draw_tmap, but renders as flat poly
333 //we need this to do the cloaked effect
334 extern void draw_tmap_flat();
336 //what darkening level to use when cloaked
337 #define CLOAKED_FADE_LEVEL 28
339 #define CLOAK_FADEIN_DURATION_PLAYER F2_0
340 #define CLOAK_FADEOUT_DURATION_PLAYER F2_0
342 #define CLOAK_FADEIN_DURATION_ROBOT F1_0
343 #define CLOAK_FADEOUT_DURATION_ROBOT F1_0
345 //do special cloaked render
346 void draw_cloaked_object(object *obj,fix light,fix *glow,fix cloak_start_time,fix cloak_end_time)
348 fix cloak_delta_time,total_cloaked_time;
349 fix light_scale=F1_0;
351 int fading=0; //if true, fading, else cloaking
352 fix Cloak_fadein_duration=F1_0;
353 fix Cloak_fadeout_duration=F1_0;
356 total_cloaked_time = cloak_end_time-cloak_start_time;
360 Cloak_fadein_duration = CLOAK_FADEIN_DURATION_PLAYER;
361 Cloak_fadeout_duration = CLOAK_FADEOUT_DURATION_PLAYER;
364 Cloak_fadein_duration = CLOAK_FADEIN_DURATION_ROBOT;
365 Cloak_fadeout_duration = CLOAK_FADEOUT_DURATION_ROBOT;
368 Int3(); // Contact Mike: Unexpected object type in draw_cloaked_object.
371 cloak_delta_time = GameTime - cloak_start_time;
373 if (cloak_delta_time < Cloak_fadein_duration/2) {
375 light_scale = fixdiv(Cloak_fadein_duration/2 - cloak_delta_time,Cloak_fadein_duration/2);
379 else if (cloak_delta_time < Cloak_fadein_duration) {
381 cloak_value = f2i(fixdiv(cloak_delta_time - Cloak_fadein_duration/2,Cloak_fadein_duration/2) * CLOAKED_FADE_LEVEL);
383 } else if (GameTime < cloak_end_time-Cloak_fadeout_duration) {
384 static int cloak_delta=0,cloak_dir=1;
385 static fix cloak_timer=0;
387 //note, if more than one cloaked object is visible at once, the
388 //pulse rate will change!
390 cloak_timer -= FrameTime;
391 while (cloak_timer < 0) {
393 cloak_timer += Cloak_fadeout_duration/12;
395 cloak_delta += cloak_dir;
397 if (cloak_delta==0 || cloak_delta==4)
398 cloak_dir = -cloak_dir;
401 cloak_value = CLOAKED_FADE_LEVEL - cloak_delta;
403 } else if (GameTime < cloak_end_time-Cloak_fadeout_duration/2) {
405 cloak_value = f2i(fixdiv(total_cloaked_time - Cloak_fadeout_duration/2 - cloak_delta_time,Cloak_fadeout_duration/2) * CLOAKED_FADE_LEVEL);
409 light_scale = fixdiv(Cloak_fadeout_duration/2 - (total_cloaked_time - cloak_delta_time),Cloak_fadeout_duration/2);
415 fix new_light,save_glow;
416 bitmap_index * alt_textures = NULL;
419 if ( obj->rtype.pobj_info.alt_textures > 0 )
420 alt_textures = multi_player_textures[obj->rtype.pobj_info.alt_textures-1];
423 new_light = fixmul(light,light_scale);
425 glow[0] = fixmul(glow[0],light_scale);
426 draw_polygon_model(&obj->pos,
428 (vms_angvec *)&obj->rtype.pobj_info.anim_angles,
429 obj->rtype.pobj_info.model_num,obj->rtype.pobj_info.subobj_flags,
436 Gr_scanline_darkening_level = cloak_value;
437 gr_setcolor(BM_XRGB(0,0,0)); //set to black (matters for s3)
438 g3_set_special_render(draw_tmap_flat,NULL,NULL); //use special flat drawer
439 draw_polygon_model(&obj->pos,
441 (vms_angvec *)&obj->rtype.pobj_info.anim_angles,
442 obj->rtype.pobj_info.model_num,obj->rtype.pobj_info.subobj_flags,
446 g3_set_special_render(NULL,NULL,NULL);
447 Gr_scanline_darkening_level = GR_FADE_LEVELS;
452 //draw an object which renders as a polygon model
453 void draw_polygon_object(object *obj)
457 fix engine_glow_value[2]; //element 0 is for engine glow, 1 for headlight
459 light = compute_object_light(obj,NULL);
461 // If option set for bright players in netgame, brighten them!
463 if (Game_mode & GM_MULTI)
464 if (Netgame.BrightPlayers)
468 //make robots brighter according to robot glow field
469 if (obj->type == OBJ_ROBOT)
470 light += (Robot_info[obj->id].glow<<12); //convert 4:4 to 16:16
472 if (obj->type == OBJ_WEAPON)
473 if (obj->id == FLARE_ID)
476 if (obj->type == OBJ_MARKER)
480 imsave = Interpolation_method;
481 if (Linear_tmap_polygon_objects)
482 Interpolation_method = 1;
484 //set engine glow value
485 engine_glow_value[0] = f1_0/5;
486 if (obj->movement_type == MT_PHYSICS) {
488 if (obj->mtype.phys_info.flags & PF_USES_THRUST && obj->type==OBJ_PLAYER && obj->id==Player_num) {
489 fix thrust_mag = vm_vec_mag_quick(&obj->mtype.phys_info.thrust);
490 engine_glow_value[0] += (fixdiv(thrust_mag,Player_ship->max_thrust)*4)/5;
493 fix speed = vm_vec_mag_quick(&obj->mtype.phys_info.velocity);
494 engine_glow_value[0] += (fixdiv(speed,MAX_VELOCITY)*3)/5;
498 //set value for player headlight
499 if (obj->type == OBJ_PLAYER) {
500 if (Players[obj->id].flags & PLAYER_FLAGS_HEADLIGHT && !Endlevel_sequence)
501 if (Players[obj->id].flags & PLAYER_FLAGS_HEADLIGHT_ON)
502 engine_glow_value[1] = -2; //draw white!
504 engine_glow_value[1] = -1; //draw normal color (grey)
506 engine_glow_value[1] = -3; //don't draw
509 if (obj->rtype.pobj_info.tmap_override != -1) {
511 polymodel *pm = &Polygon_models[obj->rtype.pobj_info.model_num];
513 bitmap_index bm_ptrs[12];
517 Assert(pm->n_textures<=12);
519 for (i=0;i<12;i++) //fill whole array, in case simple model needs more
520 bm_ptrs[i] = Textures[obj->rtype.pobj_info.tmap_override];
522 draw_polygon_model(&obj->pos,
524 (vms_angvec *)&obj->rtype.pobj_info.anim_angles,
525 obj->rtype.pobj_info.model_num,
526 obj->rtype.pobj_info.subobj_flags,
533 if (obj->type==OBJ_PLAYER && (Players[obj->id].flags&PLAYER_FLAGS_CLOAKED))
534 draw_cloaked_object(obj,light,engine_glow_value,Players[obj->id].cloak_time,Players[obj->id].cloak_time+CLOAK_TIME_MAX);
535 else if ((obj->type == OBJ_ROBOT) && (obj->ctype.ai_info.CLOAKED)) {
536 if (Robot_info[obj->id].boss_flag)
537 draw_cloaked_object(obj,light,engine_glow_value, Boss_cloak_start_time, Boss_cloak_end_time);
539 draw_cloaked_object(obj,light,engine_glow_value, GameTime-F1_0*10, GameTime+F1_0*10);
541 bitmap_index * alt_textures = NULL;
544 if ( obj->rtype.pobj_info.alt_textures > 0 )
545 alt_textures = multi_player_textures[obj->rtype.pobj_info.alt_textures-1];
548 // Snipers get bright when they fire.
549 if (Ai_local_info[obj-Objects].next_fire < F1_0/8) {
550 if (obj->ctype.ai_info.behavior == AIB_SNIPE)
551 light = 2*light + F1_0;
554 draw_polygon_model(&obj->pos,
556 (vms_angvec *)&obj->rtype.pobj_info.anim_angles,obj->rtype.pobj_info.model_num,
557 obj->rtype.pobj_info.subobj_flags,
561 if (obj->type == OBJ_WEAPON && (Weapon_info[obj->id].model_num_inner > -1 )) {
562 fix dist_to_eye = vm_vec_dist_quick(&Viewer->pos, &obj->pos);
563 if (dist_to_eye < Simple_model_threshhold_scale * F1_0*2)
564 draw_polygon_model(&obj->pos,
566 (vms_angvec *)&obj->rtype.pobj_info.anim_angles,
567 Weapon_info[obj->id].model_num_inner,
568 obj->rtype.pobj_info.subobj_flags,
576 Interpolation_method = imsave;
580 //------------------------------------------------------------------------------
581 // These variables are used to keep a list of the 3 closest robots to the viewer.
582 // The code works like this: Every time render object is called with a polygon model,
583 // it finds the distance of that robot to the viewer. If this distance if within 10
584 // segments of the viewer, it does the following: If there aren't already 3 robots in
585 // the closet-robots list, it just sticks that object into the list along with its distance.
586 // If the list already contains 3 robots, then it finds the robot in that list that is
587 // farthest from the viewer. If that object is farther than the object currently being
588 // rendered, then the new object takes over that far object's slot. *Then* after all
589 // objects are rendered, object_render_targets is called an it draws a target on top
590 // of all the objects.
592 //091494: #define MAX_CLOSE_ROBOTS 3
593 //--unused-- static int Object_draw_lock_boxes = 0;
594 //091494: static int Object_num_close = 0;
595 //091494: static object * Object_close_ones[MAX_CLOSE_ROBOTS];
596 //091494: static fix Object_close_distance[MAX_CLOSE_ROBOTS];
598 //091494: set_close_objects(object *obj)
602 //091494: if ( (obj->type != OBJ_ROBOT) || (Object_draw_lock_boxes==0) )
605 //091494: // The following code keeps a list of the 10 closest robots to the
606 //091494: // viewer. See comments in front of this function for how this works.
607 //091494: dist = vm_vec_dist( &obj->pos, &Viewer->pos );
608 //091494: if ( dist < i2f(20*10) ) {
609 //091494: if ( Object_num_close < MAX_CLOSE_ROBOTS ) {
610 //091494: Object_close_ones[Object_num_close] = obj;
611 //091494: Object_close_distance[Object_num_close] = dist;
612 //091494: Object_num_close++;
614 //091494: int i, farthest_robot;
615 //091494: fix farthest_distance;
616 //091494: // Find the farthest robot in the list
617 //091494: farthest_robot = 0;
618 //091494: farthest_distance = Object_close_distance[0];
619 //091494: for (i=1; i<Object_num_close; i++ ) {
620 //091494: if ( Object_close_distance[i] > farthest_distance ) {
621 //091494: farthest_distance = Object_close_distance[i];
622 //091494: farthest_robot = i;
625 //091494: // If this object is closer to the viewer than
626 //091494: // the farthest in the list, replace the farthest with this object.
627 //091494: if ( farthest_distance > dist ) {
628 //091494: Object_close_ones[farthest_robot] = obj;
629 //091494: Object_close_distance[farthest_robot] = dist;
635 int Player_fired_laser_this_frame=-1;
639 // -----------------------------------------------------------------------------
640 //this routine checks to see if an robot rendered near the middle of
641 //the screen, and if so and the player had fired, "warns" the robot
642 void set_robot_location_info(object *objp)
644 if (Player_fired_laser_this_frame != -1) {
647 g3_rotate_point(&temp,&objp->pos);
649 if (temp.p3_codes & CC_BEHIND) //robot behind the screen
652 //the code below to check for object near the center of the screen
653 //completely ignores z, which may not be good
655 if ((abs(temp.p3_x) < F1_0*4) && (abs(temp.p3_y) < F1_0*4)) {
656 objp->ctype.ai_info.danger_laser_num = Player_fired_laser_this_frame;
657 objp->ctype.ai_info.danger_laser_signature = Objects[Player_fired_laser_this_frame].signature;
664 // ------------------------------------------------------------------------------------------------------------------
665 void create_small_fireball_on_object(object *objp, fix size_scale, int sound_flag)
668 vms_vector pos, rand_vec;
672 make_random_vector(&rand_vec);
674 vm_vec_scale(&rand_vec, objp->size/2);
676 vm_vec_add2(&pos, &rand_vec);
678 size = fixmul(size_scale, F1_0/2 + d_rand()*4/2);
680 segnum = find_point_seg(&pos, objp->segnum);
683 expl_obj = object_create_explosion(segnum, &pos, size, VCLIP_SMALL_EXPLOSION);
686 obj_attach(objp,expl_obj);
687 if (d_rand() < 8192) {
689 if (objp->type == OBJ_ROBOT)
692 digi_link_sound_to_object(SOUND_EXPLODING_WALL, objp-Objects, 0, vol);
697 // ------------------------------------------------------------------------------------------------------------------
698 void create_vclip_on_object(object *objp, fix size_scale, int vclip_num)
701 vms_vector pos, rand_vec;
705 make_random_vector(&rand_vec);
707 vm_vec_scale(&rand_vec, objp->size/2);
709 vm_vec_add2(&pos, &rand_vec);
711 size = fixmul(size_scale, F1_0 + d_rand()*4);
713 segnum = find_point_seg(&pos, objp->segnum);
716 expl_obj = object_create_explosion(segnum, &pos, size, vclip_num);
720 expl_obj->movement_type = MT_PHYSICS;
721 expl_obj->mtype.phys_info.velocity.x = objp->mtype.phys_info.velocity.x/2;
722 expl_obj->mtype.phys_info.velocity.y = objp->mtype.phys_info.velocity.y/2;
723 expl_obj->mtype.phys_info.velocity.z = objp->mtype.phys_info.velocity.z/2;
727 // -- mk, 02/05/95 -- #define VCLIP_INVULNERABILITY_EFFECT VCLIP_SMALL_EXPLOSION
728 // -- mk, 02/05/95 --
729 // -- mk, 02/05/95 -- // -----------------------------------------------------------------------------
730 // -- mk, 02/05/95 -- void do_player_invulnerability_effect(object *objp)
731 // -- mk, 02/05/95 -- {
732 // -- mk, 02/05/95 -- if (d_rand() < FrameTime*8) {
733 // -- mk, 02/05/95 -- create_vclip_on_object(objp, F1_0, VCLIP_INVULNERABILITY_EFFECT);
734 // -- mk, 02/05/95 -- }
735 // -- mk, 02/05/95 -- }
737 // -----------------------------------------------------------------------------
738 // Render an object. Calls one of several routines based on type
739 void render_object(object *obj)
743 if ( obj == Viewer ) return;
745 if ( obj->type==OBJ_NONE ) {
747 mprintf( (1, "ERROR!!!! Bogus obj %d in seg %d is rendering!\n", obj-Objects, obj->segnum ));
753 mld_save = Max_linear_depth;
754 Max_linear_depth = Max_linear_depth_objects;
756 switch (obj->render_type) {
758 case RT_NONE: break; //doesn't render, like the player
762 draw_polygon_object(obj);
764 //"warn" robot if being shot at
765 if (obj->type == OBJ_ROBOT)
766 set_robot_location_info(obj);
768 //JOHN SAID TO: if ( (obj->type==OBJ_PLAYER) && ((keyd_pressed[KEY_W]) || (keyd_pressed[KEY_I])))
769 //JOHN SAID TO: object_render_id(obj);
771 // -- mk, 02/05/95 -- if (obj->type == OBJ_PLAYER)
772 // -- mk, 02/05/95 -- if (Players[obj->id].flags & PLAYER_FLAGS_INVULNERABLE)
773 // -- mk, 02/05/95 -- do_player_invulnerability_effect(obj);
777 case RT_MORPH: draw_morph_object(obj); break;
779 case RT_FIREBALL: draw_fireball(obj); break;
781 case RT_WEAPON_VCLIP: draw_weapon_vclip(obj); break;
783 case RT_HOSTAGE: draw_hostage(obj); break;
785 case RT_POWERUP: draw_powerup(obj); break;
787 case RT_LASER: Laser_render(obj); break;
789 default: Error("Unknown render_type <%d>",obj->render_type);
793 if ( obj->render_type != RT_NONE )
794 if ( Newdemo_state == ND_STATE_RECORDING ) {
795 if (!WasRecorded[obj-Objects]) {
796 newdemo_record_render_object(obj);
797 WasRecorded[obj-Objects]=1;
802 Max_linear_depth = mld_save;
806 //--unused-- void object_toggle_lock_targets() {
807 //--unused-- Object_draw_lock_boxes ^= 1;
810 //091494: //draw target boxes for nearby robots
811 //091494: void object_render_targets()
813 //091494: g3s_point pt;
814 //091494: ubyte codes;
816 //091494: int radius,x,y;
818 //091494: if (Object_draw_lock_boxes==0)
821 //091494: for (i=0; i<Object_num_close; i++ ) {
823 //091494: codes = g3_rotate_point(&pt, &Object_close_ones[i]->pos );
824 //091494: if ( !(codes & CC_BEHIND) ) {
825 //091494: g3_project_point(&pt);
826 //091494: if (pt.p3_flags & PF_PROJECTED) {
827 //091494: x = f2i(pt.p3_sx);
828 //091494: y = f2i(pt.p3_sy);
829 //091494: radius = f2i(fixdiv((grd_curcanv->cv_bitmap.bm_w*Object_close_ones[i]->size)/8,pt.z));
830 //091494: gr_setcolor( BM_XRGB(0,31,0) );
831 //091494: gr_box(x-radius,y-radius,x+radius,y+radius);
835 //091494: Object_num_close=0;
837 //--unused-- //draw target boxes for nearby robots
838 //--unused-- void object_render_id(object * obj)
840 //--unused-- g3s_point pt;
841 //--unused-- ubyte codes;
842 //--unused-- int x,y;
843 //--unused-- int w, h, aw;
844 //--unused-- char s[20], *s1;
846 //--unused-- s1 = network_get_player_name( obj-Objects );
849 //--unused-- sprintf( s, "%s", s1 );
851 //--unused-- sprintf( s, "<%d>", obj->id );
853 //--unused-- codes = g3_rotate_point(&pt, &obj->pos );
854 //--unused-- if ( !(codes & CC_BEHIND) ) {
855 //--unused-- g3_project_point(&pt);
856 //--unused-- if (pt.p3_flags & PF_PROJECTED) {
857 //--unused-- gr_get_string_size( s, &w, &h, &aw );
858 //--unused-- x = f2i(pt.p3_sx) - w/2;
859 //--unused-- y = f2i(pt.p3_sy) - h/2;
860 //--unused-- if ( x>= 0 && y>=0 && (x+w)<=grd_curcanv->cv_bitmap.bm_w && (y+h)<grd_curcanv->cv_bitmap.bm_h ) {
861 //--unused-- gr_set_fontcolor( BM_XRGB(0,31,0), -1 );
862 //--unused-- gr_string( x, y, s );
868 void check_and_fix_matrix(vms_matrix *m);
870 #define vm_angvec_zero(v) (v)->p=(v)->b=(v)->h=0
872 void reset_player_object()
878 vm_vec_zero(&ConsoleObject->mtype.phys_info.velocity);
879 vm_vec_zero(&ConsoleObject->mtype.phys_info.thrust);
880 vm_vec_zero(&ConsoleObject->mtype.phys_info.rotvel);
881 vm_vec_zero(&ConsoleObject->mtype.phys_info.rotthrust);
882 ConsoleObject->mtype.phys_info.brakes = ConsoleObject->mtype.phys_info.turnroll = 0;
883 ConsoleObject->mtype.phys_info.mass = Player_ship->mass;
884 ConsoleObject->mtype.phys_info.drag = Player_ship->drag;
885 ConsoleObject->mtype.phys_info.flags |= PF_TURNROLL | PF_LEVELLING | PF_WIGGLE | PF_USES_THRUST;
889 ConsoleObject->render_type = RT_POLYOBJ;
890 ConsoleObject->rtype.pobj_info.model_num = Player_ship->model_num; //what model is this?
891 ConsoleObject->rtype.pobj_info.subobj_flags = 0; //zero the flags
892 ConsoleObject->rtype.pobj_info.tmap_override = -1; //no tmap override!
894 for (i=0;i<MAX_SUBMODELS;i++)
895 vm_angvec_zero(&ConsoleObject->rtype.pobj_info.anim_angles[i]);
899 ConsoleObject->flags = 0;
904 //make object0 the player, setting all relevant fields
905 void init_player_object()
907 ConsoleObject->type = OBJ_PLAYER;
908 ConsoleObject->id = 0; //no sub-types for player
910 ConsoleObject->signature = 0; //player has zero, others start at 1
912 ConsoleObject->size = Polygon_models[Player_ship->model_num].rad;
914 ConsoleObject->control_type = CT_SLEW; //default is player slewing
915 ConsoleObject->movement_type = MT_PHYSICS; //change this sometime
917 ConsoleObject->lifeleft = IMMORTAL_TIME;
919 ConsoleObject->attached_obj = -1;
921 reset_player_object();
925 //sets up the free list & init player & whatever else
932 for (i=0;i<MAX_OBJECTS;i++) {
933 free_obj_list[i] = i;
934 Objects[i].type = OBJ_NONE;
935 Objects[i].segnum = -1;
938 for (i=0;i<MAX_SEGMENTS;i++)
939 Segments[i].objects = -1;
941 ConsoleObject = Viewer = &Objects[0];
943 init_player_object();
944 obj_link(ConsoleObject-Objects,0); //put in the world in segment 0
946 num_objects = 1; //just the player
947 Highest_object_index = 0;
952 //after calling init_object(), the network code has grabbed specific
953 //object slots without allocating them. Go though the objects & build
954 //the free list, then set the apporpriate globals
955 void special_reset_objects(void)
959 num_objects=MAX_OBJECTS;
961 Highest_object_index = 0;
962 Assert(Objects[0].type != OBJ_NONE); //0 should be used
964 for (i=MAX_OBJECTS;i--;)
965 if (Objects[i].type == OBJ_NONE)
966 free_obj_list[--num_objects] = i;
968 if (i > Highest_object_index)
969 Highest_object_index = i;
973 int is_object_in_seg( int segnum, int objn )
975 int objnum, count = 0;
977 for (objnum=Segments[segnum].objects;objnum!=-1;objnum=Objects[objnum].next) {
978 if ( count > MAX_OBJECTS ) {
982 if ( objnum==objn ) count++;
987 int search_all_segments_for_object( int objnum )
992 for (i=0; i<=Highest_segment_index; i++) {
993 count += is_object_in_seg( i, objnum );
998 void johns_obj_unlink(int segnum, int objnum)
1000 object *obj = &Objects[objnum];
1001 segment *seg = &Segments[segnum];
1003 Assert(objnum != -1);
1005 if (obj->prev == -1)
1006 seg->objects = obj->next;
1008 Objects[obj->prev].next = obj->next;
1010 if (obj->next != -1) Objects[obj->next].prev = obj->prev;
1013 void remove_incorrect_objects()
1015 int segnum, objnum, count;
1017 for (segnum=0; segnum <= Highest_segment_index; segnum++) {
1019 for (objnum=Segments[segnum].objects;objnum!=-1;objnum=Objects[objnum].next) {
1022 if ( count > MAX_OBJECTS ) {
1023 mprintf((1, "Object list in segment %d is circular.\n", segnum ));
1027 if (Objects[objnum].segnum != segnum ) {
1029 mprintf((0, "Removing object %d from segment %d.\n", objnum, segnum ));
1032 johns_obj_unlink(segnum,objnum);
1038 void remove_all_objects_but( int segnum, int objnum )
1042 for (i=0; i<=Highest_segment_index; i++) {
1044 if (is_object_in_seg( i, objnum )) {
1045 johns_obj_unlink( i, objnum );
1051 int check_duplicate_objects()
1055 for (i=0;i<=Highest_object_index;i++) {
1056 if ( Objects[i].type != OBJ_NONE ) {
1057 count = search_all_segments_for_object( i );
1060 mprintf((1, "Object %d is in %d segments!\n", i, count ));
1063 remove_all_objects_but( Objects[i].segnum, i );
1071 void list_seg_objects( int segnum )
1073 int objnum, count = 0;
1075 for (objnum=Segments[segnum].objects;objnum!=-1;objnum=Objects[objnum].next) {
1077 if ( count > MAX_OBJECTS ) {
1087 //link the object into the list for its segment
1088 void obj_link(int objnum,int segnum)
1090 object *obj = &Objects[objnum];
1092 Assert(objnum != -1);
1094 Assert(obj->segnum == -1);
1096 Assert(segnum>=0 && segnum<=Highest_segment_index);
1098 obj->segnum = segnum;
1100 obj->next = Segments[segnum].objects;
1103 Segments[segnum].objects = objnum;
1105 if (obj->next != -1) Objects[obj->next].prev = objnum;
1107 //list_seg_objects( segnum );
1108 //check_duplicate_objects();
1110 Assert(Objects[0].next != 0);
1111 if (Objects[0].next == 0)
1112 Objects[0].next = -1;
1114 Assert(Objects[0].prev != 0);
1115 if (Objects[0].prev == 0)
1116 Objects[0].prev = -1;
1119 void obj_unlink(int objnum)
1121 object *obj = &Objects[objnum];
1122 segment *seg = &Segments[obj->segnum];
1124 Assert(objnum != -1);
1126 if (obj->prev == -1)
1127 seg->objects = obj->next;
1129 Objects[obj->prev].next = obj->next;
1131 if (obj->next != -1) Objects[obj->next].prev = obj->prev;
1135 Assert(Objects[0].next != 0);
1136 Assert(Objects[0].prev != 0);
1139 int Object_next_signature = 1; //player gets 0, others start at 1
1141 int Debris_object_count=0;
1143 int Unused_object_slots;
1145 //returns the number of a free object, updating Highest_object_index.
1146 //Generally, obj_create() should be called to get an object, since it
1147 //fills in important fields and does the linking.
1148 //returns -1 if no free objects
1149 int obj_allocate(void)
1153 if ( num_objects >= MAX_OBJECTS-2 ) {
1156 num_freed = free_object_slots(MAX_OBJECTS-10);
1157 mprintf((0, " *** Freed %i objects in frame %i\n", num_freed, FrameCount));
1160 if ( num_objects >= MAX_OBJECTS ) {
1162 mprintf((1, "Object creation failed - too many objects!\n" ));
1167 objnum = free_obj_list[num_objects++];
1169 if (objnum > Highest_object_index) {
1170 Highest_object_index = objnum;
1171 if (Highest_object_index > Highest_ever_object_index)
1172 Highest_ever_object_index = Highest_object_index;
1177 Unused_object_slots=0;
1178 for (i=0; i<=Highest_object_index; i++)
1179 if (Objects[i].type == OBJ_NONE)
1180 Unused_object_slots++;
1185 //frees up an object. Generally, obj_delete() should be called to get
1186 //rid of an object. This function deallocates the object entry after
1187 //the object has been unlinked
1188 void obj_free(int objnum)
1190 free_obj_list[--num_objects] = objnum;
1191 Assert(num_objects >= 0);
1193 if (objnum == Highest_object_index)
1194 while (Objects[--Highest_object_index].type == OBJ_NONE);
1197 //-----------------------------------------------------------------------------
1198 // Scan the object list, freeing down to num_used objects
1199 // Returns number of slots freed.
1200 int free_object_slots(int num_used)
1203 int obj_list[MAX_OBJECTS];
1204 int num_already_free, num_to_free, original_num_to_free;
1207 num_already_free = MAX_OBJECTS - Highest_object_index - 1;
1209 if (MAX_OBJECTS - num_already_free < num_used)
1212 for (i=0; i<=Highest_object_index; i++) {
1213 if (Objects[i].flags & OF_SHOULD_BE_DEAD) {
1215 if (MAX_OBJECTS - num_already_free < num_used)
1216 return num_already_free;
1218 switch (Objects[i].type) {
1221 if (MAX_OBJECTS - num_already_free < num_used)
1226 Int3(); // This is curious. What is an object that is a wall?
1231 obj_list[olind++] = i;
1247 num_to_free = MAX_OBJECTS - num_used - num_already_free;
1248 original_num_to_free = num_to_free;
1250 if (num_to_free > olind) {
1251 mprintf((1, "Warning: Asked to free %i objects, but can only free %i.\n", num_to_free, olind));
1252 num_to_free = olind;
1255 for (i=0; i<num_to_free; i++)
1256 if (Objects[obj_list[i]].type == OBJ_DEBRIS) {
1258 mprintf((0, "Freeing DEBRIS object %3i\n", obj_list[i]));
1259 Objects[obj_list[i]].flags |= OF_SHOULD_BE_DEAD;
1263 return original_num_to_free;
1265 for (i=0; i<num_to_free; i++)
1266 if (Objects[obj_list[i]].type == OBJ_FIREBALL && Objects[obj_list[i]].ctype.expl_info.delete_objnum==-1) {
1268 mprintf((0, "Freeing FIREBALL object %3i\n", obj_list[i]));
1269 Objects[obj_list[i]].flags |= OF_SHOULD_BE_DEAD;
1273 return original_num_to_free;
1275 for (i=0; i<num_to_free; i++)
1276 if ((Objects[obj_list[i]].type == OBJ_WEAPON) && (Objects[obj_list[i]].id == FLARE_ID)) {
1278 Objects[obj_list[i]].flags |= OF_SHOULD_BE_DEAD;
1282 return original_num_to_free;
1284 for (i=0; i<num_to_free; i++)
1285 if ((Objects[obj_list[i]].type == OBJ_WEAPON) && (Objects[obj_list[i]].id != FLARE_ID)) {
1287 mprintf((0, "Freeing WEAPON object %3i\n", obj_list[i]));
1288 Objects[obj_list[i]].flags |= OF_SHOULD_BE_DEAD;
1291 return original_num_to_free - num_to_free;
1294 //-----------------------------------------------------------------------------
1295 //initialize a new object. adds to the list for the given segment
1296 //note that segnum is really just a suggestion, since this routine actually
1297 //searches for the correct segment
1298 //returns the object number
1299 int obj_create(ubyte type,ubyte id,int segnum,vms_vector *pos,
1300 vms_matrix *orient,fix size,ubyte ctype,ubyte mtype,ubyte rtype)
1305 Assert(segnum <= Highest_segment_index);
1306 Assert (segnum >= 0);
1307 Assert(ctype <= CT_CNTRLCEN);
1309 if (type==OBJ_DEBRIS && Debris_object_count>=Max_debris_objects)
1312 if (get_seg_masks(pos, segnum, 0, __FILE__, __LINE__).centermask != 0)
1313 if ((segnum=find_point_seg(pos,segnum))==-1) {
1315 mprintf((0,"Bad segnum in obj_create (type=%d)\n",type));
1317 return -1; //don't create this object
1320 // Find next free object
1321 objnum = obj_allocate();
1323 if (objnum == -1) //no free objects
1326 Assert(Objects[objnum].type == OBJ_NONE); //make sure unused
1328 obj = &Objects[objnum];
1330 Assert(obj->segnum == -1);
1332 // Zero out object structure to keep weird bugs from happening
1333 // in uninitialized fields.
1334 memset( obj, 0, sizeof(object) );
1336 obj->signature = Object_next_signature++;
1339 obj->last_pos = *pos;
1343 //@@if (orient != NULL)
1344 //@@ obj->orient = *orient;
1346 obj->orient = orient?*orient:vmd_identity_matrix;
1348 obj->control_type = ctype;
1349 obj->movement_type = mtype;
1350 obj->render_type = rtype;
1351 obj->contains_type = -1;
1353 obj->lifeleft = IMMORTAL_TIME; //assume immortal
1354 obj->attached_obj = -1;
1356 if (obj->control_type == CT_POWERUP)
1357 obj->ctype.powerup_info.count = 1;
1359 // Init physics info for this object
1360 if (obj->movement_type == MT_PHYSICS) {
1362 vm_vec_zero(&obj->mtype.phys_info.velocity);
1363 vm_vec_zero(&obj->mtype.phys_info.thrust);
1364 vm_vec_zero(&obj->mtype.phys_info.rotvel);
1365 vm_vec_zero(&obj->mtype.phys_info.rotthrust);
1367 obj->mtype.phys_info.mass = 0;
1368 obj->mtype.phys_info.drag = 0;
1369 obj->mtype.phys_info.brakes = 0;
1370 obj->mtype.phys_info.turnroll = 0;
1371 obj->mtype.phys_info.flags = 0;
1374 if (obj->render_type == RT_POLYOBJ)
1375 obj->rtype.pobj_info.tmap_override = -1;
1377 obj->shields = 20*F1_0;
1379 segnum = find_point_seg(pos,segnum); //find correct segment
1383 obj->segnum = -1; //set to zero by memset, above
1384 obj_link(objnum,segnum);
1386 // Set (or not) persistent bit in phys_info.
1387 if (obj->type == OBJ_WEAPON) {
1388 Assert(obj->control_type == CT_WEAPON);
1389 obj->mtype.phys_info.flags |= (Weapon_info[obj->id].persistent*PF_PERSISTENT);
1390 obj->ctype.laser_info.creation_time = GameTime;
1391 obj->ctype.laser_info.last_hitobj = -1;
1392 obj->ctype.laser_info.multiplier = F1_0;
1395 if (obj->control_type == CT_POWERUP)
1396 obj->ctype.powerup_info.creation_time = GameTime;
1398 if (obj->control_type == CT_EXPLOSION)
1399 obj->ctype.expl_info.next_attach = obj->ctype.expl_info.prev_attach = obj->ctype.expl_info.attach_parent = -1;
1402 if (print_object_info)
1403 mprintf( (0, "Created object %d of type %d\n", objnum, obj->type ));
1406 if (obj->type == OBJ_DEBRIS)
1407 Debris_object_count++;
1413 //create a copy of an object. returns new object number
1414 int obj_create_copy(int objnum, vms_vector *new_pos, int newsegnum)
1419 // Find next free object
1420 newobjnum = obj_allocate();
1422 if (newobjnum == -1)
1425 obj = &Objects[newobjnum];
1427 *obj = Objects[objnum];
1429 obj->pos = obj->last_pos = *new_pos;
1431 obj->next = obj->prev = obj->segnum = -1;
1433 obj_link(newobjnum,newsegnum);
1435 obj->signature = Object_next_signature++;
1437 //we probably should initialize sub-structures here
1444 extern void newdemo_record_guided_end();
1446 //remove object from the world
1447 void obj_delete(int objnum)
1450 object *obj = &Objects[objnum];
1452 Assert(objnum != -1);
1453 Assert(objnum != 0 );
1454 Assert(obj->type != OBJ_NONE);
1455 Assert(obj != ConsoleObject);
1457 if (obj->type==OBJ_WEAPON && obj->id==GUIDEDMISS_ID) {
1458 pnum=Objects[obj->ctype.laser_info.parent_num].id;
1459 mprintf ((0,"Deleting a guided missile! Player %d\n\n",pnum));
1461 if (pnum!=Player_num) {
1462 mprintf ((0,"deleting missile that belongs to %d (%s)!\n",pnum,Players[pnum].callsign));
1463 Guided_missile[pnum]=NULL;
1465 else if (Newdemo_state==ND_STATE_RECORDING)
1466 newdemo_record_guided_end();
1470 if (obj == Viewer) //deleting the viewer?
1471 Viewer = ConsoleObject; //..make the player the viewer
1473 if (obj->flags & OF_ATTACHED) //detach this from object
1474 obj_detach_one(obj);
1476 if (obj->attached_obj != -1) //detach all objects from this
1477 obj_detach_all(obj);
1479 #if !defined(NDEBUG) && !defined(NMONO)
1480 if (print_object_info) mprintf( (0, "Deleting object %d of type %d\n", objnum, Objects[objnum].type ));
1483 if (obj->type == OBJ_DEBRIS)
1484 Debris_object_count--;
1488 Assert(Objects[0].next != 0);
1490 obj->type = OBJ_NONE; //unused!
1491 obj->signature = -1;
1492 obj->segnum=-1; // zero it!
1497 #define DEATH_SEQUENCE_LENGTH (F1_0*5)
1498 #define DEATH_SEQUENCE_EXPLODE_TIME (F1_0*2)
1500 int Player_is_dead = 0; // If !0, then player is dead, but game continues so he can watch.
1501 object *Dead_player_camera = NULL; // Object index of object watching deader.
1502 fix Player_time_of_death; // Time at which player died.
1503 object *Viewer_save;
1504 int Player_flags_save;
1505 int Player_exploded = 0;
1506 int Death_sequence_aborted=0;
1507 int Player_eggs_dropped=0;
1508 fix Camera_to_player_dist_goal=F1_0*4;
1510 ubyte Control_type_save, Render_type_save;
1511 extern int Cockpit_mode_save; //set while in letterbox or rear view, or -1
1513 // ------------------------------------------------------------------------------------------------------------------
1514 void dead_player_end(void)
1516 if (!Player_is_dead)
1519 if (Newdemo_state == ND_STATE_RECORDING)
1520 newdemo_record_restore_cockpit();
1523 Player_exploded = 0;
1524 obj_delete(Dead_player_camera-Objects);
1525 Dead_player_camera = NULL;
1526 select_cockpit(Cockpit_mode_save);
1527 Cockpit_mode_save = -1;
1528 Viewer = Viewer_save;
1529 ConsoleObject->type = OBJ_PLAYER;
1530 ConsoleObject->flags = Player_flags_save;
1532 Assert((Control_type_save == CT_FLYING) || (Control_type_save == CT_SLEW));
1534 ConsoleObject->control_type = Control_type_save;
1535 ConsoleObject->render_type = Render_type_save;
1536 Players[Player_num].flags &= ~PLAYER_FLAGS_INVULNERABLE;
1537 Player_eggs_dropped = 0;
1541 // ------------------------------------------------------------------------------------------------------------------
1542 // Camera is less than size of player away from
1543 void set_camera_pos(vms_vector *camera_pos, object *objp)
1546 fix camera_player_dist;
1549 camera_player_dist = vm_vec_dist_quick(camera_pos, &objp->pos);
1551 if (camera_player_dist < Camera_to_player_dist_goal) { //2*objp->size) {
1552 // Camera is too close to player object, so move it away.
1553 vms_vector player_camera_vec;
1556 vms_vector local_p1;
1558 vm_vec_sub(&player_camera_vec, camera_pos, &objp->pos);
1559 if ((player_camera_vec.x == 0) && (player_camera_vec.y == 0) && (player_camera_vec.z == 0))
1560 player_camera_vec.x += F1_0/16;
1562 hit_data.hit_type = HIT_WALL;
1565 while ((hit_data.hit_type != HIT_NONE) && (count++ < 6)) {
1566 vms_vector closer_p1;
1567 vm_vec_normalize_quick(&player_camera_vec);
1568 vm_vec_scale(&player_camera_vec, Camera_to_player_dist_goal);
1571 vm_vec_add(&closer_p1, &objp->pos, &player_camera_vec); // This is the actual point we want to put the camera at.
1572 vm_vec_scale(&player_camera_vec, far_scale); // ...but find a point 50% further away...
1573 vm_vec_add(&local_p1, &objp->pos, &player_camera_vec); // ...so we won't have to do as many cuts.
1576 fq.startseg = objp->segnum;
1578 fq.thisobjnum = objp-Objects;
1579 fq.ignore_obj_list = NULL;
1581 find_vector_intersection( &fq, &hit_data);
1583 if (hit_data.hit_type == HIT_NONE) {
1584 *camera_pos = closer_p1;
1586 make_random_vector(&player_camera_vec);
1587 far_scale = 3*F1_0/2;
1593 extern void drop_player_eggs(object *objp);
1594 extern int get_explosion_vclip(object *obj,int stage);
1595 extern void multi_cap_objects();
1596 extern int Proximity_dropped,Smartmines_dropped;
1598 // ------------------------------------------------------------------------------------------------------------------
1599 void dead_player_frame(void)
1604 if (Player_is_dead) {
1605 time_dead = GameTime - Player_time_of_death;
1607 // If unable to create camera at time of death, create now.
1608 if (Dead_player_camera == Viewer_save) {
1610 object *player = &Objects[Players[Player_num].objnum];
1612 // this next line was changed by WraithX, instead of CT_FLYING, it was CT_NONE: instead of MT_PHYSICS, it was MT_NONE.
1613 objnum = obj_create(OBJ_CAMERA, 0, player->segnum, &player->pos, &player->orient, 0, CT_FLYING, MT_PHYSICS, RT_NONE);
1615 mprintf((0, "Creating new dead player camera.\n"));
1617 Viewer = Dead_player_camera = &Objects[objnum];
1619 mprintf((1, "Can't create dead player camera.\n"));
1624 ConsoleObject->mtype.phys_info.rotvel.x = max(0, DEATH_SEQUENCE_EXPLODE_TIME - time_dead)/4;
1625 ConsoleObject->mtype.phys_info.rotvel.y = max(0, DEATH_SEQUENCE_EXPLODE_TIME - time_dead)/2;
1626 ConsoleObject->mtype.phys_info.rotvel.z = max(0, DEATH_SEQUENCE_EXPLODE_TIME - time_dead)/3;
1628 Camera_to_player_dist_goal = min(time_dead*8, F1_0*20) + ConsoleObject->size;
1630 set_camera_pos(&Dead_player_camera->pos, ConsoleObject);
1632 // the following line uncommented by WraithX, 4-12-00
1633 if (time_dead < DEATH_SEQUENCE_EXPLODE_TIME + F1_0 * 2)
1635 vm_vec_sub(&fvec, &ConsoleObject->pos, &Dead_player_camera->pos);
1636 vm_vector_2_matrix(&Dead_player_camera->orient, &fvec, NULL, NULL);
1637 Dead_player_camera->mtype.phys_info = ConsoleObject->mtype.phys_info;
1639 // the following "if" added by WraithX to get rid of camera "wiggle"
1640 if (Dead_player_camera->mtype.phys_info.flags & PF_WIGGLE)
1642 Dead_player_camera->mtype.phys_info.flags = (Dead_player_camera->mtype.phys_info.flags & ~PF_WIGGLE);
1643 }// end "if" added by WraithX, 4/13/00
1645 // the following line uncommented by WraithX, 4-12-00
1649 // the following line uncommented by WraithX, 4-11-00
1650 Dead_player_camera->movement_type = MT_PHYSICS;
1651 //Dead_player_camera->mtype.phys_info.rotvel.y = F1_0/8;
1652 // the following line uncommented by WraithX, 4-12-00
1654 // end addition by WX
1656 if (time_dead > DEATH_SEQUENCE_EXPLODE_TIME) {
1657 if (!Player_exploded) {
1659 if (Players[Player_num].hostages_on_board > 1)
1660 HUD_init_message(TXT_SHIP_DESTROYED_2, Players[Player_num].hostages_on_board);
1661 else if (Players[Player_num].hostages_on_board == 1)
1662 HUD_init_message(TXT_SHIP_DESTROYED_1);
1664 HUD_init_message(TXT_SHIP_DESTROYED_0);
1672 Player_exploded = 1;
1674 if (Game_mode & GM_NETWORK)
1677 multi_cap_objects();
1681 drop_player_eggs(ConsoleObject);
1682 Player_eggs_dropped = 1;
1684 if (Game_mode & GM_MULTI)
1686 //multi_send_position(Players[Player_num].objnum);
1687 multi_send_player_explode(MULTI_PLAYER_EXPLODE);
1691 explode_badass_player(ConsoleObject);
1693 //is this next line needed, given the badass call above?
1694 explode_object(ConsoleObject,0);
1695 ConsoleObject->flags &= ~OF_SHOULD_BE_DEAD; //don't really kill player
1696 ConsoleObject->render_type = RT_NONE; //..just make him disappear
1697 ConsoleObject->type = OBJ_GHOST; //..and kill intersections
1698 Players[Player_num].flags &= ~PLAYER_FLAGS_HEADLIGHT_ON;
1701 if (d_rand() < FrameTime*4) {
1703 if (Game_mode & GM_MULTI)
1704 multi_send_create_explosion(Player_num);
1706 create_small_fireball_on_object(ConsoleObject, F1_0, 1);
1711 if (Death_sequence_aborted) { //time_dead > DEATH_SEQUENCE_LENGTH) {
1712 if (!Player_eggs_dropped) {
1715 if (Game_mode & GM_NETWORK)
1718 multi_cap_objects();
1722 drop_player_eggs(ConsoleObject);
1723 Player_eggs_dropped = 1;
1725 if (Game_mode & GM_MULTI)
1727 //multi_send_position(Players[Player_num].objnum);
1728 multi_send_player_explode(MULTI_PLAYER_EXPLODE);
1733 DoPlayerDead(); //kill_player();
1739 void AdjustMineSpawn()
1741 if (!(Game_mode & GM_NETWORK))
1742 return; // No need for this function in any other mode
1744 if (!(Game_mode & GM_HOARD))
1745 Players[Player_num].secondary_ammo[PROXIMITY_INDEX]+=Proximity_dropped;
1746 Players[Player_num].secondary_ammo[SMART_MINE_INDEX]+=Smartmines_dropped;
1747 Proximity_dropped=0;
1748 Smartmines_dropped=0;
1753 int Killed_in_frame = -1;
1754 short Killed_objnum = -1;
1755 extern char Multi_killed_yourself;
1757 // ------------------------------------------------------------------------------------------------------------------
1758 void start_player_death_sequence(object *player)
1762 Assert(player == ConsoleObject);
1763 if ((Player_is_dead != 0) || (Dead_player_camera != NULL))
1766 //Assert(Player_is_dead == 0);
1767 //Assert(Dead_player_camera == NULL);
1771 if (!(Game_mode & GM_MULTI))
1772 HUD_clear_messages();
1774 Killed_in_frame = FrameCount;
1775 Killed_objnum = player-Objects;
1776 Death_sequence_aborted = 0;
1779 if (Game_mode & GM_MULTI)
1781 multi_send_kill(Players[Player_num].objnum);
1783 // If Hoard, increase number of orbs by 1
1784 // Only if you haven't killed yourself
1785 // This prevents cheating
1787 if (Game_mode & GM_HOARD)
1788 if (Players[Player_num].secondary_ammo[PROXIMITY_INDEX]<12)
1789 if (!Multi_killed_yourself)
1790 Players[Player_num].secondary_ammo[PROXIMITY_INDEX]++;
1802 //Players[Player_num].flags &= ~(PLAYER_FLAGS_AFTERBURNER);
1804 vm_vec_zero(&player->mtype.phys_info.rotthrust);
1805 vm_vec_zero(&player->mtype.phys_info.thrust);
1807 Player_time_of_death = GameTime;
1809 // this next line was changed by WraithX, instead of CT_FLYING, it was CT_NONE: instead of MT_PHYSICS, it was MT_NONE.
1810 objnum = obj_create(OBJ_CAMERA, 0, player->segnum, &player->pos, &player->orient, 0, CT_FLYING, MT_PHYSICS, RT_NONE);
1811 Viewer_save = Viewer;
1813 Viewer = Dead_player_camera = &Objects[objnum];
1815 mprintf((1, "Can't create dead player camera.\n"));
1817 Dead_player_camera = Viewer;
1820 if (Cockpit_mode_save == -1) //if not already saved
1821 Cockpit_mode_save = Cockpit_mode;
1822 select_cockpit(CM_LETTERBOX);
1823 if (Newdemo_state == ND_STATE_RECORDING)
1824 newdemo_record_letterbox();
1826 Player_flags_save = player->flags;
1827 Control_type_save = player->control_type;
1828 Render_type_save = player->render_type;
1830 player->flags &= ~OF_SHOULD_BE_DEAD;
1831 // Players[Player_num].flags |= PLAYER_FLAGS_INVULNERABLE;
1832 player->control_type = CT_FLYING; // change from CT_NONE to CT_FLYING by WraithX
1833 player->shields = F1_0*1000;
1835 PALETTE_FLASH_SET(0,0,0);
1838 // ------------------------------------------------------------------------------------------------------------------
1839 void obj_delete_all_that_should_be_dead()
1843 int local_dead_player_object=-1;
1848 for (i=0;i<=Highest_object_index;i++) {
1849 if ((objp->type!=OBJ_NONE) && (objp->flags&OF_SHOULD_BE_DEAD) ) {
1850 Assert(!(objp->type==OBJ_FIREBALL && objp->ctype.expl_info.delete_time!=-1));
1851 if (objp->type==OBJ_PLAYER) {
1852 if ( objp->id == Player_num ) {
1853 if (local_dead_player_object == -1) {
1854 start_player_death_sequence(objp);
1855 local_dead_player_object = objp-Objects;
1857 Int3(); // Contact Mike: Illegal, killed player twice in this frame!
1858 // Ok to continue, won't start death sequence again!
1869 //when an object has moved into a new segment, this function unlinks it
1870 //from its old segment, and links it into the new segment
1871 void obj_relink(int objnum,int newsegnum)
1874 Assert((objnum >= 0) && (objnum <= Highest_object_index));
1875 Assert((newsegnum <= Highest_segment_index) && (newsegnum >= 0));
1879 obj_link(objnum,newsegnum);
1882 if (get_seg_masks(&Objects[objnum].pos, Objects[objnum].segnum, 0, __FILE__, __LINE__).centermask != 0)
1883 mprintf((1, "obj_relink violates seg masks.\n"));
1887 //process a continuously-spinning object
1889 spin_object(object *obj)
1892 vms_matrix rotmat, new_pm;
1894 Assert(obj->movement_type == MT_SPINNING);
1896 rotangs.p = fixmul(obj->mtype.spin_rate.x,FrameTime);
1897 rotangs.h = fixmul(obj->mtype.spin_rate.y,FrameTime);
1898 rotangs.b = fixmul(obj->mtype.spin_rate.z,FrameTime);
1900 vm_angles_2_matrix(&rotmat,&rotangs);
1902 vm_matrix_x_matrix(&new_pm,&obj->orient,&rotmat);
1903 obj->orient = new_pm;
1905 check_and_fix_matrix(&obj->orient);
1908 int Drop_afterburner_blob_flag; //ugly hack
1909 extern void multi_send_drop_blobs(char);
1910 extern void fuelcen_check_for_goal (segment *);
1912 //see if wall is volatile, and if so, cause damage to player
1913 //returns true if player is in lava
1914 int check_volatile_wall(object *obj,int segnum,int sidenum,vms_vector *hitpt);
1916 // Time at which this object last created afterburner blobs.
1917 fix Last_afterburner_time[MAX_OBJECTS];
1919 //--------------------------------------------------------------------
1920 //move an object for the current frame
1921 void object_move_one( object * obj )
1926 int previous_segment = obj->segnum;
1928 obj->last_pos = obj->pos; // Save the current position
1930 if ((obj->type==OBJ_PLAYER) && (Player_num==obj->id)) {
1934 if (Game_mode & GM_CAPTURE)
1935 fuelcen_check_for_goal (&Segments[obj->segnum]);
1936 if (Game_mode & GM_HOARD)
1937 fuelcen_check_for_hoard_goal (&Segments[obj->segnum]);
1940 fuel=fuelcen_give_fuel( &Segments[obj->segnum], INITIAL_ENERGY-Players[Player_num].energy );
1942 Players[Player_num].energy += fuel;
1945 shields = repaircen_give_shields( &Segments[obj->segnum], INITIAL_ENERGY-Players[Player_num].energy );
1947 Players[Player_num].shields += shields;
1951 if (obj->lifeleft != IMMORTAL_TIME) { //if not immortal...
1952 // Ok, this is a big hack by MK.
1953 // If you want an object to last for exactly one frame, then give it a lifeleft of ONE_FRAME_TIME.
1954 if (obj->lifeleft != ONE_FRAME_TIME)
1955 obj->lifeleft -= FrameTime; //...inevitable countdown towards death
1958 Drop_afterburner_blob_flag = 0;
1960 switch (obj->control_type) {
1962 case CT_NONE: break;
1966 #if !defined(NDEBUG) && !defined(NMONO)
1967 if (print_object_info>1) mprintf( (0, "Moving player object #%d\n", obj-Objects ));
1970 read_flying_controls( obj );
1974 case CT_REPAIRCEN: Int3(); // -- hey! these are no longer supported!! -- do_repair_sequence(obj); break;
1976 case CT_POWERUP: do_powerup_frame(obj); break;
1978 case CT_MORPH: //morph implies AI
1979 do_morph_frame(obj);
1980 //NOTE: FALLS INTO AI HERE!!!!
1983 //NOTE LINK TO CT_MORPH ABOVE!!!
1984 if (Game_suspended & SUSP_ROBOTS) return;
1985 #if !defined(NDEBUG) && !defined(NMONO)
1986 if (print_object_info>1)
1987 mprintf( (0, "AI: Moving robot object #%d\n",obj-Objects ));
1992 case CT_WEAPON: Laser_do_weapon_sequence(obj); break;
1993 case CT_EXPLOSION: do_explosion_sequence(obj); break;
1997 if ( keyd_pressed[KEY_PAD5] ) slew_stop( obj );
1998 if ( keyd_pressed[KEY_NUMLOCK] ) {
1999 slew_reset_orient( obj );
2000 * (ubyte *) 0x417 &= ~0x20; //kill numlock
2002 slew_frame(0 ); // Does velocity addition for us.
2007 // case CT_FLYTHROUGH:
2008 // do_flythrough(obj,0); // HACK:do_flythrough should operate on an object!!!!
2009 // //check_object_seg(obj);
2010 // return; // DON'T DO THE REST OF OBJECT STUFF SINCE THIS IS A SPECIAL CASE!!!
2013 case CT_DEBRIS: do_debris_frame(obj); break;
2015 case CT_LIGHT: break; //doesn't do anything
2017 case CT_REMOTE: break; //movement is handled in com_process_input
2019 case CT_CNTRLCEN: do_controlcen_frame(obj); break;
2024 Error("Unknown control type %d in object %li, sig/type/id = %i/%i/%i",obj->control_type, obj-Objects, obj->signature, obj->type, obj->id);
2026 Error("Unknown control type %d in object %i, sig/type/id = %i/%i/%i",obj->control_type, obj-Objects, obj->signature, obj->type, obj->id);
2033 if (obj->lifeleft < 0 ) { // We died of old age
2034 obj->flags |= OF_SHOULD_BE_DEAD;
2035 if ( obj->type==OBJ_WEAPON && Weapon_info[obj->id].damage_radius )
2036 explode_badass_weapon(obj,&obj->pos);
2037 else if ( obj->type==OBJ_ROBOT) //make robots explode
2038 explode_object(obj,0);
2041 if (obj->type == OBJ_NONE)
2042 return; // object has been deleted
2044 // stay around if !dead, for WraithX's death-cam
2045 if (!Player_is_dead && obj->flags&OF_SHOULD_BE_DEAD)
2048 switch (obj->movement_type) {
2050 case MT_NONE: break; //this doesn't move
2052 case MT_PHYSICS: do_physics_sim(obj); break; //move by physics
2054 case MT_SPINNING: spin_object(obj); break;
2058 // If player and moved to another segment, see if hit any triggers.
2059 // also check in player under a lavafall
2060 if (obj->type == OBJ_PLAYER && obj->movement_type==MT_PHYSICS) {
2062 if (previous_segment != obj->segnum) {
2065 int old_level = Current_level_num;
2067 for (i=0;i<n_phys_segs-1;i++) {
2068 connect_side = find_connect_side(&Segments[phys_seglist[i+1]], &Segments[phys_seglist[i]]);
2069 if (connect_side != -1)
2070 check_trigger(&Segments[phys_seglist[i]], connect_side, obj-Objects,0);
2072 else { // segments are not directly connected, so do binary subdivision until you find connected segments.
2073 mprintf((1, "UNCONNECTED SEGMENTS %d,%d\n",phys_seglist[i+1],phys_seglist[i]));
2074 // -- Unnecessary, MK, 09/04/95 -- Int3();
2078 //maybe we've gone on to the next level. if so, bail!
2080 if (Current_level_num != old_level)
2087 int sidemask,under_lavafall=0;
2088 static int lavafall_hiss_playing[MAX_PLAYERS]={0};
2090 sidemask = get_seg_masks(&obj->pos, obj->segnum, obj->size, __FILE__, __LINE__).sidemask;
2092 int sidenum,bit,wall_num;
2094 for (sidenum=0,bit=1;sidenum<6;bit<<=1,sidenum++)
2095 if ((sidemask & bit) && ((wall_num=Segments[obj->segnum].sides[sidenum].wall_num)!=-1) && Walls[wall_num].type==WALL_ILLUSION) {
2097 if ((type=check_volatile_wall(obj,obj->segnum,sidenum,&obj->pos))!=0) {
2098 int sound = (type==1)?SOUND_LAVAFALL_HISS:SOUND_SHIP_IN_WATERFALL;
2100 if (!lavafall_hiss_playing[obj->id]) {
2101 digi_link_sound_to_object3( sound, obj-Objects, 1, F1_0, i2f(256), -1, -1);
2102 lavafall_hiss_playing[obj->id] = 1;
2108 if (!under_lavafall && lavafall_hiss_playing[obj->id]) {
2109 digi_kill_sound_linked_to_object( obj-Objects);
2110 lavafall_hiss_playing[obj->id] = 0;
2115 //see if guided missile has flown through exit trigger
2116 if (obj==Guided_missile[Player_num] && obj->signature==Guided_missile_sig[Player_num]) {
2117 if (previous_segment != obj->segnum) {
2119 connect_side = find_connect_side(&Segments[obj->segnum], &Segments[previous_segment]);
2120 if (connect_side != -1) {
2121 int wall_num,trigger_num;
2122 wall_num = Segments[previous_segment].sides[connect_side].wall_num;
2123 if ( wall_num != -1 ) {
2124 trigger_num = Walls[wall_num].trigger;
2125 if (trigger_num != -1)
2126 if (Triggers[trigger_num].type == TT_EXIT)
2127 Guided_missile[Player_num]->lifeleft = 0;
2133 if (Drop_afterburner_blob_flag) {
2134 Assert(obj==ConsoleObject);
2135 drop_afterburner_blobs(obj, 2, i2f(5)/2, -1); // -1 means use default lifetime
2137 if (Game_mode & GM_MULTI)
2138 multi_send_drop_blobs(Player_num);
2140 Drop_afterburner_blob_flag = 0;
2143 if ((obj->type == OBJ_WEAPON) && (Weapon_info[obj->id].afterburner_size)) {
2144 int objnum = obj-Objects;
2145 fix vel = vm_vec_mag_quick(&obj->mtype.phys_info.velocity);
2146 fix delay, lifetime;
2150 else if (vel > F1_0*40)
2151 delay = fixdiv(F1_0*13,vel);
2155 lifetime = (delay * 3)/2;
2156 if (!(Game_mode & GM_MULTI)) {
2161 if ((Last_afterburner_time[objnum] + delay < GameTime) || (Last_afterburner_time[objnum] > GameTime)) {
2162 drop_afterburner_blobs(obj, 1, i2f(Weapon_info[obj->id].afterburner_size)/16, lifetime);
2163 Last_afterburner_time[objnum] = GameTime;
2168 obj++; //kill warning
2172 int Max_used_objects = MAX_OBJECTS - 20;
2174 //--------------------------------------------------------------------
2175 //move all objects for the current frame
2176 void object_move_all()
2181 // -- mprintf((0, "Frame %i: %i/%i objects used.\n", FrameCount, num_objects, MAX_OBJECTS));
2183 // check_duplicate_objects();
2184 // remove_incorrect_objects();
2186 if (Highest_object_index > Max_used_objects)
2187 free_object_slots(Max_used_objects); // Free all possible object slots.
2189 obj_delete_all_that_should_be_dead();
2191 if (Auto_leveling_on)
2192 ConsoleObject->mtype.phys_info.flags |= PF_LEVELLING;
2194 ConsoleObject->mtype.phys_info.flags &= ~PF_LEVELLING;
2200 for (i=0;i<=Highest_object_index;i++) {
2201 if ( (objp->type != OBJ_NONE) && (!(objp->flags&OF_SHOULD_BE_DEAD)) ) {
2202 object_move_one( objp );
2210 // check_duplicate_objects();
2211 // remove_incorrect_objects();
2216 //--unused-- // -----------------------------------------------------------
2217 //--unused-- // Moved here from eobject.c on 02/09/94 by MK.
2218 //--unused-- int find_last_obj(int i)
2220 //--unused-- for (i=MAX_OBJECTS;--i>=0;)
2221 //--unused-- if (Objects[i].type != OBJ_NONE) break;
2223 //--unused-- return i;
2228 //make object array non-sparse
2229 void compress_objects(void)
2231 int start_i; //,last_i;
2233 //last_i = find_last_obj(MAX_OBJECTS);
2235 // Note: It's proper to do < (rather than <=) Highest_object_index here because we
2236 // are just removing gaps, and the last object can't be a gap.
2237 for (start_i=0;start_i<Highest_object_index;start_i++)
2239 if (Objects[start_i].type == OBJ_NONE) {
2243 segnum_copy = Objects[Highest_object_index].segnum;
2245 obj_unlink(Highest_object_index);
2247 Objects[start_i] = Objects[Highest_object_index];
2250 if (Cur_object_index == Highest_object_index)
2251 Cur_object_index = start_i;
2254 Objects[Highest_object_index].type = OBJ_NONE;
2256 obj_link(start_i,segnum_copy);
2258 while (Objects[--Highest_object_index].type == OBJ_NONE);
2260 //last_i = find_last_obj(last_i);
2264 reset_objects(num_objects);
2268 //called after load. Takes number of objects, and objects should be
2269 //compressed. resets free list, marks unused objects as unused
2270 void reset_objects(int n_objs)
2274 num_objects = n_objs;
2276 Assert(num_objects>0);
2278 for (i=num_objects;i<MAX_OBJECTS;i++) {
2279 free_obj_list[i] = i;
2280 Objects[i].type = OBJ_NONE;
2281 Objects[i].segnum = -1;
2284 Highest_object_index = num_objects-1;
2286 Debris_object_count = 0;
2289 //Tries to find a segment for an object, using find_point_seg()
2290 int find_object_seg(object * obj )
2292 return find_point_seg(&obj->pos,obj->segnum);
2296 //If an object is in a segment, set its segnum field and make sure it's
2297 //properly linked. If not in any segment, returns 0, else 1.
2298 //callers should generally use find_vector_intersection()
2299 int update_object_seg(object * obj )
2303 newseg = find_object_seg(obj);
2308 if ( newseg != obj->segnum )
2309 obj_relink(obj-Objects, newseg );
2315 //go through all objects and make sure they have the correct segment numbers
2321 for (i=0;i<=Highest_object_index;i++)
2322 if (Objects[i].type != OBJ_NONE)
2323 if (update_object_seg(&Objects[i]) == 0) {
2324 mprintf((1,"Cannot find segment for object %d in fix_object_segs()\n"));
2326 compute_segment_center(&Objects[i].pos,&Segments[Objects[i].segnum]);
2331 //--unused-- void object_use_new_object_list( object * new_list )
2333 //--unused-- int i, segnum;
2334 //--unused-- object *obj;
2336 //--unused-- // First, unlink all the old objects for the segments array
2337 //--unused-- for (segnum=0; segnum <= Highest_segment_index; segnum++) {
2338 //--unused-- Segments[segnum].objects = -1;
2340 //--unused-- // Then, erase all the objects
2341 //--unused-- reset_objects(1);
2343 //--unused-- // Fill in the object array
2344 //--unused-- memcpy( Objects, new_list, sizeof(object)*MAX_OBJECTS );
2346 //--unused-- Highest_object_index=-1;
2348 //--unused-- // Relink 'em
2349 //--unused-- for (i=0; i<MAX_OBJECTS; i++ ) {
2350 //--unused-- obj = &Objects[i];
2351 //--unused-- if ( obj->type != OBJ_NONE ) {
2352 //--unused-- num_objects++;
2353 //--unused-- Highest_object_index = i;
2354 //--unused-- segnum = obj->segnum;
2355 //--unused-- obj->next = obj->prev = obj->segnum = -1;
2356 //--unused-- obj_link(i,segnum);
2357 //--unused-- } else {
2358 //--unused-- obj->next = obj->prev = obj->segnum = -1;
2364 //delete objects, such as weapons & explosions, that shouldn't stay between levels
2365 // Changed by MK on 10/15/94, don't remove proximity bombs.
2366 //if clear_all is set, clear even proximity bombs
2367 void clear_transient_objects(int clear_all)
2372 for (objnum=0,obj=&Objects[0];objnum<=Highest_object_index;objnum++,obj++)
2373 if (((obj->type == OBJ_WEAPON) && !(Weapon_info[obj->id].flags&WIF_PLACABLE) && (clear_all || ((obj->id != PROXIMITY_ID) && (obj->id != SUPERPROX_ID)))) ||
2374 obj->type == OBJ_FIREBALL ||
2375 obj->type == OBJ_DEBRIS ||
2376 obj->type == OBJ_DEBRIS ||
2377 (obj->type!=OBJ_NONE && obj->flags & OF_EXPLODING)) {
2380 if (Objects[objnum].lifeleft > i2f(2))
2381 mprintf((0,"Note: Clearing object %d (type=%d, id=%d) with lifeleft=%x\n",objnum,Objects[objnum].type,Objects[objnum].id,Objects[objnum].lifeleft));
2386 else if (Objects[objnum].type!=OBJ_NONE && Objects[objnum].lifeleft < i2f(2))
2387 mprintf((0,"Note: NOT clearing object %d (type=%d, id=%d) with lifeleft=%x\n",objnum,Objects[objnum].type,Objects[objnum].id,Objects[objnum].lifeleft));
2391 //attaches an object, such as a fireball, to another object, such as a robot
2392 void obj_attach(object *parent,object *sub)
2394 Assert(sub->type == OBJ_FIREBALL);
2395 Assert(sub->control_type == CT_EXPLOSION);
2397 Assert(sub->ctype.expl_info.next_attach==-1);
2398 Assert(sub->ctype.expl_info.prev_attach==-1);
2400 Assert(parent->attached_obj==-1 || Objects[parent->attached_obj].ctype.expl_info.prev_attach==-1);
2402 sub->ctype.expl_info.next_attach = parent->attached_obj;
2404 if (sub->ctype.expl_info.next_attach != -1)
2405 Objects[sub->ctype.expl_info.next_attach].ctype.expl_info.prev_attach = sub-Objects;
2407 parent->attached_obj = sub-Objects;
2409 sub->ctype.expl_info.attach_parent = parent-Objects;
2410 sub->flags |= OF_ATTACHED;
2412 Assert(sub->ctype.expl_info.next_attach != sub-Objects);
2413 Assert(sub->ctype.expl_info.prev_attach != sub-Objects);
2416 //dettaches one object
2417 void obj_detach_one(object *sub)
2419 Assert(sub->flags & OF_ATTACHED);
2420 Assert(sub->ctype.expl_info.attach_parent != -1);
2422 if ((Objects[sub->ctype.expl_info.attach_parent].type == OBJ_NONE) || (Objects[sub->ctype.expl_info.attach_parent].attached_obj == -1))
2424 sub->flags &= ~OF_ATTACHED;
2428 if (sub->ctype.expl_info.next_attach != -1) {
2429 Assert(Objects[sub->ctype.expl_info.next_attach].ctype.expl_info.prev_attach=sub-Objects);
2430 Objects[sub->ctype.expl_info.next_attach].ctype.expl_info.prev_attach = sub->ctype.expl_info.prev_attach;
2433 if (sub->ctype.expl_info.prev_attach != -1) {
2434 Assert(Objects[sub->ctype.expl_info.prev_attach].ctype.expl_info.next_attach=sub-Objects);
2435 Objects[sub->ctype.expl_info.prev_attach].ctype.expl_info.next_attach = sub->ctype.expl_info.next_attach;
2438 Assert(Objects[sub->ctype.expl_info.attach_parent].attached_obj=sub-Objects);
2439 Objects[sub->ctype.expl_info.attach_parent].attached_obj = sub->ctype.expl_info.next_attach;
2442 sub->ctype.expl_info.next_attach = sub->ctype.expl_info.prev_attach = -1;
2443 sub->flags &= ~OF_ATTACHED;
2447 //dettaches all objects from this object
2448 void obj_detach_all(object *parent)
2450 while (parent->attached_obj != -1)
2451 obj_detach_one(&Objects[parent->attached_obj]);
2454 //creates a marker object in the world. returns the object number
2455 int drop_marker_object(vms_vector *pos,int segnum,vms_matrix *orient, int marker_num)
2459 Assert(Marker_model_num != -1);
2461 objnum = obj_create(OBJ_MARKER, marker_num, segnum, pos, orient, Polygon_models[Marker_model_num].rad, CT_NONE, MT_NONE, RT_POLYOBJ);
2464 object *obj = &Objects[objnum];
2466 obj->rtype.pobj_info.model_num = Marker_model_num;
2468 vm_vec_copy_scale(&obj->mtype.spin_rate,&obj->orient.uvec,F1_0/2);
2470 // MK, 10/16/95: Using lifeleft to make it flash, thus able to trim lightlevel from all objects.
2471 obj->lifeleft = IMMORTAL_TIME - 1;
2477 extern int Ai_last_missile_camera;
2479 // *viewer is a viewer, probably a missile.
2480 // wake up all robots that were rendered last frame subject to some constraints.
2481 void wake_up_rendered_objects(object *viewer, int window_num)
2485 // Make sure that we are processing current data.
2486 if (FrameCount != Window_rendered_data[window_num].frame) {
2487 mprintf((1, "Warning: Called wake_up_rendered_objects with a bogus window.\n"));
2491 Ai_last_missile_camera = viewer-Objects;
2493 for (i=0; i<Window_rendered_data[window_num].num_objects; i++) {
2496 int fcval = FrameCount & 3;
2498 objnum = Window_rendered_data[window_num].rendered_objects[i];
2499 if ((objnum & 3) == fcval) {
2500 objp = &Objects[objnum];
2502 if (objp->type == OBJ_ROBOT) {
2503 if (vm_vec_dist_quick(&viewer->pos, &objp->pos) < F1_0*100) {
2504 ai_local *ailp = &Ai_local_info[objnum];
2505 if (ailp->player_awareness_type == 0) {
2506 objp->ctype.ai_info.SUB_FLAGS |= SUB_FLAGS_CAMERA_AWAKE;
2507 ailp->player_awareness_type = PA_WEAPON_ROBOT_COLLISION;
2508 ailp->player_awareness_time = F1_0*3;
2509 ailp->previous_visibility = 2;