|
发表于 2008-11-10 11:40:42
|
显示全部楼层
[codes=jass]
globals
constant integer Ha=8191
constant integer Hb=1987
integer I
handle H
unit U
integer array Gz_Hi
endglobals
function Gz_Hash takes integer I,handle H,boolean b returns integer
local integer ha=I-I/Ha*Ha
local integer hb=(I/Hb+1)*Hb-I
loop
exitwhen (b and Gz_Hi[ha]==0)or(not b and Gz_Hi[ha]==I)
set ha=ha+hb
if ha>=Ha then
set ha=ha-Ha
endif
endloop
if b then
set Gz_Hi[ha]=I
endif
return ha
endfunction
globals
constant integer Gz_id='e001' //钩子头单位的ID
constant integer Gz_id1='e002' //锁链单位的ID,另外两个是+1再+1
constant real Gz_tmr=.04 //计时器的运行间隔
constant real Gz_sp=600 //钩子的初始速度
constant real Gz_sp1=100 //钩子速度每级的增长值
constant real Gz_h=1 //钩子返回时速度倍率
constant real Gz_l=1300 //钩子的范围
constant real Gz_l1=200 //钩子范围的每级增长值
constant real Gz_r=100 //钩子头钩取单位的范围
constant real Gz_r1=20 //钩子头钩取范围的每级增长值
constant real Gz_z=180/3.14159 //弧度转角度
integer array Gu_i1
integer array Gu_i2
real array Gsf_sp
integer array Gsf_l
real array Gsf_r
integer array Gsf_id
integer array Gsf_b
unit array Gn_u
unit array Gn_u1
unit array Gn_u2
unit array Gn_u3
integer array Gn_i
integer array Gn_l
real array Gn_f
integer array Gn_b
endglobals
function Gztm_f takes unit u,integer n,location l returns nothing
local integer this=Gn_i[n]
local real x=GetUnitX(u)
local real y=GetUnitY(u)
set x=x+Cos(Gn_f[n])*Gsf_sp[this]
set y=y+Sin(Gn_f[n])*Gsf_sp[this]
set l=Location(x,y)
if GetLocationZ(l)<=30 and not IsTerrainPathable(x,y,PATHING_TYPE_FLYABILITY) then
call SetUnitX(u,x)
call SetUnitY(u,y)
call RemoveLocation(l)
return
endif
call RemoveLocation(l)
set Gn_f[n]=-Gn_f[n]+3.14159
set x=x+Cos(Gn_f[n])*Gsf_sp[this]
set y=y+Sin(Gn_f[n])*Gsf_sp[this]
set l=Location(x,y)
if GetLocationZ(l)<=30 and not IsTerrainPathable(x,y,PATHING_TYPE_FLYABILITY) then
call SetUnitX(u,x)
call SetUnitY(u,y)
call RemoveLocation(l)
return
endif
call RemoveLocation(l)
set Gn_f[n]=Gn_f[n]+3.14159
set x=x+Cos(Gn_f[n])*Gsf_sp[this]*2
set y=y+Sin(Gn_f[n])*Gsf_sp[this]*2
set l=Location(x,y)
if GetLocationZ(l)<=50 and not IsTerrainPathable(x,y,PATHING_TYPE_FLYABILITY) then
call SetUnitX(u,x)
call SetUnitY(u,y)
call RemoveLocation(l)
return
endif
call RemoveLocation(l)
set Gn_f[n]=-Gn_f[n]+3.14159
set x=x+Cos(Gn_f[n])*Gsf_sp[this]*1.5
set y=y+Sin(Gn_f[n])*Gsf_sp[this]*1.5
call SetUnitX(u,x)
call SetUnitY(u,y)
endfunction
function Gztm_g takes unit ug,integer n returns integer
local unit u=Gn_u1[n]
local unit ux=Gn_u[n]
local real x=GetUnitX(u)
local real y=GetUnitY(u)
local real s=Gsf_r[Gn_i[n]]
local real x1
local real y1
local real s1
local group g=CreateGroup()
call GroupEnumUnitsInRange(g,x,y,s,null)
set s=s*s
loop
set u=FirstOfGroup(g)
exitwhen u==null
call GroupRemoveUnit(g,u)
if u!=ux and not IsUnitType(u,UNIT_TYPE_STRUCTURE) then
set x1=x-GetUnitX(u)
set y1=y-GetUnitY(u)
set s1=x1*x1+y1*y1
if s1<=s then
set ug=u
set s=s1
endif
endif
endloop
call DestroyGroup(g)
set g=null
set ux=null
return ug
return 0
endfunction
function Gztm_tm2 takes nothing returns nothing
local timer t=GetExpiredTimer()
local integer n=Gz_Hash(0,t,false)
local integer th=Gn_i[n]
local integer this
local unit ux=Gn_u[n]
local integer I
local unit U=Gn_u2[n]
local unit ug=Gn_u1[n]
local real x=GetUnitX(Gn_u[n])
local real y=GetUnitY(Gn_u[n])
local real x1
local real y1
local real f
local boolean b=false
if U!=ug then
set f=Gsf_sp[Gn_i[n]]*Gz_h
set f=f*f
loop
set x1=x-GetUnitX(U)
set y1=y-GetUnitY(U)
set this=Gz_Hash(0,U,false)
if x1*x1+y1*y1<=f then
call RemoveUnit(U)
set Gz_Hi[this]=0
else
set Gn_u2[n]=U
set U=Gn_u[n]
set Gu_i2[this]=I
set b=true
exitwhen true
endif
set I=Gu_i1[this]
exitwhen U==ug
endloop
endif
if b then
set U=Gn_u2[n]
loop
set x=GetUnitX(U)
set y=GetUnitY(U)
set f=Atan2(GetUnitY(ux)-y,GetUnitX(ux)-x)
call SetUnitX(U,x+Cos(f)*Gsf_sp[th]*Gz_h)
call SetUnitY(U,y+Sin(f)*Gsf_sp[th]*Gz_h)
call SetUnitFacing(U,180+f*Gz_z)
set this=Gz_Hash(0,U,false)
set ux=U
set I=Gu_i1[this]
exitwhen I==0
endloop
if Gn_u3[n]!=null then
call SetUnitX(Gn_u3[n],GetUnitX(ux))
call SetUnitY(Gn_u3[n],GetUnitY(ux))
else
set I=Gztm_g(null,n)
set Gn_u3[n]=U
endif
else
set Gz_Hi[Gz_Hash(0,Gn_u1[n],false)]=0
call RemoveUnit(Gn_u1[n])
set Gn_u3[n]=null
call PauseTimer(t)
call DestroyTimer(t)
endif
set t=null
set I=0
set ug=null
set ux=null
endfunction
function Gztm_tm1 takes nothing returns nothing
local timer t=GetExpiredTimer()
local integer n=Gz_Hash(0,t,false)
local integer this
local real x
local real y
local real f
local unit ug=Gn_u1[n]
local integer th=Gn_i[n]
local unit U
local integer I=Gztm_g(null,n)
if I==0 then
call Gztm_f(ug,n,null)
set Gn_l[n]=Gn_l[n]-1
loop
set this=Gz_Hash(0,ug,false)
set I=Gu_i2[this]
exitwhen I==0
set x=GetUnitX(U)
set y=GetUnitY(U)
set f=Atan2(GetUnitY(ug)-y,GetUnitX(ug)-x)
call SetUnitFacing(U,f*Gz_z)
call SetUnitX(U,x+Cos(f)*Gsf_sp[th])
call SetUnitY(U,y+Sin(f)*Gsf_sp[th])
set ug=U
endloop
if Gn_b[n]>=Gsf_b[th] then
set U=Gn_u[n]
set U=CreateUnit(GetOwningPlayer(ug),Gsf_id[th],GetUnitX(U),GetUnitY(U),Atan2(GetUnitY(ug)-GetUnitY(U),GetUnitX(ug)-GetUnitX(U))*Gz_z)
set Gn_u2[n]=U
set Gu_i2[this]=I
set Gn_b[n]=0
set th=Gz_Hash(0,U,true)
set Gu_i1[th]=Gz_Hi[this]
set Gu_i2[th]=0
else
set Gn_b[n]=Gn_b[n]+1
endif
else
set Gn_u3[n]=U
endif
if Gn_l[n]==0 or Gn_u3[n]!=null then
call PauseTimer(t)
call TimerStart(t,Gz_tmr,true,function Gztm_tm2)
endif
set I=0
set ug=null
set t=null
endfunction
function Gztm_func1 takes unit u,location l returns nothing
local timer t=CreateTimer()
local integer n=Gz_Hash(0,t,true)
local integer this=Gz_Hash(0,u,false)
local real x=GetUnitX(u)
local real y=GetUnitY(u)
set Gn_u[n]=u
set Gn_f[n]=Atan2(GetLocationY(l)-y,GetLocationX(l)-x)
set u=CreateUnit(GetOwningPlayer(u),Gz_id,x,y,0)
set Gn_u1[n]=u
set Gn_u2[n]=u
set Gn_i[n]=this
set Gn_l[n]=Gsf_l[this]
set Gn_b[n]=0
set this=Gz_Hash(0,u,true)
set Gu_i1[this]=0
set Gu_i2[this]=0
call TimerStart(t,Gz_tmr,true,function Gztm_tm1)
endfunction
function Gztm_tm0 takes nothing returns nothing
local integer n=Gz_Hash(0,GetExpiredTimer(),false)
call Gztm_f(Gn_u[n],n,null)
endfunction
function Gztm_func0 takes unit u,location l returns nothing
local timer t=CreateTimer()
local integer n=Gz_Hash(0,t,true)
local real x=GetUnitX(u)
local real y=GetUnitY(u)
set Gn_u[n]=CreateUnit(GetOwningPlayer(u),Gz_id,x,y,0)
set Gn_f[n]=Atan2(GetLocationY(l)-y,GetLocationX(l)-x)
set Gn_i[n]=Gz_Hash(0,u,false)
call TimerStart(t,Gz_tmr,true,function Gztm_tm0)
set t=null
endfunction
function Gztm_func takes nothing returns nothing
local location l
if GetSpellAbilityId()=='A002' then
call Gztm_func1(GetTriggerUnit(),GetSpellTargetLoc())
call RemoveLocation(l)
elseif GetSpellAbilityId()=='A000' then
call Gztm_func0(GetTriggerUnit(),GetSpellTargetLoc())
call RemoveLocation(l)
endif
set l=null
endfunction
[/codes] |
|