|
[codes=jass]function H2I takes handle h returns integer
return h
return 0
endfunction
function I2U takes integer i returns unit
return i
return null
endfunction
function Move_LOOP takes nothing returns nothing
local timer t = GetExpiredTimer()
local integer i = 0
local unit orderUnit=I2U(GetStoredInteger(udg_GC,I2S(H2I(t)),"orderUnit"))
local real UnitLocX = GetStoredReal(udg_GC,I2S(H2I(t)),"X")
local real UnitLocY = GetStoredReal(udg_GC,I2S(H2I(t)),"Y")
local real tempLocX
local real tempLocY
local real angle = GetStoredReal(udg_GC,I2S(H2I(t)),"angle")
local real dis = GetStoredReal(udg_GC,I2S(H2I(t)),"distance")
local integer steps= GetStoredInteger(udg_GC,I2S(H2I(t)),"steps")
local integer Max= GetStoredInteger(udg_GC,I2S(H2I(t)),"Max")
if steps>0 then
set steps=steps-1
call StoreInteger(udg_GC,I2S(H2I(t)),"steps",steps)
set tempLocX = UnitLocX + dis*Cos(angle*bj_DEGTORAD)*(Max-steps)
set tempLocY = UnitLocY + dis*Sin(angle*bj_DEGTORAD)*(Max-steps)
if tempLocX > udg_Map_X_Max then
set tempLocX = udg_Map_X_Max
endif
if tempLocX < udg_Map_X_Min then
set tempLocX = udg_Map_X_Min
endif
if tempLocY > udg_Map_Y_Max then
set tempLocY = udg_Map_Y_Max
endif
if tempLocY < udg_Map_Y_Min then
set tempLocY = udg_Map_Y_Min
endif
call SetUnitX(orderUnit,tempLocX)
call SetUnitY(orderUnit,tempLocY)
else
set i=0
call FlushStoredMission(udg_GC,I2S(H2I(t)))
call DestroyTimer(t)
endif
set orderUnit=null
endfunction
function UnitMove takes unit orderUnit,real lasttime,real interval,real dis,real angle returns nothing
local real UnitLocX = GetUnitX(orderUnit)
local real UnitLocY = GetUnitY(orderUnit)
local timer t=CreateTimer()
local integer steps=R2I(lasttime/interval)
call StoreReal(udg_GC,I2S(H2I(t)),"X",UnitLocX)
call StoreReal(udg_GC,I2S(H2I(t)),"Y",UnitLocY)
call StoreInteger(udg_GC,I2S(H2I(t)),"steps",steps)
call StoreInteger(udg_GC,I2S(H2I(t)),"Max",steps)
call StoreReal(udg_GC,I2S(H2I(t)),"angle",angle)
call StoreReal(udg_GC,I2S(H2I(t)),"distance",dis)
call StoreInteger(udg_GC,I2S(H2I(t)),"orderUnit",H2I(orderUnit))
call TimerStart(t,interval,true,function Move_LOOP)
set t=null
endfunction[/codes]
比如:我想单位向前移动700距离(即CH牛头30大技),怎么写?下面2句的算法怎么理解?
set tempLocX = UnitLocX + dis*Cos(angle*bj_DEGTORAD)*(Max-steps)
set tempLocY = UnitLocY + dis*Sin(angle*bj_DEGTORAD)*(Max-steps) |
|