|
发表于 2009-7-19 13:29:56
|
显示全部楼层
[jass]
function NearbyElevatorExistsEnum takes nothing returns nothing
local destructable d = GetEnumDestructable()
local integer dType = GetDestructableTypeId(d)
if (dType == bj_ELEVATOR_CODE01) or (dType == bj_ELEVATOR_CODE02) then
set bj_elevatorNeighbor = d
endif
endfunction
//===========================================================================
function NearbyElevatorExists takes real x, real y returns boolean
local real findThreshold = 32
local rect r
// If another elevator is overlapping this one, ignore the wall.
set r = Rect(x - findThreshold, y - findThreshold, x + findThreshold, y + findThreshold)
set bj_elevatorNeighbor = null
call EnumDestructablesInRect(r, null, function NearbyElevatorExistsEnum)
call RemoveRect(r)
return bj_elevatorNeighbor != null
endfunction
//==========================================================================
function NudgeUnitsInRectEnum takes nothing returns nothing
local unit nudgee = GetEnumUnit()
call SetUnitPosition(nudgee, GetUnitX(nudgee), GetUnitY(nudgee))
endfunction
//===========================================================================
function NudgeObjectsInRect takes rect nudgeArea returns nothing
local group g
set g = CreateGroup()
call GroupEnumUnitsInRect(g, nudgeArea, null)
call ForGroup(g, function NudgeUnitsInRectEnum)
call DestroyGroup(g)
call EnumItemsInRect(nudgeArea, null, function NudgeItemsInRectEnum)
endfunction
//==========================================================================
function ChangeElevatorWallBlocker takes real x, real y, real facing, boolean open returns nothing
local destructable blocker = null
local real findThreshold = 32
local real nudgeLength = 4.25 * bj_CELLWIDTH
local real nudgeWidth = 1.25 * bj_CELLWIDTH
local rect r
// Search for the pathing blocker within the general area.
set r = Rect(x - findThreshold, y - findThreshold, x + findThreshold, y + findThreshold)
set bj_elevatorWallBlocker = null
call EnumDestructablesInRect(r, null, function FindElevatorWallBlockerEnum)
call RemoveRect(r)
set blocker = bj_elevatorWallBlocker
// Ensure that the blocker exists.
if (blocker == null) then
set blocker = CreateDeadDestructable(bj_ELEVATOR_BLOCKER_CODE, x, y, facing, 1, 0)
elseif (GetDestructableTypeId(blocker) != bj_ELEVATOR_BLOCKER_CODE) then
// If a different destructible exists in the blocker's spot, ignore
// the request. (Two destructibles cannot occupy the same location
// on the map, so we cannot create an elevator blocker here.)
return
endif
if (open) then
// Ensure that the blocker is dead.
if (GetDestructableLife(blocker) > 0) then
call KillDestructable(blocker)
endif
else
// Ensure that the blocker is alive.
if (GetDestructableLife(blocker) <= 0) then
call DestructableRestoreLife(blocker, GetDestructableMaxLife(blocker), false)
endif
// Nudge any objects standing in the blocker's way.
if (facing == 0) then
set r = Rect(x - nudgeWidth/2, y - nudgeLength/2, x + nudgeWidth/2, y + nudgeLength/2)
call NudgeObjectsInRect(r)
call RemoveRect(r)
elseif (facing == 90) then
set r = Rect(x - nudgeLength/2, y - nudgeWidth/2, x + nudgeLength/2, y + nudgeWidth/2)
call NudgeObjectsInRect(r)
call RemoveRect(r)
else
// Unrecognized blocker angle - don't nudge anything.
endif
endif
endfunction
//================================================================================
function ChangeElevatorWalls takes boolean open, integer walls, destructable d returns nothing
local real x = GetDestructableX(d)
local real y = GetDestructableY(d)
local real distToBlocker = 192
local real distToNeighbor = 256
if (walls == bj_ELEVATOR_WALL_TYPE_ALL) or (walls == bj_ELEVATOR_WALL_TYPE_EAST) then
if (not NearbyElevatorExists(x + distToNeighbor, y)) then
call ChangeElevatorWallBlocker(x + distToBlocker, y, 0, open)
endif
endif
if (walls == bj_ELEVATOR_WALL_TYPE_ALL) or (walls == bj_ELEVATOR_WALL_TYPE_NORTH) then
if (not NearbyElevatorExists(x, y + distToNeighbor)) then
call ChangeElevatorWallBlocker(x, y + distToBlocker, 90, open)
endif
endif
if (walls == bj_ELEVATOR_WALL_TYPE_ALL) or (walls == bj_ELEVATOR_WALL_TYPE_SOUTH) then
if (not NearbyElevatorExists(x, y - distToNeighbor)) then
call ChangeElevatorWallBlocker(x, y - distToBlocker, 90, open)
endif
endif
if (walls == bj_ELEVATOR_WALL_TYPE_ALL) or (walls == bj_ELEVATOR_WALL_TYPE_WEST) then
if (not NearbyElevatorExists(x - distToNeighbor, y)) then
call ChangeElevatorWallBlocker(x - distToBlocker, y, 0, open)
endif
endif
endfunction
[/jass]
看一下就知道了 |
|