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

Function AITargetCheck

Descent3/AImain.cpp:5835–5910  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5833#define AI_FORGIVE_AGRESSION_MULTIPLIER 1.2f
5834
5835void AITargetCheck(object *obj, object *target, object **best_obj, float *best_dot, float *best_dist) {
5836 bool f_use_dot = (obj->ai_info->flags & AIF_TARGET_BY_DIST) != 0;
5837
5838 if (AIObjEnemy(obj, target)) {
5839 float dot;
5840 float dist;
5841 vector to_obj;
5842 fvi_query fq;
5843 fvi_info hit_info;
5844 int fate;
5845
5846 if (obj == target)
5847 return;
5848
5849 if (!BOA_IsVisible(obj->roomnum, target->roomnum))
5850 return;
5851
5852 if (!AIDetermineObjVisLevel(obj, target))
5853 return;
5854
5855 if (target->type == OBJ_PLAYER && (Players[target->id].flags & (PLAYER_FLAGS_DEAD | PLAYER_FLAGS_DYING)))
5856 return;
5857
5858 to_obj = target->pos - obj->pos;
5859
5860 dist = vm_NormalizeVector(&to_obj);
5861
5862 if (dist > MAX_SEE_TARGET_DIST)
5863 return;
5864
5865 vector look_dir;
5866 AIDetermineFovVec(obj, &look_dir);
5867
5868 dot = to_obj * look_dir;
5869
5870 if (f_use_dot && dot <= *best_dot) {
5871 return;
5872 } else if (!f_use_dot && dist >= *best_dist) {
5873 return;
5874 }
5875
5876 fq.p0 = &obj->pos;
5877 fq.p1 = &target->pos;
5878 fq.startroom = obj->roomnum;
5879
5880 fq.rad = 0.0f;
5881 fq.flags = FQ_CHECK_OBJS | FQ_ONLY_DOOR_OBJ | FQ_NO_RELINK;
5882 fq.thisobjnum = -1;
5883
5884 int ignore_obj_list[100];
5885 ignore_obj_list[0] = OBJNUM(obj);
5886 int num_ignored = 1;
5887 int i;
5888
5889 // CHRISHACK - ONLY IGNORES FIRST LEVEL OF CHILDREN - DO RECERSIVE
5890 for (i = 0; i < Poly_models[obj->rtype.pobj_info.model_num].n_attach; i++) {
5891 object *child;
5892

Callers 1

AIDetermineTargetFunction · 0.85

Calls 7

AIObjEnemyFunction · 0.85
BOA_IsVisibleFunction · 0.85
AIDetermineObjVisLevelFunction · 0.85
vm_NormalizeVectorFunction · 0.85
AIDetermineFovVecFunction · 0.85
ObjGetFunction · 0.85
fvi_FindIntersectionFunction · 0.85

Tested by

no test coverage detected