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.
16 static char rcsid[] = "$Id: object.c,v 1.1.1.1 2001-01-19 03:30:00 bradleyb Exp $";
25 #include <string.h> // for memset
84 #include "editor\editor.h"
95 extern byte WasRecorded[MAX_OBJECTS];
97 ubyte CollisionResult[MAX_OBJECT_TYPES][MAX_OBJECT_TYPES];
99 object *ConsoleObject; //the object that is the player
101 static short free_obj_list[MAX_OBJECTS];
107 //info on the various types of objects
109 object Object_minus_one;
112 object Objects[MAX_OBJECTS];
114 int Highest_object_index=0;
115 int Highest_ever_object_index=0;
117 // grs_bitmap *robot_bms[MAX_ROBOT_BITMAPS]; //all bitmaps for all robots
119 // int robot_bm_nums[MAX_ROBOT_TYPES]; //starting bitmap num for each robot
120 // int robot_n_bitmaps[MAX_ROBOT_TYPES]; //how many bitmaps for each robot
122 // char *robot_names[MAX_ROBOT_TYPES]; //name of each robot
124 //--unused-- int Num_robot_types=0;
126 int print_object_info = 0;
127 //@@int Object_viewer = 0;
129 //object * Slew_object = NULL; // Object containing slew object info.
131 //--unused-- int Player_controller_type = 0;
133 window_rendered_data Window_rendered_data[MAX_RENDERED_WINDOWS];
136 char Object_type_names[MAX_OBJECT_TYPES][9] = {
157 //set viewer object to next object in array
158 void object_goto_next_viewer()
160 int i, start_obj = 0;
162 start_obj = Viewer - Objects; //get viewer object number
164 for (i=0;i<=Highest_object_index;i++) {
167 if (start_obj > Highest_object_index ) start_obj = 0;
169 if (Objects[start_obj].type != OBJ_NONE ) {
170 Viewer = &Objects[start_obj];
175 Error( "Couldn't find a viewer object!" );
179 //set viewer object to next object in array
180 void object_goto_prev_viewer()
182 int i, start_obj = 0;
184 start_obj = Viewer - Objects; //get viewer object number
186 for (i=0; i<=Highest_object_index; i++) {
189 if (start_obj < 0 ) start_obj = Highest_object_index;
191 if (Objects[start_obj].type != OBJ_NONE ) {
192 Viewer = &Objects[start_obj];
197 Error( "Couldn't find a viewer object!" );
202 object *obj_find_first_of_type (int type)
206 for (i=0;i<=Highest_object_index;i++)
207 if (Objects[i].type==type)
208 return (&Objects[i]);
209 return ((object *)NULL);
212 int obj_return_num_of_type (int type)
216 for (i=0;i<=Highest_object_index;i++)
217 if (Objects[i].type==type)
221 int obj_return_num_of_typeid (int type,int id)
225 for (i=0;i<=Highest_object_index;i++)
226 if (Objects[i].type==type && Objects[i].id==id)
231 int global_orientation = 0;
233 //draw an object that has one bitmap & doesn't rotate
234 void draw_object_blob(object *obj,bitmap_index bmi)
237 grs_bitmap * bm = &GameBitmaps[bmi.index];
240 if (obj->type == OBJ_FIREBALL)
241 orientation = (obj-Objects) & 7;
243 orientation = global_orientation;
246 //@@ if (obj->type == OBJ_POWERUP) {
247 //@@ if ( GameBitmaps[(bmi).index].bm_flags & BM_FLAG_PAGED_OUT)
248 //@@ piggy_bitmap_page_in_w( bmi,1 );
250 //@@ if (bm->bm_handle) {
251 //@@ DDGRUNLOCK(dd_grd_curcanv);
254 PIGGY_PAGE_IN( bmi );
257 if (bm->bm_w > bm->bm_h)
259 g3_draw_bitmap(&obj->pos,obj->size,fixmuldiv(obj->size,bm->bm_h,bm->bm_w),bm, orientation);
263 g3_draw_bitmap(&obj->pos,fixmuldiv(obj->size,bm->bm_w,bm->bm_h),obj->size,bm, orientation);
266 //@@ if (bm->bm_handle) {
267 //@@ DDGRLOCK(dd_grd_curcanv);
272 //draw an object that is a texture-mapped rod
273 void draw_object_tmap_rod(object *obj,bitmap_index bitmapi,int lighted)
275 grs_bitmap * bitmap = &GameBitmaps[bitmapi.index];
278 vms_vector delta,top_v,bot_v;
279 g3s_point top_p,bot_p;
281 PIGGY_PAGE_IN(bitmapi);
283 bitmap->bm_handle = bitmapi.index;
285 vm_vec_copy_scale(&delta,&obj->orient.uvec,obj->size);
287 vm_vec_add(&top_v,&obj->pos,&delta);
288 vm_vec_sub(&bot_v,&obj->pos,&delta);
290 g3_rotate_point(&top_p,&top_v);
291 g3_rotate_point(&bot_p,&bot_v);
294 light = compute_object_light(obj,&top_p.p3_vec);
299 _3dfx_rendering_poly_obj = 1;
302 #ifdef PA_3DFX_VOODOO
306 g3_draw_rod_tmap(bitmap,&bot_p,obj->size,&top_p,obj->size,light);
309 _3dfx_rendering_poly_obj = 0;
314 int Linear_tmap_polygon_objects = 1;
316 extern fix Max_thrust;
318 //used for robot engine glow
319 #define MAX_VELOCITY i2f(50)
321 //function that takes the same parms as draw_tmap, but renders as flat poly
322 //we need this to do the cloaked effect
323 extern void draw_tmap_flat();
325 //what darkening level to use when cloaked
326 #define CLOAKED_FADE_LEVEL 28
328 #define CLOAK_FADEIN_DURATION_PLAYER F2_0
329 #define CLOAK_FADEOUT_DURATION_PLAYER F2_0
331 #define CLOAK_FADEIN_DURATION_ROBOT F1_0
332 #define CLOAK_FADEOUT_DURATION_ROBOT F1_0
334 //do special cloaked render
335 void draw_cloaked_object(object *obj,fix light,fix *glow,fix cloak_start_time,fix cloak_end_time)
337 fix cloak_delta_time,total_cloaked_time;
340 int fading=0; //if true, fading, else cloaking
341 fix Cloak_fadein_duration;
342 fix Cloak_fadeout_duration;
345 total_cloaked_time = cloak_end_time-cloak_start_time;
349 Cloak_fadein_duration = CLOAK_FADEIN_DURATION_PLAYER;
350 Cloak_fadeout_duration = CLOAK_FADEOUT_DURATION_PLAYER;
353 Cloak_fadein_duration = CLOAK_FADEIN_DURATION_ROBOT;
354 Cloak_fadeout_duration = CLOAK_FADEOUT_DURATION_ROBOT;
357 Int3(); // Contact Mike: Unexpected object type in draw_cloaked_object.
360 cloak_delta_time = GameTime - cloak_start_time;
362 if (cloak_delta_time < Cloak_fadein_duration/2) {
364 light_scale = fixdiv(Cloak_fadein_duration/2 - cloak_delta_time,Cloak_fadein_duration/2);
368 else if (cloak_delta_time < Cloak_fadein_duration) {
370 cloak_value = f2i(fixdiv(cloak_delta_time - Cloak_fadein_duration/2,Cloak_fadein_duration/2) * CLOAKED_FADE_LEVEL);
372 } else if (GameTime < cloak_end_time-Cloak_fadeout_duration) {
373 static int cloak_delta=0,cloak_dir=1;
374 static fix cloak_timer=0;
376 //note, if more than one cloaked object is visible at once, the
377 //pulse rate will change!
379 cloak_timer -= FrameTime;
380 while (cloak_timer < 0) {
382 cloak_timer += Cloak_fadeout_duration/12;
384 cloak_delta += cloak_dir;
386 if (cloak_delta==0 || cloak_delta==4)
387 cloak_dir = -cloak_dir;
390 cloak_value = CLOAKED_FADE_LEVEL - cloak_delta;
392 } else if (GameTime < cloak_end_time-Cloak_fadeout_duration/2) {
394 cloak_value = f2i(fixdiv(total_cloaked_time - Cloak_fadeout_duration/2 - cloak_delta_time,Cloak_fadeout_duration/2) * CLOAKED_FADE_LEVEL);
398 light_scale = fixdiv(Cloak_fadeout_duration/2 - (total_cloaked_time - cloak_delta_time),Cloak_fadeout_duration/2);
404 fix new_light,save_glow;
405 bitmap_index * alt_textures = NULL;
408 if ( obj->rtype.pobj_info.alt_textures > 0 )
409 alt_textures = multi_player_textures[obj->rtype.pobj_info.alt_textures-1];
412 new_light = fixmul(light,light_scale);
414 glow[0] = fixmul(glow[0],light_scale);
415 draw_polygon_model(&obj->pos,&obj->orient,&obj->rtype.pobj_info.anim_angles,obj->rtype.pobj_info.model_num,obj->rtype.pobj_info.subobj_flags,new_light,glow, alt_textures );
419 Gr_scanline_darkening_level = cloak_value;
420 gr_setcolor(BM_XRGB(0,0,0)); //set to black (matters for s3)
421 g3_set_special_render(draw_tmap_flat,NULL,NULL); //use special flat drawer
422 draw_polygon_model(&obj->pos,&obj->orient,&obj->rtype.pobj_info.anim_angles,obj->rtype.pobj_info.model_num,obj->rtype.pobj_info.subobj_flags,light,glow,NULL );
423 g3_set_special_render(NULL,NULL,NULL);
424 Gr_scanline_darkening_level = GR_FADE_LEVELS;
429 //draw an object which renders as a polygon model
430 void draw_polygon_object(object *obj)
434 fix engine_glow_value[2]; //element 0 is for engine glow, 1 for headlight
436 light = compute_object_light(obj,NULL);
438 // If option set for bright players in netgame, brighten them!
440 if (Game_mode & GM_MULTI)
441 if (Netgame.BrightPlayers)
445 //make robots brighter according to robot glow field
446 if (obj->type == OBJ_ROBOT)
447 light += (Robot_info[obj->id].glow<<12); //convert 4:4 to 16:16
449 if (obj->type == OBJ_WEAPON)
450 if (obj->id == FLARE_ID)
453 if (obj->type == OBJ_MARKER)
457 imsave = Interpolation_method;
458 if (Linear_tmap_polygon_objects)
459 Interpolation_method = 1;
461 //set engine glow value
462 engine_glow_value[0] = f1_0/5;
463 if (obj->movement_type == MT_PHYSICS) {
465 if (obj->mtype.phys_info.flags & PF_USES_THRUST && obj->type==OBJ_PLAYER && obj->id==Player_num) {
466 fix thrust_mag = vm_vec_mag_quick(&obj->mtype.phys_info.thrust);
467 engine_glow_value[0] += (fixdiv(thrust_mag,Player_ship->max_thrust)*4)/5;
470 fix speed = vm_vec_mag_quick(&obj->mtype.phys_info.velocity);
471 engine_glow_value[0] += (fixdiv(speed,MAX_VELOCITY)*3)/5;
475 //set value for player headlight
476 if (obj->type == OBJ_PLAYER) {
477 if (Players[obj->id].flags & PLAYER_FLAGS_HEADLIGHT && !Endlevel_sequence)
478 if (Players[obj->id].flags & PLAYER_FLAGS_HEADLIGHT_ON)
479 engine_glow_value[1] = -2; //draw white!
481 engine_glow_value[1] = -1; //draw normal color (grey)
483 engine_glow_value[1] = -3; //don't draw
486 if (obj->rtype.pobj_info.tmap_override != -1) {
487 polymodel *pm = &Polygon_models[obj->rtype.pobj_info.model_num];
488 bitmap_index bm_ptrs[12];
492 Assert(pm->n_textures<=12);
494 for (i=0;i<12;i++) //fill whole array, in case simple model needs more
495 bm_ptrs[i] = Textures[obj->rtype.pobj_info.tmap_override];
497 draw_polygon_model(&obj->pos,&obj->orient,&obj->rtype.pobj_info.anim_angles,obj->rtype.pobj_info.model_num,obj->rtype.pobj_info.subobj_flags,light,engine_glow_value,bm_ptrs);
501 if (obj->type==OBJ_PLAYER && (Players[obj->id].flags&PLAYER_FLAGS_CLOAKED))
502 draw_cloaked_object(obj,light,engine_glow_value,Players[obj->id].cloak_time,Players[obj->id].cloak_time+CLOAK_TIME_MAX);
503 else if ((obj->type == OBJ_ROBOT) && (obj->ctype.ai_info.CLOAKED)) {
504 if (Robot_info[obj->id].boss_flag)
505 draw_cloaked_object(obj,light,engine_glow_value, Boss_cloak_start_time, Boss_cloak_end_time);
507 draw_cloaked_object(obj,light,engine_glow_value, GameTime-F1_0*10, GameTime+F1_0*10);
509 bitmap_index * alt_textures = NULL;
512 if ( obj->rtype.pobj_info.alt_textures > 0 )
513 alt_textures = multi_player_textures[obj->rtype.pobj_info.alt_textures-1];
516 // Snipers get bright when they fire.
517 if (Ai_local_info[obj-Objects].next_fire < F1_0/8) {
518 if (obj->ctype.ai_info.behavior == AIB_SNIPE)
519 light = 2*light + F1_0;
522 draw_polygon_model(&obj->pos,&obj->orient,&obj->rtype.pobj_info.anim_angles,obj->rtype.pobj_info.model_num,obj->rtype.pobj_info.subobj_flags,light,engine_glow_value,alt_textures);
523 if (obj->type == OBJ_WEAPON && (Weapon_info[obj->id].model_num_inner > -1 )) {
524 fix dist_to_eye = vm_vec_dist_quick(&Viewer->pos, &obj->pos);
525 if (dist_to_eye < Simple_model_threshhold_scale * F1_0*2)
526 draw_polygon_model(&obj->pos,&obj->orient,&obj->rtype.pobj_info.anim_angles,Weapon_info[obj->id].model_num_inner,obj->rtype.pobj_info.subobj_flags,light,engine_glow_value,alt_textures);
531 Interpolation_method = imsave;
535 //------------------------------------------------------------------------------
536 // These variables are used to keep a list of the 3 closest robots to the viewer.
537 // The code works like this: Every time render object is called with a polygon model,
538 // it finds the distance of that robot to the viewer. If this distance if within 10
539 // segments of the viewer, it does the following: If there aren't already 3 robots in
540 // the closet-robots list, it just sticks that object into the list along with its distance.
541 // If the list already contains 3 robots, then it finds the robot in that list that is
542 // farthest from the viewer. If that object is farther than the object currently being
543 // rendered, then the new object takes over that far object's slot. *Then* after all
544 // objects are rendered, object_render_targets is called an it draws a target on top
545 // of all the objects.
547 //091494: #define MAX_CLOSE_ROBOTS 3
548 //--unused-- static int Object_draw_lock_boxes = 0;
549 //091494: static int Object_num_close = 0;
550 //091494: static object * Object_close_ones[MAX_CLOSE_ROBOTS];
551 //091494: static fix Object_close_distance[MAX_CLOSE_ROBOTS];
553 //091494: set_close_objects(object *obj)
557 //091494: if ( (obj->type != OBJ_ROBOT) || (Object_draw_lock_boxes==0) )
560 //091494: // The following code keeps a list of the 10 closest robots to the
561 //091494: // viewer. See comments in front of this function for how this works.
562 //091494: dist = vm_vec_dist( &obj->pos, &Viewer->pos );
563 //091494: if ( dist < i2f(20*10) ) {
564 //091494: if ( Object_num_close < MAX_CLOSE_ROBOTS ) {
565 //091494: Object_close_ones[Object_num_close] = obj;
566 //091494: Object_close_distance[Object_num_close] = dist;
567 //091494: Object_num_close++;
569 //091494: int i, farthest_robot;
570 //091494: fix farthest_distance;
571 //091494: // Find the farthest robot in the list
572 //091494: farthest_robot = 0;
573 //091494: farthest_distance = Object_close_distance[0];
574 //091494: for (i=1; i<Object_num_close; i++ ) {
575 //091494: if ( Object_close_distance[i] > farthest_distance ) {
576 //091494: farthest_distance = Object_close_distance[i];
577 //091494: farthest_robot = i;
580 //091494: // If this object is closer to the viewer than
581 //091494: // the farthest in the list, replace the farthest with this object.
582 //091494: if ( farthest_distance > dist ) {
583 //091494: Object_close_ones[farthest_robot] = obj;
584 //091494: Object_close_distance[farthest_robot] = dist;
590 int Player_fired_laser_this_frame=-1;
594 // -----------------------------------------------------------------------------
595 //this routine checks to see if an robot rendered near the middle of
596 //the screen, and if so and the player had fired, "warns" the robot
597 void set_robot_location_info(object *objp)
599 if (Player_fired_laser_this_frame != -1) {
602 g3_rotate_point(&temp,&objp->pos);
604 if (temp.p3_codes & CC_BEHIND) //robot behind the screen
607 //the code below to check for object near the center of the screen
608 //completely ignores z, which may not be good
610 if ((abs(temp.p3_x) < F1_0*4) && (abs(temp.p3_y) < F1_0*4)) {
611 objp->ctype.ai_info.danger_laser_num = Player_fired_laser_this_frame;
612 objp->ctype.ai_info.danger_laser_signature = Objects[Player_fired_laser_this_frame].signature;
619 // ------------------------------------------------------------------------------------------------------------------
620 void create_small_fireball_on_object(object *objp, fix size_scale, int sound_flag)
623 vms_vector pos, rand_vec;
627 make_random_vector(&rand_vec);
629 vm_vec_scale(&rand_vec, objp->size/2);
631 vm_vec_add2(&pos, &rand_vec);
633 size = fixmul(size_scale, F1_0/2 + d_rand()*4/2);
635 segnum = find_point_seg(&pos, objp->segnum);
638 expl_obj = object_create_explosion(segnum, &pos, size, VCLIP_SMALL_EXPLOSION);
641 obj_attach(objp,expl_obj);
642 if (d_rand() < 8192) {
644 if (objp->type == OBJ_ROBOT)
647 digi_link_sound_to_object(SOUND_EXPLODING_WALL, objp-Objects, 0, vol);
652 // ------------------------------------------------------------------------------------------------------------------
653 void create_vclip_on_object(object *objp, fix size_scale, int vclip_num)
656 vms_vector pos, rand_vec;
660 make_random_vector(&rand_vec);
662 vm_vec_scale(&rand_vec, objp->size/2);
664 vm_vec_add2(&pos, &rand_vec);
666 size = fixmul(size_scale, F1_0 + d_rand()*4);
668 segnum = find_point_seg(&pos, objp->segnum);
671 expl_obj = object_create_explosion(segnum, &pos, size, vclip_num);
675 expl_obj->movement_type = MT_PHYSICS;
676 expl_obj->mtype.phys_info.velocity.x = objp->mtype.phys_info.velocity.x/2;
677 expl_obj->mtype.phys_info.velocity.y = objp->mtype.phys_info.velocity.y/2;
678 expl_obj->mtype.phys_info.velocity.z = objp->mtype.phys_info.velocity.z/2;
682 // -- mk, 02/05/95 -- #define VCLIP_INVULNERABILITY_EFFECT VCLIP_SMALL_EXPLOSION
683 // -- mk, 02/05/95 --
684 // -- mk, 02/05/95 -- // -----------------------------------------------------------------------------
685 // -- mk, 02/05/95 -- void do_player_invulnerability_effect(object *objp)
686 // -- mk, 02/05/95 -- {
687 // -- mk, 02/05/95 -- if (d_rand() < FrameTime*8) {
688 // -- mk, 02/05/95 -- create_vclip_on_object(objp, F1_0, VCLIP_INVULNERABILITY_EFFECT);
689 // -- mk, 02/05/95 -- }
690 // -- mk, 02/05/95 -- }
692 // -----------------------------------------------------------------------------
693 // Render an object. Calls one of several routines based on type
694 void render_object(object *obj)
698 if ( obj == Viewer ) return;
700 if ( obj->type==OBJ_NONE ) {
702 mprintf( (1, "ERROR!!!! Bogus obj %d in seg %d is rendering!\n", obj-Objects, obj->segnum ));
708 mld_save = Max_linear_depth;
709 Max_linear_depth = Max_linear_depth_objects;
711 switch (obj->render_type) {
713 case RT_NONE: break; //doesn't render, like the player
717 draw_polygon_object(obj);
719 //"warn" robot if being shot at
720 if (obj->type == OBJ_ROBOT)
721 set_robot_location_info(obj);
723 //JOHN SAID TO: if ( (obj->type==OBJ_PLAYER) && ((keyd_pressed[KEY_W]) || (keyd_pressed[KEY_I])))
724 //JOHN SAID TO: object_render_id(obj);
726 // -- mk, 02/05/95 -- if (obj->type == OBJ_PLAYER)
727 // -- mk, 02/05/95 -- if (Players[obj->id].flags & PLAYER_FLAGS_INVULNERABLE)
728 // -- mk, 02/05/95 -- do_player_invulnerability_effect(obj);
732 case RT_MORPH: draw_morph_object(obj); break;
734 case RT_FIREBALL: draw_fireball(obj); break;
736 case RT_WEAPON_VCLIP: draw_weapon_vclip(obj); break;
738 case RT_HOSTAGE: draw_hostage(obj); break;
740 case RT_POWERUP: draw_powerup(obj); break;
742 case RT_LASER: Laser_render(obj); break;
744 default: Error("Unknown render_type <%d>",obj->render_type);
748 if ( obj->render_type != RT_NONE )
749 if ( Newdemo_state == ND_STATE_RECORDING ) {
750 if (!WasRecorded[obj-Objects]) {
751 newdemo_record_render_object(obj);
752 WasRecorded[obj-Objects]=1;
757 Max_linear_depth = mld_save;
761 //--unused-- void object_toggle_lock_targets() {
762 //--unused-- Object_draw_lock_boxes ^= 1;
765 //091494: //draw target boxes for nearby robots
766 //091494: void object_render_targets()
768 //091494: g3s_point pt;
769 //091494: ubyte codes;
771 //091494: int radius,x,y;
773 //091494: if (Object_draw_lock_boxes==0)
776 //091494: for (i=0; i<Object_num_close; i++ ) {
778 //091494: codes = g3_rotate_point(&pt, &Object_close_ones[i]->pos );
779 //091494: if ( !(codes & CC_BEHIND) ) {
780 //091494: g3_project_point(&pt);
781 //091494: if (pt.p3_flags & PF_PROJECTED) {
782 //091494: x = f2i(pt.p3_sx);
783 //091494: y = f2i(pt.p3_sy);
784 //091494: radius = f2i(fixdiv((grd_curcanv->cv_bitmap.bm_w*Object_close_ones[i]->size)/8,pt.z));
785 //091494: gr_setcolor( BM_XRGB(0,31,0) );
786 //091494: gr_box(x-radius,y-radius,x+radius,y+radius);
790 //091494: Object_num_close=0;
792 //--unused-- //draw target boxes for nearby robots
793 //--unused-- void object_render_id(object * obj)
795 //--unused-- g3s_point pt;
796 //--unused-- ubyte codes;
797 //--unused-- int x,y;
798 //--unused-- int w, h, aw;
799 //--unused-- char s[20], *s1;
801 //--unused-- s1 = network_get_player_name( obj-Objects );
804 //--unused-- sprintf( s, "%s", s1 );
806 //--unused-- sprintf( s, "<%d>", obj->id );
808 //--unused-- codes = g3_rotate_point(&pt, &obj->pos );
809 //--unused-- if ( !(codes & CC_BEHIND) ) {
810 //--unused-- g3_project_point(&pt);
811 //--unused-- if (pt.p3_flags & PF_PROJECTED) {
812 //--unused-- gr_get_string_size( s, &w, &h, &aw );
813 //--unused-- x = f2i(pt.p3_sx) - w/2;
814 //--unused-- y = f2i(pt.p3_sy) - h/2;
815 //--unused-- if ( x>= 0 && y>=0 && (x+w)<=grd_curcanv->cv_bitmap.bm_w && (y+h)<grd_curcanv->cv_bitmap.bm_h ) {
816 //--unused-- gr_set_fontcolor( BM_XRGB(0,31,0), -1 );
817 //--unused-- gr_string( x, y, s );
823 void check_and_fix_matrix(vms_matrix *m);
825 #define vm_angvec_zero(v) (v)->p=(v)->b=(v)->h=0
827 void reset_player_object()
833 vm_vec_zero(&ConsoleObject->mtype.phys_info.velocity);
834 vm_vec_zero(&ConsoleObject->mtype.phys_info.thrust);
835 vm_vec_zero(&ConsoleObject->mtype.phys_info.rotvel);
836 vm_vec_zero(&ConsoleObject->mtype.phys_info.rotthrust);
837 ConsoleObject->mtype.phys_info.brakes = ConsoleObject->mtype.phys_info.turnroll = 0;
838 ConsoleObject->mtype.phys_info.mass = Player_ship->mass;
839 ConsoleObject->mtype.phys_info.drag = Player_ship->drag;
840 ConsoleObject->mtype.phys_info.flags |= PF_TURNROLL | PF_LEVELLING | PF_WIGGLE | PF_USES_THRUST;
844 ConsoleObject->render_type = RT_POLYOBJ;
845 ConsoleObject->rtype.pobj_info.model_num = Player_ship->model_num; //what model is this?
846 ConsoleObject->rtype.pobj_info.subobj_flags = 0; //zero the flags
847 ConsoleObject->rtype.pobj_info.tmap_override = -1; //no tmap override!
849 for (i=0;i<MAX_SUBMODELS;i++)
850 vm_angvec_zero(&ConsoleObject->rtype.pobj_info.anim_angles[i]);
854 ConsoleObject->flags = 0;
859 //make object0 the player, setting all relevant fields
860 void init_player_object()
862 ConsoleObject->type = OBJ_PLAYER;
863 ConsoleObject->id = 0; //no sub-types for player
865 ConsoleObject->signature = 0; //player has zero, others start at 1
867 ConsoleObject->size = Polygon_models[Player_ship->model_num].rad;
869 ConsoleObject->control_type = CT_SLEW; //default is player slewing
870 ConsoleObject->movement_type = MT_PHYSICS; //change this sometime
872 ConsoleObject->lifeleft = IMMORTAL_TIME;
874 ConsoleObject->attached_obj = -1;
876 reset_player_object();
880 //sets up the free list & init player & whatever else
887 for (i=0;i<MAX_OBJECTS;i++) {
888 free_obj_list[i] = i;
889 Objects[i].type = OBJ_NONE;
890 Objects[i].segnum = -1;
893 for (i=0;i<MAX_SEGMENTS;i++)
894 Segments[i].objects = -1;
896 ConsoleObject = Viewer = &Objects[0];
898 init_player_object();
899 obj_link(ConsoleObject-Objects,0); //put in the world in segment 0
901 num_objects = 1; //just the player
902 Highest_object_index = 0;
907 //after calling init_object(), the network code has grabbed specific
908 //object slots without allocating them. Go though the objects & build
909 //the free list, then set the apporpriate globals
910 void special_reset_objects(void)
914 num_objects=MAX_OBJECTS;
916 Highest_object_index = 0;
917 Assert(Objects[0].type != OBJ_NONE); //0 should be used
919 for (i=MAX_OBJECTS;i--;)
920 if (Objects[i].type == OBJ_NONE)
921 free_obj_list[--num_objects] = i;
923 if (i > Highest_object_index)
924 Highest_object_index = i;
928 int is_object_in_seg( int segnum, int objn )
930 int objnum, count = 0;
932 for (objnum=Segments[segnum].objects;objnum!=-1;objnum=Objects[objnum].next) {
933 if ( count > MAX_OBJECTS ) {
937 if ( objnum==objn ) count++;
942 int search_all_segments_for_object( int objnum )
947 for (i=0; i<=Highest_segment_index; i++) {
948 count += is_object_in_seg( i, objnum );
953 void johns_obj_unlink(int segnum, int objnum)
955 object *obj = &Objects[objnum];
956 segment *seg = &Segments[segnum];
958 Assert(objnum != -1);
961 seg->objects = obj->next;
963 Objects[obj->prev].next = obj->next;
965 if (obj->next != -1) Objects[obj->next].prev = obj->prev;
968 void remove_incorrect_objects()
970 int segnum, objnum, count;
972 for (segnum=0; segnum <= Highest_segment_index; segnum++) {
974 for (objnum=Segments[segnum].objects;objnum!=-1;objnum=Objects[objnum].next) {
977 if ( count > MAX_OBJECTS ) {
978 mprintf((1, "Object list in segment %d is circular.\n", segnum ));
982 if (Objects[objnum].segnum != segnum ) {
984 mprintf((0, "Removing object %d from segment %d.\n", objnum, segnum ));
987 johns_obj_unlink(segnum,objnum);
993 void remove_all_objects_but( int segnum, int objnum )
997 for (i=0; i<=Highest_segment_index; i++) {
999 if (is_object_in_seg( i, objnum )) {
1000 johns_obj_unlink( i, objnum );
1006 int check_duplicate_objects()
1010 for (i=0;i<=Highest_object_index;i++) {
1011 if ( Objects[i].type != OBJ_NONE ) {
1012 count = search_all_segments_for_object( i );
1015 mprintf((1, "Object %d is in %d segments!\n", i, count ));
1018 remove_all_objects_but( Objects[i].segnum, i );
1026 void list_seg_objects( int segnum )
1028 int objnum, count = 0;
1030 for (objnum=Segments[segnum].objects;objnum!=-1;objnum=Objects[objnum].next) {
1032 if ( count > MAX_OBJECTS ) {
1042 //link the object into the list for its segment
1043 void obj_link(int objnum,int segnum)
1045 object *obj = &Objects[objnum];
1047 Assert(objnum != -1);
1049 Assert(obj->segnum == -1);
1051 Assert(segnum>=0 && segnum<=Highest_segment_index);
1053 obj->segnum = segnum;
1055 obj->next = Segments[segnum].objects;
1058 Segments[segnum].objects = objnum;
1060 if (obj->next != -1) Objects[obj->next].prev = objnum;
1062 //list_seg_objects( segnum );
1063 //check_duplicate_objects();
1065 Assert(Objects[0].next != 0);
1066 if (Objects[0].next == 0)
1067 Objects[0].next = -1;
1069 Assert(Objects[0].prev != 0);
1070 if (Objects[0].prev == 0)
1071 Objects[0].prev = -1;
1074 void obj_unlink(int objnum)
1076 object *obj = &Objects[objnum];
1077 segment *seg = &Segments[obj->segnum];
1079 Assert(objnum != -1);
1081 if (obj->prev == -1)
1082 seg->objects = obj->next;
1084 Objects[obj->prev].next = obj->next;
1086 if (obj->next != -1) Objects[obj->next].prev = obj->prev;
1090 Assert(Objects[0].next != 0);
1091 Assert(Objects[0].prev != 0);
1094 int Object_next_signature = 1; //player gets 0, others start at 1
1096 int Debris_object_count=0;
1098 int Unused_object_slots;
1100 //returns the number of a free object, updating Highest_object_index.
1101 //Generally, obj_create() should be called to get an object, since it
1102 //fills in important fields and does the linking.
1103 //returns -1 if no free objects
1104 int obj_allocate(void)
1108 if ( num_objects >= MAX_OBJECTS-2 ) {
1111 num_freed = free_object_slots(MAX_OBJECTS-10);
1112 mprintf((0, " *** Freed %i objects in frame %i\n", num_freed, FrameCount));
1115 if ( num_objects >= MAX_OBJECTS ) {
1117 mprintf((1, "Object creation failed - too many objects!\n" ));
1122 objnum = free_obj_list[num_objects++];
1124 if (objnum > Highest_object_index) {
1125 Highest_object_index = objnum;
1126 if (Highest_object_index > Highest_ever_object_index)
1127 Highest_ever_object_index = Highest_object_index;
1132 Unused_object_slots=0;
1133 for (i=0; i<=Highest_object_index; i++)
1134 if (Objects[i].type == OBJ_NONE)
1135 Unused_object_slots++;
1140 //frees up an object. Generally, obj_delete() should be called to get
1141 //rid of an object. This function deallocates the object entry after
1142 //the object has been unlinked
1143 void obj_free(int objnum)
1145 free_obj_list[--num_objects] = objnum;
1146 Assert(num_objects >= 0);
1148 if (objnum == Highest_object_index)
1149 while (Objects[--Highest_object_index].type == OBJ_NONE);
1152 //-----------------------------------------------------------------------------
1153 // Scan the object list, freeing down to num_used objects
1154 // Returns number of slots freed.
1155 int free_object_slots(int num_used)
1158 int obj_list[MAX_OBJECTS];
1159 int num_already_free, num_to_free, original_num_to_free;
1162 num_already_free = MAX_OBJECTS - Highest_object_index - 1;
1164 if (MAX_OBJECTS - num_already_free < num_used)
1167 for (i=0; i<=Highest_object_index; i++) {
1168 if (Objects[i].flags & OF_SHOULD_BE_DEAD) {
1170 if (MAX_OBJECTS - num_already_free < num_used)
1171 return num_already_free;
1173 switch (Objects[i].type) {
1176 if (MAX_OBJECTS - num_already_free < num_used)
1181 Int3(); // This is curious. What is an object that is a wall?
1186 obj_list[olind++] = i;
1202 num_to_free = MAX_OBJECTS - num_used - num_already_free;
1203 original_num_to_free = num_to_free;
1205 if (num_to_free > olind) {
1206 mprintf((1, "Warning: Asked to free %i objects, but can only free %i.\n", num_to_free, olind));
1207 num_to_free = olind;
1210 for (i=0; i<num_to_free; i++)
1211 if (Objects[obj_list[i]].type == OBJ_DEBRIS) {
1213 mprintf((0, "Freeing DEBRIS object %3i\n", obj_list[i]));
1214 Objects[obj_list[i]].flags |= OF_SHOULD_BE_DEAD;
1218 return original_num_to_free;
1220 for (i=0; i<num_to_free; i++)
1221 if (Objects[obj_list[i]].type == OBJ_FIREBALL && Objects[obj_list[i]].ctype.expl_info.delete_objnum==-1) {
1223 mprintf((0, "Freeing FIREBALL object %3i\n", obj_list[i]));
1224 Objects[obj_list[i]].flags |= OF_SHOULD_BE_DEAD;
1228 return original_num_to_free;
1230 for (i=0; i<num_to_free; i++)
1231 if ((Objects[obj_list[i]].type == OBJ_WEAPON) && (Objects[obj_list[i]].id == FLARE_ID)) {
1233 Objects[obj_list[i]].flags |= OF_SHOULD_BE_DEAD;
1237 return original_num_to_free;
1239 for (i=0; i<num_to_free; i++)
1240 if ((Objects[obj_list[i]].type == OBJ_WEAPON) && (Objects[obj_list[i]].id != FLARE_ID)) {
1242 mprintf((0, "Freeing WEAPON object %3i\n", obj_list[i]));
1243 Objects[obj_list[i]].flags |= OF_SHOULD_BE_DEAD;
1246 return original_num_to_free - num_to_free;
1249 //-----------------------------------------------------------------------------
1250 //initialize a new object. adds to the list for the given segment
1251 //note that segnum is really just a suggestion, since this routine actually
1252 //searches for the correct segment
1253 //returns the object number
1254 int obj_create(ubyte type,ubyte id,int segnum,vms_vector *pos,
1255 vms_matrix *orient,fix size,ubyte ctype,ubyte mtype,ubyte rtype)
1260 Assert(segnum <= Highest_segment_index);
1261 Assert (segnum >= 0);
1262 Assert(ctype <= CT_CNTRLCEN);
1264 if (type==OBJ_DEBRIS && Debris_object_count>=Max_debris_objects)
1267 if (get_seg_masks(pos,segnum,0).centermask!=0)
1268 if ((segnum=find_point_seg(pos,segnum))==-1) {
1270 mprintf((0,"Bad segnum in obj_create (type=%d)\n",type));
1272 return -1; //don't create this object
1275 // Find next free object
1276 objnum = obj_allocate();
1278 if (objnum == -1) //no free objects
1281 Assert(Objects[objnum].type == OBJ_NONE); //make sure unused
1283 obj = &Objects[objnum];
1285 Assert(obj->segnum == -1);
1287 // Zero out object structure to keep weird bugs from happening
1288 // in uninitialized fields.
1289 memset( obj, 0, sizeof(object) );
1291 obj->signature = Object_next_signature++;
1294 obj->last_pos = *pos;
1298 //@@if (orient != NULL)
1299 //@@ obj->orient = *orient;
1301 obj->orient = orient?*orient:vmd_identity_matrix;
1303 obj->control_type = ctype;
1304 obj->movement_type = mtype;
1305 obj->render_type = rtype;
1306 obj->contains_type = -1;
1308 obj->lifeleft = IMMORTAL_TIME; //assume immortal
1309 obj->attached_obj = -1;
1311 if (obj->control_type == CT_POWERUP)
1312 obj->ctype.powerup_info.count = 1;
1314 // Init physics info for this object
1315 if (obj->movement_type == MT_PHYSICS) {
1317 vm_vec_zero(&obj->mtype.phys_info.velocity);
1318 vm_vec_zero(&obj->mtype.phys_info.thrust);
1319 vm_vec_zero(&obj->mtype.phys_info.rotvel);
1320 vm_vec_zero(&obj->mtype.phys_info.rotthrust);
1322 obj->mtype.phys_info.mass = 0;
1323 obj->mtype.phys_info.drag = 0;
1324 obj->mtype.phys_info.brakes = 0;
1325 obj->mtype.phys_info.turnroll = 0;
1326 obj->mtype.phys_info.flags = 0;
1329 if (obj->render_type == RT_POLYOBJ)
1330 obj->rtype.pobj_info.tmap_override = -1;
1332 obj->shields = 20*F1_0;
1334 segnum = find_point_seg(pos,segnum); //find correct segment
1338 obj->segnum = -1; //set to zero by memset, above
1339 obj_link(objnum,segnum);
1341 // Set (or not) persistent bit in phys_info.
1342 if (obj->type == OBJ_WEAPON) {
1343 Assert(obj->control_type == CT_WEAPON);
1344 obj->mtype.phys_info.flags |= (Weapon_info[obj->id].persistent*PF_PERSISTENT);
1345 obj->ctype.laser_info.creation_time = GameTime;
1346 obj->ctype.laser_info.last_hitobj = -1;
1347 obj->ctype.laser_info.multiplier = F1_0;
1350 if (obj->control_type == CT_POWERUP)
1351 obj->ctype.powerup_info.creation_time = GameTime;
1353 if (obj->control_type == CT_EXPLOSION)
1354 obj->ctype.expl_info.next_attach = obj->ctype.expl_info.prev_attach = obj->ctype.expl_info.attach_parent = -1;
1357 if (print_object_info)
1358 mprintf( (0, "Created object %d of type %d\n", objnum, obj->type ));
1361 if (obj->type == OBJ_DEBRIS)
1362 Debris_object_count++;
1368 //create a copy of an object. returns new object number
1369 int obj_create_copy(int objnum, vms_vector *new_pos, int newsegnum)
1374 // Find next free object
1375 newobjnum = obj_allocate();
1377 if (newobjnum == -1)
1380 obj = &Objects[newobjnum];
1382 *obj = Objects[objnum];
1384 obj->pos = obj->last_pos = *new_pos;
1386 obj->next = obj->prev = obj->segnum = -1;
1388 obj_link(newobjnum,newsegnum);
1390 obj->signature = Object_next_signature++;
1392 //we probably should initialize sub-structures here
1399 extern void newdemo_record_guided_end();
1401 //remove object from the world
1402 void obj_delete(int objnum)
1405 object *obj = &Objects[objnum];
1407 Assert(objnum != -1);
1408 Assert(objnum != 0 );
1409 Assert(obj->type != OBJ_NONE);
1410 Assert(obj != ConsoleObject);
1412 if (obj->type==OBJ_WEAPON && obj->id==GUIDEDMISS_ID) {
1413 pnum=Objects[obj->ctype.laser_info.parent_num].id;
1414 mprintf ((0,"Deleting a guided missile! Player %d\n\n",pnum));
1416 if (pnum!=Player_num) {
1417 mprintf ((0,"deleting missile that belongs to %d (%s)!\n",pnum,Players[pnum].callsign));
1418 Guided_missile[pnum]=NULL;
1420 else if (Newdemo_state==ND_STATE_RECORDING)
1421 newdemo_record_guided_end();
1425 if (obj == Viewer) //deleting the viewer?
1426 Viewer = ConsoleObject; //..make the player the viewer
1428 if (obj->flags & OF_ATTACHED) //detach this from object
1429 obj_detach_one(obj);
1431 if (obj->attached_obj != -1) //detach all objects from this
1432 obj_detach_all(obj);
1434 #if !defined(NDEBUG) && !defined(NMONO)
1435 if (print_object_info) mprintf( (0, "Deleting object %d of type %d\n", objnum, Objects[objnum].type ));
1438 if (obj->type == OBJ_DEBRIS)
1439 Debris_object_count--;
1443 Assert(Objects[0].next != 0);
1445 obj->type = OBJ_NONE; //unused!
1446 obj->signature = -1;
1447 obj->segnum=-1; // zero it!
1452 #define DEATH_SEQUENCE_LENGTH (F1_0*5)
1453 #define DEATH_SEQUENCE_EXPLODE_TIME (F1_0*2)
1455 int Player_is_dead = 0; // If !0, then player is dead, but game continues so he can watch.
1456 object *Dead_player_camera = NULL; // Object index of object watching deader.
1457 fix Player_time_of_death; // Time at which player died.
1458 object *Viewer_save;
1459 int Player_flags_save;
1460 int Player_exploded = 0;
1461 int Death_sequence_aborted=0;
1462 int Player_eggs_dropped=0;
1463 fix Camera_to_player_dist_goal=F1_0*4;
1465 ubyte Control_type_save, Render_type_save;
1466 extern int Cockpit_mode_save; //set while in letterbox or rear view, or -1
1468 // ------------------------------------------------------------------------------------------------------------------
1469 void dead_player_end(void)
1471 if (!Player_is_dead)
1474 if (Newdemo_state == ND_STATE_RECORDING)
1475 newdemo_record_restore_cockpit();
1478 Player_exploded = 0;
1479 obj_delete(Dead_player_camera-Objects);
1480 Dead_player_camera = NULL;
1481 select_cockpit(Cockpit_mode_save);
1482 Cockpit_mode_save = -1;
1483 Viewer = Viewer_save;
1484 ConsoleObject->type = OBJ_PLAYER;
1485 ConsoleObject->flags = Player_flags_save;
1487 Assert((Control_type_save == CT_FLYING) || (Control_type_save == CT_SLEW));
1489 ConsoleObject->control_type = Control_type_save;
1490 ConsoleObject->render_type = Render_type_save;
1491 Players[Player_num].flags &= ~PLAYER_FLAGS_INVULNERABLE;
1492 Player_eggs_dropped = 0;
1496 // ------------------------------------------------------------------------------------------------------------------
1497 // Camera is less than size of player away from
1498 void set_camera_pos(vms_vector *camera_pos, object *objp)
1501 fix camera_player_dist;
1504 camera_player_dist = vm_vec_dist_quick(camera_pos, &objp->pos);
1506 if (camera_player_dist < Camera_to_player_dist_goal) { //2*objp->size) {
1507 // Camera is too close to player object, so move it away.
1508 vms_vector player_camera_vec;
1511 vms_vector local_p1;
1513 vm_vec_sub(&player_camera_vec, camera_pos, &objp->pos);
1514 if ((player_camera_vec.x == 0) && (player_camera_vec.y == 0) && (player_camera_vec.z == 0))
1515 player_camera_vec.x += F1_0/16;
1517 hit_data.hit_type = HIT_WALL;
1520 while ((hit_data.hit_type != HIT_NONE) && (count++ < 6)) {
1521 vms_vector closer_p1;
1522 vm_vec_normalize_quick(&player_camera_vec);
1523 vm_vec_scale(&player_camera_vec, Camera_to_player_dist_goal);
1526 vm_vec_add(&closer_p1, &objp->pos, &player_camera_vec); // This is the actual point we want to put the camera at.
1527 vm_vec_scale(&player_camera_vec, far_scale); // ...but find a point 50% further away...
1528 vm_vec_add(&local_p1, &objp->pos, &player_camera_vec); // ...so we won't have to do as many cuts.
1531 fq.startseg = objp->segnum;
1533 fq.thisobjnum = objp-Objects;
1534 fq.ignore_obj_list = NULL;
1536 find_vector_intersection( &fq, &hit_data);
1538 if (hit_data.hit_type == HIT_NONE) {
1539 *camera_pos = closer_p1;
1541 make_random_vector(&player_camera_vec);
1542 far_scale = 3*F1_0/2;
1548 extern void drop_player_eggs(object *objp);
1549 extern int get_explosion_vclip(object *obj,int stage);
1550 extern void multi_cap_objects();
1551 extern int Proximity_dropped,Smartmines_dropped;
1553 // ------------------------------------------------------------------------------------------------------------------
1554 void dead_player_frame(void)
1559 if (Player_is_dead) {
1560 time_dead = GameTime - Player_time_of_death;
1562 // If unable to create camera at time of death, create now.
1563 if (Dead_player_camera == Viewer_save) {
1565 object *player = &Objects[Players[Player_num].objnum];
1567 objnum = obj_create(OBJ_CAMERA, 0, player->segnum, &player->pos, &player->orient, 0, CT_NONE, MT_NONE, RT_NONE);
1569 mprintf((0, "Creating new dead player camera.\n"));
1571 Viewer = Dead_player_camera = &Objects[objnum];
1573 mprintf((1, "Can't create dead player camera.\n"));
1578 ConsoleObject->mtype.phys_info.rotvel.x = max(0, DEATH_SEQUENCE_EXPLODE_TIME - time_dead)/4;
1579 ConsoleObject->mtype.phys_info.rotvel.y = max(0, DEATH_SEQUENCE_EXPLODE_TIME - time_dead)/2;
1580 ConsoleObject->mtype.phys_info.rotvel.z = max(0, DEATH_SEQUENCE_EXPLODE_TIME - time_dead)/3;
1582 Camera_to_player_dist_goal = min(time_dead*8, F1_0*20) + ConsoleObject->size;
1584 set_camera_pos(&Dead_player_camera->pos, ConsoleObject);
1586 // if (time_dead < DEATH_SEQUENCE_EXPLODE_TIME+F1_0*2) {
1587 vm_vec_sub(&fvec, &ConsoleObject->pos, &Dead_player_camera->pos);
1588 vm_vector_2_matrix(&Dead_player_camera->orient, &fvec, NULL, NULL);
1590 // Dead_player_camera->movement_type = MT_PHYSICS;
1591 // Dead_player_camera->mtype.phys_info.rotvel.y = F1_0/8;
1594 if (time_dead > DEATH_SEQUENCE_EXPLODE_TIME) {
1595 if (!Player_exploded) {
1597 if (Players[Player_num].hostages_on_board > 1)
1598 HUD_init_message(TXT_SHIP_DESTROYED_2, Players[Player_num].hostages_on_board);
1599 else if (Players[Player_num].hostages_on_board == 1)
1600 HUD_init_message(TXT_SHIP_DESTROYED_1);
1602 HUD_init_message(TXT_SHIP_DESTROYED_0);
1610 Player_exploded = 1;
1612 if (Game_mode & GM_NETWORK)
1615 multi_cap_objects();
1619 drop_player_eggs(ConsoleObject);
1620 Player_eggs_dropped = 1;
1622 if (Game_mode & GM_MULTI)
1624 //multi_send_position(Players[Player_num].objnum);
1625 multi_send_player_explode(MULTI_PLAYER_EXPLODE);
1629 explode_badass_player(ConsoleObject);
1631 //is this next line needed, given the badass call above?
1632 explode_object(ConsoleObject,0);
1633 ConsoleObject->flags &= ~OF_SHOULD_BE_DEAD; //don't really kill player
1634 ConsoleObject->render_type = RT_NONE; //..just make him disappear
1635 ConsoleObject->type = OBJ_GHOST; //..and kill intersections
1636 Players[Player_num].flags &= ~PLAYER_FLAGS_HEADLIGHT_ON;
1639 if (d_rand() < FrameTime*4) {
1641 if (Game_mode & GM_MULTI)
1642 multi_send_create_explosion(Player_num);
1644 create_small_fireball_on_object(ConsoleObject, F1_0, 1);
1649 if (Death_sequence_aborted) { //time_dead > DEATH_SEQUENCE_LENGTH) {
1650 if (!Player_eggs_dropped) {
1653 if (Game_mode & GM_NETWORK)
1656 multi_cap_objects();
1660 drop_player_eggs(ConsoleObject);
1661 Player_eggs_dropped = 1;
1663 if (Game_mode & GM_MULTI)
1665 //multi_send_position(Players[Player_num].objnum);
1666 multi_send_player_explode(MULTI_PLAYER_EXPLODE);
1671 DoPlayerDead(); //kill_player();
1677 void AdjustMineSpawn()
1679 if (!(Game_mode & GM_NETWORK))
1680 return; // No need for this function in any other mode
1682 if (!(Game_mode & GM_HOARD))
1683 Players[Player_num].secondary_ammo[PROXIMITY_INDEX]+=Proximity_dropped;
1684 Players[Player_num].secondary_ammo[SMART_MINE_INDEX]+=Smartmines_dropped;
1685 Proximity_dropped=0;
1686 Smartmines_dropped=0;
1691 int Killed_in_frame = -1;
1692 short Killed_objnum = -1;
1693 extern char Multi_killed_yourself;
1695 // ------------------------------------------------------------------------------------------------------------------
1696 void start_player_death_sequence(object *player)
1700 Assert(player == ConsoleObject);
1701 if ((Player_is_dead != 0) || (Dead_player_camera != NULL))
1704 //Assert(Player_is_dead == 0);
1705 //Assert(Dead_player_camera == NULL);
1709 if (!(Game_mode & GM_MULTI))
1710 HUD_clear_messages();
1712 Killed_in_frame = FrameCount;
1713 Killed_objnum = player-Objects;
1714 Death_sequence_aborted = 0;
1717 if (Game_mode & GM_MULTI)
1719 multi_send_kill(Players[Player_num].objnum);
1721 // If Hoard, increase number of orbs by 1
1722 // Only if you haven't killed yourself
1723 // This prevents cheating
1725 if (Game_mode & GM_HOARD)
1726 if (Players[Player_num].secondary_ammo[PROXIMITY_INDEX]<12)
1727 if (!Multi_killed_yourself)
1728 Players[Player_num].secondary_ammo[PROXIMITY_INDEX]++;
1740 //Players[Player_num].flags &= ~(PLAYER_FLAGS_AFTERBURNER);
1742 vm_vec_zero(&player->mtype.phys_info.rotthrust);
1743 vm_vec_zero(&player->mtype.phys_info.thrust);
1745 Player_time_of_death = GameTime;
1747 objnum = obj_create(OBJ_CAMERA, 0, player->segnum, &player->pos, &player->orient, 0, CT_NONE, MT_NONE, RT_NONE);
1748 Viewer_save = Viewer;
1750 Viewer = Dead_player_camera = &Objects[objnum];
1752 mprintf((1, "Can't create dead player camera.\n"));
1754 Dead_player_camera = Viewer;
1757 if (Cockpit_mode_save == -1) //if not already saved
1758 Cockpit_mode_save = Cockpit_mode;
1759 select_cockpit(CM_LETTERBOX);
1760 if (Newdemo_state == ND_STATE_RECORDING)
1761 newdemo_record_letterbox();
1763 Player_flags_save = player->flags;
1764 Control_type_save = player->control_type;
1765 Render_type_save = player->render_type;
1767 player->flags &= ~OF_SHOULD_BE_DEAD;
1768 // Players[Player_num].flags |= PLAYER_FLAGS_INVULNERABLE;
1769 player->control_type = CT_NONE;
1770 player->shields = F1_0*1000;
1772 PALETTE_FLASH_SET(0,0,0);
1775 // ------------------------------------------------------------------------------------------------------------------
1776 void obj_delete_all_that_should_be_dead()
1780 int local_dead_player_object=-1;
1785 for (i=0;i<=Highest_object_index;i++) {
1786 if ((objp->type!=OBJ_NONE) && (objp->flags&OF_SHOULD_BE_DEAD) ) {
1787 Assert(!(objp->type==OBJ_FIREBALL && objp->ctype.expl_info.delete_time!=-1));
1788 if (objp->type==OBJ_PLAYER) {
1789 if ( objp->id == Player_num ) {
1790 if (local_dead_player_object == -1) {
1791 start_player_death_sequence(objp);
1792 local_dead_player_object = objp-Objects;
1794 Int3(); // Contact Mike: Illegal, killed player twice in this frame!
1795 // Ok to continue, won't start death sequence again!
1806 //when an object has moved into a new segment, this function unlinks it
1807 //from its old segment, and links it into the new segment
1808 void obj_relink(int objnum,int newsegnum)
1811 Assert((objnum >= 0) && (objnum <= Highest_object_index));
1812 Assert((newsegnum <= Highest_segment_index) && (newsegnum >= 0));
1816 obj_link(objnum,newsegnum);
1819 if (get_seg_masks(&Objects[objnum].pos,Objects[objnum].segnum,0).centermask!=0)
1820 mprintf((1, "obj_relink violates seg masks.\n"));
1824 //process a continuously-spinning object
1825 spin_object(object *obj)
1828 vms_matrix rotmat, new_pm;
1830 Assert(obj->movement_type == MT_SPINNING);
1832 rotangs.p = fixmul(obj->mtype.spin_rate.x,FrameTime);
1833 rotangs.h = fixmul(obj->mtype.spin_rate.y,FrameTime);
1834 rotangs.b = fixmul(obj->mtype.spin_rate.z,FrameTime);
1836 vm_angles_2_matrix(&rotmat,&rotangs);
1838 vm_matrix_x_matrix(&new_pm,&obj->orient,&rotmat);
1839 obj->orient = new_pm;
1841 check_and_fix_matrix(&obj->orient);
1844 int Drop_afterburner_blob_flag; //ugly hack
1845 extern void multi_send_drop_blobs(char);
1846 extern void fuelcen_check_for_goal (segment *);
1848 //see if wall is volatile, and if so, cause damage to player
1849 //returns true if player is in lava
1850 int check_volatile_wall(object *obj,int segnum,int sidenum,vms_vector *hitpt);
1852 // Time at which this object last created afterburner blobs.
1853 fix Last_afterburner_time[MAX_OBJECTS];
1855 //--------------------------------------------------------------------
1856 //move an object for the current frame
1857 void object_move_one( object * obj )
1862 int previous_segment = obj->segnum;
1864 obj->last_pos = obj->pos; // Save the current position
1866 if ((obj->type==OBJ_PLAYER) && (Player_num==obj->id)) {
1870 if (Game_mode & GM_CAPTURE)
1871 fuelcen_check_for_goal (&Segments[obj->segnum]);
1872 if (Game_mode & GM_HOARD)
1873 fuelcen_check_for_hoard_goal (&Segments[obj->segnum]);
1876 fuel=fuelcen_give_fuel( &Segments[obj->segnum], INITIAL_ENERGY-Players[Player_num].energy );
1878 Players[Player_num].energy += fuel;
1883 if (obj->lifeleft != IMMORTAL_TIME) { //if not immortal...
1884 // Ok, this is a big hack by MK.
1885 // If you want an object to last for exactly one frame, then give it a lifeleft of ONE_FRAME_TIME.
1886 if (obj->lifeleft != ONE_FRAME_TIME)
1887 obj->lifeleft -= FrameTime; //...inevitable countdown towards death
1890 Drop_afterburner_blob_flag = 0;
1892 switch (obj->control_type) {
1894 case CT_NONE: break;
1898 #if !defined(NDEBUG) && !defined(NMONO)
1899 if (print_object_info>1) mprintf( (0, "Moving player object #%d\n", obj-Objects ));
1902 read_flying_controls( obj );
1906 case CT_REPAIRCEN: Int3(); // -- hey! these are no longer supported!! -- do_repair_sequence(obj); break;
1908 case CT_POWERUP: do_powerup_frame(obj); break;
1910 case CT_MORPH: //morph implies AI
1911 do_morph_frame(obj);
1912 //NOTE: FALLS INTO AI HERE!!!!
1915 //NOTE LINK TO CT_MORPH ABOVE!!!
1916 if (Game_suspended & SUSP_ROBOTS) return;
1917 #if !defined(NDEBUG) && !defined(NMONO)
1918 if (print_object_info>1) mprintf( (0, "AI: Moving robot object #%d\n",obj-Objects ));
1923 case CT_WEAPON: Laser_do_weapon_sequence(obj); break;
1924 case CT_EXPLOSION: do_explosion_sequence(obj); break;
1928 if ( keyd_pressed[KEY_PAD5] ) slew_stop( obj );
1929 if ( keyd_pressed[KEY_NUMLOCK] ) {
1930 slew_reset_orient( obj );
1931 * (ubyte *) 0x417 &= ~0x20; //kill numlock
1933 slew_frame(0 ); // Does velocity addition for us.
1938 // case CT_FLYTHROUGH:
1939 // do_flythrough(obj,0); // HACK:do_flythrough should operate on an object!!!!
1940 // //check_object_seg(obj);
1941 // return; // DON'T DO THE REST OF OBJECT STUFF SINCE THIS IS A SPECIAL CASE!!!
1944 case CT_DEBRIS: do_debris_frame(obj); break;
1946 case CT_LIGHT: break; //doesn't do anything
1948 case CT_REMOTE: break; //movement is handled in com_process_input
1950 case CT_CNTRLCEN: do_controlcen_frame(obj); break;
1954 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);
1960 if (obj->lifeleft < 0 ) { // We died of old age
1961 obj->flags |= OF_SHOULD_BE_DEAD;
1962 if ( obj->type==OBJ_WEAPON && Weapon_info[obj->id].damage_radius )
1963 explode_badass_weapon(obj,&obj->pos);
1964 else if ( obj->type==OBJ_ROBOT) //make robots explode
1965 explode_object(obj,0);
1968 if (obj->type == OBJ_NONE || obj->flags&OF_SHOULD_BE_DEAD)
1969 return; //object has been deleted
1971 switch (obj->movement_type) {
1973 case MT_NONE: break; //this doesn't move
1975 case MT_PHYSICS: do_physics_sim(obj); break; //move by physics
1977 case MT_SPINNING: spin_object(obj); break;
1981 // If player and moved to another segment, see if hit any triggers.
1982 // also check in player under a lavafall
1983 if (obj->type == OBJ_PLAYER && obj->movement_type==MT_PHYSICS) {
1985 if (previous_segment != obj->segnum) {
1988 int old_level = Current_level_num;
1990 for (i=0;i<n_phys_segs-1;i++) {
1991 connect_side = find_connect_side(&Segments[phys_seglist[i+1]], &Segments[phys_seglist[i]]);
1992 if (connect_side != -1)
1993 check_trigger(&Segments[phys_seglist[i]], connect_side, obj-Objects,0);
1995 else { // segments are not directly connected, so do binary subdivision until you find connected segments.
1996 mprintf((1, "UNCONNECTED SEGMENTS %d,%d\n",phys_seglist[i+1],phys_seglist[i]));
1997 // -- Unnecessary, MK, 09/04/95 -- Int3();
2001 //maybe we've gone on to the next level. if so, bail!
2003 if (Current_level_num != old_level)
2010 int sidemask,under_lavafall=0;
2011 static int lavafall_hiss_playing[MAX_PLAYERS]={0};
2013 sidemask = get_seg_masks(&obj->pos,obj->segnum,obj->size).sidemask;
2015 int sidenum,bit,wall_num;
2017 for (sidenum=0,bit=1;sidenum<6;bit<<=1,sidenum++)
2018 if ((sidemask & bit) && ((wall_num=Segments[obj->segnum].sides[sidenum].wall_num)!=-1) && Walls[wall_num].type==WALL_ILLUSION) {
2020 if ((type=check_volatile_wall(obj,obj->segnum,sidenum,&obj->pos))!=0) {
2021 int sound = (type==1)?SOUND_LAVAFALL_HISS:SOUND_SHIP_IN_WATERFALL;
2023 if (!lavafall_hiss_playing[obj->id]) {
2024 digi_link_sound_to_object3( sound, obj-Objects, 1, F1_0, i2f(256), -1, -1);
2025 lavafall_hiss_playing[obj->id] = 1;
2031 if (!under_lavafall && lavafall_hiss_playing[obj->id]) {
2032 digi_kill_sound_linked_to_object( obj-Objects);
2033 lavafall_hiss_playing[obj->id] = 0;
2038 //see if guided missile has flown through exit trigger
2039 if (obj==Guided_missile[Player_num] && obj->signature==Guided_missile_sig[Player_num]) {
2040 if (previous_segment != obj->segnum) {
2042 connect_side = find_connect_side(&Segments[obj->segnum], &Segments[previous_segment]);
2043 if (connect_side != -1) {
2044 int wall_num,trigger_num;
2045 wall_num = Segments[previous_segment].sides[connect_side].wall_num;
2046 if ( wall_num != -1 ) {
2047 trigger_num = Walls[wall_num].trigger;
2048 if (trigger_num != -1)
2049 if (Triggers[trigger_num].type == TT_EXIT)
2050 Guided_missile[Player_num]->lifeleft = 0;
2056 if (Drop_afterburner_blob_flag) {
2057 Assert(obj==ConsoleObject);
2058 drop_afterburner_blobs(obj, 2, i2f(5)/2, -1); // -1 means use default lifetime
2060 if (Game_mode & GM_MULTI)
2061 multi_send_drop_blobs(Player_num);
2063 Drop_afterburner_blob_flag = 0;
2066 if ((obj->type == OBJ_WEAPON) && (Weapon_info[obj->id].afterburner_size)) {
2067 int objnum = obj-Objects;
2068 fix vel = vm_vec_mag_quick(&obj->mtype.phys_info.velocity);
2069 fix delay, lifetime;
2073 else if (vel > F1_0*40)
2074 delay = fixdiv(F1_0*13,vel);
2078 lifetime = (delay * 3)/2;
2079 if (!(Game_mode & GM_MULTI)) {
2084 if ((Last_afterburner_time[objnum] + delay < GameTime) || (Last_afterburner_time[objnum] > GameTime)) {
2085 drop_afterburner_blobs(obj, 1, i2f(Weapon_info[obj->id].afterburner_size)/16, lifetime);
2086 Last_afterburner_time[objnum] = GameTime;
2091 obj++; //kill warning
2095 int Max_used_objects = MAX_OBJECTS - 20;
2097 //--------------------------------------------------------------------
2098 //move all objects for the current frame
2099 void object_move_all()
2104 // -- mprintf((0, "Frame %i: %i/%i objects used.\n", FrameCount, num_objects, MAX_OBJECTS));
2106 // check_duplicate_objects();
2107 // remove_incorrect_objects();
2109 if (Highest_object_index > Max_used_objects)
2110 free_object_slots(Max_used_objects); // Free all possible object slots.
2112 obj_delete_all_that_should_be_dead();
2114 if (Auto_leveling_on)
2115 ConsoleObject->mtype.phys_info.flags |= PF_LEVELLING;
2117 ConsoleObject->mtype.phys_info.flags &= ~PF_LEVELLING;
2123 for (i=0;i<=Highest_object_index;i++) {
2124 if ( (objp->type != OBJ_NONE) && (!(objp->flags&OF_SHOULD_BE_DEAD)) ) {
2125 object_move_one( objp );
2133 // check_duplicate_objects();
2134 // remove_incorrect_objects();
2139 //--unused-- // -----------------------------------------------------------
2140 //--unused-- // Moved here from eobject.c on 02/09/94 by MK.
2141 //--unused-- int find_last_obj(int i)
2143 //--unused-- for (i=MAX_OBJECTS;--i>=0;)
2144 //--unused-- if (Objects[i].type != OBJ_NONE) break;
2146 //--unused-- return i;
2151 //make object array non-sparse
2152 void compress_objects(void)
2154 int start_i; //,last_i;
2156 //last_i = find_last_obj(MAX_OBJECTS);
2158 // Note: It's proper to do < (rather than <=) Highest_object_index here because we
2159 // are just removing gaps, and the last object can't be a gap.
2160 for (start_i=0;start_i<Highest_object_index;start_i++)
2162 if (Objects[start_i].type == OBJ_NONE) {
2166 segnum_copy = Objects[Highest_object_index].segnum;
2168 obj_unlink(Highest_object_index);
2170 Objects[start_i] = Objects[Highest_object_index];
2173 if (Cur_object_index == Highest_object_index)
2174 Cur_object_index = start_i;
2177 Objects[Highest_object_index].type = OBJ_NONE;
2179 obj_link(start_i,segnum_copy);
2181 while (Objects[--Highest_object_index].type == OBJ_NONE);
2183 //last_i = find_last_obj(last_i);
2187 reset_objects(num_objects);
2191 //called after load. Takes number of objects, and objects should be
2192 //compressed. resets free list, marks unused objects as unused
2193 void reset_objects(int n_objs)
2197 num_objects = n_objs;
2199 Assert(num_objects>0);
2201 for (i=num_objects;i<MAX_OBJECTS;i++) {
2202 free_obj_list[i] = i;
2203 Objects[i].type = OBJ_NONE;
2204 Objects[i].segnum = -1;
2207 Highest_object_index = num_objects-1;
2209 Debris_object_count = 0;
2212 //Tries to find a segment for an object, using find_point_seg()
2213 int find_object_seg(object * obj )
2215 return find_point_seg(&obj->pos,obj->segnum);
2219 //If an object is in a segment, set its segnum field and make sure it's
2220 //properly linked. If not in any segment, returns 0, else 1.
2221 //callers should generally use find_vector_intersection()
2222 int update_object_seg(object * obj )
2226 newseg = find_object_seg(obj);
2231 if ( newseg != obj->segnum )
2232 obj_relink(obj-Objects, newseg );
2238 //go through all objects and make sure they have the correct segment numbers
2243 for (i=0;i<=Highest_object_index;i++)
2244 if (Objects[i].type != OBJ_NONE)
2245 if (update_object_seg(&Objects[i]) == 0) {
2246 mprintf((1,"Cannot find segment for object %d in fix_object_segs()\n"));
2248 compute_segment_center(&Objects[i].pos,&Segments[Objects[i].segnum]);
2253 //--unused-- void object_use_new_object_list( object * new_list )
2255 //--unused-- int i, segnum;
2256 //--unused-- object *obj;
2258 //--unused-- // First, unlink all the old objects for the segments array
2259 //--unused-- for (segnum=0; segnum <= Highest_segment_index; segnum++) {
2260 //--unused-- Segments[segnum].objects = -1;
2262 //--unused-- // Then, erase all the objects
2263 //--unused-- reset_objects(1);
2265 //--unused-- // Fill in the object array
2266 //--unused-- memcpy( Objects, new_list, sizeof(object)*MAX_OBJECTS );
2268 //--unused-- Highest_object_index=-1;
2270 //--unused-- // Relink 'em
2271 //--unused-- for (i=0; i<MAX_OBJECTS; i++ ) {
2272 //--unused-- obj = &Objects[i];
2273 //--unused-- if ( obj->type != OBJ_NONE ) {
2274 //--unused-- num_objects++;
2275 //--unused-- Highest_object_index = i;
2276 //--unused-- segnum = obj->segnum;
2277 //--unused-- obj->next = obj->prev = obj->segnum = -1;
2278 //--unused-- obj_link(i,segnum);
2279 //--unused-- } else {
2280 //--unused-- obj->next = obj->prev = obj->segnum = -1;
2286 //delete objects, such as weapons & explosions, that shouldn't stay between levels
2287 // Changed by MK on 10/15/94, don't remove proximity bombs.
2288 //if clear_all is set, clear even proximity bombs
2289 void clear_transient_objects(int clear_all)
2294 for (objnum=0,obj=&Objects[0];objnum<=Highest_object_index;objnum++,obj++)
2295 if (((obj->type == OBJ_WEAPON) && !(Weapon_info[obj->id].flags&WIF_PLACABLE) && (clear_all || ((obj->id != PROXIMITY_ID) && (obj->id != SUPERPROX_ID)))) ||
2296 obj->type == OBJ_FIREBALL ||
2297 obj->type == OBJ_DEBRIS ||
2298 obj->type == OBJ_DEBRIS ||
2299 (obj->type!=OBJ_NONE && obj->flags & OF_EXPLODING)) {
2302 if (Objects[objnum].lifeleft > i2f(2))
2303 mprintf((0,"Note: Clearing object %d (type=%d, id=%d) with lifeleft=%x\n",objnum,Objects[objnum].type,Objects[objnum].id,Objects[objnum].lifeleft));
2308 else if (Objects[objnum].type!=OBJ_NONE && Objects[objnum].lifeleft < i2f(2))
2309 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));
2313 //attaches an object, such as a fireball, to another object, such as a robot
2314 void obj_attach(object *parent,object *sub)
2316 Assert(sub->type == OBJ_FIREBALL);
2317 Assert(sub->control_type == CT_EXPLOSION);
2319 Assert(sub->ctype.expl_info.next_attach==-1);
2320 Assert(sub->ctype.expl_info.prev_attach==-1);
2322 Assert(parent->attached_obj==-1 || Objects[parent->attached_obj].ctype.expl_info.prev_attach==-1);
2324 sub->ctype.expl_info.next_attach = parent->attached_obj;
2326 if (sub->ctype.expl_info.next_attach != -1)
2327 Objects[sub->ctype.expl_info.next_attach].ctype.expl_info.prev_attach = sub-Objects;
2329 parent->attached_obj = sub-Objects;
2331 sub->ctype.expl_info.attach_parent = parent-Objects;
2332 sub->flags |= OF_ATTACHED;
2334 Assert(sub->ctype.expl_info.next_attach != sub-Objects);
2335 Assert(sub->ctype.expl_info.prev_attach != sub-Objects);
2338 //dettaches one object
2339 void obj_detach_one(object *sub)
2341 Assert(sub->flags & OF_ATTACHED);
2342 Assert(sub->ctype.expl_info.attach_parent != -1);
2344 if ((Objects[sub->ctype.expl_info.attach_parent].type == OBJ_NONE) || (Objects[sub->ctype.expl_info.attach_parent].attached_obj == -1))
2346 sub->flags &= ~OF_ATTACHED;
2350 if (sub->ctype.expl_info.next_attach != -1) {
2351 Assert(Objects[sub->ctype.expl_info.next_attach].ctype.expl_info.prev_attach=sub-Objects);
2352 Objects[sub->ctype.expl_info.next_attach].ctype.expl_info.prev_attach = sub->ctype.expl_info.prev_attach;
2355 if (sub->ctype.expl_info.prev_attach != -1) {
2356 Assert(Objects[sub->ctype.expl_info.prev_attach].ctype.expl_info.next_attach=sub-Objects);
2357 Objects[sub->ctype.expl_info.prev_attach].ctype.expl_info.next_attach = sub->ctype.expl_info.next_attach;
2360 Assert(Objects[sub->ctype.expl_info.attach_parent].attached_obj=sub-Objects);
2361 Objects[sub->ctype.expl_info.attach_parent].attached_obj = sub->ctype.expl_info.next_attach;
2364 sub->ctype.expl_info.next_attach = sub->ctype.expl_info.prev_attach = -1;
2365 sub->flags &= ~OF_ATTACHED;
2369 //dettaches all objects from this object
2370 void obj_detach_all(object *parent)
2372 while (parent->attached_obj != -1)
2373 obj_detach_one(&Objects[parent->attached_obj]);
2376 //creates a marker object in the world. returns the object number
2377 int drop_marker_object(vms_vector *pos,int segnum,vms_matrix *orient, int marker_num)
2381 Assert(Marker_model_num != -1);
2383 objnum = obj_create(OBJ_MARKER, marker_num, segnum, pos, orient, Polygon_models[Marker_model_num].rad, CT_NONE, MT_NONE, RT_POLYOBJ);
2386 object *obj = &Objects[objnum];
2388 obj->rtype.pobj_info.model_num = Marker_model_num;
2390 vm_vec_copy_scale(&obj->mtype.spin_rate,&obj->orient.uvec,F1_0/2);
2392 // MK, 10/16/95: Using lifeleft to make it flash, thus able to trim lightlevel from all objects.
2393 obj->lifeleft = IMMORTAL_TIME - 1;
2399 extern int Ai_last_missile_camera;
2401 // *viewer is a viewer, probably a missile.
2402 // wake up all robots that were rendered last frame subject to some constraints.
2403 void wake_up_rendered_objects(object *viewer, int window_num)
2407 // Make sure that we are processing current data.
2408 if (FrameCount != Window_rendered_data[window_num].frame) {
2409 mprintf((1, "Warning: Called wake_up_rendered_objects with a bogus window.\n"));
2413 Ai_last_missile_camera = viewer-Objects;
2415 for (i=0; i<Window_rendered_data[window_num].num_objects; i++) {
2418 int fcval = FrameCount & 3;
2420 objnum = Window_rendered_data[window_num].rendered_objects[i];
2421 if ((objnum & 3) == fcval) {
2422 objp = &Objects[objnum];
2424 if (objp->type == OBJ_ROBOT) {
2425 if (vm_vec_dist_quick(&viewer->pos, &objp->pos) < F1_0*100) {
2426 ai_local *ailp = &Ai_local_info[objnum];
2427 if (ailp->player_awareness_type == 0) {
2428 objp->ctype.ai_info.SUB_FLAGS |= SUB_FLAGS_CAMERA_AWAKE;
2429 ailp->player_awareness_type = PA_WEAPON_ROBOT_COLLISION;
2430 ailp->player_awareness_time = F1_0*3;
2431 ailp->previous_visibility = 2;