找回密码
 点一下
查看: 912|回复: 1

PointPathingCost有bug

[复制链接]
发表于 2011-7-12 01:44:02 | 显示全部楼层 |阅读模式
自制的一个函数..
参数
inGroup 原单位组
inPoint 用作比较的目标点
count 输入数量

返回
n个距离目标点路径最近的单位形成的单位组
  1. unitgroup    UnitGroupNearestPathingUnit (unitgroup inGroup, point inPoint, int count) {
  2.     unitgroup groupCopy = UnitGroupCopy(inGroup);
  3.     unitgroup groupNearestUnits = UnitGroupEmpty();
  4.     
  5.     unit nearestUnit; int minCost; int pathCost; int i;
  6.     unit u = null;
  7.     point p = null;
  8.     
  9.     int countFound = 0;
  10.     
  11. &#160;&#160;&#160;&#160;while ( countFound < count ) {
  12. &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;i = 1; nearestUnit = null; minCost = 99999; pathCost = 0; p = null;
  13. &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;while (i <= UnitGroupCount(groupCopy, c_unitCountAll)) {
  14. &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;u = UnitGroupUnit(groupCopy, i);
  15. &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;p = UnitGetPosition(u);
  16. &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;//pathCost = PointPathingCost(p, inPoint); //用这个选出的不一定是路径最近的
  17. &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;pathCost = FixedToInt(DistanceBetweenPoints(p, inPoint));//用这个就对了,可惜是距离而不是路径
  18. &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;if (pathCost < minCost) {
  19. &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;minCost = pathCost;
  20. &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;nearestUnit = u;
  21. &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;}
  22. &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;i += 1;
  23. &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;}
  24. &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;
  25. &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;if (nearestUnit != null) {
  26. &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;UnitGroupAdd&#160;&#160;&#160;&#160;(groupNearestUnits, nearestUnit);
  27. &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;UnitGroupRemove (groupCopy, nearestUnit);
  28. &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;countFound+=1;
  29. &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;}&#160;&#160;&#160;&#160;else {&#160;&#160;&#160;&#160;break;&#160;&#160;&#160;&#160;}
  30. &#160;&#160;&#160;&#160;}
  31. &#160;&#160;&#160;&#160;
  32. &#160;&#160;&#160;&#160;return groupNearestUnits;
  33. }
复制代码
发表于 2011-7-12 02:40:52 | 显示全部楼层
你用错了函数

PointPathingCost()会计算路径中的单位。所以目标点如果有个占地儿的建筑,那么显然就会判定为无法通行。就返回65535了。


这里应该使用AIPathingCostMap()。这个函数返回的值是忽略任何单位的。这个函数有2个参数,都是point类型。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 点一下

本版积分规则

Archiver|移动端|小黑屋|地精研究院

GMT+8, 2024-8-8 05:25 , Processed in 0.038208 second(s), 18 queries .

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表