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

Function DrawElectricalWeapon

Descent3/WeaponFire.cpp:2026–2219  ·  view source on GitHub ↗

Draws a lighting like chain of electricity

Source from the content-addressed store, hash-verified

2024
2025// Draws a lighting like chain of electricity
2026void DrawElectricalWeapon(object *obj) {
2027 int i, t;
2028 vector center_vecs[20];
2029 vector arc_vec;
2030 g3Point arc_points[100];
2031 vector dest_vector, src_vector, line_norm;
2032 float line_mag;
2033 g3Point *pntlist[20];
2034 vector dir;
2035 object *parent_obj = ObjGet(obj->parent_handle);
2036 float view_dp = 0;
2037
2038 if (!parent_obj)
2039 return;
2040
2041 if (parent_obj->type == OBJ_PLAYER) {
2042 if (Players[parent_obj->id].flags & (PLAYER_FLAGS_DYING | PLAYER_FLAGS_DEAD))
2043 return;
2044 } else {
2045 if (parent_obj->flags & OF_DYING)
2046 return;
2047 }
2048
2049 int bm_handle = GetWeaponFireImage(obj->id, 0);
2050 ASSERT(bm_handle >= 0);
2051
2052 WeaponCalcGun(&src_vector, &dir, parent_obj, obj->ctype.laser_info.src_gun_num);
2053
2054 if (obj->ctype.laser_info.track_handle == OBJECT_HANDLE_NONE || ObjGet(obj->ctype.laser_info.track_handle) == NULL) {
2055 dest_vector = src_vector + (obj->orient.fvec * 50);
2056 } else {
2057 object *obj_to_track = ObjGet(obj->ctype.laser_info.track_handle);
2058 dest_vector = obj_to_track->pos;
2059 if (obj_to_track == Player_object) {
2060 vector subvec = src_vector - dest_vector;
2061 float mag = vm_GetMagnitudeFast(&subvec);
2062
2063 if (mag < .5) {
2064 obj->lifeleft = 0;
2065 return;
2066 }
2067
2068 subvec /= mag;
2069
2070 dest_vector += subvec; // This prevents rendering errors
2071 }
2072 }
2073
2074 // Find out if it is o.k. to create a weapon here.
2075 fvi_query fq;
2076 fvi_info hit_data;
2077 int fate;
2078
2079 fq.p0 = &src_vector;
2080 fq.startroom = obj->roomnum;
2081 fq.p1 = &dest_vector;
2082 fq.rad = 0;
2083 fq.thisobjnum = -1;

Callers 1

DrawWeaponObjectFunction · 0.85

Calls 15

ObjGetFunction · 0.85
GetWeaponFireImageFunction · 0.85
WeaponCalcGunFunction · 0.85
fvi_FindIntersectionFunction · 0.85
CreateRandomSparksFunction · 0.85
ps_randFunction · 0.85
g3_RotatePointFunction · 0.85
g3_DrawPolyFunction · 0.85
DrawColoredDiskFunction · 0.85
FindArgFunction · 0.70
vm_GetMagnitudeFastFunction · 0.50
vm_VectorToMatrixFunction · 0.50

Tested by

no test coverage detected