- Joined
- Nov 30, 2007
- Messages
- 1,202
method searchForNearbyFortNodes is the one that isn't working. It never finds the saved unit for some reason. I attached the debug log where you can see that there is in fact two corresponding coordinates, saved and loaded but still no unit... :/
JASS:
library Fortification initializer Init uses UnitIndexer, UnderConstruction
globals
private constant integer E = 0
private constant integer N = 1
private constant integer W = 2
private constant integer S = 3
private constant integer ALL_CLOSED = 0
private constant integer ALL_OPEN = 15
private constant integer E_OPEN = 1
private constant integer N_OPEN = 2
private constant integer W_OPEN = 4
private constant integer S_OPEN = 8
private constant integer D4X4 = 0
private constant integer D6X6 = 16
private constant integer HEIGHT_0 = 0
private constant integer HEIGHT_1 = 32
private constant integer HEIGHT_2 = 64
private constant integer VARIATION_0 = 0
private constant integer VARIATION_1 = 128
private constant integer VARIATION_2 = 256
private hashtable hash = InitHashtable()
Wall array wall
endglobals
struct Pathing
real x
real y
boolean array open[4]
boolean array canOpen[4]
integer data = 0
integer width
integer height
static integer array id
static real array facing
endstruct
module ConnectionHandler
integer width
unit u
real x
real y
private hashtable hash_fort = InitHashtable()
private static real array gridX
private static real array gridY
method saveAsFortification takes nothing returns nothing
call BJDebugMsg("Saved: " + GetUnitName(this.u) + "(" + R2S(this.x) + "," + R2S(this.y))
call SaveUnitHandle(hash_fort, R2I(this.x), R2I(this.y), this.u)
endmethod
method searchForNearbyFortNodes takes nothing returns nothing
local unit u
local integer i = 0
local integer max = 12
local integer search
if .width == D6X6 then
set i = 4
set max = 16
endif
loop
call BJDebugMsg("Search Q: " + R2S(this.x + thistype.gridX[i]) + "," + R2S(this.y + thistype.gridY[i]))
set u = LoadUnitHandle(hash_fort, R2I(this.x + thistype.gridX[i]), R2I(this.y + thistype.gridY[i]))
// THIS PART: u always null even though the coordinates all seem to correspond, makes no sense.
call BJDebugMsg("UNIT: " + GetUnitName(u))
if not (u == null) then
call BJDebugMsg("FOUUUUND!!!")
call GroupAddUnit(bj_lastCreatedGroup, u)
endif
set i = i + 1
exitwhen i == max
endloop
endmethod
private static method onInit takes nothing returns nothing
set thistype.gridX[N] = 0.
set thistype.gridY[N] = 128.
set thistype.gridX[S] = 0.
set thistype.gridY[S] = -128.
set thistype.gridX[E] = 128
set thistype.gridY[E] = 0
set thistype.gridX[W] = -128
set thistype.gridY[W] = 0
set thistype.gridX[N + 4] = 32
set thistype.gridY[N + 4] = 160
set thistype.gridX[S + 4] = -32
set thistype.gridY[S + 4] = -160
set thistype.gridX[E + 4] = 160
set thistype.gridY[E + 4] = -32
set thistype.gridX[W + 4] = -160
set thistype.gridY[W + 4] = 32
set thistype.gridX[N + 8] = -32
set thistype.gridY[N + 8] = 160
set thistype.gridX[S + 8] = 32
set thistype.gridY[S + 8] = -160
set thistype.gridX[E + 8] = 160
set thistype.gridY[E + 8] = 32
set thistype.gridX[W + 8] = -160
set thistype.gridY[W + 8] = -32
set thistype.gridX[N + 12] = 0.
set thistype.gridY[N + 12] = 192.
set thistype.gridX[S + 12] = 0.
set thistype.gridY[S + 12] = -192.
set thistype.gridX[E + 12] = 192
set thistype.gridY[E + 12] = 0
set thistype.gridX[W + 12] = -192
set thistype.gridY[W + 12] = 0
endmethod
endmodule
struct Wall
static constant integer INDETIFIER_ABILITY = 'A00B'
static constant integer ID_BUILD = 'n001'
static constant integer ID_BOX = 'n009'
static constant integer ID_DEAD_END_0 = 'n00A'
static constant integer ID_DEAD_END_90 = 'n00B'
static constant integer ID_DEAD_END_180 = 'n00C'
static constant integer ID_DEAD_END_270 = 'n00D'
static constant integer ID_PASS_0 = 'n00E'
static constant integer ID_PASS_90 = 'n00F'
static constant integer ID_LTURN_0 = 'n00G'
static constant integer ID_LTURN_90 = 'n00H'
static constant integer ID_LTURN_180 = 'n00I'
static constant integer ID_LTURN_270 = 'n00J'
static constant integer ID_TCROSS_0 = 'n00K'
static constant integer ID_TCROSS_90 = 'n00L'
static constant integer ID_TCROSS_180 = 'n00M'
static constant integer ID_TCROSS_270 = 'n00N'
static constant integer ID_CROSS_ROAD = 'N00O'
implement ConnectionHandler
Pathing path
static method filter takes unit u returns boolean
return GetUnitAbilityLevel(u, thistype.INDETIFIER_ABILITY) > 0
endmethod
private static method onConstructionFinish takes nothing returns nothing
local unit u
local integer i = GetUnitUserData(lastConstructedUnit)
call BJDebugMsg(I2S(i))
// Creates instance
set wall[i] = .allocate()
set wall[i].width = D4X4
set wall[i].x = GetUnitX(lastConstructedUnit)
set wall[i].y = GetUnitY(lastConstructedUnit)
// Connecions
call wall[i].searchForNearbyFortNodes()
loop
set u = FirstOfGroup(bj_lastCreatedGroup)
exitwhen u == null
call GroupRemoveUnit(bj_lastCreatedGroup, u)
call BJDebugMsg("Found One!")
endloop
set wall[i].u = ReplaceIndexedUnit(lastConstructedUnit, ID_BOX, wall[i].x, wall[i].y, 0)
call BJDebugMsg("Replaced :" + GetUnitName(wall[i].u))
call wall[i].saveAsFortification()
call BJDebugMsg("Done.")
//set u = null //set u = ReplaceIndexedUnit(u, ID_BOX, GetUnitX(u), GetUnitY(u), GetUnitFacing(u))
endmethod
static method init takes nothing returns nothing
local trigger t = CreateTrigger()
call TrgRegisterGenericConstructionFinish(t, thistype.ID_BUILD)
call TriggerAddAction(t, function thistype.onConstructionFinish)
set t = null
endmethod
endstruct
private function Init takes nothing returns nothing
call Wall.init()
endfunction
endlibrary
Last edited: