23 12
发新话题
打印

[原创演示] 坐标的细用,使用坐标位移单位且判断所有障碍

坐标的细用,使用坐标位移单位且判断所有障碍

这个演示是用坐标来位移单位的,因为设置坐标是Jass里最低级的语句之一,它的内部函数不会有多余的判断.
这个演示就是演示如何来增加这些判断的.
在语法和编写风格上新人也值得一看,希望能帮到大家.
地图中不常用自定义函数注释:

判断坐标X,Y是否超越地图边界
[jass]
function MapLimit takes real UnitX,real UnitY returns boolean
    local real MinX=GetRectMinX(bj_mapInitialPlayableArea)
    local real MinY=GetRectMinY(bj_mapInitialPlayableArea)
    local real MaxX=GetRectMaxX(bj_mapInitialPlayableArea)
    local real MaxY=GetRectMaxY(bj_mapInitialPlayableArea)
    if UnitX<MinX or UnitY<MinY or UnitX>MaxX or UnitY>MaxY then
        return false
    endif
    return true
endfunction
[/jass]
判断地形路径是否为地面单位可通行
[jass]
function PassableTerraEx takes real LocationX,real LocationY returns boolean
    if IsTerrainPathable(LocationX,LocationY,PATHING_TYPE_WALKABILITY)==false then
        return true
    endif
    return false
endfunction
[/jass]
判断是否有单位障碍
[jass]
function PassableUnitExHelp takes nothing returns boolean
    local unit FilterUnit=GetFilterUnit()
    local unit PortUnit=I2U(GetInteger("PassableUnitEx","PortUnit"))
    local boolean FilterUnitIsLife=GetUnitState(FilterUnit,UNIT_STATE_LIFE)>0
    local boolean FilterUnitIsHidden=IsUnitHidden(FilterUnit)==false
    local boolean FilterUnitNotPortUnit=FilterUnit!=PortUnit
    if FilterUnitIsLife and FilterUnitIsHidden and FilterUnitNotPortUnit then
        call SaveInteger("PassableUnitEx","UnitSum",GetInteger("PassableUnitEx","UnitSum")+1)
    endif
    set FilterUnit=null
    set PortUnit=null
    return false
endfunction
function PassableUnitEx takes unit PortUnit,real LocationX,real LocationY returns boolean
    local group GroupTemp=CreateGroup()
    local boolexpr BoolexprTemp=Condition(function PassableUnitExHelp)
    local boolean BooleanTemp
    call SaveInteger("PassableUnitEx","PortUnit",H2I(PortUnit))
    call GroupEnumUnitsInRange(GroupTemp,LocationX,LocationY,32,BoolexprTemp)
    if GetInteger("PassableUnitEx","UnitSum")>0 then
        set BooleanTemp=false
    else
        set BooleanTemp=true
    endif
    call FlushEx("PassableUnitEx")
    call DestroyBoolExpr(BoolexprTemp)
    call DestroyGroup(GroupTemp)
    set GroupTemp=null
    set BoolexprTemp=null
    return BooleanTemp
endfunction
[/jass]
判断是否有可破坏障碍
[jass]
function PassableDoodadExHelp takes nothing returns boolean
    if GetDestructableLife(GetFilterDestructable())>0 then
        call SaveInteger("PassableDoodadEx","DoodadSum",GetInteger("PassableDoodadEx","DoodadSum")+1)
    endif
    return false
endfunction
function PassableDoodadEx takes real LocationX,real LocationY returns boolean
    local rect RectTemp=Rect(LocationX-80,LocationY-80,LocationX+80,LocationY+32)
    local boolean BooleanTemp
    call EnumDestructablesInRect(RectTemp,null,function PassableDoodadExHelp)
    if GetInteger("PassableDoodadEx","DoodadSum")>0 then
        set BooleanTemp=false
    else
        set BooleanTemp=true
    endif
    call FlushEx("PassableDoodadEx")
    call RemoveRect(RectTemp)
    set RectTemp=null
    return BooleanTemp
endfunction
[/jass]
取得<参数单位坐标X><角度><距离>的坐标
[jass]
function GetUnitAngleX takes unit PortUnit,real UnitFacing,real Distance returns real
    return GetUnitX(PortUnit)+Distance*Cos(UnitFacing*(3.14159/180))
endfunction
[/jass]
取得<参数单位坐标Y><角度><距离>的坐标
[jass]
function GetUnitAngleY takes unit PortUnit,real UnitFacing,real Distance returns real
    return GetUnitY(PortUnit)+Distance*Sin(UnitFacing*(3.14159/180))
