Ticket #3539: groupObstruction.patch
File groupObstruction.patch, 4.4 KB (added by , 9 years ago) |
---|
-
source/simulation2/components/CCmpUnitMotion.cpp
553 553 return m_State == STATE_FORMATIONMEMBER_PATH; 554 554 } 555 555 556 entity_id_t GetGroup() const 557 { 558 return IsFormationMember() ? m_TargetEntity : GetEntityId(); 559 } 560 556 561 bool HasValidPath() const 557 562 { 558 563 return m_PathState == PATHSTATE_FOLLOWING … … 668 673 /** 669 674 * Returns an appropriate obstruction filter for use with path requests. 670 675 */ 671 ControlGroupMovementObstructionFilter GetObstructionFilter(bool avoidPathfindingShapes ) const;676 ControlGroupMovementObstructionFilter GetObstructionFilter(bool avoidPathfindingShapes, bool noTarget) const; 672 677 673 678 /** 674 679 * Checks our movement towards the next path waypoint. … … 1080 1085 1081 1086 PathGoal goal = { PathGoal::POINT, followingPoint.x, followingPoint.z }; 1082 1087 m_Planning.expectedPathTicket = cmpPathfinder->ComputeShortPathAsync( 1083 nextPoint.x, nextPoint.z, m_Clearance, SHORT_PATH_SEARCH_RANGE, goal, m_PassClass, false, m_TargetEntity, GetEntityId());1088 nextPoint.x, nextPoint.z, m_Clearance, SHORT_PATH_SEARCH_RANGE, goal, m_PassClass, false, GetGroup(), GetEntityId()); 1084 1089 } 1085 1090 } 1086 1091 … … 1124 1129 return false; 1125 1130 1126 1131 // Check if there's any collisions on that route 1127 if (!cmpPathfinder->CheckMovement(GetObstructionFilter(true ), from.X, from.Y, goalPos.X, goalPos.Y, m_Clearance, m_PassClass))1132 if (!cmpPathfinder->CheckMovement(GetObstructionFilter(true, false), from.X, from.Y, goalPos.X, goalPos.Y, m_Clearance, m_PassClass)) 1128 1133 return false; 1129 1134 1130 1135 // That route is okay, so update our path … … 1159 1164 // Find the point on the goal shape that we should head towards 1160 1165 CFixedVector2D goalPos = goal.NearestPointOnGoal(from); 1161 1166 1162 // Check if there's any collisions on that route 1163 if (!cmpPathfinder->CheckMovement(GetObstructionFilter(true ), from.X, from.Y, goalPos.X, goalPos.Y, m_Clearance, m_PassClass))1167 // Check if there's any collisions on that route (except the target itself) 1168 if (!cmpPathfinder->CheckMovement(GetObstructionFilter(true, true), from.X, from.Y, goalPos.X, goalPos.Y, m_Clearance, m_PassClass)) 1164 1169 return false; 1165 1170 1166 1171 // That route is okay, so update our path … … 1268 1273 } 1269 1274 } 1270 1275 1271 ControlGroupMovementObstructionFilter CCmpUnitMotion::GetObstructionFilter(bool avoidPathfindingShapes) const 1276 /** 1277 * Notarget is true when used inside tryGoingStraightToTargetEntity, in which case we do not want the target obstruction 1278 */ 1279 ControlGroupMovementObstructionFilter CCmpUnitMotion::GetObstructionFilter(bool avoidPathfindingShapes, bool noTarget) const 1272 1280 { 1273 1281 entity_id_t group; 1274 if ( IsFormationMember())1282 if (noTarget) 1275 1283 group = m_TargetEntity; 1276 1284 else 1277 group = Get EntityId();1285 group = GetGroup(); 1278 1286 1279 1287 return ControlGroupMovementObstructionFilter(avoidPathfindingShapes, ShouldAvoidMovingUnits(), group); 1280 1288 } … … 1285 1293 if (m_PassabilityMapChangedRecently) 1286 1294 { 1287 1295 CmpPtr<ICmpPathfinder> cmpPathfinder(GetSystemEntity()); 1288 return cmpPathfinder && cmpPathfinder->CheckMovement(GetObstructionFilter(true ), x0, z0, x1, z1, m_Clearance, m_PassClass);1296 return cmpPathfinder && cmpPathfinder->CheckMovement(GetObstructionFilter(true, false), x0, z0, x1, z1, m_Clearance, m_PassClass); 1289 1297 } 1290 1298 1291 1299 // If an obstruction blocks tile-based pathfinding, it will be handled during the path computation 1292 1300 // and doesn't need to be matched by this filter for the movement. 1293 ControlGroupMovementObstructionFilter filter = GetObstructionFilter(false );1301 ControlGroupMovementObstructionFilter filter = GetObstructionFilter(false, false); 1294 1302 1295 1303 CmpPtr<ICmpObstructionManager> cmpObstructionManager(GetSystemEntity()); 1296 1304 return cmpObstructionManager && !cmpObstructionManager->TestLine(filter, x0, z0, x1, z1, m_Clearance); … … 1383 1391 if (!cmpPathfinder) 1384 1392 return; 1385 1393 1386 m_ExpectedPathTicket = cmpPathfinder->ComputeShortPathAsync(from.X, from.Y, m_Clearance, SHORT_PATH_SEARCH_RANGE, goal, m_PassClass, avoidMovingUnits, m_TargetEntity, GetEntityId());1394 m_ExpectedPathTicket = cmpPathfinder->ComputeShortPathAsync(from.X, from.Y, m_Clearance, SHORT_PATH_SEARCH_RANGE, goal, m_PassClass, avoidMovingUnits, GetGroup(), GetEntityId()); 1387 1395 } 1388 1396 1389 1397 bool CCmpUnitMotion::MoveToPointRange(entity_pos_t x, entity_pos_t z, entity_pos_t minRange, entity_pos_t maxRange)