- Joined
- Mar 24, 2013
- Messages
- 1,105
JASS:
function Filter_Condition takes nothing returns boolean
return (IsUnitType(GetFilterUnit(), UNIT_TYPE_STRUCTURE) == true)
endfunction
function Detection takes player pl, real x1, real y1 returns nothing
local group g
local unit u
local unit u2
local integer i = 0 // spots to check
local integer i2 = 0 // spots around the spot to check
local integer i3 = 0 // counter of buildings that surround a spot
local real offset
local real offset2
local boolean b = false
loop
exitwhen b == true or i == 5
set i = i+1
set i3 = 0
if i == 5 then
//
else
if i == 1 then
set x1 = x1 + 0.
set y1 = y1 + 128.
elseif i == 2 then
set x1 = x1 + 128.
set y1 = y1 - 128.
elseif i == 3 then
set x1 = x1 - 128.
set y1 = y1 - 128.
elseif i == 4 then
set x1 = x1 - 128.
set y1 = y1 + 128.
endif
loop
exitwhen i2 == 4
set g = CreateGroup()
set i2 = i2 + 1
if i2 == 5 then
//
else
if i2 == 1 then
set offset = 0.
set offset2 = 128.
elseif i2 == 2 then
set offset = 128.
set offset2 = 0.
elseif i2 == 3 then
set offset = 0.
set offset2 = -128.
elseif i2 == 4 then
set offset = -128.
set offset2 = 0.
endif
endif
call GroupEnumUnitsInRange(g, x1+offset, y1+offset2, 10., Condition(function Filter_Condition))
set u = FirstOfGroup(g)
if u == null then
else
set i3 = i3 + 1
if i3 == 4 then
set b = true
else
endif
endif
call DestroyGroup(g)
endloop
endif
endloop
if b == true then
set u2 = CreateUnit(Player(pl, 'h002', x1, y1, 270)
// do more
else
endif
set g = null
set u = null
set u2 = null
endfunction
Basically the purpose of this is to see when an empty spot on a grid has been blocked on its 4 sides. If it has then do something otherwise not.
My problem is that currently the only time it seems to properly work is when the last side that is covered is the spot underneath the empty spot.
To better explain view:
[] [1] []
[2] _ [3]
[] [x] []
When the last spot that gets occupied is x, the code gives the intended result, however when its 1,2, or 3 that is the last to block all sides, it does not produce the intended result.
I'm assuming something is wrong with my 2nd loop but I can't seem to figure it out.
Thanks for any assistance.
Last edited: