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

Function AIFindRandomRoom

Descent3/AImain.cpp:3503–3587  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3501int AIGoalGotoRandomRoom() { return -1; }
3502
3503int AIFindRandomRoom(object *obj, ai_frame *ai_info, goal *goal_ptr, int avoid_room, int min_depth, int max_depth,
3504 bool f_check_path, bool f_cur_room_ok, int *depth) {
3505 int random_room = obj->roomnum;
3506 int n_tries = 0;
3507 bool valid = false;
3508 bool f_use_depth = false;
3509 int cur_depth;
3510 int cur_room = obj->roomnum;
3511 int mine_rooms[MAX_ROOMS];
3512 int num_mine_rooms = 0;
3513 int cur_mine = MINE_INDEX(obj->roomnum);
3514 int i;
3515
3516 for (i = 0; i <= Highest_room_index; i++) {
3517 if (Rooms[i].used && !(Rooms[i].flags & RF_EXTERNAL) && cur_mine == MINE_INDEX(i)) {
3518 mine_rooms[num_mine_rooms++] = i;
3519 ASSERT(Rooms[mine_rooms[num_mine_rooms - 1]].used);
3520 }
3521 }
3522
3523 if (max_depth >= 0 && min_depth >= 0) {
3524 f_use_depth = true;
3525 cur_depth = min_depth + (float)ps_rand() / (float)D3_RAND_MAX * (max_depth - min_depth);
3526 }
3527
3528 do {
3529 random_room = mine_rooms[ps_rand() % num_mine_rooms];
3530 valid = true;
3531
3532 if (random_room == avoid_room || ((!f_cur_room_ok) && (random_room == obj->roomnum)) || (!Rooms[random_room].used))
3533 valid = false;
3534
3535 if (valid && f_check_path) {
3536 ASSERT(Rooms[random_room].used);
3537 ASSERT(Rooms[obj->roomnum].used);
3538 valid = AIPathAllocPath(obj, ai_info, goal_ptr, &obj->roomnum, &obj->pos, &random_room,
3539 &Rooms[random_room].path_pnt, 0.0f, 0, obj->handle);
3540 }
3541
3542 n_tries++;
3543 } while (!valid && n_tries <= FRR_MAX_TRIES && num_mine_rooms > 1);
3544
3545 if (valid && f_use_depth) {
3546 while (cur_room != random_room && cur_depth > 0) {
3547 cur_room = BOA_NEXT_ROOM(cur_room, random_room);
3548 cur_depth--;
3549 }
3550
3551 random_room = cur_room;
3552 }
3553
3554 if (!valid) {
3555 int next_rooms[100];
3556 int i;
3557 int pick_list[100];
3558 int num_pickable = 0;
3559
3560 int num_next_rooms = AIMakeNextRoomList(obj->roomnum, next_rooms, 100);

Callers 1

GoalInitWanderAroundFunction · 0.85

Calls 4

ps_randFunction · 0.85
AIPathAllocPathFunction · 0.85
AIMakeNextRoomListFunction · 0.85

Tested by

no test coverage detected