- Joined
- Nov 30, 2007
- Messages
- 1,202
The black area is the ground pathing, in this case a 8x8 grid. The red regions are the enter of the regions adjacent to the black area. I want to search the blue areas for buildings, how do I go about that?
So, how do I confiure a rect to the size of 8x2 only knowing the center of either the black or red rect?
The purpose is to search for buildings that are right next to it.
So I would move the rect around using this i think...
... And for searching for buildings and trees nearby hmmm..
I got this far, but when I tried to change the rect it prevented the loop from happening again. What I was trying to achieve was to random out location (check) and move it there.
All Units get created at 0,0... No idea whats wrong.
So, how do I confiure a rect to the size of 8x2 only knowing the center of either the black or red rect?
The purpose is to search for buildings that are right next to it.
So I would move the rect around using this i think...
JASS:
call SetRect(r, 0, 0, dimension*64,128)
call MoveRectTo(r, x[i], y[i])
... And for searching for buildings and trees nearby hmmm..
I got this far, but when I tried to change the rect it prevented the loop from happening again. What I was trying to achieve was to random out location (check) and move it there.
All Units get created at 0,0... No idea whats wrong.
JASS:
library FireSpreadSystem initializer Init
globals
private constant integer FIRE_LIMIT = 10
private hashtable hash = InitHashtable()
private rect area = null
private group g = CreateGroup()
endglobals
private function Kill takes nothing returns nothing
call KillUnit(GetEnumUnit())
endfunction
private function Main takes nothing returns nothing
local unit u = GetTriggerUnit()
local boolean array vert
local real array x
local real array y
local integer i
local integer j
local integer k
local integer curMax = 4
local integer nGrid = LoadInteger(hash, GetUnitTypeId(u), 0)
if nGrid != 0 then
set k = (nGrid/4 + 1)*64
set x[0] = GetUnitX(u)
set y[0] = GetUnitY(u)
set vert[1] = false
set vert[2] = false
set vert[3] = true
set vert[4] = true
set x[1] = x[0] - k
set y[1] = y[0]
set x[2] = x[0] + k
set y[2] = y[0]
set x[3] = x[0]
set y[3] = y[0] - k
set x[4] = x[0]
set y[4] = y[0] + k
loop
exitwhen curMax < 1
set i = GetRandomInt(1, curMax)
//set u = CreateUnit(Player(0), 'hpea', x[i], y[i], 0)
if vert[i] == true then
set area = Rect(x[i], y[i], x[i] + nGrid*64, y[i] + 64*3)
call BJDebugMsg("Vertical")
else
set area = Rect(x[i], y[i], x[i] + 64*3, y[i] + nGrid*64)
call BJDebugMsg("Horizontal")
endif
call GroupEnumUnitsInRect(g, area, null)
loop
set u = FirstOfGroup(g)
exitwhen u == null
call GroupRemoveUnit(g, u)
call KillUnit(u)
endloop
call TriggerSleepAction(0.8) // debug
set vert[i] = vert[curMax]
set x[i] = x[curMax]
set y[i] = y[curMax]
set curMax = curMax - 1
endloop
endif
endfunction
private function Init takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterPlayerUnitEvent(t, Player(0), EVENT_PLAYER_UNIT_SELECTED, null)
call TriggerAddAction(t, function Main)
call SaveInteger(hash, 'hhou', 0, 4) // 4x4 Pathing Size
call SaveInteger(hash, 'halt', 0, 6)
call SaveInteger(hash, 'hbla', 0, 8)
call SaveInteger(hash, 'hlum', 0, 10)
call SaveInteger(hash, 'htow', 0, 12)
endfunction
endlibrary
Attachments
Last edited: