| 179 | */ |
| 180 | |
| 181 | qboolean NPC_GetMoveDirection( vec3_t out, float *distance ) |
| 182 | { |
| 183 | vec3_t angles; |
| 184 | |
| 185 | //Clear the struct |
| 186 | memset( &frameNavInfo, 0, sizeof( frameNavInfo ) ); |
| 187 | |
| 188 | //Get our movement, if any |
| 189 | if ( NPC_GetMoveInformation( frameNavInfo.direction, &frameNavInfo.distance ) == qfalse ) |
| 190 | return qfalse; |
| 191 | |
| 192 | //Setup the return value |
| 193 | *distance = frameNavInfo.distance; |
| 194 | |
| 195 | //For starters |
| 196 | VectorCopy( frameNavInfo.direction, frameNavInfo.pathDirection ); |
| 197 | |
| 198 | //If on a ladder, move appropriately |
| 199 | if ( NPC->watertype & CONTENTS_LADDER ) |
| 200 | { |
| 201 | NPC_LadderMove( frameNavInfo.direction ); |
| 202 | return qtrue; |
| 203 | } |
| 204 | |
| 205 | //Attempt a straight move to goal |
| 206 | if ( NPC_ClearPathToGoal( frameNavInfo.direction, NPCInfo->goalEntity ) == qfalse ) |
| 207 | { |
| 208 | //See if we're just stuck |
| 209 | if ( NAV_MoveToGoal( NPC, frameNavInfo ) == WAYPOINT_NONE ) |
| 210 | { |
| 211 | //Can't reach goal, just face |
| 212 | vectoangles( frameNavInfo.direction, angles ); |
| 213 | NPCInfo->desiredYaw = AngleNormalize360( angles[YAW] ); |
| 214 | VectorCopy( frameNavInfo.direction, out ); |
| 215 | *distance = frameNavInfo.distance; |
| 216 | return qfalse; |
| 217 | } |
| 218 | |
| 219 | frameNavInfo.flags |= NIF_MACRO_NAV; |
| 220 | } |
| 221 | |
| 222 | //Avoid any collisions on the way |
| 223 | if ( NAV_AvoidCollision( NPC, NPCInfo->goalEntity, frameNavInfo ) == qfalse ) |
| 224 | { |
| 225 | //FIXME: Emit a warning, this is a worst case scenario |
| 226 | //FIXME: if we have a clear path to our goal (exluding bodies), but then this |
| 227 | // check (against bodies only) fails, shouldn't we fall back |
| 228 | // to macro navigation? Like so: |
| 229 | if ( !(frameNavInfo.flags&NIF_MACRO_NAV) ) |
| 230 | {//we had a clear path to goal and didn't try macro nav, but can't avoid collision so try macro nav here |
| 231 | //See if we're just stuck |
| 232 | if ( NAV_MoveToGoal( NPC, frameNavInfo ) == WAYPOINT_NONE ) |
| 233 | { |
| 234 | //Can't reach goal, just face |
| 235 | vectoangles( frameNavInfo.direction, angles ); |
| 236 | NPCInfo->desiredYaw = AngleNormalize360( angles[YAW] ); |
| 237 | VectorCopy( frameNavInfo.direction, out ); |
| 238 | *distance = frameNavInfo.distance; |
no test coverage detected