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

Function AquireElectricalTarget

Descent3/WeaponFire.cpp:1068–1210  ·  view source on GitHub ↗

Picks out a target for an elecrical weapon to fire on

Source from the content-addressed store, hash-verified

1066
1067// Picks out a target for an elecrical weapon to fire on
1068void AquireElectricalTarget(object *obj) {
1069 int i;
1070 float closest_dist = 99999, dist;
1071 object *closest_obj = NULL, *hit_obj_ptr;
1072
1073 if (obj->mtype.phys_info.flags & PF_HOMING) {
1074 for (i = 0; i <= Highest_object_index; i++) {
1075 hit_obj_ptr = &Objects[i];
1076
1077 if ((hit_obj_ptr->render_type == RT_NONE) ||
1078 !(hit_obj_ptr->type == OBJ_PLAYER || hit_obj_ptr->type == OBJ_ROBOT ||
1079 (hit_obj_ptr->type == OBJ_BUILDING && hit_obj_ptr->ai_info)))
1080 continue;
1081
1082 if (ObjectsAreRelated(OBJNUM(obj), i))
1083 continue;
1084
1085 if (obj == hit_obj_ptr)
1086 continue;
1087
1088 if (hit_obj_ptr->flags & OF_DEAD)
1089 continue;
1090
1091 // The GB has an "electric shield" that works kind of like a Faraday's Cage (it also
1092 // make him less annoying as a player's own Omega will not track his GB)
1093 if (IS_GUIDEBOT(hit_obj_ptr))
1094 continue;
1095
1096 // Make sure this target is within our view cone
1097 vector subvec = hit_obj_ptr->pos - obj->pos;
1098 vm_NormalizeVectorFast(&subvec);
1099 if (vm_DotProduct(&subvec, &obj->orient.fvec) < .8)
1100 continue;
1101
1102 // The distance is actually the objects' centers minus some of the hit object's radius (I set it to 80%)
1103 if ((hit_obj_ptr->flags & OF_POLYGON_OBJECT) && hit_obj_ptr->type != OBJ_WEAPON &&
1104 hit_obj_ptr->type != OBJ_POWERUP && hit_obj_ptr->type != OBJ_DEBRIS) {
1105 vector pos;
1106 pos = hit_obj_ptr->pos + hit_obj_ptr->wall_sphere_offset;
1107
1108 dist = vm_VectorDistanceQuick(&pos, &obj->pos) - Poly_models[hit_obj_ptr->rtype.pobj_info.model_num].wall_size;
1109 } else {
1110 dist = vm_VectorDistanceQuick(&hit_obj_ptr->pos, &obj->pos) - hit_obj_ptr->size;
1111 }
1112
1113 if (dist < 0.0f)
1114 dist = 0.0f;
1115 if (dist > 50)
1116 continue;
1117
1118 if (dist <= closest_dist) {
1119 closest_dist = dist;
1120 closest_obj = hit_obj_ptr;
1121 }
1122 }
1123 }
1124
1125 if (closest_obj != NULL) {

Callers 1

CreateAndFireWeaponFunction · 0.85

Calls 9

ObjectsAreRelatedFunction · 0.85
vm_NormalizeVectorFastFunction · 0.85
collide_two_objectsFunction · 0.85
ObjGetFunction · 0.85
CallGameDLLFunction · 0.85
fvi_FindIntersectionFunction · 0.85
collide_object_with_wallFunction · 0.85
vm_DotProductFunction · 0.50
vm_VectorDistanceQuickFunction · 0.50

Tested by

no test coverage detected