$$QUERY Objects b:[o:TargetObject] is within the [i:Cone=90] degree view cone of [o:Object] using flags [g:FVIHitFlags=1048585:16269119] qObjCanSeeObjAdvanced Can object see the target object Determines if the specified object can see the other object using the given flags Parameters: Object: The object doing the looking TargetObject: The target object Cone: Angle between 0-360 which make
| 5382 | $$END |
| 5383 | */ |
| 5384 | bool qObjCanSeeObjAdvanced(int handletarget, int cone, int handlesrc, int fvi_flags) { |
| 5385 | vector vsource, vtarget; |
| 5386 | int sourceroom; |
| 5387 | |
| 5388 | msafe_struct mstruct; |
| 5389 | |
| 5390 | // Get half of the angle that the user specified because they specified a cone, and we want an angle |
| 5391 | double cangle = (double)((double)cone / (double)2); |
| 5392 | |
| 5393 | double testangle = cos(cangle * PI / 180); |
| 5394 | |
| 5395 | mstruct.objhandle = handletarget; |
| 5396 | MSafe_GetValue(MSAFE_OBJECT_POS, &mstruct); |
| 5397 | vtarget = mstruct.pos; |
| 5398 | |
| 5399 | mstruct.objhandle = handlesrc; |
| 5400 | MSafe_GetValue(MSAFE_OBJECT_POS, &mstruct); |
| 5401 | vsource = mstruct.pos; |
| 5402 | |
| 5403 | mstruct.objhandle = handlesrc; |
| 5404 | MSafe_GetValue(MSAFE_OBJECT_ROOMNUM, &mstruct); |
| 5405 | sourceroom = mstruct.roomnum; |
| 5406 | |
| 5407 | mstruct.objhandle = handlesrc; |
| 5408 | MSafe_GetValue(MSAFE_OBJECT_ORIENT, &mstruct); |
| 5409 | |
| 5410 | vector subvec = vtarget - vsource; |
| 5411 | vm_VectorNormalizeFast(&subvec); |
| 5412 | float dotp = vm_DotProduct(&subvec, &mstruct.orient.fvec); |
| 5413 | |
| 5414 | if (dotp > testangle) { |
| 5415 | // see if we can cast a ray to the object |
| 5416 | ray_info ray; |
| 5417 | fvi_flags |= FQ_CHECK_OBJS; |
| 5418 | int fate = FVI_RayCast(handlesrc, &vsource, &vtarget, sourceroom, 0.0f, fvi_flags, &ray); |
| 5419 | if (fate == HIT_NONE) |
| 5420 | return true; |
| 5421 | |
| 5422 | if (fate == HIT_OBJECT) { |
| 5423 | if (ray.hit_object == handletarget) { |
| 5424 | return true; |
| 5425 | } |
| 5426 | } |
| 5427 | } |
| 5428 | return false; |
| 5429 | } |
| 5430 | |
| 5431 | /* |
| 5432 | $$QUERY |
no test coverage detected