void hud_show_mini_ship_integrity(object* objp, int x_force, int y_force) { char text_integrity[64]; int numeric_integrity; float p_target_integrity; int final_pos[2]; p_target_integrity = get_hull_pct(objp); numeric_integrity = fl2i(p_target_integrity * 100 + 0.5f); if (numeric_integrity > 100) { numeric_integrity = 100; } // Assert(numeric_integrity <= 100); // 3 digit hull strength if (numeric_integrity == 100) { memcpy(final_pos, current_hud->Hud_mini_3digit, sizeof(final_pos)); } // 1 digit hull strength else if (numeric_integrity < 10) { memcpy(final_pos, current_hud->Hud_mini_1digit, sizeof(final_pos)); } // 2 digit hull strength else { memcpy(final_pos, current_hud->Hud_mini_2digit, sizeof(final_pos)); } if (numeric_integrity == 0) { if (p_target_integrity > 0) { numeric_integrity = 1; } } final_pos[0] += fl2i(HUD_offset_x); final_pos[1] += fl2i(HUD_offset_y); sprintf(text_integrity, "%d", numeric_integrity); if (numeric_integrity < 100) { hud_num_make_mono(text_integrity); } gr_string(final_pos[0] + HUD_nose_x, final_pos[1] + HUD_nose_y, text_integrity); }
void HudGaugeRadarDradis::initSound(int loop_snd, float loop_snd_volume, int arrival_snd, int departure_snd, int stealth_arrival_snd, int stealth_departue_snd, float arrival_delay, float departure_delay) { this->m_loop_snd = loop_snd; this->loop_sound_handle = -1; this->loop_sound_volume = loop_snd_volume; this->arrival_beep_snd = arrival_snd; this->departure_beep_snd = departure_snd; this->m_stealth_arrival_snd = stealth_arrival_snd; this->stealth_departure_snd = stealth_departue_snd; this->arrival_beep_delay = fl2i(arrival_delay * 1000.0f); this->departure_beep_delay = fl2i(departure_delay * 1000.0f); }
// force slider to new position manually void UI_SLIDER2::set_currentItem(int _currentItem) { if (_currentItem > numberItems) return; if (_currentItem == currentItem) return; if (_currentItem < 0) return; if (_currentItem > currentItem) { while (currentItem != _currentItem) { currentItem++; if (downCallback != NULL) downCallback(); } } else if (_currentItem < currentItem) { while (currentItem != _currentItem) { currentItem--; if (upCallback != NULL) upCallback(); } } currentPosition = fl2i(((float)currentItem/(float)numberItems) * (float)numberPositions); }
// Init the playback portion of the real-time voice system // exit: 0 => success // !0 => failure, playback not possible int rtvoice_init_playback() { rtv_format *rtvf=NULL; if ( !Rtv_playback_inited ) { rtvoice_reset_out_buffers(); Rtv_playback_format=0; rtvf = &Rtv_formats[Rtv_playback_format]; if ( Rtv_playback_uncompressed_buffer ) { vm_free(Rtv_playback_uncompressed_buffer); Rtv_playback_uncompressed_buffer=NULL; } Rtv_playback_uncompressed_buffer_size = rtvf->frequency * (RTV_BUFFER_TIME) * fl2i(rtvf->bits_per_sample/8.0f); Rtv_playback_uncompressed_buffer = (unsigned char*)vm_malloc(Rtv_playback_uncompressed_buffer_size); Assert(Rtv_playback_uncompressed_buffer); Rtv_playback_inited=1; } return 0; }
// Figure out the y-coord to start drawing the popup text. The text // is centered vertically within the popup. int popup_calc_starting_y(popup_info *pi, int flags) { int sy, total_h=0; int num_lines = pi->nlines > Popup_max_display[gr_screen.res] ? Popup_max_display[gr_screen.res] : pi->nlines; if ( flags & (PF_TITLE | PF_TITLE_BIG) ) { if ( flags & PF_TITLE_BIG ) { gr_set_font(FONT2); } else { gr_set_font(FONT1); } total_h += gr_get_font_height(); } if ( flags & PF_BODY_BIG ) { gr_set_font(FONT2); } else { gr_set_font(FONT1); } total_h += num_lines * gr_get_font_height(); sy = fl2i((Popup_text_coords[gr_screen.res][1] + Popup_text_coords[gr_screen.res][3]/2.0f) - total_h/2.0f + 0.5f); // if this is an input style box, add in some y if(flags & PF_INPUT){ sy += Popup_input_text_y_offset[gr_screen.res]; } return sy; }
// force slider to new position manually void UI_SLIDER2::set_currentItem(int _currentItem) { if (_currentItem > numberItems) goto cpSafety; if (_currentItem == currentItem) goto cpSafety; if (_currentItem < 0) goto cpSafety; if (_currentItem > currentItem) { while (currentItem != _currentItem) { currentItem++; if (downCallback != NULL) downCallback(); } } else if (_currentItem < currentItem) { while (currentItem != _currentItem) { currentItem--; if (upCallback != NULL) upCallback(); } } currentPosition = fl2i(((float)currentItem/(float)numberItems) * (float)numberPositions); cpSafety: // helps fix math problem on x86_64 if (currentPosition > numberItems) currentPosition = numberItems; if (currentPosition < 0) currentPosition = 0; }
void HudGaugeThreatIndicator::renderLockThreat() { int frame_offset, num_frames; //Let's find out how many frames our ani has, and adjust accordingly num_frames = lock_warn.num_frames; //We need at least two frames here Assert( num_frames >= 2 ); if ( Player->threat_flags & (THREAT_LOCK | THREAT_ATTEMPT_LOCK) ) { if ( timestamp_elapsed(lock_warn_timer) ) { if ( Player->threat_flags & THREAT_LOCK ) { lock_warn_timer = timestamp(fl2i(THREAT_LOCK_FLASH/2.0f)); } else { lock_warn_timer = timestamp(THREAT_LOCK_FLASH); } lock_warn_frame++; if ( lock_warn_frame > (num_frames - 1) ) { //The first frame being the default "off" setting, we need to cycle through all the other frames lock_warn_frame = 1; } } frame_offset = lock_warn_frame; } else { frame_offset = 0; } renderBitmap(lock_warn.first_frame+frame_offset, position[0] + Lock_warn_offsets[0], position[1] + Lock_warn_offsets[1]); }
// Set the correct frame of animation for the shockwave void shockwave_set_framenum(int index) { int framenum; shockwave *sw; shockwave_info *si; Assert( (index >= 0) && (index < MAX_SHOCKWAVES) ); sw = &Shockwaves[index]; si = &Shockwave_info[sw->shockwave_info_index]; // skip this if it's a 3d shockwave since it won't have the maps managed here if (si->bitmap_id < 0) return; framenum = fl2i(sw->time_elapsed / sw->total_time * si->num_frames + 0.5); // ensure we don't go past the number of frames of animation if ( framenum > (si->num_frames-1) ) { framenum = (si->num_frames-1); Objects[sw->objnum].flags |= OF_SHOULD_BE_DEAD; } if ( framenum < 0 ) { framenum = 0; } sw->current_bitmap = si->bitmap_id + framenum; }
void UI_SLIDER2::force_currentItem(int _currentItem) { currentItem = _currentItem; if(currentItem < 0){ currentItem = 0; }; currentPosition = fl2i(((float)currentItem/(float)numberItems) * (float)numberPositions); }
// given a shockwave index and the number of frames in an animation return what // the current frame # should be (for use with 3d shockwaves) int shockwave_get_framenum(int index, int num_frames) { int framenum; shockwave *sw; if ( (index < 0) || (index >= MAX_SHOCKWAVES) ) { Int3(); return 0; } sw = &Shockwaves[index]; framenum = fl2i(sw->time_elapsed / sw->total_time * num_frames + 0.5); // ensure we don't go past the number of frames of animation if ( framenum > (num_frames-1) ) { framenum = (num_frames-1); Objects[sw->objnum].flags |= OF_SHOULD_BE_DEAD; } if ( framenum < 0 ) { framenum = 0; } return framenum; }
void HudGaugeRadarStd::plotBlip(blip *b, int *x, int *y) { float zdist, rscale; vec3d *pos = &b->position; if (b->dist < pos->xyz.z) { rscale = 0.0f; } else { rscale = (float) acos(pos->xyz.z / b->dist) / PI; //2.0f; } zdist = fl_sqrt((pos->xyz.x * pos->xyz.x) + (pos->xyz.y * pos->xyz.y)); float new_x_dist, clipped_x_dist; float new_y_dist, clipped_y_dist; if (zdist < 0.01f) { new_x_dist = 0.0f; new_y_dist = 0.0f; } else { new_x_dist = (pos->xyz.x / zdist) * rscale * (Radar_radius[0]/2.0f); new_y_dist = (pos->xyz.y / zdist) * rscale * (Radar_radius[1]/2.0f); // force new_x_dist and new_y_dist to be inside the radar float hypotenuse; float max_radius; hypotenuse = (float) _hypot(new_x_dist, new_y_dist); max_radius = i2fl(Radar_radius[0] - 5); if (hypotenuse >= max_radius) { clipped_x_dist = max_radius * (new_x_dist / hypotenuse); clipped_y_dist = max_radius * (new_y_dist / hypotenuse); new_x_dist = clipped_x_dist; new_y_dist = clipped_y_dist; } } *x = fl2i(position[0] + Radar_center_offsets[0] + new_x_dist); *y = fl2i(position[1] + Radar_center_offsets[1] - new_y_dist); }
int multi_lag_get_random_lag() { // first determine the percentage we'll be checking against int ret; int mod; // if the lag system isn't inited, don't do anything (no lag) if(!Multi_lag_inited){ return 0; } // pick a value // see if we should be going up or down (loss max/loss min) float rand_val = rand() * RAND_MAX_1f; mod = 0; if (rand_val < 0.5f) { // down if (Multi_lag_min >= 0) { mod = -fl2i((Multi_lag_base - Multi_lag_min) * rand_val); } } else { // up if (Multi_lag_max >= 0) { mod = fl2i((Multi_lag_max - Multi_lag_base) * rand_val); } } // if the current streak has elapsed, calculate a new one if((Multi_streak_stamp == -1) || (timestamp_elapsed(Multi_streak_stamp))){ // timestamp the new streak Multi_streak_stamp = timestamp(Multi_streak_time); // set the return value ret = Multi_lag_base + mod; // set the lag value of this current streak Multi_current_streak = ret; } // otherwise use the lag for the current streak else { ret = Multi_current_streak; } return ret; }
void UI_SLIDER2::forceUp() { if (currentItem > 0) { currentItem--; currentPosition = fl2i(((float)currentItem/(float)numberItems) * (float)numberPositions); if (currentPosition < 0) currentPosition = 0; } }
// draw the shield icon and integrity for the escort ship void hud_escort_show_icon(int x, int y, int index) { #ifndef NEW_HUD if((Game_mode & GM_MULTIPLAYER) && (Netgame.type_flags & NG_TYPE_DOGFIGHT) && index <= 2) { hud_escort_show_icon_dogfight(x, y, index); return; } float shields, integrity; int screen_integrity, offset; char buf[255]; object *objp = &Objects[Escort_ships[index].objnum]; ship *sp = &Ships[objp->instance]; // determine if its "friendly" or not // Goober5000 - changed in favor of just passing the team hud_escort_set_gauge_color(index, sp->team); /* if(Player_ship != NULL){ hud_escort_set_gauge_color(index, (sp->team == Player_ship->team) ? 1 : 0); } else { hud_escort_set_gauge_color(index, 1); } */ // draw a 'D' if a ship is disabled if ( (sp->flags & SF_DISABLED) || (ship_subsys_disrupted(sp, SUBSYSTEM_ENGINE)) ) { emp_hud_string( x + current_hud->Escort_status[0], y + current_hud->Escort_status[1], EG_NULL, XSTR( "D", 284)); } // print out ship name strcpy(buf, sp->ship_name); gr_force_fit_string(buf, 255, 100); emp_hud_string( x + current_hud->Escort_name[0], y + current_hud->Escort_name[1], EG_ESCORT1 + index, buf); // show ship integrity hud_get_target_strength(objp, &shields, &integrity); screen_integrity = fl2i(integrity*100 + 0.5f); offset = 0; if ( screen_integrity < 100 ) { offset = 2; if ( screen_integrity == 0 ) { if ( integrity > 0 ) { screen_integrity = 1; } } } emp_hud_printf( x+current_hud->Escort_integrity[0] + offset, y+current_hud->Escort_integrity[1], EG_NULL, "%d", screen_integrity); //Let's be nice. hud_set_gauge_color(HUD_ESCORT_VIEW); #endif }
/** * Draw one ETS bar to screen */ void HudGaugeEts::blitGauge(int index) { int y_start, y_end, clip_h, w, h, x, y; clip_h = fl2i( (1 - Energy_levels[index]) * ETS_bar_h ); bm_get_info(Ets_bar.first_frame,&w,&h); if ( index < NUM_ENERGY_LEVELS-1 ) { // some portion of dark needs to be drawn setGaugeColor(); // draw the top portion x = position[0] + Top_offsets[0]; y = position[1] + Top_offsets[1]; renderBitmapEx(Ets_bar.first_frame,x,y,w,clip_h,0,0); // draw the bottom portion x = position[0] + Bottom_offsets[0]; y = position[1] + Bottom_offsets[1]; y_start = y + (ETS_bar_h - clip_h); y_end = y + ETS_bar_h; renderBitmapEx(Ets_bar.first_frame, x, y_start, w, y_end-y_start, 0, ETS_bar_h-clip_h); } if ( index > 0 ) { if ( maybeFlashSexp() == 1 ) { setGaugeColor(HUD_C_DIM); // hud_set_dim_color(); } else { setGaugeColor(HUD_C_BRIGHT); // hud_set_bright_color(); } // some portion of recharge needs to be drawn // draw the top portion x = position[0] + Top_offsets[0]; y = position[1] + Top_offsets[1]; y_start = y + clip_h; y_end = y + ETS_bar_h; renderBitmapEx(Ets_bar.first_frame+1, x, y_start, w, y_end-y_start, 0, clip_h); // draw the bottom portion x = position[0] + Bottom_offsets[0]; y = position[1] + Bottom_offsets[1]; renderBitmapEx(Ets_bar.first_frame+2, x,y,w,ETS_bar_h-clip_h,0,0); } }
/** * Render jump node * * @param pos World position * @param view_pos Viewer's world position, can be NULL */ void CJumpNode::RenderDEPRECATED(vec3d *pos, vec3d *view_pos) { Assert(pos != NULL); // Assert(view_pos != NULL); - view_pos can be NULL if(m_flags & JN_HIDE) return; if(m_modelnum < 0) return; matrix node_orient = IDENTITY_MATRIX; int mr_flags = MR_NO_LIGHTING; if(!(m_flags & JN_SHOW_POLYS)) { mr_flags |= MR_NO_CULL | MR_NO_POLYS | MR_SHOW_OUTLINE_PRESET; } if ( Fred_running ) { gr_set_color_fast(&m_display_color); model_render_DEPRECATED(m_modelnum, &node_orient, pos, mr_flags ); } else { if (m_flags & JN_USE_DISPLAY_COLOR) { gr_set_color_fast(&m_display_color); } else if ( view_pos != NULL) { int alpha_index = HUD_color_alpha; // generate alpha index based on distance to jump this float dist; dist = vm_vec_dist_quick(view_pos, pos); // linearly interpolate alpha. At 1000m or less, full intensity. At 10000m or more 1/2 intensity. if ( dist < 1000 ) { alpha_index = HUD_COLOR_ALPHA_USER_MAX - 2; } else if ( dist > 10000 ) { alpha_index = HUD_COLOR_ALPHA_USER_MIN; } else { alpha_index = fl2i( HUD_COLOR_ALPHA_USER_MAX - 2 + (dist-1000) * (HUD_COLOR_ALPHA_USER_MIN-HUD_COLOR_ALPHA_USER_MAX-2) / (9000) + 0.5f); if ( alpha_index < HUD_COLOR_ALPHA_USER_MIN ) { alpha_index = HUD_COLOR_ALPHA_USER_MIN; } } gr_set_color_fast(&HUD_color_defaults[alpha_index]); } else { gr_set_color(HUD_color_red, HUD_color_green, HUD_color_blue); } model_render_DEPRECATED(m_modelnum, &node_orient, pos, mr_flags ); } }
// draw the shield icon and integrity for the escort ship void HudGaugeEscort::renderIcon(int x, int y, int index) { if(MULTI_DOGFIGHT && index <= 2) { renderIconDogfight(x, y, index); return; } float shields, integrity; int screen_integrity, offset; char buf[255]; object *objp = &Objects[Escort_ships[index].objnum]; ship *sp = &Ships[objp->instance]; // determine if its "friendly" or not // Goober5000 - changed in favor of just passing the team setGaugeColorEscort(index, sp->team); /* if(Player_ship != NULL){ hud_escort_set_gauge_color(index, (sp->team == Player_ship->team) ? 1 : 0); } else { hud_escort_set_gauge_color(index, 1); } */ // draw a 'D' if a ship is disabled if ( (sp->flags & SF_DISABLED) || (ship_subsys_disrupted(sp, SUBSYSTEM_ENGINE)) ) { renderString( x + ship_status_offsets[0], y + ship_status_offsets[1], EG_NULL, XSTR( "D", 284)); } // print out ship name strcpy_s(buf, sp->ship_name); gr_force_fit_string(buf, 255, ship_name_max_width); end_string_at_first_hash_symbol(buf); renderString( x + ship_name_offsets[0], y + ship_name_offsets[1], EG_ESCORT1 + index, buf); // show ship integrity hud_get_target_strength(objp, &shields, &integrity); screen_integrity = fl2i(integrity*100 + 0.5f); offset = 0; if ( screen_integrity < 100 ) { offset = 2; if ( screen_integrity == 0 ) { if ( integrity > 0 ) { screen_integrity = 1; } } } renderPrintf( x+ship_integrity_offsets[0] + offset, y+ship_integrity_offsets[1], EG_NULL, "%d", screen_integrity); //Let's be nice. setGaugeColor(); }
void HudGaugeShieldMini::showIntegrity(float p_target_integrity) { char text_integrity[64]; int numeric_integrity; int final_pos[2]; numeric_integrity = fl2i(p_target_integrity*100 + 0.5f); if(numeric_integrity > 100){ numeric_integrity = 100; } // Assert(numeric_integrity <= 100); // 3 digit hull strength if ( numeric_integrity == 100 ) { memcpy(final_pos, Mini_3digit_offsets, sizeof(final_pos)); } // 1 digit hull strength else if ( numeric_integrity < 10 ) { memcpy(final_pos, Mini_1digit_offsets, sizeof(final_pos)); } // 2 digit hull strength else { memcpy(final_pos, Mini_2digit_offsets, sizeof(final_pos)); } if ( numeric_integrity == 0 ) { if ( p_target_integrity > 0 ) { numeric_integrity = 1; } } final_pos[0] += fl2i( HUD_offset_x ) + position[0]; final_pos[1] += fl2i( HUD_offset_y ) + position[1]; sprintf(text_integrity, "%d", numeric_integrity); if ( numeric_integrity < 100 ) { hud_num_make_mono(text_integrity, font_num); } renderString(final_pos[0], final_pos[1], text_integrity); }
// hud_calculate_lock_start_pos() will determine where to draw the starting location of the lock // indicator. It does this by picking a location that is Lock_start_dist pixels away from the current // target (in 2D). This is accomplished by finding the endpoint of a line that passes through the // origin, and connects the target and lock indicator postion (and has a magnitude of Lock_start_dist) void hud_calculate_lock_start_pos() { double hypotenuse; double delta_y; double delta_x; double target_mag, target_x, target_y; delta_x = Player->current_target_sx - gr_screen.clip_center_x; delta_y = Player->current_target_sy - gr_screen.clip_center_y; if ( (delta_x == 0.0) && (delta_y == 0.0) ) { Players[Player_num].lock_indicator_start_x = fl2i(gr_screen.clip_center_x + Lock_start_dist); Players[Player_num].lock_indicator_start_y = fl2i(gr_screen.clip_center_y); return; } hypotenuse = _hypot(delta_y, delta_x); if (hypotenuse >= Lock_start_dist) { Players[Player_num].lock_indicator_start_x = fl2i(gr_screen.clip_center_x); Players[Player_num].lock_indicator_start_y = fl2i(gr_screen.clip_center_y); return; } target_mag = Lock_start_dist - hypotenuse; target_x = target_mag * (delta_x / hypotenuse); target_y = target_mag * (delta_y / hypotenuse); Players[Player_num].lock_indicator_start_x = fl2i(gr_screen.clip_center_x - target_x); Players[Player_num].lock_indicator_start_y = fl2i(gr_screen.clip_center_y - target_y); CLAMP(Players[Player_num].lock_indicator_start_x, gr_screen.clip_left, gr_screen.clip_right); CLAMP(Players[Player_num].lock_indicator_start_y, gr_screen.clip_top, gr_screen.clip_bottom); }
// Creates a bunch of particles. You pass a structure // rather than a bunch of parameters. void particle_emit( particle_emitter *pe, int type, int optional_data, float range ) { int i, n; if ( !Particles_enabled ) return; int n1, n2; // Account for detail int percent = get_percent(Detail.num_particles); //Particle rendering drops out too soon. Seems to be around 150 m. Is it detail level controllable? I'd like it to be 500-1000 float min_dist = 125.0f; float dist = vm_vec_dist_quick( &pe->pos, &Eye_position ) / range; if ( dist > min_dist ) { percent = fl2i( i2fl(percent)*min_dist / dist ); if ( percent < 1 ) { return; } } //mprintf(( "Dist = %.1f, percent = %d%%\n", dist, percent )); n1 = (pe->num_low*percent)/100; n2 = (pe->num_high*percent)/100; // How many to emit? n = (rand() % (n2-n1+1)) + n1; if ( n < 1 ) return; for (i=0; i<n; i++ ) { // Create a particle vec3d tmp_vel; vec3d normal; // What normal the particle emit arond float radius = (( pe->max_rad - pe->min_rad ) * frand()) + pe->min_rad; float speed = (( pe->max_vel - pe->min_vel ) * frand()) + pe->min_vel; float life = (( pe->max_life - pe->min_life ) * frand()) + pe->min_life; normal.xyz.x = pe->normal.xyz.x + (frand()*2.0f - 1.0f)*pe->normal_variance; normal.xyz.y = pe->normal.xyz.y + (frand()*2.0f - 1.0f)*pe->normal_variance; normal.xyz.z = pe->normal.xyz.z + (frand()*2.0f - 1.0f)*pe->normal_variance; vm_vec_normalize_safe( &normal ); vm_vec_scale_add( &tmp_vel, &pe->vel, &normal, speed ); particle_create( &pe->pos, &tmp_vel, life, radius, type, optional_data ); } }
// called once per frame to update the reticle gauges. Makes calls to // ship_dumbfire_threat() and ship_lock_threat() and updates Threat_flags. void hud_update_reticle( player *pp ) { int rval; ship *shipp; // multiplayer clients won't call this routine if ( MULTIPLAYER_CLIENT || MULTI_OBSERVER(Net_players[MY_NET_PLAYER_NUM])) return; shipp = &Ships[Objects[pp->objnum].instance]; if ( ship_dumbfire_threat(shipp) ) { pp->threat_flags |= THREAT_DUMBFIRE; pp->update_dumbfire_time = timestamp(THREAT_UPDATE_DUMBFIRE_TIME); } if ( timestamp_elapsed(pp->update_dumbfire_time) ) { pp->update_dumbfire_time = timestamp(THREAT_UPDATE_DUMBFIRE_TIME); pp->threat_flags &= ~THREAT_DUMBFIRE; } if ( timestamp_elapsed(pp->update_lock_time) ) { pp->threat_flags &= ~(THREAT_LOCK | THREAT_ATTEMPT_LOCK); pp->update_lock_time = timestamp(THREAT_UPDATE_LOCK_TIME); rval = ship_lock_threat(shipp); if ( rval == 1 ) { pp->threat_flags |= THREAT_ATTEMPT_LOCK; } else if ( rval == 2 ) { pp->threat_flags |= THREAT_LOCK; } } if(Player->threat_flags & THREAT_LOCK ) { // a less hacked up version of the missile launch warning hud_start_text_flash(XSTR("Launch", 1507), THREAT_LOCK_FLASH, fl2i(THREAT_LOCK_FLASH/2.0f)); } if ( Player->threat_flags & (THREAT_ATTEMPT_LOCK) ) { if ( timestamp_elapsed(Threat_lock_timer) ) { Threat_lock_timer = timestamp(THREAT_LOCK_FLASH); Threat_lock_frame++; if ( Threat_lock_frame > 2 ) { Threat_lock_frame = 1; } if ( (Threat_lock_frame == 2) && (Player->threat_flags & THREAT_ATTEMPT_LOCK ) ) { snd_play( &Snds[ship_get_sound(Player_obj, SND_THREAT_FLASH)]); } } } }
/** * Create a new head animation object */ anim_instance* HudGaugeTalkingHead::createAnim(int anim_start_frame, anim* anim_data) { anim_play_struct aps; anim_play_init(&aps, anim_data, position[0] + Anim_offsets[0] + fl2i(HUD_offset_x), position[1] + Anim_offsets[1] + fl2i(HUD_offset_y), base_w, base_h); aps.start_at = anim_start_frame; // aps.color = &HUD_color_defaults[HUD_color_alpha]; aps.color = &HUD_config.clr[HUD_TALKING_HEAD]; // I'd much rather use gr_init_color and retrieve the colors from this object but no, aps.color just happens to be a pointer. // So, just give it the address from the player's HUD configuration. You win, aps.color. I'll take care of you next time. (Swifty) return anim_play(&aps); }
// draw copyright message on the bottom on the screen void player_select_display_copyright() { int sx, sy, w; char Copyright_msg1[256], Copyright_msg2[256]; // strcpy_s(Copyright_msg1, XSTR("Descent: FreeSpace - The Great War, Copyright c 1998, Volition, Inc.", -1)); gr_set_color_fast(&Color_white); // sprintf(Copyright_msg1, NOX("FreeSpace 2")); get_version_string(Copyright_msg1, sizeof(Copyright_msg1)); sprintf(Copyright_msg2, XSTR("Copyright %c 1999, Volition, Inc. All rights reserved.", 385), Lcl_special_chars + 4); gr_get_string_size(&w, NULL, Copyright_msg1); sx = fl2i((gr_screen.max_w_unscaled / 2) - w/2.0f + 0.5f); sy = (gr_screen.max_h_unscaled - 2) - 2*gr_get_font_height(); gr_string(sx, sy, Copyright_msg1, GR_RESIZE_MENU); gr_get_string_size(&w, NULL, Copyright_msg2); sx = fl2i((gr_screen.max_w_unscaled / 2) - w/2.0f + 0.5f); sy = (gr_screen.max_h_unscaled - 2) - gr_get_font_height(); gr_string(sx, sy, Copyright_msg2, GR_RESIZE_MENU); }
void dc_draw_cursor( SCP_string &cmd_string, int x, int y ) { int t; int w, h; // gr_string width and height t = timer_get_fixed_seconds() / (F1_0/3); if ( t & 1 ) { gr_get_string_size( &w, &h, cmd_string.c_str() ); w %= (DCOLS * col_width); //gr_string( w, debug_y*16, "_" ); gr_rect(gr_screen.center_offset_x + (x + (w + 1)), gr_screen.center_offset_y + (y + (h + 1)), 2, fl2i(font::get_current_font()->getHeight()), GR_RESIZE_NONE); } }
// Draw the title centered within the popup void popup_draw_title(int sy, char *line, int flags) { int w, h, sx; if ( flags & PF_TITLE_BIG ) { gr_set_font(FONT2); } else { gr_set_font(FONT1); } gr_get_string_size(&w, &h, line); sx = fl2i(Title_coords[gr_screen.res][4] - w/2.0f + 0.5f); popup_set_title_color(flags); gr_string(sx,sy,line,GR_RESIZE_MENU); }
/** * Renders everything for a head animation * Also checks for when new head ani's need to start playing */ void HudGaugeTalkingHead::render(float frametime) { if ( Head_frame.first_frame == -1 ){ return; } if(msg_id != -1 && head_anim != NULL) { if(!head_anim->done_playing) { // draw frame // hud_set_default_color(); setGaugeColor(); // clear setClip(position[0] + Anim_offsets[0], position[1] + Anim_offsets[1], Anim_size[0], Anim_size[1]); gr_clear(); resetClip(); renderBitmap(Head_frame.first_frame, position[0], position[1]); // head ani border gr_set_screen_scale(base_w, base_h); setGaugeColor(); generic_anim_render(head_anim,frametime, position[0] + Anim_offsets[0] + fl2i(HUD_offset_x), position[1] + Anim_offsets[1] + fl2i(HUD_offset_y)); // draw title renderString(position[0] + Header_offsets[0], position[1] + Header_offsets[1], XSTR("message", 217)); } else { for (int j = 0; j < Num_messages_playing; ++j) { if (Playing_messages[j].id == msg_id) { Playing_messages[j].play_anim = false; break; // only one head ani plays at a time } } msg_id = -1; // allow repeated messages to display a new head ani head_anim = NULL; // Nothing to see here anymore, move along } } // check playing messages to see if we have any messages with talking animations that need to be created. for (int i = 0; i < Num_messages_playing; i++ ) { if(Playing_messages[i].play_anim && Playing_messages[i].id != msg_id ) { msg_id = Playing_messages[i].id; if (Playing_messages[i].anim_data) head_anim = Playing_messages[i].anim_data; else head_anim = NULL; return; } } }
// Draw the message text nicely formatted in the popup void popup_draw_msg_text(popup_info *pi, int flags) { int sx, sy, i, w, h; int line_index; int line_count; // figure out the starting display line_index = popup_calc_starting_index(pi); // figure out the starting y: sy = popup_calc_starting_y(pi, flags); // draw title if required if ( flags & (PF_TITLE | PF_TITLE_BIG) ) { popup_draw_title(sy, pi->title, flags); sy += gr_get_font_height(); } // draw body if ( flags & PF_BODY_BIG ) { gr_set_font(FONT2); } else { gr_set_font(FONT1); } popup_set_text_color(flags); line_count = 0; for ( i = line_index; i < pi->nlines; i++, line_count++ ) { // if we've already displayed the max # of lines if(line_count >= Popup_max_display[gr_screen.res]){ break; } gr_get_string_size(&w, &h, pi->msg_lines[i]); sx = fl2i(Title_coords[gr_screen.res][4] - w/2.0f + 0.5f); gr_string(sx, sy + line_count * h, pi->msg_lines[i], GR_RESIZE_MENU); } // maybe draw "more" h = 10; if(i < pi->nlines){ gr_set_color_fast(&Color_more_bright); gr_string(Title_coords[gr_screen.res][4], sy + (Popup_max_display[gr_screen.res]) * h, XSTR("More", 459), GR_RESIZE_MENU); } gr_set_font(FONT1); // reset back to regular font size }
void hud_show_mini_ship_integrity(object *objp, int x_force, int y_force) { char text_integrity[64]; int numeric_integrity; float p_target_integrity; int final_pos[2]; p_target_integrity = get_hull_pct(objp); numeric_integrity = fl2i(p_target_integrity*100 + 0.5f); if(numeric_integrity > 100){ numeric_integrity = 100; } // Assert(numeric_integrity <= 100); // 3 digit hull strength if ( numeric_integrity == 100 ) { final_pos[0] = x_force + Hud_mini_3digit[gr_screen.res][0] - Shield_mini_coords[gr_screen.res][0]; final_pos[1] = y_force + Hud_mini_3digit[gr_screen.res][1] - Shield_mini_coords[gr_screen.res][1]; } // 1 digit hull strength else if ( numeric_integrity < 10 ) { final_pos[0] = x_force + Hud_mini_1digit[gr_screen.res][0] - Shield_mini_coords[gr_screen.res][0]; final_pos[1] = y_force + Hud_mini_1digit[gr_screen.res][1] - Shield_mini_coords[gr_screen.res][1]; } // 2 digit hull strength else { final_pos[0] = x_force + Hud_mini_2digit[gr_screen.res][0] - Shield_mini_coords[gr_screen.res][0]; final_pos[1] = y_force + Hud_mini_2digit[gr_screen.res][1] - Shield_mini_coords[gr_screen.res][1]; } if ( numeric_integrity == 0 ) { if ( p_target_integrity > 0 ) { numeric_integrity = 1; } } sprintf(text_integrity, "%d", numeric_integrity); if ( numeric_integrity < 100 ) { hud_num_make_mono(text_integrity); } gr_string(final_pos[0], final_pos[1], text_integrity); }
// change range. reset back to position 0 void UI_SLIDER2::set_numberItems(int _numberItems, int _reset) { numberItems = _numberItems; if (_reset) { currentItem = 0; currentPosition = 0; } else { // recalcluate current position currentPosition = fl2i((((float)currentItem/(float)numberItems) * (float)numberPositions)-.49); if (currentPosition < 0){ currentPosition = 0; } if (currentPosition > numberPositions){ currentPosition = numberPositions; } } if (numberItems <= 0){ disabled_flag = 1; } else { disabled_flag = 0; } }
void UI_SLIDER2::force_currentItem(int _currentItem) { if (_currentItem > numberItems) goto cpSafety; if (_currentItem == currentItem) goto cpSafety; currentItem = _currentItem; if(currentItem < 0){ currentItem = 0; }; currentPosition = fl2i(((float)currentItem/(float)numberItems) * (float)numberPositions); cpSafety: // helps fix math problem on x86_64 if (currentPosition > numberItems) currentPosition = numberItems; if (currentPosition < 0) currentPosition = 0; }