- Joined
- Aug 26, 2016
- Messages
- 139
Hello, I have a system Dungeon Generator & Stamp, I'm trying to figure out how to configure it and I'm faced with the problem of clearing stamp memory, variables are not reset.It’s strange that when updating, some of the stamps are saved and some are reset.
JASS:
library DungeonStamp uses Ascii
stamp.register
globals
//=========================================
//configurables
private constant integer TERRAIN_DEFAULT_TILE = 'Ddrt' //defines the default ground tile for the dungeon
private constant integer TERRAIN_DEFAULT_VARIANCE = 17 //defines the variation used for the default tile (use -1 for random)
private constant integer STAMP_SIZE = 5 //defines the edge size of each stamp; must be an odd number
private constant integer STAMP_SIZE_SQUARED = 25 //please calculate STAMP_SIZE*STAMP_SIZE and enter the value here
//limit:
// -> n * STAMP_SIZE_SQUARED < 8192
// -> for n = number of registered stamps
// -> print registry methods only supported for stamp size of 5
// -> for other sizes use rect registry method instead
private constant integer MAX_DESTRUCTABLES_PER_STAMP = 25 //defines the maximum number of destructables per stamp
//limit:
// -> n * MAX_DESTRUCTABLES_PER_STAMP < 8192
// -> for n = number of registered stamps
// -> print registry methods only supported for MAX_DESTRUCTABLES_PER_STAMP = 25
// -> for other values use rect registry method instead
constant string DUNGEON_PRINT_DIRECTORY = ".\\save\\" //This is the directory where all generated text files from the print commands will be saved.
//=========================================
//=========================================
constant integer STAMP_SIZE_REAL = STAMP_SIZE*128
constant integer ORIENTATION_0 = 0
constant integer ORIENTATION_90 = 200
constant integer ORIENTATION_180 = 400
constant integer ORIENTATION_270 = 600
private constant hashtable HASH = InitHashtable()
private constant integer CAVE_OFFSET = 20
private constant integer STAIR_UP_OFFSET = 40
private constant integer STAIR_DOWN_OFFSET = 80
/*
These are the stamp shapes for the dungeon type
*/
constant integer SHAPE_BLACK = 0
constant integer SHAPE_HALL = 1 // Default Orientation:
constant integer SHAPE_WALL_L = 2 // I = 0° (left wall)
constant integer SHAPE_WALL_L_B = 3 // I_ = 0° (left wall and bottom wall)
constant integer SHAPE_WALL_L_B_R = 4 // I_I = 0° (left wall, bottom wall and right wall (dead end))
constant integer SHAPE_WALL_BL = 5 // . = 0° (wall in bottom left corner)
constant integer SHAPE_WALL_BL_TL = 6 // : = 0° (wall in bottom left and top left corner)
constant integer SHAPE_WALL_BL_TR = 7 // . ' = 0° (wall in bottom left and top right corner)
constant integer SHAPE_WALL_BL_TL_BR = 8 // : . = 0° (wall in bottom left, top left and bottom right corner)
constant integer SHAPE_WALL_BL_TL_BR_TP = 9 // : : = 0° (wall in all corners, plus-shaped corridor)
constant integer SHAPE_WALL_L_BR = 10 // I . = 0° (left wall and bottom right corner)
constant integer SHAPE_WALL_L_TR = 11 // I ' = 0° (left wall and top right corner)
constant integer SHAPE_WALL_L_R = 12 // I I = 0° (left wall and right wall)
constant integer SHAPE_WALL_L_B_TR = 13 // I_' = 0° (left wall, bottom wall, top-right corner)
constant integer SHAPE_WALL_L_BR_TR = 14 // I : = 0° (left wall, bottom-right corner and top-right corner)
constant integer SHAPE_STAIRS_UP_WALL = SHAPE_WALL_L + STAIR_UP_OFFSET
// I> = 0° (Stairs in western wall, poiting east)
constant integer SHAPE_STAIRS_UP_HALL = SHAPE_HALL + STAIR_UP_OFFSET
// > = 0° (Stairs inside room, pointing east)
constant integer SHAPE_STAIRS_UP_END = SHAPE_WALL_L_B_R + STAIR_UP_OFFSET
// I^I = 0° (Stairs at dead end, pointing north)
constant integer SHAPE_STAIRS_DOWN_WALL = SHAPE_WALL_L + STAIR_DOWN_OFFSET
// I> = 0° (Stairs in western wall, poiting east)
constant integer SHAPE_STAIRS_DOWN_HALL = SHAPE_HALL + STAIR_DOWN_OFFSET
// > = 0° (Stairs inside room, pointing east)
constant integer SHAPE_STAIRS_DOWN_END = SHAPE_WALL_L_B_R + STAIR_DOWN_OFFSET
// I^I = 0° (Stairs at dead end, pointing north)
/*
These are the stamp shapes for the cavern type
*/
constant integer SHAPE_CAVE_HALL = 1+CAVE_OFFSET // Default Orientation:
constant integer SHAPE_CAVE_WALL_L = 2+CAVE_OFFSET // I = 0° (left wall)
constant integer SHAPE_CAVE_WALL_L_B = 3+CAVE_OFFSET // I_ = 0° (left wall and bottom wall)
constant integer SHAPE_CAVE_WALL_L_B_R = 4+CAVE_OFFSET // I_I = 0° (left wall, bottom wall and right wall (dead end))
constant integer SHAPE_CAVE_WALL_BL = 5+CAVE_OFFSET // . = 0° (wall in bottom left corner)
constant integer SHAPE_CAVE_WALL_BL_TL = 6+CAVE_OFFSET // : = 0° (wall in bottom left and top left corner)
constant integer SHAPE_CAVE_WALL_BL_TR = 7+CAVE_OFFSET // . ' = 0° (wall in bottom left and top right corner)
constant integer SHAPE_CAVE_WALL_BL_TL_BR = 8+CAVE_OFFSET // : . = 0° (wall in bottom left, top left and bottom right corner)
constant integer SHAPE_CAVE_WALL_BL_TL_BR_TP = 9+CAVE_OFFSET // : : = 0° (wall in all corners, plus-shaped corridor)
constant integer SHAPE_CAVE_WALL_L_BR = 10+CAVE_OFFSET // I . = 0° (left wall and bottom right corner)
constant integer SHAPE_CAVE_WALL_L_TR = 11+CAVE_OFFSET // I ' = 0° (left wall and top right corner)
constant integer SHAPE_CAVE_WALL_L_R = 12+CAVE_OFFSET // I I = 0° (left wall and right wall)
constant integer SHAPE_CAVE_WALL_L_B_TR = 13+CAVE_OFFSET // I_' = 0° (left wall, bottom wall, top-right corner)
constant integer SHAPE_CAVE_WALL_L_BR_TR = 14+CAVE_OFFSET // I : = 0° (left wall, bottom-right corner and top-right corner)
constant integer SHAPE_CAVE_STAIRS_UP_WALL = SHAPE_WALL_L + STAIR_UP_OFFSET + CAVE_OFFSET
// I> = 0° (Stairs in western wall, poiting east)
constant integer SHAPE_CAVE_STAIRS_UP_HALL = SHAPE_HALL + STAIR_UP_OFFSET + CAVE_OFFSET
// > = 0° (Stairs inside room, pointing east)
constant integer SHAPE_CAVE_STAIRS_UP_END = SHAPE_WALL_L_B_R + STAIR_UP_OFFSET + CAVE_OFFSET
// I^I = 0° (Stairs at dead end, pointing north)
constant integer SHAPE_CAVE_STAIRS_DOWN_WALL = SHAPE_WALL_L + STAIR_DOWN_OFFSET + CAVE_OFFSET
// I> = 0° (Stairs in western wall, poiting east)
constant integer SHAPE_CAVE_STAIRS_DOWN_HALL = SHAPE_HALL + STAIR_DOWN_OFFSET + CAVE_OFFSET
// > = 0° (Stairs inside room, pointing east)
constant integer SHAPE_CAVE_STAIRS_DOWN_END = SHAPE_WALL_L_B_R + STAIR_DOWN_OFFSET + CAVE_OFFSET
// I^I = 0° (Stairs at dead end, pointing north)
endglobals
struct stamp
private integer shape
private integer number
private integer tile
private real rare
integer data
real value
integer array destraw[MAX_DESTRUCTABLES_PER_STAMP]
real array destx[MAX_DESTRUCTABLES_PER_STAMP]
real array desty[MAX_DESTRUCTABLES_PER_STAMP]
real array destrot[MAX_DESTRUCTABLES_PER_STAMP]
integer array terrain[STAMP_SIZE_SQUARED]
integer array variation[STAMP_SIZE_SQUARED]
private static thistype temp
private static integer tempindex = 0
private static real tempx = 0
private static real tempy = 0
static method create takes integer shp, integer tileset, real rarity, integer customdata, real customvalue returns thistype
local thistype this = thistype.allocate()
set this.shape = shp
set this.tile = tileset
set this.rare = rarity
set this.data = customdata
set this.value = customvalue
set this.number = LoadInteger(HASH, this.shape, 0) + 1
call SaveInteger(HASH, this.shape, 0, this.number)
call SaveInteger(HASH, this.shape, this.number, this)
return this
endmethod
static method setDestructableData takes integer raw, real scale, real z, boolean dead returns nothing
call SaveReal(HASH, raw, 0, scale)
call SaveReal(HASH, raw, 1, z)
call SaveBoolean(HASH, raw, 2, dead)
endmethod
static method getDestructableScale takes integer raw returns real
if HaveSavedReal(HASH, raw, 0) then
return LoadReal(HASH, raw, 0)
endif
return 1.
endmethod
static method getDestructableZ takes integer raw returns real
if HaveSavedReal(HASH, raw, 1) then
return LoadReal(HASH, raw, 1)
endif
return 0.
endmethod
static method getDestructableAlive takes integer raw returns boolean
if HaveSavedBoolean(HASH, raw, 2) then
return LoadBoolean(HASH, raw, 2)
endif
return true
endmethod
method canHaveStairs takes nothing returns boolean
local integer shp = ModuloInteger(this.shape, CAVE_OFFSET)
return (shp == SHAPE_WALL_L or shp == SHAPE_WALL_L_B_R or shp == SHAPE_HALL)
endmethod
static method removeSub takes nothing returns nothing
call RemoveDestructable(GetEnumDestructable())
endmethod
static method remove takes rect area, integer gridX, integer gridY returns nothing
local integer i = 0
local integer j
local real x = GetRectMinX(area)+gridX*STAMP_SIZE_REAL
local real y = GetRectMinY(area)+gridY*STAMP_SIZE_REAL
local rect r = Rect(x-16, y-16, x+16+STAMP_SIZE_REAL, y+16+STAMP_SIZE_REAL)
loop
exitwhen i >= STAMP_SIZE
set j = 0
loop
exitwhen j >= STAMP_SIZE
set x = GetRectMinX(area)+gridX*STAMP_SIZE_REAL+i*128
set y = GetRectMinY(area)+gridY*STAMP_SIZE_REAL+j*128
if x <= GetRectMaxX(area) and y <= GetRectMaxY(area) then
call SetTerrainType(x, y, TERRAIN_DEFAULT_TILE, TERRAIN_DEFAULT_VARIANCE, 1, 1)
endif
set j = j + 1
endloop
set i = i + 1
endloop
if GetRectMaxX(r) <= GetRectMaxX(area) and GetRectMaxY(r) <= GetRectMaxY(area) then
call EnumDestructablesInRect(r, null, function thistype.removeSub)
else
call SetRect(r, GetRectMinX(r), GetRectMinY(r), GetRectMaxX(area), GetRectMaxY(area))
call EnumDestructablesInRect(r, null, function thistype.removeSub)
endif
call RemoveRect(r)
set r = null
endmethod
method place takes rect area, integer gridX, integer gridY, integer orientation returns nothing
local integer i = 0
local integer j
local location loc = Location(0,0)
local real x
local real y
local integer u
local integer v
call thistype.remove(area, gridX, gridY) //remove existing stamps
//paint ground tiles
if GetRectMinX(area)+gridX*STAMP_SIZE_REAL <= GetRectMaxX(area) and GetRectMinY(area)+gridY*STAMP_SIZE_REAL <= GetRectMaxY(area) then
loop
exitwhen i >= STAMP_SIZE
set j = 0
loop
exitwhen j >= STAMP_SIZE
set x = GetRectMinX(area)+gridX*STAMP_SIZE_REAL+i*128
set y = GetRectMinY(area)+gridY*STAMP_SIZE_REAL+j*128
if orientation == ORIENTATION_0 then
set u = i
set v = j
elseif orientation == ORIENTATION_90 then
set u = j
set v = STAMP_SIZE-1-i
elseif orientation == ORIENTATION_180 then
set u = STAMP_SIZE-1-i
set v = STAMP_SIZE-1-j
else
set u = STAMP_SIZE-1-j
set v = i
endif
call SetTerrainType(x, y, this.terrain[u*STAMP_SIZE+v], this.variation[u*STAMP_SIZE+v], 1, 1)
if i == (STAMP_SIZE-1) then
if this.terrain[u*STAMP_SIZE+v] != TERRAIN_DEFAULT_TILE and GetTerrainType(x+128, y) == TERRAIN_DEFAULT_TILE then
call SetTerrainType(x+128, y, this.terrain[u*STAMP_SIZE+v], this.variation[u*STAMP_SIZE+v], 1, 1)
endif
endif
if j == (STAMP_SIZE-1) then
if this.terrain[u*STAMP_SIZE+v] != TERRAIN_DEFAULT_TILE and GetTerrainType(x, y+128) == TERRAIN_DEFAULT_TILE then
call SetTerrainType(x, y+128, this.terrain[u*STAMP_SIZE+v], this.variation[u*STAMP_SIZE+v], 1, 1)
endif
endif
if u == (STAMP_SIZE-1) and j == (STAMP_SIZE-1) then
if this.terrain[u*STAMP_SIZE+v] != TERRAIN_DEFAULT_TILE and GetTerrainType(x+128, y+128) == TERRAIN_DEFAULT_TILE then
call SetTerrainType(x+128, y+128, this.terrain[u*STAMP_SIZE+v], this.variation[u*STAMP_SIZE+v], 1, 1)
endif
endif
set j = j + 1
endloop
set i = i + 1
endloop
//place destructables
set i = 0
loop
exitwhen i >= MAX_DESTRUCTABLES_PER_STAMP
if this.destraw[i] != 0 then
if orientation == ORIENTATION_0 then
call MoveLocation(loc, GetRectMinX(area)+gridX*STAMP_SIZE_REAL+STAMP_SIZE_REAL/2+this.destx[i], GetRectMinY(area)+gridY*STAMP_SIZE_REAL+STAMP_SIZE_REAL/2+this.desty[i])
if stamp.getDestructableAlive(this.destraw[i]) then
call CreateDestructableZ(this.destraw[i], GetLocationX(loc), GetLocationY(loc), GetLocationZ(loc)+stamp.getDestructableZ(this.destraw[i]), this.destrot[i], stamp.getDestructableScale(this.destraw[i]), 0)
else
call CreateDeadDestructableZ(this.destraw[i], GetLocationX(loc), GetLocationY(loc), GetLocationZ(loc)+stamp.getDestructableZ(this.destraw[i]), this.destrot[i], stamp.getDestructableScale(this.destraw[i]), 0)
endif
elseif orientation == ORIENTATION_90 then
call MoveLocation(loc, GetRectMinX(area)+gridX*STAMP_SIZE_REAL+STAMP_SIZE_REAL/2-this.desty[i], GetRectMinY(area)+gridY*STAMP_SIZE_REAL+STAMP_SIZE_REAL/2+this.destx[i])
if stamp.getDestructableAlive(this.destraw[i]) then
call CreateDestructableZ(this.destraw[i], GetLocationX(loc), GetLocationY(loc), GetLocationZ(loc)+stamp.getDestructableZ(this.destraw[i]), this.destrot[i]+90, stamp.getDestructableScale(this.destraw[i]), 0)
else
call CreateDeadDestructableZ(this.destraw[i], GetLocationX(loc), GetLocationY(loc), GetLocationZ(loc)+stamp.getDestructableZ(this.destraw[i]), this.destrot[i]+90, stamp.getDestructableScale(this.destraw[i]), 0)
endif
elseif orientation == ORIENTATION_180 then
call MoveLocation(loc, GetRectMinX(area)+gridX*STAMP_SIZE_REAL+STAMP_SIZE_REAL/2-this.destx[i], GetRectMinY(area)+gridY*STAMP_SIZE_REAL+STAMP_SIZE_REAL/2-this.desty[i])
if stamp.getDestructableAlive(this.destraw[i]) then
call CreateDestructableZ(this.destraw[i], GetLocationX(loc), GetLocationY(loc), GetLocationZ(loc)+stamp.getDestructableZ(this.destraw[i]), this.destrot[i]+180, stamp.getDestructableScale(this.destraw[i]), 0)
else
call CreateDeadDestructableZ(this.destraw[i], GetLocationX(loc), GetLocationY(loc), GetLocationZ(loc)+stamp.getDestructableZ(this.destraw[i]), this.destrot[i]+180, stamp.getDestructableScale(this.destraw[i]), 0)
endif
else
call MoveLocation(loc, GetRectMinX(area)+gridX*STAMP_SIZE_REAL+STAMP_SIZE_REAL/2+this.desty[i], GetRectMinY(area)+gridY*STAMP_SIZE_REAL+STAMP_SIZE_REAL/2-this.destx[i])
if stamp.getDestructableAlive(this.destraw[i]) then
call CreateDestructableZ(this.destraw[i], GetLocationX(loc), GetLocationY(loc), GetLocationZ(loc)+stamp.getDestructableZ(this.destraw[i]), this.destrot[i]+270, stamp.getDestructableScale(this.destraw[i]), 0)
else
call CreateDeadDestructableZ(this.destraw[i], GetLocationX(loc), GetLocationY(loc), GetLocationZ(loc)+stamp.getDestructableZ(this.destraw[i]), this.destrot[i]+270, stamp.getDestructableScale(this.destraw[i]), 0)
endif
endif
endif
set i = i + 1
endloop
endif
call RemoveLocation(loc)
set loc = null
endmethod
private static method getDest takes nothing returns boolean
local destructable d = GetFilterDestructable()
if thistype.tempindex < MAX_DESTRUCTABLES_PER_STAMP then
set thistype.temp.destraw[thistype.tempindex] = GetDestructableTypeId(d)
set thistype.temp.destx[thistype.tempindex] = GetDestructableX(d)-thistype.tempx
set thistype.temp.desty[thistype.tempindex] = GetDestructableY(d)-thistype.tempy
if GetDestructableLife(d) == GetDestructableMaxLife(d) then
set thistype.temp.destrot[thistype.tempindex] = 0
else
set thistype.temp.destrot[thistype.tempindex] = ModuloReal(GetDestructableLife(d)/GetDestructableMaxLife(d)*1000, 360)
endif
set thistype.tempindex = thistype.tempindex + 1
else
call BJDebugMsg("ERROR: Stamp contains too many destructables! Increase MAX_DESTRUCTABLES_PER_STAMP or reduce number of destructables!")
endif
set d = null
return false
endmethod
static method register takes rect which, integer shp, integer tileset, real rarity, integer customdata, real customvalue returns thistype
local thistype this = thistype.create(shp, tileset, rarity, customdata, customvalue)
local integer i = 0
local integer j
set thistype.temp = this
set thistype.tempindex = 0
set thistype.tempx = GetRectMinX(which)+STAMP_SIZE_REAL/2
set thistype.tempy = GetRectMinY(which)+STAMP_SIZE_REAL/2
call EnumDestructablesInRect(which, Condition(function thistype.getDest), null)
loop
exitwhen i >= STAMP_SIZE
set j = 0
loop
exitwhen j >= STAMP_SIZE
set this.terrain[i*STAMP_SIZE+j] = GetTerrainType(GetRectMinX(which)+i*128, GetRectMinY(which)+j*128)
set this.variation[i*STAMP_SIZE+j] = GetTerrainVariance(GetRectMinX(which)+i*128, GetRectMinY(which)+j*128)
set j = j + 1
endloop
set i = i + 1
endloop
return this
endmethod
static method placeByLogic takes rect area, integer x, integer y, boolean isCave, boolean isStairs, boolean isUp, integer fromTileset, boolean sw, boolean w, boolean nw, boolean s, boolean c, boolean n, boolean se, boolean e, boolean ne returns thistype
local integer wc = 0
local integer cc = 0
local thistype this
local thistype array valid
local integer validcount = 0
local integer i = 0
local integer shp = -1
local integer max = 0
local integer orient = 0
local integer stairs = 0
if isStairs then
if isUp then
set stairs = STAIR_UP_OFFSET
else
set stairs = STAIR_DOWN_OFFSET
endif
endif
if sw and not (s or w) then
set cc = cc + 1
endif
if nw and not (n or w) then
set cc = cc + 1
endif
if se and not (s or e) then
set cc = cc + 1
endif
if ne and not (n or e) then
set cc = cc + 1
endif
if w then
set wc = wc + 1
endif
if s then
set wc = wc + 1
endif
if n then
set wc = wc + 1
endif
if e then
set wc = wc + 1
endif
if c then
set shp = SHAPE_BLACK + ORIENTATION_0
else
if wc == 0 then
if cc == 0 then
set shp = SHAPE_HALL + GetRandomInt(0,3)*ORIENTATION_90 + stairs
elseif cc == 1 then
if sw then
set shp = SHAPE_WALL_BL + ORIENTATION_0
elseif se then
set shp = SHAPE_WALL_BL + ORIENTATION_90
elseif ne then
set shp = SHAPE_WALL_BL + ORIENTATION_180
elseif nw then
set shp = SHAPE_WALL_BL + ORIENTATION_270
endif
elseif cc == 2 then
if sw and nw then
set shp = SHAPE_WALL_BL_TL + ORIENTATION_0
elseif sw and se then
set shp = SHAPE_WALL_BL_TL + ORIENTATION_90
elseif se and ne then
set shp = SHAPE_WALL_BL_TL + ORIENTATION_180
elseif ne and nw then
set shp = SHAPE_WALL_BL_TL + ORIENTATION_270
elseif sw and ne then
set shp = SHAPE_WALL_BL_TR + (GetRandomInt(0,1)*2)*ORIENTATION_90
elseif se and nw then
set shp = SHAPE_WALL_BL_TR + (GetRandomInt(0,1)*2+1)*ORIENTATION_90
endif
elseif cc == 3 then
if not ne then
set shp = SHAPE_WALL_BL_TL_BR + ORIENTATION_0
elseif not nw then
set shp = SHAPE_WALL_BL_TL_BR + ORIENTATION_90
elseif not sw then
set shp = SHAPE_WALL_BL_TL_BR + ORIENTATION_180
elseif not se then
set shp = SHAPE_WALL_BL_TL_BR + ORIENTATION_270
endif
elseif cc == 4 then
set shp = SHAPE_WALL_BL_TL_BR_TP + GetRandomInt(0,3)*ORIENTATION_90
endif
elseif wc == 1 then
if cc == 0 then
if w then
set shp = SHAPE_WALL_L + ORIENTATION_0 + stairs
elseif s then
set shp = SHAPE_WALL_L + ORIENTATION_90 + stairs
elseif e then
set shp = SHAPE_WALL_L + ORIENTATION_180 + stairs
elseif n then
set shp = SHAPE_WALL_L + ORIENTATION_270 + stairs
endif
elseif cc == 1 then
if w then
if se then
set shp = SHAPE_WALL_L_BR + ORIENTATION_0
elseif ne then
set shp = SHAPE_WALL_L_TR + ORIENTATION_0
endif
elseif s then
if ne then
set shp = SHAPE_WALL_L_BR + ORIENTATION_90
elseif nw then
set shp = SHAPE_WALL_L_TR + ORIENTATION_90
endif
elseif e then
if nw then
set shp = SHAPE_WALL_L_BR + ORIENTATION_180
elseif sw then
set shp = SHAPE_WALL_L_TR + ORIENTATION_180
endif
elseif n then
if sw then
set shp = SHAPE_WALL_L_BR + ORIENTATION_270
elseif se then
set shp = SHAPE_WALL_L_TR + ORIENTATION_270
endif
endif
elseif cc == 2 then
if w then
set shp = SHAPE_WALL_L_BR_TR + ORIENTATION_0
elseif s then
set shp = SHAPE_WALL_L_BR_TR + ORIENTATION_90
elseif e then
set shp = SHAPE_WALL_L_BR_TR + ORIENTATION_180
elseif n then
set shp = SHAPE_WALL_L_BR_TR + ORIENTATION_270
endif
endif
elseif wc == 2 then
if cc == 0 then
if w and s then
set shp = SHAPE_WALL_L_B + ORIENTATION_0
elseif s and e then
set shp = SHAPE_WALL_L_B + ORIENTATION_90
elseif e and n then
set shp = SHAPE_WALL_L_B + ORIENTATION_180
elseif n and w then
set shp = SHAPE_WALL_L_B + ORIENTATION_270
elseif w and e then
set shp = SHAPE_WALL_L_R + (GetRandomInt(0,1)*2)*ORIENTATION_90
elseif n and s then
set shp = SHAPE_WALL_L_R + (GetRandomInt(0,1)*2+1)*ORIENTATION_90
endif
elseif cc == 1 then
if w and s then
set shp = SHAPE_WALL_L_B_TR + ORIENTATION_0
elseif s and e then
set shp = SHAPE_WALL_L_B_TR + ORIENTATION_90
elseif e and n then
set shp = SHAPE_WALL_L_B_TR + ORIENTATION_180
elseif n and w then
set shp = SHAPE_WALL_L_B_TR + ORIENTATION_270
endif
endif
elseif wc == 3 then
if not n then
set shp = SHAPE_WALL_L_B_R + ORIENTATION_0 + stairs
elseif not w then
set shp = SHAPE_WALL_L_B_R + ORIENTATION_90 + stairs
elseif not s then
set shp = SHAPE_WALL_L_B_R + ORIENTATION_180 + stairs
elseif not e then
set shp = SHAPE_WALL_L_B_R + ORIENTATION_270 + stairs
endif
elseif wc == 4 then
set shp = SHAPE_BLACK + ORIENTATION_0
endif
endif
if shp == -1 then
call BJDebugMsg("ERROR: no shape found by wall logic!")
return 0
else
if isCave then
set shp = shp + CAVE_OFFSET
endif
set max = shp
set shp = ModuloInteger(shp,ORIENTATION_90)
set orient = max-shp
endif
set max = LoadInteger(HASH, shp, 0)
set i = 1
loop
exitwhen i > max
set this = LoadInteger(HASH, shp, i)
if this.tile == fromTileset then
if validcount <= 0 then
set valid[validcount] = this
set validcount = validcount+1
elseif GetRandomReal(0,1) <= this.rare then
set valid[validcount] = this
set validcount = validcount+1
endif
endif
set i = i + 1
endloop
if validcount <= 0 then
if HaveSavedInteger(HASH, shp, 1) then
set valid[0] = LoadInteger(HASH, shp, 1)
set validcount = 1
else
call BJDebugMsg("ERROR: No registered stamp found. Please register stamps for this tileset before calling the build algorithm!")
return 0
endif
endif
set this = valid[GetRandomInt(0,validcount-1)]
call this.place(area,x,y,orient)
return this
endmethod
method print takes nothing returns nothing
local integer i = 0
local string terraindump = ""
local string variationdump = ""
local string destrawdump = ""
local string xdump = ""
local string ydump = ""
local string facedump = ""
if MAX_DESTRUCTABLES_PER_STAMP == 25 and STAMP_SIZE_SQUARED == 25 then
loop
exitwhen i >= 25
if i > 0 then
set terraindump = terraindump + ",'" + A2S(this.terrain[i]) + "'"
set variationdump = variationdump + "," + I2S(this.variation[i])
if this.destraw[i] != 0 then
set destrawdump = destrawdump + ",'" + A2S(this.destraw[i]) + "'"
else
set destrawdump = destrawdump + ",0"
endif
set xdump = xdump + "," + I2S(R2I(this.destx[i]))
set ydump = ydump + "," + I2S(R2I(this.desty[i]))
set facedump = facedump + "," + I2S(R2I(this.destrot[i]))
else
set terraindump = "'" + A2S(this.terrain[i]) + "'"
set variationdump = I2S(this.variation[i])
if this.destraw[i] != 0 then
set destrawdump = "'" + A2S(this.destraw[i]) + "'"
else
set destrawdump = "0"
endif
set xdump = I2S(R2I(this.destx[i]))
set ydump = I2S(R2I(this.desty[i]))
set facedump = I2S(R2I(this.destrot[i]))
endif
set i = i + 1
endloop
call PreloadGenClear()
call PreloadGenStart()
call Preload("\")\n\n call data.registerTerrain("+terraindump+") \n\n//")
call Preload("\")\n\n call data.registerVariation("+variationdump+") \n\n//")
call Preload("\")\n\n call data.registerDestructable("+destrawdump+") \n\n//")
call Preload("\")\n\n call data.registerDestX("+xdump+") \n\n//")
call Preload("\")\n\n call data.registerDestY("+ydump+") \n\n//")
call Preload("\")\n\n call data.registerDestFace("+facedump+") \n\n//")
call Preload("\")\n\n \n\n//")
call PreloadGenEnd(DUNGEON_PRINT_DIRECTORY+"stamp(shape"+I2S(this.shape)+").txt")
else
call BJDebugMsg("ERROR: Text-based stamp registry only supported for default values of stamp size (5x5) and destructables per stamp (25)!")
endif
endmethod
//==========================================================================
//The following methods are wrappers designed for use with the .print method
//==========================================================================
method registerTerrain takes integer t00, integer t01, integer t02, integer t03, integer t04, integer t10, integer t11, integer t12, integer t13, integer t14, integer t20, integer t21, integer t22, integer t23, integer t24, integer t30, integer t31, integer t32, integer t33, integer t34, integer t40, integer t41, integer t42, integer t43, integer t44 returns nothing
if STAMP_SIZE_SQUARED == 25 then
set this.terrain[0] = t00
set this.terrain[1] = t01
set this.terrain[2] = t02
set this.terrain[3] = t03
set this.terrain[4] = t04
set this.terrain[5] = t10
set this.terrain[6] = t11
set this.terrain[7] = t12
set this.terrain[8] = t13
set this.terrain[9] = t14
set this.terrain[10] = t20
set this.terrain[11] = t21
set this.terrain[12] = t22
set this.terrain[13] = t23
set this.terrain[14] = t24
set this.terrain[15] = t30
set this.terrain[16] = t31
set this.terrain[17] = t32
set this.terrain[18] = t33
set this.terrain[19] = t34
set this.terrain[20] = t40
set this.terrain[21] = t41
set this.terrain[22] = t42
set this.terrain[23] = t43
set this.terrain[24] = t44
endif
endmethod
method registerVariation takes integer t00, integer t01, integer t02, integer t03, integer t04, integer t10, integer t11, integer t12, integer t13, integer t14, integer t20, integer t21, integer t22, integer t23, integer t24, integer t30, integer t31, integer t32, integer t33, integer t34, integer t40, integer t41, integer t42, integer t43, integer t44 returns nothing
if STAMP_SIZE_SQUARED == 25 then
set this.variation[0] = t00
set this.variation[1] = t01
set this.variation[2] = t02
set this.variation[3] = t03
set this.variation[4] = t04
set this.variation[5] = t10
set this.variation[6] = t11
set this.variation[7] = t12
set this.variation[8] = t13
set this.variation[9] = t14
set this.variation[10] = t20
set this.variation[11] = t21
set this.variation[12] = t22
set this.variation[13] = t23
set this.variation[14] = t24
set this.variation[15] = t30
set this.variation[16] = t31
set this.variation[17] = t32
set this.variation[18] = t33
set this.variation[19] = t34
set this.variation[20] = t40
set this.variation[21] = t41
set this.variation[22] = t42
set this.variation[23] = t43
set this.variation[24] = t44
endif
endmethod
method registerDestructable takes integer t00, integer t01, integer t02, integer t03, integer t04, integer t10, integer t11, integer t12, integer t13, integer t14, integer t20, integer t21, integer t22, integer t23, integer t24, integer t30, integer t31, integer t32, integer t33, integer t34, integer t40, integer t41, integer t42, integer t43, integer t44 returns nothing
if MAX_DESTRUCTABLES_PER_STAMP == 25 then
set this.destraw[0] = t00
set this.destraw[1] = t01
set this.destraw[2] = t02
set this.destraw[3] = t03
set this.destraw[4] = t04
set this.destraw[5] = t10
set this.destraw[6] = t11
set this.destraw[7] = t12
set this.destraw[8] = t13
set this.destraw[9] = t14
set this.destraw[10] = t20
set this.destraw[11] = t21
set this.destraw[12] = t22
set this.destraw[13] = t23
set this.destraw[14] = t24
set this.destraw[15] = t30
set this.destraw[16] = t31
set this.destraw[17] = t32
set this.destraw[18] = t33
set this.destraw[19] = t34
set this.destraw[20] = t40
set this.destraw[21] = t41
set this.destraw[22] = t42
set this.destraw[23] = t43
set this.destraw[24] = t44
endif
endmethod
method registerDestX takes real t00, real t01, real t02, real t03, real t04, real t10, real t11, real t12, real t13, real t14, real t20, real t21, real t22, real t23, real t24, real t30, real t31, real t32, real t33, real t34, real t40, real t41, real t42, real t43, real t44 returns nothing
if MAX_DESTRUCTABLES_PER_STAMP == 25 then
set this.destx[0] = t00
set this.destx[1] = t01
set this.destx[2] = t02
set this.destx[3] = t03
set this.destx[4] = t04
set this.destx[5] = t10
set this.destx[6] = t11
set this.destx[7] = t12
set this.destx[8] = t13
set this.destx[9] = t14
set this.destx[10] = t20
set this.destx[11] = t21
set this.destx[12] = t22
set this.destx[13] = t23
set this.destx[14] = t24
set this.destx[15] = t30
set this.destx[16] = t31
set this.destx[17] = t32
set this.destx[18] = t33
set this.destx[19] = t34
set this.destx[20] = t40
set this.destx[21] = t41
set this.destx[22] = t42
set this.destx[23] = t43
set this.destx[24] = t44
endif
endmethod
method registerDestY takes real t00, real t01, real t02, real t03, real t04, real t10, real t11, real t12, real t13, real t14, real t20, real t21, real t22, real t23, real t24, real t30, real t31, real t32, real t33, real t34, real t40, real t41, real t42, real t43, real t44 returns nothing
if MAX_DESTRUCTABLES_PER_STAMP == 25 then
set this.desty[0] = t00
set this.desty[1] = t01
set this.desty[2] = t02
set this.desty[3] = t03
set this.desty[4] = t04
set this.desty[5] = t10
set this.desty[6] = t11
set this.desty[7] = t12
set this.desty[8] = t13
set this.desty[9] = t14
set this.desty[10] = t20
set this.desty[11] = t21
set this.desty[12] = t22
set this.desty[13] = t23
set this.desty[14] = t24
set this.desty[15] = t30
set this.desty[16] = t31
set this.desty[17] = t32
set this.desty[18] = t33
set this.desty[19] = t34
set this.desty[20] = t40
set this.desty[21] = t41
set this.desty[22] = t42
set this.desty[23] = t43
set this.desty[24] = t44
endif
endmethod
method registerDestFace takes real t00, real t01, real t02, real t03, real t04, real t10, real t11, real t12, real t13, real t14, real t20, real t21, real t22, real t23, real t24, real t30, real t31, real t32, real t33, real t34, real t40, real t41, real t42, real t43, real t44 returns nothing
if MAX_DESTRUCTABLES_PER_STAMP == 25 then
set this.destrot[0] = t00
set this.destrot[1] = t01
set this.destrot[2] = t02
set this.destrot[3] = t03
set this.destrot[4] = t04
set this.destrot[5] = t10
set this.destrot[6] = t11
set this.destrot[7] = t12
set this.destrot[8] = t13
set this.destrot[9] = t14
set this.destrot[10] = t20
set this.destrot[11] = t21
set this.destrot[12] = t22
set this.destrot[13] = t23
set this.destrot[14] = t24
set this.destrot[15] = t30
set this.destrot[16] = t31
set this.destrot[17] = t32
set this.destrot[18] = t33
set this.destrot[19] = t34
set this.destrot[20] = t40
set this.destrot[21] = t41
set this.destrot[22] = t42
set this.destrot[23] = t43
set this.destrot[24] = t44
endif
endmethod
endstruct
endlibrary