void HudGaugeEtsWeapons::render(float frametime) { int i; ship* ship_p = &Ships[Player_obj->instance]; if ( Ets_bar.first_frame < 0 ) { return; } // if at least two gauges are not shown, don't show any i = 0; if (!ship_has_energy_weapons(ship_p)) i++; if (Player_obj->flags & OF_NO_SHIELDS) i++; if (!ship_has_engine_power(ship_p)) i++; if (i >= 2) return; // no weapon energy, no weapon gauge if (!ship_has_energy_weapons(ship_p)) { return; } setGaugeColor(); // draw the letters for the gauge first, before any clipping occurs renderPrintf(position[0] + Letter_offsets[0], position[1] + Letter_offsets[1], NOX("%c"), Letter); // draw the gauges for the weapon system blitGauge(ship_p->weapon_recharge_index); }
/** * Render the ETS retail gauge to the screen (weapon+shield+engine) */ void HudGaugeEtsRetail::render(float frametime) { int i; int initial_position; ship* ship_p = &Ships[Player_obj->instance]; if ( Ets_bar.first_frame < 0 ) { return; } // if at least two gauges are not shown, don't show any i = 0; if (!ship_has_energy_weapons(ship_p)) i++; if (Player_obj->flags & OF_NO_SHIELDS) i++; if (!ship_has_engine_power(ship_p)) i++; if (i >= 2) return; setGaugeColor(); // draw the letters for the gauges first, before any clipping occurs // skip letter for any missing gauges (max one, see check above) initial_position = 0; if (ship_has_energy_weapons(ship_p)) { Letter = Letters[0]; position[0] = Gauge_positions[initial_position++]; renderPrintf(position[0] + Letter_offsets[0], position[1] + Letter_offsets[1], NOX("%c"), Letter); } if (!(Player_obj->flags & OF_NO_SHIELDS)) { Letter = Letters[1]; position[0] = Gauge_positions[initial_position++]; renderPrintf(position[0] + Letter_offsets[0], position[1] + Letter_offsets[1], NOX("%c"), Letter); } if (ship_has_engine_power(ship_p)) { Letter = Letters[2]; position[0] = Gauge_positions[initial_position++]; renderPrintf(position[0] + Letter_offsets[0], position[1] + Letter_offsets[1], NOX("%c"), Letter); } // draw gauges, skipping any gauge that is missing initial_position = 0; if (ship_has_energy_weapons(ship_p)) { Letter = Letters[0]; position[0] = Gauge_positions[initial_position++]; blitGauge(ship_p->weapon_recharge_index); } if (!(Player_obj->flags & OF_NO_SHIELDS)) { Letter = Letters[1]; position[0] = Gauge_positions[initial_position++]; blitGauge(ship_p->shield_recharge_index); } if (ship_has_engine_power(ship_p)) { Letter = Letters[2]; position[0] = Gauge_positions[initial_position++]; blitGauge(ship_p->engine_recharge_index); } }
/** * adjust input ETS indexes to handle missing systems on the target ship * return true if indexes are valid to be set */ bool validate_ship_ets_indxes(const int &ship_idx, int (&ets_indexes)[num_retail_ets_gauges]) { if (ship_idx < 0) { return false; } if (Ships[ship_idx].objnum < 0) { return false; } ship *ship_p = &Ships[ship_idx]; if (ship_p->flags2 & SF2_NO_ETS) return false; // handle ships that are missing parts of the ETS int ship_properties = 0; if (ship_has_energy_weapons(ship_p)) { ship_properties |= HAS_WEAPONS; } if (!(Objects[ship_p->objnum].flags & OF_NO_SHIELDS)) { ship_properties |= HAS_SHIELDS; } if (ship_has_engine_power(ship_p)) { ship_properties |= HAS_ENGINES; } switch ( ship_properties ) { case HAS_ENGINES | HAS_WEAPONS | HAS_SHIELDS: // all present, don't change ets indexes break; case HAS_ENGINES | HAS_SHIELDS: zero_one_ets(&ets_indexes[WEAPONS], &ets_indexes[ENGINES], &ets_indexes[SHIELDS]); break; case HAS_WEAPONS | HAS_SHIELDS: zero_one_ets(&ets_indexes[ENGINES], &ets_indexes[SHIELDS], &ets_indexes[WEAPONS]); break; case HAS_ENGINES | HAS_WEAPONS: zero_one_ets(&ets_indexes[SHIELDS], &ets_indexes[ENGINES], &ets_indexes[WEAPONS]); break; case HAS_ENGINES: case HAS_SHIELDS: case HAS_WEAPONS: // can't change anything if only one is active on this ship return false; break; default: Error(LOCATION, "Encountered a ship (%s) with a broken ETS", ship_p->ship_name); break; } return true; }
// ------------------------------------------------------------------------------------------------- // transfer_energy_to_shields() will transfer ENERGY_DIVERT_DELTA percent of weapon energy // to shield energy. void transfer_energy_to_shields(object* obj) { ship* ship_p = &Ships[obj->instance]; if (ship_p->flags & SF_DYING) return; if ( !ship_has_energy_weapons(ship_p) || obj->flags & OF_NO_SHIELDS ) { return; } transfer_energy_weapon_common(obj, ship_p->weapon_energy, shield_get_strength(obj), &ship_p->target_weapon_energy_delta, &ship_p->target_shields_delta, ship_p->ship_max_shield_strength, 0.5f); }
// ------------------------------------------------------------------------------------------------- // transfer_energy_to_weapons() will transfer ENERGY_DIVERT_DELTA percent of shield energy // to weapon energy. void transfer_energy_to_weapons(object* obj) { ship* ship_p = &Ships[obj->instance]; ship_info* sinfo_p = &Ship_info[ship_p->ship_info_index]; if (ship_p->flags & SF_DYING) return; if ( !ship_has_energy_weapons(ship_p) || obj->flags & OF_NO_SHIELDS ) { return; } transfer_energy_weapon_common(obj, shield_get_strength(obj), ship_p->weapon_energy, &ship_p->target_shields_delta, &ship_p->target_weapon_energy_delta, sinfo_p->max_weapon_reserve, 1.0f); }
// ------------------------------------------------------------------------------------------------- // decrease_recharge_rate() will decrease the energy flow to the specified system (one of // WEAPONS, SHIELDS or ENGINES). The decrease in energy will result in an increase to // the other two systems. void decrease_recharge_rate(object* obj, SYSTEM_TYPE ship_system) { int *lose_index=NULL, *gain_index1=NULL, *gain_index2=NULL, *tmp=NULL; int count; ship *ship_p = &Ships[obj->instance]; if (ship_p->flags2 & SF2_NO_ETS) return; switch ( ship_system ) { case WEAPONS: if ( !ship_has_energy_weapons(ship_p) ) return; lose_index = &ship_p->weapon_recharge_index; if ( obj->flags & OF_NO_SHIELDS ) gain_index1 = NULL; else gain_index1 = &ship_p->shield_recharge_index; if ( !ship_has_engine_power(ship_p) ) gain_index2 = NULL; else gain_index2 = &ship_p->engine_recharge_index; break; case SHIELDS: if ( obj->flags & OF_NO_SHIELDS ) return; lose_index = &ship_p->shield_recharge_index; if ( !ship_has_energy_weapons(ship_p) ) gain_index1 = NULL; else gain_index1 = &ship_p->weapon_recharge_index; if ( !ship_has_engine_power(ship_p) ) gain_index2 = NULL; else gain_index2 = &ship_p->engine_recharge_index; break; case ENGINES: if ( !ship_has_engine_power(ship_p) ) return; lose_index = &ship_p->engine_recharge_index; if ( !ship_has_energy_weapons(ship_p) ) gain_index1 = NULL; else gain_index1 = &ship_p->weapon_recharge_index; if ( obj->flags & OF_NO_SHIELDS ) gain_index2 = NULL; else gain_index2 = &ship_p->shield_recharge_index; break; } // end switch // return if we can't transfer energy if (!gain_index1 && !gain_index2) return; // check how much there is to lose count = MIN(2, *lose_index); if ( count <= 0 ) { if ( obj == Player_obj ) { snd_play( &Snds[SND_ENERGY_TRANS_FAIL], 0.0f ); } return; } *lose_index -= count; // make sure that the gain starts with the system which needs it most if ( gain_index1 && gain_index2 ) { if ( *gain_index1 > *gain_index2 ) { tmp = gain_index1; gain_index1 = gain_index2; gain_index2 = tmp; } } int sanity=0; while(count > 0) { if ( gain_index1 && *gain_index1 < MAX_ENERGY_INDEX ) { *gain_index1 += 1; count--; } if ( count <= 0 ) break; if ( gain_index2 && *gain_index2 < MAX_ENERGY_INDEX ) { *gain_index2 += 1; count--; } if ( sanity++ > 10 ) { Int3(); // get Alan break; } } if ( obj == Player_obj ) snd_play( &Snds[SND_ENERGY_TRANS], 0.0f ); }
// ------------------------------------------------------------------------------------------------- // increase_recharge_rate() will increase the energy flow to the specified system (one of // WEAPONS, SHIELDS or ENGINES). The increase in energy will result in a decrease to // the other two systems. void increase_recharge_rate(object* obj, SYSTEM_TYPE ship_system) { int *gain_index=NULL, *lose_index1=NULL, *lose_index2=NULL, *tmp=NULL; int count=0; ship *ship_p = &Ships[obj->instance]; if (ship_p->flags2 & SF2_NO_ETS) return; switch ( ship_system ) { case WEAPONS: if ( !ship_has_energy_weapons(ship_p) ) return; gain_index = &ship_p->weapon_recharge_index; if ( obj->flags & OF_NO_SHIELDS ) lose_index1 = NULL; else lose_index1 = &ship_p->shield_recharge_index; if ( !ship_has_engine_power(ship_p) ) lose_index2 = NULL; else lose_index2 = &ship_p->engine_recharge_index; break; case SHIELDS: if ( obj->flags & OF_NO_SHIELDS ) return; gain_index = &ship_p->shield_recharge_index; if ( !ship_has_energy_weapons(ship_p) ) lose_index1 = NULL; else lose_index1 = &ship_p->weapon_recharge_index; if ( !ship_has_engine_power(ship_p) ) lose_index2 = NULL; else lose_index2 = &ship_p->engine_recharge_index; break; case ENGINES: if ( !ship_has_engine_power(ship_p) ) return; gain_index = &ship_p->engine_recharge_index; if ( !ship_has_energy_weapons(ship_p) ) lose_index1 = NULL; else lose_index1 = &ship_p->weapon_recharge_index; if ( obj->flags & OF_NO_SHIELDS ) lose_index2 = NULL; else lose_index2 = &ship_p->shield_recharge_index; break; } // end switch // return if we can't transfer energy if (!lose_index1 && !lose_index2) return; // already full, nothing to do count = MAX_ENERGY_INDEX - *gain_index; if ( count > 2 ) count = 2; if ( count <= 0 ) { if ( obj == Player_obj ) { snd_play( &Snds[SND_ENERGY_TRANS_FAIL], 0.0f ); } return; } *gain_index += count; // ensure that the highest lose index takes the first decrease if ( lose_index1 && lose_index2 ) { if ( *lose_index1 < *lose_index2 ) { tmp = lose_index1; lose_index1 = lose_index2; lose_index2 = tmp; } } int sanity = 0; while(count > 0) { if ( lose_index1 && *lose_index1 > 0 ) { *lose_index1 -= 1; count--; } if ( count <= 0 ) break; if ( lose_index2 && *lose_index2 > 0 ) { *lose_index2 -= 1; count--; } if ( sanity++ > 10 ) { Int3(); // get Alan break; } } if ( obj == Player_obj ) snd_play( &Snds[SND_ENERGY_TRANS], 0.0f ); }
// ------------------------------------------------------------------------------------------------- // set_default_recharge_rates() will set the charge levels for the weapons, shields and // engines to their default levels void set_default_recharge_rates(object* obj) { int ship_properties; ship* ship_p = &Ships[obj->instance]; ship_info* ship_info_p = &Ship_info[ship_p->ship_info_index]; if ( ship_info_p->power_output == 0 ) return; ship_properties = 0; if (ship_has_energy_weapons(ship_p)) ship_properties |= HAS_WEAPONS; if (!(obj->flags & OF_NO_SHIELDS)) ship_properties |= HAS_SHIELDS; if (ship_has_engine_power(ship_p)) ship_properties |= HAS_ENGINES; // the default charge rate depends on what systems are on each ship switch ( ship_properties ) { case HAS_ENGINES | HAS_WEAPONS | HAS_SHIELDS: ship_p->shield_recharge_index = INTIAL_SHIELD_RECHARGE_INDEX; ship_p->weapon_recharge_index = INTIAL_WEAPON_RECHARGE_INDEX; ship_p->engine_recharge_index = INTIAL_ENGINE_RECHARGE_INDEX; break; case HAS_ENGINES | HAS_SHIELDS: ship_p->shield_recharge_index = ONE_HALF_INDEX; ship_p->weapon_recharge_index = ZERO_INDEX; ship_p->engine_recharge_index = ONE_HALF_INDEX; break; case HAS_WEAPONS | HAS_SHIELDS: ship_p->shield_recharge_index = ONE_HALF_INDEX; ship_p->weapon_recharge_index = ONE_HALF_INDEX; ship_p->engine_recharge_index = ZERO_INDEX; break; case HAS_ENGINES | HAS_WEAPONS: ship_p->shield_recharge_index = ZERO_INDEX; ship_p->weapon_recharge_index = ONE_HALF_INDEX; ship_p->engine_recharge_index = ONE_HALF_INDEX; break; case HAS_SHIELDS: ship_p->shield_recharge_index = ALL_INDEX; ship_p->weapon_recharge_index = ZERO_INDEX; ship_p->engine_recharge_index = ZERO_INDEX; break; case HAS_ENGINES: ship_p->shield_recharge_index = ZERO_INDEX; ship_p->weapon_recharge_index = ZERO_INDEX; ship_p->engine_recharge_index = ALL_INDEX; break; case HAS_WEAPONS: ship_p->shield_recharge_index = ZERO_INDEX; ship_p->weapon_recharge_index = ALL_INDEX; ship_p->engine_recharge_index = ZERO_INDEX; break; default: Int3(); // if no systems, power output should be zero, and this funtion shouldn't be called break; } // end switch }
// ------------------------------------------------------------------------------------------------- // hud_show_ets() will display the charge rates for the three systems, and the reserve // energy for shields and weapons. hud_show_ets() is called once per frame. // void hud_show_ets() { int i, j, index, y_start, y_end, clip_h, w, h, x, y; ship* ship_p = &Ships[Player_obj->instance]; if (Ets_gauge.first_frame < 0) { return; } // if at least two gauges are not shown, don't show any i = 0; if (!ship_has_energy_weapons(ship_p)) i++; if (Player_obj->flags & OF_NO_SHIELDS) i++; if (!ship_has_engine_power(ship_p)) i++; if (i >= 2) return; hud_set_gauge_color(HUD_ETS_GAUGE); // draw the letters for the gauges first, before any clipping occurs i = 0; for (j = 0; j < 3; j++) { if (j == 0 && !ship_has_energy_weapons(ship_p)) { continue; } if (j == 1 && Player_obj->flags & OF_NO_SHIELDS) { continue; } if (j == 2 && !ship_has_engine_power(ship_p)) { continue; } Assert(Ets_gauge_info != NULL); gr_printf(Ets_gauge_info[i].letter_coords[0], Ets_gauge_info[i].letter_coords[1], NOX("%c"), Ets_gauge_info[j].letter); i++; } // draw the three energy gauges i = 0; index = 0; for (j = 0; j < 3; j++) { switch (j) { case 0: index = ship_p->weapon_recharge_index; if (!ship_has_energy_weapons(ship_p)) { continue; } break; case 1: index = ship_p->shield_recharge_index; if (Player_obj->flags & OF_NO_SHIELDS) { continue; } break; case 2: index = ship_p->engine_recharge_index; if (!ship_has_engine_power(ship_p)) { continue; } break; } clip_h = fl2i((1 - Energy_levels[index]) * ETS_bar_h[gr_screen.res]); bm_get_info(Ets_gauge.first_frame, &w, &h); if (index < NUM_ENERGY_LEVELS - 1) { // some portion of dark needs to be drawn hud_set_gauge_color(HUD_ETS_GAUGE); // draw the top portion Assert(Ets_gauge_info != NULL); x = Ets_gauge_info[i].top_coords[0]; y = Ets_gauge_info[i].top_coords[1]; hud_aabitmap_ex(Ets_gauge.first_frame, x, y, w, clip_h, 0, 0); // draw the bottom portion Assert(Ets_gauge_info != NULL); x = Ets_gauge_info[i].bottom_coords[0]; y = Ets_gauge_info[i].bottom_coords[1]; y_start = y + (ETS_bar_h[gr_screen.res] - clip_h); y_end = y + ETS_bar_h[gr_screen.res]; hud_aabitmap_ex(Ets_gauge.first_frame, x, y_start, w, y_end - y_start, 0, ETS_bar_h[gr_screen.res] - clip_h); } if (index > 0) { if (hud_gauge_maybe_flash(HUD_ETS_GAUGE) == 1) { hud_set_gauge_color(HUD_ETS_GAUGE, HUD_C_DIM); // hud_set_dim_color(); } else { hud_set_gauge_color(HUD_ETS_GAUGE, HUD_C_BRIGHT); // hud_set_bright_color(); } // some portion of recharge needs to be drawn // draw the top portion Assert(Ets_gauge_info != NULL); x = Ets_gauge_info[i].top_coords[0]; y = Ets_gauge_info[i].top_coords[1]; y_start = y + clip_h; y_end = y + ETS_bar_h[gr_screen.res]; hud_aabitmap_ex(Ets_gauge.first_frame + 1, x, y_start, w, y_end - y_start, 0, clip_h); // draw the bottom portion Assert(Ets_gauge_info != NULL); x = Ets_gauge_info[i].bottom_coords[0]; y = Ets_gauge_info[i].bottom_coords[1]; hud_aabitmap_ex(Ets_gauge.first_frame + 2, x, y, w, ETS_bar_h[gr_screen.res] - clip_h, 0, 0); } i++; } // hud_set_default_color(); }