endfunction
[/jass]
计算<坐标X1><坐标Y1>与<坐标X2><坐Y2>之间的距离
[jass]
function GetLocationDistance takes real LocationAX,real LocationAY,real LocationBX,real LocationBY returns real
    return SquareRoot(((LocationBX-LocationAX)*(LocationBX-LocationAX))+((LocationBY-LocationAY)*(LocationBY-LocationAY)))
endfunction
[/jass]
计算<坐标X1><坐标Y1>与<坐标X2><坐Y2>之间的角度
[jass]
function GetLocationAngle takes real LocationAX,real LocationAY,real LocationBX,real LocationBY returns real
    return (180/3.14159)*Atan2(LocationBY-LocationAY,LocationBX-LocationAX)
endfunction
[/jass]

[ 本帖最后由 Crs.CoolRabbit 于 2008-8-1 23:17 编辑 ]

附件

IsTerrainPathable.w3x (43.32 KB)

2008-7-28 11:34, 下载次数: 10

本帖最近评分记录
  • aeris 威望 +1 很好的例子,支持原创 2008-7-28 18:45
  • aeris 金钱 +20 很好的例子,支持原创 2008-7-28 18:45

TOP

function DestCheck takes nothing returns nothing
    if GetDestructableLife(GetFilterDestructable())>0 then
        set udg_TempBool = true
    endif
endfunction

set udg_TempBool = false
call SetRect(udg_TempRect,x-50,y-50,x+50,y+50)
call EnumDestructablesInRect(udg_TempRect,null,function DestCheck)


---made by 老狼
The Low of Causality in The Chaos

TOP

不错
挺详细的
学习下

TOP

终于写了个简便的。
LZ的函数不错,但还可以改进。

比如:
function MapLimit takes real UnitX,real UnitY returns boolean
    local real MinX=GetRectMinX(bj_mapInitialPlayableArea)
    local real MinY=GetRectMinY(bj_mapInitialPlayableArea)
    local real MaxX=GetRectMaxX(bj_mapInitialPlayableArea)
    local real MaxY=GetRectMaxY(bj_mapInitialPlayableArea)
    if UnitX<MinX or UnitY<MinY or UnitX>MaxX or UnitY>MaxY then
        return false
    endif
    return true
endfunction

这个函数,会不断进行4个local real ,而在冲锋类的函数里这样的东西就不如用全局来设置了,因为这4个值是不变的。
The Low of Causality in The Chaos

TOP

申明变量对电脑来说比1+1还简单-.-
你们总是考虑这效率那效率的,还是把心思放到别的地方上吧.

什么到按效率的思路走就做不出好东西了.
那Cache也不要用了,都用全局吧-.-
Cache读取与写入比全局要慢几个级别哩...

[ 本帖最后由 Crs.CoolRabbit 于 2008-7-28 17:49 编辑 ]

TOP

路过支持下

~~

TOP

当然有用全局的,还有GC和全局都用的。
而我支持后者。
The Low of Causality in The Chaos

TOP

引用:
原帖由 280259078 于 2008-7-28 16:27 发表
终于写了个简便的。
LZ的函数不错,但还可以改进。

比如:
function MapLimit takes real UnitX,real UnitY returns boolean
    local real MinX=GetRectMinX(bj_mapInitialPlayableArea)
    local real  ...
显然你不懂计算机操作原理。。。用局部比用全局快。。。。
你用local,计算机只要声明一个存储位置就可以了,用udg_之类的,他会去缓存或者内存里面查这个数据来的

TOP

缓存比全局、局部变量慢不止一个数量级,但必须承认  缓存在很多情况下是数据储存的一种优秀选择

TOP

你们不用管7楼-。-
他认为他自己是最优秀的。。。
我也没什么说的

TOP

我狂汗 既然数据是确定的 那还用什么全局啊 量出来 然后直接写数字

TOP

引用:
原帖由 Cream_Charlotte 于 2008-7-29 20:59 发表
我狂汗 既然数据是确定的 那还用什么全局啊 量出来 然后直接写数字
用尺量吗

TOP

量 有两种方法
1  GetRectMinX(bj_mapInitialPlayableArea)
    GetRectMinY(bj_mapInitialPlayableArea)
    GetRectMaxX(bj_mapInitialPlayableArea)
    GetRectMaxY(bj_mapInitialPlayableArea)
然后在屏幕上显示出来 (这种比较精确)
2  鼠标移过的地方坐标是有显示滴~ (这种不精确,但很适合懒人)

TOP

脱裤子放屁
本帖最近评分记录
  • aeris 金钱 -1 请注意文明用语 2008-7-31 01:22

TOP

TOP

 23 12
发新话题