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

Function MeleeHitOk

Descent3/AImain.cpp:2272–2352  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2270#define AI_AVE_MELEE_TIME .45f
2271
2272bool MeleeHitOk(object *obj) {
2273 ai_frame *ai_info = obj->ai_info;
2274 vector intp;
2275 float col_dist;
2276 int num_attacks = 0;
2277 float delay = 0.0f;
2278 const int ai_movement = ai_info->movement_type;
2279 polyobj_info *p_info = &obj->rtype.pobj_info;
2280 float time_left;
2281
2282 if (p_info->anim_end_frame != p_info->anim_start_frame) {
2283 float time_per_frame = p_info->anim_time / ((float)p_info->anim_end_frame - (float)p_info->anim_start_frame);
2284
2285 time_left = time_per_frame * (p_info->anim_end_frame - p_info->anim_frame);
2286 } else {
2287 time_left = 0.0f;
2288 }
2289
2290 vector relative_vel;
2291 vector g_end_pos;
2292
2293 object *target = ObjGet(ai_info->target_handle);
2294
2295 if (target == NULL || ai_info->dist_to_target_perceived > 100.0f) {
2296 return false;
2297 }
2298
2299 float dist = vm_VectorDistance(&obj->pos, &target->pos);
2300
2301 if (dist <= AI_MAX_MELEE_RANGE) {
2302 return true;
2303 }
2304
2305 if (ai_info->flags & AIF_MELEE1) {
2306 num_attacks++;
2307 delay += Object_info[obj->id].anim[ai_movement].elem[AS_MELEE1].spc;
2308 }
2309
2310 if (ai_info->flags & AIF_MELEE2) {
2311 num_attacks++;
2312 delay += Object_info[obj->id].anim[ai_movement].elem[AS_MELEE2].spc;
2313 }
2314
2315 if (!num_attacks) {
2316 return false;
2317 } else if (num_attacks > 1) {
2318 delay = delay / (float)num_attacks;
2319 }
2320
2321 delay += time_left + Frametime;
2322
2323 // Determines the relative velocities
2324 if (obj->movement_type == MT_PHYSICS || obj->movement_type == MT_PHYSICS) {
2325 if (target->movement_type == MT_PHYSICS || target->movement_type == MT_PHYSICS) {
2326 relative_vel = obj->mtype.phys_info.velocity - target->mtype.phys_info.velocity;
2327 } else {
2328 relative_vel = obj->mtype.phys_info.velocity;
2329 }

Callers 1

AiMeleeFunction · 0.85

Calls 3

ObjGetFunction · 0.85
check_vector_to_sphere_1Function · 0.85
vm_VectorDistanceFunction · 0.50

Tested by

no test coverage detected