|
自制的一个函数..
参数
inGroup 原单位组
inPoint 用作比较的目标点
count 输入数量
返回
n个距离目标点路径最近的单位形成的单位组
- unitgroup    UnitGroupNearestPathingUnit (unitgroup inGroup, point inPoint, int count) {
-     unitgroup groupCopy = UnitGroupCopy(inGroup);
-     unitgroup groupNearestUnits = UnitGroupEmpty();
-     
-     unit nearestUnit; int minCost; int pathCost; int i;
-     unit u = null;
-     point p = null;
-     
-     int countFound = 0;
-     
-     while ( countFound < count ) {
-         i = 1; nearestUnit = null; minCost = 99999; pathCost = 0; p = null;
-         while (i <= UnitGroupCount(groupCopy, c_unitCountAll)) {
-             u = UnitGroupUnit(groupCopy, i);
-             p = UnitGetPosition(u);
-             //pathCost = PointPathingCost(p, inPoint); //用这个选出的不一定是路径最近的
-             pathCost = FixedToInt(DistanceBetweenPoints(p, inPoint));//用这个就对了,可惜是距离而不是路径
-             if (pathCost < minCost) {
-                 minCost = pathCost;
-                 nearestUnit = u;
-             }
-             i += 1;
-         }
-         
-         if (nearestUnit != null) {
-             UnitGroupAdd    (groupNearestUnits, nearestUnit);
-             UnitGroupRemove (groupCopy, nearestUnit);
-             countFound+=1;
-         }    else {    break;    }
-     }
-     
-     return groupNearestUnits;
- }
复制代码 |
|