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

Function AIFindObjOfType

Descent3/AImain.cpp:6368–6421  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6366bool AIFindHidePos(object *hide_obj, object *view_obj, vector *hpos, int *hroom, float max_hide_time) { return false; }
6367
6368object *AIFindObjOfType(object *obj, int type, int id, bool f_ignore_init_room, int parent_handle) {
6369 int cur_room = obj->roomnum;
6370 float best_dist = 0.0f;
6371 object *best_obj = NULL;
6372 int i;
6373 int my_obj_index = OBJNUM(obj);
6374
6375 for (i = 0; i <= Highest_object_index; i++) {
6376 if ((Objects[i].type == type || (type == OBJ_ROBOT && Objects[i].type == OBJ_BUILDING)) && i != my_obj_index) {
6377 float cur_dist;
6378
6379 if (f_ignore_init_room && (Objects[i].roomnum == obj->roomnum))
6380 continue;
6381
6382 if (id != -1 && id != Objects[i].id)
6383 continue;
6384
6385 // Allow us to find a players powerups
6386 if (parent_handle != OBJECT_HANDLE_NONE && parent_handle != Objects[i].parent_handle)
6387 continue;
6388
6389 // Invisible powerups
6390 if (Objects[i].render_type == RT_NONE)
6391 continue;
6392
6393 // Dying robots, other non-active robots
6394 if (Objects[i].type == OBJ_ROBOT && Objects[i].control_type != CT_AI)
6395 continue;
6396
6397 // Robots that don't shoot
6398 poly_model *pm = &Poly_models[Objects[i].rtype.pobj_info.model_num];
6399 if (Objects[i].type == OBJ_ROBOT && pm->num_wbs == 0)
6400 continue;
6401
6402 // cameras
6403 if (Objects[i].type == OBJ_ROBOT && pm->num_wbs == 1 && Object_info[Objects[i].id].static_wb[0].num_masks == 1 &&
6404 Object_info[Objects[i].id].static_wb[0].gp_fire_masks[0] == 0)
6405 continue;
6406
6407 if (BOA_ComputeMinDist(obj->roomnum, Objects[i].roomnum, 0.0f, &cur_dist, NULL)) {
6408 if (best_obj == NULL || cur_dist < best_dist) {
6409 bool f_path_exists = AIFindAltPath(obj, cur_room, Objects[i].roomnum, &cur_dist);
6410
6411 if (f_path_exists && (best_obj == NULL || cur_dist < best_dist)) {
6412 best_dist = cur_dist;
6413 best_obj = &Objects[i];
6414 }
6415 }
6416 }
6417 }
6418 }
6419
6420 return best_obj;
6421}
6422
6423int AIMakeNextRoomList(int roomnum, int *next_rooms, int max_rooms) {
6424 int num_next_rooms = 0;

Callers 1

osipf_AIFindObjOfTypeFunction · 0.85

Calls 2

BOA_ComputeMinDistFunction · 0.85
AIFindAltPathFunction · 0.85

Tested by

no test coverage detected