MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / FireWeaponFromPlayer

Function FireWeaponFromPlayer

Descent3/WeaponFire.cpp:2838–3027  ·  view source on GitHub ↗

Fires a weapon from our player. Won't fire if ammo/energy requirements aren't met. Parameters: weapon_type - either PW_PRIMARY or PW_SECONDARY

Source from the content-addressed store, hash-verified

2836// Fires a weapon from our player. Won't fire if ammo/energy requirements aren't met.
2837// Parameters: weapon_type - either PW_PRIMARY or PW_SECONDARY
2838void FireWeaponFromPlayer(object *objp, int weapon_type, int down_count, bool down_state, float down_time) {
2839 // Check parms
2840 ASSERT(objp->type == OBJ_PLAYER);
2841 // ASSERT(objp->id == Player_num);
2842 ASSERT((weapon_type == PW_PRIMARY) || (weapon_type == PW_SECONDARY));
2843
2844 // Set up various vars
2845 player *player = &Players[objp->id];
2846 player_weapon *pw = &player->weapon[weapon_type];
2847 int weapon_battery_index = pw->index;
2848 ship *ship = &Ships[player->ship_index];
2849 otype_wb_info *wb = &ship->static_wb[weapon_battery_index];
2850 int fire_on_release = (ship->fire_flags[weapon_battery_index] & (SFF_FUSION | SFF_ZOOM));
2851 bool can_fire_now = WBIsBatteryReady(objp, wb, weapon_battery_index);
2852 dynamic_wb_info *p_dwb = &objp->dynamic_wb[weapon_battery_index];
2853 float ammo_scalar = 1.0;
2854
2855 if (p_dwb->flags & DWBF_QUAD)
2856 ammo_scalar = 2.0;
2857
2858 // Don't allow down_time to be zero if we have a down count
2859 if (down_count && (down_time == 0.0))
2860 down_time = 1.0f / 100.0f;
2861
2862 // Check to see if we can release a guided
2863 if (down_count && down_time != 0.0 && Players[objp->id].guided_obj != NULL && weapon_type == PW_SECONDARY &&
2864 can_fire_now) {
2865 ReleaseGuidedMissile(objp->id);
2866 p_dwb->last_fire_time = Gametime;
2867 return;
2868 }
2869
2870 // Check to see if we can release a user timeout weapon
2871 if (down_count && down_time != 0.0 && Players[objp->id].user_timeout_obj != NULL && weapon_type == PW_SECONDARY &&
2872 can_fire_now) {
2873 if (Game_mode & GM_MULTI)
2874 MultiSendReleaseTimeoutMissile();
2875
2876 ReleaseUserTimeoutMissile(objp->id);
2877 p_dwb->last_fire_time = Gametime;
2878 return;
2879 }
2880
2881 // Check for weapon stopped firing
2882 if ((down_count == 0) && (down_time == 0)) {
2883 if (ship->fire_flags[weapon_battery_index] & SFF_ZOOM)
2884 DoZoomEffect(pw, 0);
2885
2886 // Abort if we weren't firing last frame either
2887 if (pw->firing_time == 0.0)
2888 return;
2889
2890 // Check for fire-on-release weapon
2891 if (fire_on_release) {
2892 if (can_fire_now) {
2893 float scalar = 1.0;
2894
2895 // Ready?

Callers 2

DoFlyingControlFunction · 0.85
DSSetControllerInfoFunction · 0.85

Calls 15

WBIsBatteryReadyFunction · 0.85
ReleaseGuidedMissileFunction · 0.85
DoZoomEffectFunction · 0.85
MultiSendRequestToFireFunction · 0.85
DoPermissableWeaponMaskFunction · 0.85
WBFireBatteryFunction · 0.85
AddToShakeMagnitudeFunction · 0.85
StopWeaponFunction · 0.85
AddHUDMessageFunction · 0.85
AutoSelectWeaponFunction · 0.85

Tested by

no test coverage detected