Ticket #3790: planNext.patch
File planNext.patch, 2.5 KB (added by , 8 years ago) |
---|
-
source/simulation2/components/CCmpUnitMotion.cpp
638 638 * If yes, try to anticipate. 639 639 * TODO: remove this and use a more general "pushing" manager. 640 640 */ 641 void PlanNextStep(const CFixedVector2D& pos, const CFixedVector2D& currentOffset );641 void PlanNextStep(const CFixedVector2D& pos, const CFixedVector2D& currentOffset, const fixed& maxSteps); 642 642 643 643 /** 644 644 * Decide whether to approximate the given range from a square target as a circle, … … 829 829 830 830 // else we could, so reset our number of tries. 831 831 m_Tries = 0; 832 832 833 833 // Now we've got a short path that we can follow 834 834 if (!HasValidPath()) 835 835 StartSucceeded(); … … 977 977 978 978 if (cmpPathfinder->CheckMovement(GetObstructionFilter(), pos.X, pos.Y, target.X, target.Y, m_Clearance, m_PassClass)) 979 979 { 980 PlanNextStep(pos, offset);981 980 pos = target; 981 fixed maxSteps = (offsetLength - maxdist) / maxdist; 982 PlanNextStep(pos, offset, maxSteps); 982 983 break; 983 984 } 984 985 else … … 1119 1120 } 1120 1121 } 1121 1122 1122 void CCmpUnitMotion::PlanNextStep(const CFixedVector2D& pos, const CFixedVector2D& currentOffset )1123 void CCmpUnitMotion::PlanNextStep(const CFixedVector2D& pos, const CFixedVector2D& currentOffset, const fixed& maxSteps) 1123 1124 { 1124 1125 if (m_LongPath.m_Waypoints.empty()) 1125 1126 return; 1126 1127 // Do not plan if a path is already being computed 1128 if (m_ExpectedPathTicket) 1129 return; 1130 1127 1131 CmpPtr<ICmpPathfinder> cmpPathfinder(GetSystemEntity()); 1128 1132 CmpPtr<ICmpObstructionManager> cmpObstructionManager(GetSystemEntity()); 1129 1133 if (!cmpPathfinder || !cmpObstructionManager) 1130 1134 return; 1131 1132 m_Planning = SUnitMotionPlanning(); 1133 1134 // see 2 turns in advance, otherwise this would start to lag in MP 1135 CFixedVector2D futurePos = pos + currentOffset*2; 1136 1135 1136 // Plan 1 turn in advance 1137 fixed step = std::min(fixed::FromFloat(1.0f), maxSteps); 1138 CFixedVector2D futurePos = pos + currentOffset.Multiply(step); 1139 1137 1140 // Don't actually use CheckMovement since we want to check against units only, we assume the rest is taken care of. 1138 1141 if (!cmpObstructionManager->TestLine(GetObstructionFilter(true, false), pos.X, pos.Y, futurePos.X, futurePos.Y, m_Clearance, true)) 1139 1142 return; 1140 1143 1141 1144 // we will run into a static unit obstruction. Try to shortpath around it. 1142 1145 PathGoal goal; 1143 1146 if (m_LongPath.m_Waypoints.size() > 1 || m_FinalGoal.DistanceToPoint(pos) > LONG_PATH_MIN_DIST)