| 1757 | } |
| 1758 | |
| 1759 | void EntityAI::AvoidCollision(float deltaT, float& speedWanted, float& headChange) |
| 1760 | { |
| 1761 | AIUnit* unit = PilotUnit(); |
| 1762 | if (!unit) |
| 1763 | { |
| 1764 | return; |
| 1765 | } |
| 1766 | |
| 1767 | const float neutralAside = 0; |
| 1768 | |
| 1769 | AISubgroup* mySubgrp = unit->GetSubgroup(); |
| 1770 | _avoidAsideWanted = neutralAside; |
| 1771 | |
| 1772 | if (mySubgrp && mySubgrp->GetMode() == AISubgroup::DirectGo) |
| 1773 | { |
| 1774 | return; |
| 1775 | } |
| 1776 | // if we are stopped, do not try to avoid |
| 1777 | const float maxSpeedStopped = 0.05; |
| 1778 | if (fabs(speedWanted) <= maxSpeedStopped) |
| 1779 | { |
| 1780 | return; |
| 1781 | } |
| 1782 | // avoid collisions |
| 1783 | float mySize = CollisionSize(); // assume vehicle is not round |
| 1784 | float mySpeedSize = fabs(ModelSpeed()[2]); |
| 1785 | float maxSpeed = GetType()->GetMaxSpeedMs(); |
| 1786 | float myBrakeDist = Square(mySpeedSize) * 0.2; |
| 1787 | float myBrakeTime = mySpeedSize * 0.05; |
| 1788 | float maxDist = floatMax(GetPrecision() * 4, 5) + myBrakeDist * 1.3; |
| 1789 | // check if we are on collision course |
| 1790 | VehicleCollisionBuffer ret; |
| 1791 | float gapFactor = Interpolativ(mySpeedSize, maxSpeed * 0.5, maxSpeed, 0.5, 1); |
| 1792 | float gap = mySize * gapFactor; |
| 1793 | float maxTime = 1.5 + myBrakeTime * 1.3; |
| 1794 | |
| 1795 | GLOB_LAND->PredictCollision(ret, this, maxTime, gap, maxDist); |
| 1796 | if (ret.Size() <= 0) |
| 1797 | { |
| 1798 | return; |
| 1799 | } |
| 1800 | |
| 1801 | bool iAmMan = unit->IsSoldier(); |
| 1802 | bool iAmHeavy = GetMass() > 5000; |
| 1803 | |
| 1804 | AIGroup* myGroup = unit->GetGroup(); |
| 1805 | AICenter* myCenter = myGroup ? myGroup->GetCenter() : nullptr; |
| 1806 | |
| 1807 | // precalculate |
| 1808 | float invMaxSpeed = 1 / maxSpeed; |
| 1809 | |
| 1810 | saturate(speedWanted, -maxSpeed, maxSpeed); |
| 1811 | Vector3 mySpeed = Direction() * speedWanted; |
| 1812 | |
| 1813 | float maxAvoid = GetPrecision() * 0.5; |
| 1814 | saturate(maxAvoid, 1, 4); // 4m is enough to avoid on any road with any vehicle |
| 1815 | float wantAvoid = 0; |
| 1816 |
nothing calls this directly
no test coverage detected