$$QUERY Objects b:Player is within the [i:Cone=90] degree view cone of [o:Object] at a max distance of [f:Distance] qObjCanSeePlayer Can object see a player Determines if the specified object can see a player Parameters: Object: The object doing the looking Cone: Angle between 0-360 which makes the viewcone that determines if the object can see the other object Distance: The player must b
| 6158 | $$END |
| 6159 | */ |
| 6160 | bool qObjCanSeePlayer(int cone, int handlesrc, float max_distance) { |
| 6161 | vector vsource, vtarget, viewvec; |
| 6162 | msafe_struct mstruct; |
| 6163 | |
| 6164 | // Get half of the angle that the user specified because they specified a cone, and we want an angle |
| 6165 | double cangle = (double)((double)cone / (double)2); |
| 6166 | double t = cangle * PI / 180; |
| 6167 | double testangle = cos(t); |
| 6168 | |
| 6169 | // Loop though all possible players |
| 6170 | for (int p = 0; p < MAX_PLAYERS; p++) { |
| 6171 | |
| 6172 | // Get player position |
| 6173 | mstruct.slot = p; |
| 6174 | MSafe_GetValue(MSAFE_OBJECT_PLAYER_HANDLE, &mstruct); |
| 6175 | |
| 6176 | // See if this player active |
| 6177 | if (mstruct.objhandle == OBJECT_HANDLE_NONE) |
| 6178 | continue; |
| 6179 | |
| 6180 | // Get the target position |
| 6181 | MSafe_GetValue(MSAFE_OBJECT_POS, &mstruct); |
| 6182 | vtarget = mstruct.pos; |
| 6183 | |
| 6184 | // Get the viewer position |
| 6185 | mstruct.objhandle = handlesrc; |
| 6186 | MSafe_GetValue(MSAFE_OBJECT_POS, &mstruct); |
| 6187 | vsource = mstruct.pos; |
| 6188 | |
| 6189 | // Get the viewer orientation |
| 6190 | mstruct.objhandle = handlesrc; |
| 6191 | MSafe_GetValue(MSAFE_OBJECT_ORIENT, &mstruct); |
| 6192 | |
| 6193 | // Get the normalized vector from the source to the target |
| 6194 | float dist = vm_GetNormalizedDirFast(&viewvec, &vtarget, &vsource); |
| 6195 | |
| 6196 | // Get the angle between the objects |
| 6197 | float dot = vm_DotProduct(&viewvec, &mstruct.orient.fvec); |
| 6198 | |
| 6199 | // Check angle and distance |
| 6200 | if ((dot > testangle) && (dist < max_distance)) |
| 6201 | return 1; |
| 6202 | } |
| 6203 | |
| 6204 | // Didn't find any in the view cone |
| 6205 | return 0; |
| 6206 | } |
| 6207 | |
| 6208 | /* |
| 6209 | $$QUERY |
no test coverage detected