Ticket #1537: rangedFix-example.patch

File rangedFix-example.patch, 1.4 KB (added by wraitii, 12 years ago)
  • source/simulation2/components/CCmpUnitMotion.cpp

     
    13561356        {
    13571357            // Too close to the square - need to move away
    13581358
    1359             // TODO: maybe we should do the ShouldTreatTargetAsCircle thing here?
    1360 
     1359            // TODO: maybe we should do the ShouldTreatTargetAsCircle thing here?           
    13611360            entity_pos_t goalDistance = minRange + g_GoalDelta;
    13621361
     1362            // Add the walking speed of the target, and also divide by (my speed - his speed)/6 if that would be < 1.
     1363            // should be consistent.
     1364            CmpPtr<ICmpUnitMotion> cmpTargetUnitMotion(GetSimContext(), target);
     1365            if (cmpTargetUnitMotion)
     1366            {
     1367                CmpPtr<ICmpUnitMotion> cmpUnitMotion(GetSimContext(), GetEntityId());
     1368                if (cmpUnitMotion && cmpUnitMotion->GetWalkSpeed() > cmpTargetUnitMotion->GetWalkSpeed() + entity_pos_t::FromInt(2))
     1369                {
     1370                    goalDistance += cmpTargetUnitMotion->GetWalkSpeed();
     1371                    fixed speedDifference = (cmpUnitMotion->GetWalkSpeed() - cmpTargetUnitMotion->GetWalkSpeed())/6;
     1372                    if (speedDifference < entity_pos_t::FromInt(1) )
     1373                        goalDistance = goalDistance/speedDifference;
     1374                    if (goalDistance > maxRange)
     1375                        goalDistance = maxRange;
     1376                }
     1377            }
     1378
     1379           
    13631380            goal.type = ICmpPathfinder::Goal::SQUARE;
    13641381            goal.u = obstruction.u;
    13651382            goal.v = obstruction.v;