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

Method FindHome

scripts/AIGame3.cpp:3212–3275  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3210#define HOME_LOOK_OFFSET 0.18f // for a 40 degree search pyramid
3211#define HOME_PLACE_DISTANCE 1.0f
3212bool AlienOrganism::FindHome(int me) {
3213 int num_attempts;
3214 bool home_found;
3215 vector start_pos, target_pos, landed_pos, home_dir;
3216 int start_room, landed_room;
3217 matrix start_orient;
3218 int flags, fate;
3219 ray_info ray;
3220 float size;
3221
3222 // Find start point
3223 Obj_Value(me, VF_GET, OBJV_V_POS, &start_pos);
3224 Obj_Value(me, VF_GET, OBJV_I_ROOMNUM, &start_room);
3225 Obj_Value(me, VF_GET, OBJV_M_ORIENT, &start_orient);
3226 Obj_Value(me, VF_GET, OBJV_F_SIZE, &size);
3227
3228 home_found = false;
3229 num_attempts = 0;
3230 while (!home_found && num_attempts < MAX_HOME_FINDING_ATTEMPTS) {
3231 // Determine ray angle
3232 home_dir = start_orient.fvec;
3233 home_dir += start_orient.uvec * (HOME_LOOK_OFFSET - ((float)rand() / (float)D3_RAND_MAX) * 2.0f * HOME_LOOK_OFFSET);
3234 home_dir += start_orient.rvec * (HOME_LOOK_OFFSET - ((float)rand() / (float)D3_RAND_MAX) * 2.0f * HOME_LOOK_OFFSET);
3235
3236 // Cast home-finding ray
3237 target_pos = start_pos + (home_dir * MAX_HOME_FINDING_DIST);
3238 flags = FQ_CHECK_OBJS | FQ_IGNORE_POWERUPS | FQ_IGNORE_WEAPONS | FQ_IGNORE_MOVING_OBJECTS |
3239 FQ_IGNORE_NON_LIGHTMAP_OBJECTS;
3240 fate = FVI_RayCast(me, &start_pos, &target_pos, start_room, size, flags, &ray);
3241
3242 // Check if it hit a face
3243 if (fate == HIT_WALL) {
3244 matrix temp;
3245
3246 memory->home_pos = ray.hit_face_pnt;
3247 memory->home_room = ray.hit_face_room;
3248 memory->home_uvec = ray.hit_wallnorm;
3249
3250 vm_VectorToMatrix(&temp, &memory->home_uvec, NULL, NULL);
3251 if (rand() % 100 > 50) {
3252 memory->home_fvec = temp.uvec;
3253 } else {
3254 memory->home_fvec = temp.rvec;
3255 }
3256 if (rand() % 100 > 50)
3257 memory->home_fvec = -memory->home_fvec;
3258
3259 // Place the object a little away from the wall
3260 target_pos = memory->home_pos + (memory->home_uvec * HOME_PLACE_DISTANCE);
3261 flags = FQ_CHECK_OBJS | FQ_IGNORE_POWERUPS | FQ_IGNORE_WEAPONS | FQ_IGNORE_MOVING_OBJECTS |
3262 FQ_IGNORE_NON_LIGHTMAP_OBJECTS;
3263 FVI_RayCast(me, &memory->home_pos, &target_pos, memory->home_room, 0.0f, flags, &ray);
3264
3265 memory->home_pos = ray.hit_point;
3266 memory->home_room = ray.hit_room;
3267
3268 home_found = true;
3269 }

Callers

nothing calls this directly

Calls 2

Obj_ValueFunction · 0.85
vm_VectorToMatrixFunction · 0.70

Tested by

no test coverage detected