// draw a frame of the rotating lock triangles animation void hud_draw_lock_triangles(int center_x, int center_y, float frametime) { if ( Lock_anim.first_frame == -1 ) { hud_draw_lock_triangles_old(center_x, center_y, Lock_target_box_width[gr_screen.res]/2); } else { // render the anim Lock_anim.sx = center_x - Lockspin_half_w[gr_screen.res]; Lock_anim.sy = center_y - Lockspin_half_h[gr_screen.res]; // if its still animating if(Lock_anim.time_elapsed < Lock_anim.total_time){ hud_anim_render(&Lock_anim, frametime, 1, 0, 1); } else { // if the timestamp is unset or expired if((Lock_gauge_draw_stamp < 0) || timestamp_elapsed(Lock_gauge_draw_stamp)){ // reset timestamp Lock_gauge_draw_stamp = timestamp(1000 / (2 * LOCK_GAUGE_BLINK_RATE)); // switch between draw and dont-draw Lock_gauge_draw = !Lock_gauge_draw; } // maybe draw the anim Lock_gauge.time_elapsed = 0.0f; if(Lock_gauge_draw){ hud_anim_render(&Lock_anim, frametime, 1, 0, 1); } } } }
// hud_show_lock_indicator() will display the lock indicator for homing missiles void hud_show_lock_indicator(float frametime) { int target_objnum, sx, sy; object *targetp; if (!Players[Player_num].lock_indicator_visible){ return; } target_objnum = Player_ai->target_objnum; Assert(target_objnum != -1); targetp = &Objects[target_objnum]; // check to see if there are any missile to fire.. we don't want to show the // lock indicator if there are missiles to fire. if ( !ship_secondary_bank_has_ammo(Player_obj->instance) ) { return; } hud_set_iff_color(targetp); // nprintf(("Alan","lockx: %d, locky: %d TargetX: %d, TargetY: %d\n", Players[Player_num].lock_indicator_x, Players[Player_num].lock_indicator_y, Player->current_target_sx, Player->current_target_sy)); if (Player_ai->current_target_is_locked) { sx = Player->current_target_sx; sy = Player->current_target_sy; // show the rotating triangles if target is locked hud_draw_lock_triangles(sx, sy, frametime); } else { sx = Players[Player_num].lock_indicator_x; sy = Players[Player_num].lock_indicator_y; } // show locked indicator /* if ( Lock_gauge.first_frame >= 0 ) { gr_set_bitmap(Lock_gauge.first_frame); gr_aabitmap(sx - Lock_gauge_half_w[gr_screen.res], sy - Lock_gauge_half_h[gr_screen.res]); } else { hud_draw_diamond(sx, sy, Lock_target_box_width[gr_screen.res], Lock_target_box_height[gr_screen.res]); } */ Lock_gauge.sx = sx - Lock_gauge_half_w[gr_screen.res]; Lock_gauge.sy = sy - Lock_gauge_half_h[gr_screen.res]; if(Player_ai->current_target_is_locked){ Lock_gauge.time_elapsed = 0.0f; hud_anim_render(&Lock_gauge, 0.0f, 1); } else { hud_anim_render(&Lock_gauge, frametime, 1); } }
// hud_show_lock_indicator() will display the lock indicator for homing missiles. // lock_point_pos should be the world coordinates of the target being locked. Assuming all the // necessary locking calculations are done for this frame, this function will compute // where the indicator should be relative to the player's viewpoint and will render accordingly. void HudGaugeLock::render(float frametime) { int target_objnum, sx, sy; object *targetp; vertex lock_point; bool locked = Player_ai->current_target_is_locked ? true : false; bool reset_timers = false; if ( locked != Last_lock_status ) { // check if player lock status has changed since the last frame. reset_timers = true; Last_lock_status = locked; } if (Player_ai->target_objnum == -1) { return; } if (Player->target_is_dying) { return; } if (!Players[Player_num].lock_indicator_visible){ return; } target_objnum = Player_ai->target_objnum; Assert(target_objnum != -1); targetp = &Objects[target_objnum]; // check to see if there are any missile to fire.. we don't want to show the // lock indicator if there are missiles to fire. if ( !ship_secondary_bank_has_ammo(Player_obj->instance) ) { return; } bool in_frame = g3_in_frame() > 0; if(!in_frame) g3_start_frame(0); gr_set_screen_scale(base_w, base_h); // Get the target's current position on the screen. If he's not on there, // we're not going to draw the lock indicator even if he's in front // of our ship, so bail out. g3_rotate_vertex(&lock_point, &lock_world_pos); g3_project_vertex(&lock_point); if (lock_point.codes & PF_OVERFLOW) { gr_reset_screen_scale(); if(!in_frame) g3_end_frame(); return; } hud_set_iff_color(targetp); // nprintf(("Alan","lockx: %d, locky: %d TargetX: %d, TargetY: %d\n", Players[Player_num].lock_indicator_x, Players[Player_num].lock_indicator_y, Player->current_target_sx, Player->current_target_sy)); // We have the coordinates of the lock indicator relative to the target in our "virtual frame" // so, we calculate where it should be drawn based on the player's viewpoint. if (Player_ai->current_target_is_locked) { sx = fl2i(lock_point.screen.xyw.x); sy = fl2i(lock_point.screen.xyw.y); gr_unsize_screen_pos(&sx, &sy); // show the rotating triangles if target is locked renderLockTriangles(sx, sy, frametime); if ( reset_timers ) { Lock_gauge.time_elapsed = 0.0f; } } else { const float scaling_factor = (gr_screen.clip_center_x < gr_screen.clip_center_y) ? (gr_screen.clip_center_x / VIRTUAL_FRAME_HALF_WIDTH) : (gr_screen.clip_center_y / VIRTUAL_FRAME_HALF_HEIGHT); sx = fl2i(lock_point.screen.xyw.x) - fl2i(i2fl(Player->current_target_sx - Players[Player_num].lock_indicator_x) * scaling_factor); sy = fl2i(lock_point.screen.xyw.y) - fl2i(i2fl(Player->current_target_sy - Players[Player_num].lock_indicator_y) * scaling_factor); gr_unsize_screen_pos(&sx, &sy); if ( reset_timers ) { Lock_gauge_draw_stamp = -1; Lock_gauge_draw = 0; Lock_anim.time_elapsed = 0.0f; } } // show locked indicator Lock_gauge.sx = sx - Lock_gauge_half_w; Lock_gauge.sy = sy - Lock_gauge_half_h; if (Player_ai->current_target_is_locked) { hud_anim_render(&Lock_gauge, 0.0f, 1); } else { hud_anim_render(&Lock_gauge, frametime, 1); } gr_reset_screen_scale(); if(!in_frame) g3_end_frame(); }
// hud_show_lock_indicator() will display the lock indicator for homing missiles. // lock_point_pos should be the world coordinates of the target being locked. Assuming all the // necessary locking calculations are done for this frame, this function will compute // where the indicator should be relative to the player's viewpoint and will render accordingly. void hud_show_lock_indicator(float frametime, vec3d* lock_point_pos) { int target_objnum, sx, sy; object* targetp; vertex lock_point; if (!Players[Player_num].lock_indicator_visible) { return; } target_objnum = Player_ai->target_objnum; Assert(target_objnum != -1); targetp = &Objects[target_objnum]; // check to see if there are any missile to fire.. we don't want to show the // lock indicator if there are missiles to fire. if (!ship_secondary_bank_has_ammo(Player_obj->instance)) { return; } // Get the target's current position on the screen. If he's not on there, // we're not going to draw the lock indicator even if he's in front // of our ship, so bail out. g3_rotate_vertex(&lock_point, lock_point_pos); g3_project_vertex(&lock_point); if (lock_point.codes & PF_OVERFLOW) return; hud_set_iff_color(targetp); // nprintf(("Alan","lockx: %d, locky: %d TargetX: %d, TargetY: %d\n", Players[Player_num].lock_indicator_x, Players[Player_num].lock_indicator_y, Player->current_target_sx, Player->current_target_sy)); // We have the coordinates of the lock indicator relative to the target in our "virtual frame" // so, we calculate where it should be drawn based on the player's viewpoint. if (Player_ai->current_target_is_locked) { sx = fl2i(lock_point.sx); sy = fl2i(lock_point.sy); gr_unsize_screen_pos(&sx, &sy); // show the rotating triangles if target is locked hud_draw_lock_triangles(sx, sy, frametime); } else { sx = fl2i(lock_point.sx) - (Player->current_target_sx - Players[Player_num].lock_indicator_x); sy = fl2i(lock_point.sy) - (Player->current_target_sy - Players[Player_num].lock_indicator_y); gr_unsize_screen_pos(&sx, &sy); } // show locked indicator /* if ( Lock_gauge.first_frame >= 0 ) { gr_set_bitmap(Lock_gauge.first_frame); gr_aabitmap(sx - Lock_gauge_half_w[gr_screen.res], sy - Lock_gauge_half_h[gr_screen.res]); } else { hud_draw_diamond(sx, sy, Lock_target_box_width[gr_screen.res], Lock_target_box_height[gr_screen.res]); } */ Lock_gauge.sx = sx - Lock_gauge_half_w[Hud_reticle_style][gr_screen.res]; Lock_gauge.sy = sy - Lock_gauge_half_h[gr_screen.res]; if (Player_ai->current_target_is_locked) { Lock_gauge.time_elapsed = 0.0f; hud_anim_render(&Lock_gauge, 0.0f, 1); } else { hud_anim_render(&Lock_gauge, frametime, 1); } }