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

Function FindSpawnHomingTarget

Descent3/WeaponFire.cpp:3242–3288  ·  view source on GitHub ↗

Returns a object to home on for spawned weapons

Source from the content-addressed store, hash-verified

3240
3241// Returns a object to home on for spawned weapons
3242object *FindSpawnHomingTarget(object *obj) {
3243 int i;
3244 float best_dist = MAX_HOMING_DIST / 2;
3245 int best_index = -1;
3246 object *weapon_parent = ObjGet(obj->parent_handle);
3247
3248 for (i = 0; i <= Highest_object_index; i++) {
3249 if ((i != OBJNUM(weapon_parent)) && ((Objects[i].type == OBJ_ROBOT) || (Objects[i].type == OBJ_PLAYER) ||
3250 (Objects[i].type == OBJ_BUILDING && Objects[i].ai_info))) {
3251 if (BOA_IsVisible(obj->roomnum, Objects[i].roomnum)) {
3252 vector to_target = Objects[i].pos - obj->pos;
3253
3254 if (Objects[i].effect_info && Objects[i].effect_info->type_flags & EF_CLOAKED)
3255 continue;
3256
3257 if (ObjGet(obj->parent_handle) &&
3258 !AIObjEnemy(ObjGetUltimateParent(ObjGet(obj->parent_handle)), ObjGetUltimateParent(&Objects[i])))
3259 continue;
3260
3261 float dist_to_target = vm_NormalizeVector(&to_target) - obj->size - Objects[i].size;
3262
3263 if (dist_to_target < best_dist) {
3264 fvi_query fq;
3265 fvi_info hit_info;
3266
3267 fq.p0 = &obj->pos;
3268 fq.startroom = obj->roomnum;
3269 fq.p1 = &Objects[i].pos;
3270 fq.rad = 0.0f;
3271 fq.thisobjnum = OBJNUM(obj);
3272 fq.ignore_obj_list = NULL;
3273 fq.flags = FQ_TRANSPOINT | FQ_CHECK_OBJS | FQ_ONLY_DOOR_OBJ | FQ_NO_RELINK;
3274
3275 fvi_FindIntersection(&fq, &hit_info);
3276 if (hit_info.hit_type[0] == HIT_NONE) {
3277 best_index = i;
3278 best_dist = dist_to_target;
3279 }
3280 }
3281 }
3282 }
3283 }
3284 if (best_index >= 0)
3285 return &Objects[best_index];
3286
3287 return NULL;
3288}
3289
3290// Creates chidren from a dying weapon
3291void CreateImpactSpawnFromWeapon(object *obj, vector *normal) {

Callers 1

Calls 6

ObjGetFunction · 0.85
BOA_IsVisibleFunction · 0.85
AIObjEnemyFunction · 0.85
ObjGetUltimateParentFunction · 0.85
vm_NormalizeVectorFunction · 0.85
fvi_FindIntersectionFunction · 0.85

Tested by

no test coverage detected