|
楼主 |
发表于 2007-11-27 13:21:08
|
显示全部楼层
改进了下,但还是卡,估计这次是内存泄露啦
[codes=jass]
//========返回一个数组里最弱的单位(enemy=true:敌人;enemy=false:自己人)======
function GetWeakestUnit takes unit center,real range,boolean enemy returns unit
local unit temp
local unit weakest
local group g=CreateGroup()
call GroupEnumUnitsInRange(g,GetUnitX(center),GetUnitY(center),range,null)
call GroupRemoveUnit(g,center)
set weakest = FirstOfGroup(g)
call GroupRemoveUnit(g,weakest)
loop
set temp=FirstOfGroup(g)
exitwhen temp == null
if (enemy and (IsUnitEnemy(temp,GetOwningPlayer(center)) and GetUnitState(temp,UNIT_STATE_LIFE)>0)) then
if GetUnitState(weakest,UNIT_STATE_LIFE)>GetUnitState(temp,UNIT_STATE_LIFE) then
set weakest = temp
endif
endif
call GroupRemoveUnit(g,temp)
endloop
call DestroyGroup(g)
set temp = null
set g = null
call DisplayTextToPlayer( Player(0), 0, 0,"找到最弱")
return weakest
endfunction
//==========返回单位组单位个数(enemy=true:敌人;enemy=false:自己人)========
function GetUnitNum takes unit center,real range,boolean enemy returns integer
local unit temp
local integer n = 0
local group g=CreateGroup()
call GroupEnumUnitsInRange(g,GetUnitX(center),GetUnitY(center),range,null)
call GroupRemoveUnit(g,center)
loop
set temp=FirstOfGroup(g)
exitwhen temp == null
if enemy and IsUnitEnemy(temp,GetOwningPlayer(center)) and GetUnitState(temp,UNIT_STATE_LIFE)>0 then
set n = n+1
endif
call GroupRemoveUnit(g,temp)
endloop
call DestroyGroup(g)
set temp = null
set g = null
call DisplayTextToPlayer( Player(0), 0, 0,I2S(n))
return n
endfunction
//===返回范围内离所有单位最近的点(enemy=true:敌人;enemy=false:自己人)======
function GetSpellPiont takes unit center,real range,boolean enemy returns location
local unit temp
local real x = 0
local real y = 0
local location p
local integer n=0
local group g=CreateGroup()
call GroupEnumUnitsInRange(g,GetUnitX(center),GetUnitY(center),range,null)
call GroupRemoveUnit(g,center)
loop
set temp=FirstOfGroup(g)
if temp==null then
call DestroyGroup(g)
set g = null
return null
endif
call GroupRemoveUnit(g,temp)
exitwhen enemy and IsUnitEnemy(temp,GetOwningPlayer(center)) and GetUnitState(temp,UNIT_STATE_LIFE)>0
endloop
loop
set temp=FirstOfGroup(g)
if enemy and IsUnitEnemy(temp,GetOwningPlayer(center)) and GetUnitState(temp,UNIT_STATE_LIFE)>0 then
set x =x+DistanceBetweenPoints(GetUnitLoc(center),GetUnitLoc(temp))
set y= y+AngleBetweenPoints(GetUnitLoc(center), GetUnitLoc(temp))
endif
call GroupRemoveUnit(g,temp)
exitwhen temp==null
endloop
set n = GetUnitNum(center,range,enemy)
set x = x/n
set y = y/n
set p = PolarProjectionBJ(GetUnitLoc(center), x, y)
call DestroyGroup(g)
set temp = null
set g = null
set n=0
set x=0
set y=0
call DisplayTextToPlayer( Player(0), 0, 0,"点ok")
return p
endfunction
//======================智能施放技能================================
function UseSkill takes unit u,integer skill returns nothing
local integer i = GetStoredInteger(udg_GC,I2S(skill),"OrderTarget")
local string s = GetStoredString(udg_GC,I2S(skill),"OrderString")
local unit ut
local integer n = 0
local integer x = 1
local real a = 0
local location p
local location sp
if i == 0 then
call IssueImmediateOrder( u, s )
endif
if i == 1 then
set ut = GetWeakestUnit(u,500,true)
call IssueTargetOrder( u, s, ut )
endif
if i == 2 then
set ut = GetWeakestUnit(u,500,false)
call IssueTargetOrder( u, s, ut )
call IssuePointOrderLoc(u,s,GetUnitLoc(ut))
endif
if i == 3 then
set sp = GetSpellPiont(u,500,true)
call IssuePointOrderLoc( u, s, sp )
endif
set i = 0
set s = null
set u = null
set n = 0
set x = 0
set a = 0
set p = null
set sp = null
endfunction
[/codes]
不知道哪里还应该清除…… |
|