坐标的细用,使用坐标位移单位且判断所有障碍
这个演示是用坐标来位移单位的,因为设置坐标是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