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

Function FireWeaponFromObject

Descent3/WeaponFire.cpp:1817–2017  ·  view source on GitHub ↗

Given an object and a weapon, fires a shot from that object

Source from the content-addressed store, hash-verified

1815
1816// Given an object and a weapon, fires a shot from that object
1817int FireWeaponFromObject(object *obj, int weapon_num, int gun_num, bool f_force_forward, bool f_force_target) {
1818 ASSERT(Weapons[weapon_num].used);
1819
1820 // Mass driver is hack
1821 static int mass_driver_id = -2;
1822 static int mass_driver_ring = -2;
1823
1824 if (mass_driver_id == -2) {
1825 mass_driver_id = FindWeaponName("Mass Driver");
1826 mass_driver_ring = FindTextureName("CloakRing.tga1");
1827 }
1828
1829 vector laser_pos, laser_dir;
1830 int objnum;
1831
1832 if (gun_num == -1) {
1833 laser_pos = obj->pos;
1834 laser_dir = obj->orient.fvec;
1835 } else {
1836 // Find the initial position of the laser
1837 poly_model *pm = &Poly_models[obj->rtype.pobj_info.model_num];
1838 // vector *pnt = &pm->gun_slots[gun_num].pnt;
1839 // vector gun_point;
1840 // matrix m;
1841
1842 if (gun_num >= pm->n_guns) {
1843 // We don't have a gun point for this gun!
1844 mprintf(0, "Trying to fire from gun %d...we don't have that gun!\n", gun_num);
1845 laser_pos = obj->pos;
1846 laser_dir = obj->orient.fvec;
1847 } else {
1848 if (f_force_forward) {
1849 WeaponCalcGun(&laser_pos, NULL, obj, gun_num);
1850 laser_dir = obj->orient.fvec;
1851 } else if (f_force_target && obj->ai_info && obj->ai_info->vec_to_target_perceived != Zero_vector) {
1852 WeaponCalcGun(&laser_pos, NULL, obj, gun_num);
1853 laser_dir = obj->ai_info->vec_to_target_perceived;
1854 } else {
1855 WeaponCalcGun(&laser_pos, &laser_dir, obj, gun_num);
1856 }
1857 }
1858 }
1859
1860 if ((obj->control_type == CT_AI) && (obj->ai_info->fire_spread || (Diff_ai_min_fire_spread[DIFF_LEVEL]))) {
1861 matrix rot_mat;
1862 angle p, h, b;
1863
1864 float diff_scale = DIFF_LEVEL / (MAX_DIFFICULTY_LEVELS - 1);
1865 float fs = (MAX_FIRE_SPREAD * (1.0f - diff_scale)) + (MIN_FIRE_SPREAD * diff_scale);
1866
1867 int16_t fire_spread = obj->ai_info->fire_spread * fs;
1868
1869 if ((obj->control_type == CT_AI && ((obj->ai_info->flags & AIF_TEAM_MASK) != AIF_TEAM_REBEL)) &&
1870 fire_spread < Diff_ai_min_fire_spread[DIFF_LEVEL] * fs) {
1871 fire_spread = Diff_ai_min_fire_spread[DIFF_LEVEL] * fs;
1872 }
1873
1874 int16_t half_fire_spread = fire_spread >> 1;

Callers 4

msafe_CallFunctionFunction · 0.85
WBFireBatteryFunction · 0.85

Calls 15

FindWeaponNameFunction · 0.85
FindTextureNameFunction · 0.85
WeaponCalcGunFunction · 0.85
ps_randFunction · 0.85
CreateAndFireWeaponFunction · 0.85
MultiSendRobotFireWeaponFunction · 0.85
DemoWriteWeaponFireFunction · 0.85
AINotifyFunction · 0.85
ObjGetFunction · 0.85
GetSmallViewerFunction · 0.85
CreateSmallViewFunction · 0.85
VisEffectCreateFunction · 0.85

Tested by

no test coverage detected