Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --{program="builder",version="1.00",date="2015-05-15"}
- ---------------------------------------
- -- builder by Kaikaku
- -- 2015-05-15, v1.00 initial version
- local cProgam ="builder"
- local cVersion ="v1.00"
- ---------------------------------------
- ---------------------------------------
- ---- DESCRIPTION ----------------------
- ---------------------------------------
- -- This program sets up the labyrinths in the pyramids
- -- It's called by other computers
- ---------------------------------------
- ---- PARAMETERS -----------------------
- ---------------------------------------
- -- debugging and testing
- local blnDebug=true --false -- -- displays debug messages
- local intDebugLevel=1--0 -- will do some filtering stuff w/ this
- -- 0 = only temp things are set to 0
- -- 1 = main steps
- -- 2 = basic info for main steps
- -- 3 = detailed function calls
- -- 4 = detailed that are probably not used any more
- -- 5 = execute also some askForText stops
- local strDebugPrompt="D:" -- debug messages start with this
- local intDebugCounter=0 -- to split screens
- local intDebugStopCounter=0 -- how often stopped
- local intDebugStopAt=9999 --9999 -- -- when to stop. If very high then no stop at all. more than 18 will hide info for sure
- local blnJustClear= false --true -- -- clears the field without putting new stuff
- local blnAllRndInteriorBlocks = false --true -- if true, all options will be used in each room
- local blnAllRndInteriorBases = false --true -- if true, all base options will be used in each room
- local blnAllRndSubinteriors = false -- true -- if true, all subinteriors will be used in each room
- local blnAllSummons = false -- true -- true -- if true, all summons will be used in each room
- local blnNoGlassRoof=false --true -- --if true, then open roof
- local blnClearBeforeBuild=true --false--
- -- room parameters
- local cRoomDepth =11 -- direction x
- local cRoomHeight=5 -- y
- local cRoomWidth =cRoomDepth -- z
- local cRoomMaterial = "minecraft:sandstone" --"minecraft:bedrock"
- local cRoomMaterialDmg = 0
- local cRoomMaterialCeiling = "chisel:glass" --"OpenBlocks:tank" --"ExtraUtilities:decorativeBlock2"
- local cRoomMaterialCeilingDmg = 6
- local cTrapProbability=0.25 -- how probable it is to trap any y=-1/0/1 chest
- -- default labyrinth values
- -- some (all?) of the default values may be overwritten if #tArgs==6
- local xHome=0
- local yHome=0
- local zHome=0
- xHome, yHome, zHome = commands.getBlockPosition() -- memo: not included in task limit!
- local cOffsetX =4
- local cOffsetY =4-22
- local cOffsetZ =4-20
- local cRoomsGridX=3 -- 5 -- -- number of rooms in x direction
- local cRoomsGridZ=3 -- 5 -- -- z direction
- local intLabLevel=2 -- 1 -- default labyrinth difficulty level
- -- material ids
- local cMatId_RoomIndicator = "266" --=minecraft:gold_ingot
- local cMatId_GoldIngot="266"
- local cMatId_GoldNugget="371"
- local cMatId_GoldOre="14"
- local cMatId_FlintAndSteel="259"
- local cMatId_WoodenSword="268"
- local cMatId_DiscCat="2257" -- not sure about this ID! Depending on mod pack?
- local cMatId_DiscFar="2260" -- not sure about this ID! Depending on mod pack?
- ---------------------------------------
- ---- tArgs ----------------------------
- ---------------------------------------
- -- (disabled) builder "del"
- -- (disabled) builder xRoom zRoom
- -- (disabled) builder xRoom zRoom "del"
- -- (disabled) builder x y z xRoom zRoom level
- -- builder x y z xRoom zRoom "del" (clear included)
- local tArgs = {...}
- local tmpArg=0
- local blntArgsOk=false
- --[[ used for developing and testing
- if #tArgs == 1 then -- no error check
- if tArgs[1]=="delete" or tArgs[1]=="del" then
- blntArgsOk=true
- blnJustClear=true
- end
- end
- if #tArgs == 2 or #tArgs == 3 then -- no error check
- cRoomsGridX=math.floor(tonumber(tArgs[1]))
- cRoomsGridZ=math.floor(tonumber(tArgs[2]))
- if cRoomsGridX<2 then cRoomsGridX=2 end
- if cRoomsGridX>5 then cRoomsGridX=5 end
- if cRoomsGridZ<2 then cRoomsGridZ=2 end
- if cRoomsGridZ>5 then cRoomsGridZ=5 end
- blntArgsOk=true
- end
- if #tArgs == 3 then -- no error check
- if tArgs[3]=="delete" or tArgs[3]=="del" then
- blntArgsOk=true
- blnJustClear=true
- end
- end
- ]]--
- if #tArgs >= 6 then -- no error check
- xHome=tonumber(tArgs[1]) cOffsetX=0
- yHome=tonumber(tArgs[2]) cOffsetY=0
- zHome=tonumber(tArgs[3]) cOffsetZ=0
- cRoomsGridX=math.floor(tonumber(tArgs[4]))
- cRoomsGridZ=math.floor(tonumber(tArgs[5]))
- if cRoomsGridX<2 then cRoomsGridX=2 end
- if cRoomsGridX>5 then cRoomsGridX=5 end
- if cRoomsGridZ<2 then cRoomsGridZ=2 end
- if cRoomsGridZ>5 then cRoomsGridZ=5 end
- tmpArg=tonumber(tArgs[6])
- if tmpArg~=nil then
- intLabLevel=tmpArg
- if intLabLevel>5 then intLabLevel=5 end
- if intLabLevel<1 then intLabLevel=1 end
- blntArgsOk=true
- elseif tArgs[6]=="delete" or tArgs[6]=="del" then
- -- del?
- blntArgsOk=true
- blnJustClear=true
- end
- else
- commands.say("Ups, sorry! Error calling pyramid builder...")
- end
- local finalCommand=""
- if #tArgs >= 7 then -- final command to finish execution?
- for i=7,#tArgs do
- finalCommand=finalCommand..tArgs[i].." "
- end
- end
- if not blntArgsOk then
- debugPrint(0,"ERROR: Something wrong with provided parameters!")
- return
- end
- ---------------------------------------
- ---- VARIABLES ------------------------
- ---------------------------------------
- local maxCommands=250 -- to overcome task limit --250
- local curCommands=0 -- to overcome task limit
- local curCounter=0
- local curCounterComplete=0
- local exitRoomZ=0 -- z coordinate of exit in doors[]
- local entrRoomZ=0 -- z coordinate of entrance in doors[]
- local countInteriors={}
- local goldDistribution={} -- used to randomly distribute gold ingots and nuggets
- -- {"id","count"}
- -- monitor thingies
- local mon = peripheral.wrap("right")
- local monLevel=0 --3x3,3x4,4x4,4x5,5x5
- if cRoomsGridX==3 then
- monLevel=1
- elseif cRoomsGridZ==5 then
- monLevel=5
- elseif cRoomsGridX==5 then
- monLevel=4
- elseif cRoomsGridZ==4 then
- monLevel=3
- elseif cRoomsGridZ==3 then
- monLevel=2
- else
- print("Error: monitor thingie")
- end
- local monCount={18500,25500,34000,43500,53500}
- term.redirect(mon) term.clear() term.setCursorPos(1,1) print(" Pyramid") print(" ",monLevel,"/5")term.redirect(term.native())
- local function updateMon()
- term.redirect(mon)
- --term.clear()
- term.setCursorPos(1,4)
- -- print(" Pyramid ",monLevel,"/5")
- print(" ~",math.floor(100*curCounter/monCount[monLevel]),"%")
- term.redirect(term.native())
- end
- --os.sleep(1)
- --updateMon()
- --if true then return true end
- ---------------------------------------
- ---- TABLES ---------------------------
- ---------------------------------------
- ------------------------------------------------------------------------------
- -- rooms[] -------------------------------------------------------------------
- -- type: grass, labyrinth, lava, water, dungeon, ...
- -- basic difficulty: 0=none/low, ...
- -- underground blocked: true, false
- -- room connections: n,s,e,w,u(underground) and/or room numbers
- -- distance from start: 4
- -- is populated: 0,1,2, ...
- -- chest likely-hood: 0.00 - 1.00
- -- grid:
- -- rooms[x][z][parameters]
- --
- -- #rooms =cRoomsGridX=number of rooms in x direction
- -- #rooms[1] =cRoomsGridZ=numbers of rooms in z direction
- -- rooms[2][3] =room in grind pos 2,3
- -- rooms[ix][iz]["interior"] = id of interiors[]
- -- rooms[ix][iz]["fromEntrance"] = how far from entrance, entrance is 1, undefined is 0
- -- rooms[ix][iz]["chest"]={{x,y,z,dmg},...} = chest(s) that is/are placed in this room
- local rooms = {}
- for ix=1,cRoomsGridX,1 do
- rooms[ix]={}
- for iz=1,cRoomsGridZ,1 do
- rooms[ix][iz]={}
- rooms[ix][iz]["chest"]={}
- rooms[ix][iz]["fromEntrance"]=0 --default
- end
- end
- ------------------------------------------------------------------------------
- -- doors[] -------------------------------------------------------------------
- -- doors[x+1][z+1][1-3]: 1=has door in neg x dir (default = 0 = no door)
- -- 2=has door in neg z dir (default = 0 = no door)
- -- 3=has underground connection tbd.
- local doors ={}
- for ix=1,cRoomsGridX+1,1 do
- doors[ix]={}
- for iz=1,cRoomsGridZ+1,1 do
- doors[ix][iz]={0,0,0} --{door in -x dir, door in -z dir, underground}
- end
- end
- ------------------------------------------------------------------------------
- -- chests[] ------------------------------------------------------------------
- -- chests[i]["x"]/["y"]/["z"] = coordinates
- -- chests[i]["dmg"] = damage value (direction not working atm)
- -- chests[i]["fromEntrance"] = value taken over from room
- -- chests[i]["items"]={}
- -- [1]["id"]=id to be used in command
- -- [1]["count"]=counter to be used in command
- local chests ={}
- ------------------------------------------------------------------------------
- -- chestItems[] --------------------------------------------------------------
- -- chestItems[i]["level"] = applied at which level
- -- chestItems[i]["chance"]= probability to be applied once(!), not per chest
- -- chestItems[i]["id"] = item id
- -- chestItems[i]["count"] = how many (maybe do an array option)
- -- chestItems[i]["dmg"] = damage value of the item
- local chestItems={}
- if true then
- -- level 1+
- chestItems[1] ={level={1,2},chance=0.4 ,id= 38,count={1,2,3},dmg=0}--poppy
- chestItems[2] ={level= 1 ,chance=0.3 ,id=391,count=1,dmg=0}--carrot
- chestItems[3] ={level= 1 ,chance=0.3 ,id=391,count=1,dmg=0}--carrot
- chestItems[4] ={level={1,2,3,4,5},chance=0.4 ,id=296,count={1,2,3},dmg=0}--wheat
- chestItems[5] ={level={1,2,3,4,5},chance=0.4 ,id=349,count={1,2},dmg=0}--raw fish
- chestItems[6] ={level={1,2},chance=0.2 ,id=346,count=1,dmg={20,40,60}}--fishing rod
- chestItems[7] ={level={1,2},chance=0.4 ,id=334,count={1,2,2},dmg=0}--leather
- chestItems[8] ={level={1,2},chance=0.4 ,id=334,count={1,2,2},dmg=0}--leather
- chestItems[9] ={level={1,2},chance=0.3 ,id=332,count={3,4,5,6},dmg=0}--snow ball
- chestItems[10]={level={1,2,3,4,5},chance=1 ,id=cMatId_WoodenSword,count=1,dmg={0,20,40}}--wooden sword
- chestItems[11]={level= 1 ,chance=0.5 ,id=272,count=1,dmg={90,100,110}}--stone sword
- chestItems[12]={level={1,2},chance=0.4 ,id=301,count=1,dmg={30,40,50}}--leather boots
- chestItems[13]={level={1,2},chance=0.4 ,id=298,count=1,dmg={30,40,50}}--leather cap
- chestItems[14]={level={1,2,3,4,5},chance=0.3 ,id=262,count={2,4,6},dmg=0}--arrow
- chestItems[15]={level={1,2,3,4,5},chance=0.1 ,id=375,count=1,dmg=0}--gold nugget
- -- level 2+
- chestItems[16]={level={2,3,4,5},chance=1.0 ,id=263,count=1,dmg=1}--charcoal
- chestItems[17]={level={2,3,4,5},chance=0.3 ,id=260,count=1,dmg=0}--apple
- chestItems[18]={level= 2 ,chance=0.3 ,id=260,count=1,dmg=0}--apple
- chestItems[19]={level= 2 ,chance=0.4 ,id=353,count=1,dmg=0}--sugar
- chestItems[20]={level={2,3,4,5},chance=0.5 ,id=334,count={2,3,3},dmg=0}--leather
- chestItems[21]={level={2,3,4,5},chance=0.5 ,id=334,count={2,3,3},dmg=0}--leather
- chestItems[22]={level={2,3} ,chance=0.4 ,id=300,count=1,dmg={10,20,50}}--leather pants
- chestItems[23]={level={2,3,4} ,chance=0.4 ,id=299,count=1,dmg={10,20,50}}--leather chest/tunic
- chestItems[24]={level={2,3,4,5},chance=0.3 ,id=261,count=1,dmg={20,30,50}}--bow
- chestItems[25]={level={2,3,4,5},chance=0.5 ,id=272,count=1,dmg={70,80,90}}--stone sword
- -- level 3+
- chestItems[26]={level={3,4,5} ,chance=0.4 ,id=360,count={1,2,3,4},dmg=0}--melon
- chestItems[27]={level={3,4,5} ,chance=0.3 ,id=265,count={1,2,3},dmg=0}--iron ingot
- chestItems[28]={level={3,4,5} ,chance=0.4 ,id=306,count=1,dmg={100,150,200}}--iron helmet
- chestItems[29]={level={3,4,5} ,chance=0.3 ,id=306,count=1,dmg={100,150,200}}--iron chest
- chestItems[30]={level={3,4,5} ,chance=0.8 ,id=cMatId_DiscCat,count=1}--disc-cat, distraction item for jukebox
- -- level 4+
- chestItems[31]={level={4,5} ,chance=0.3 ,id=306,count=1,dmg={200,300,400}}--iron pants
- chestItems[32]={level={4,5} ,chance=0.3 ,id=306,count=1,dmg={200,300,400}}--iron boots
- chestItems[33]={level={4,5} ,chance=0.3 ,id=265,count={2,3,4},dmg=0}--iron ingot
- end
- ------------------------------------------------------------------------------
- -- interiors[] ---------------------------------------------------------------
- -- interiors["name"] = name of interior
- -- interiors["chance"] = if (randomly) selected this probability applies 0.0-1.0
- -- default=1.0 for: interiors, sub-interiors, bases, blocks, summons
- -- interiors["base"] = {x,y,z,mat,dmg} platform in room, usually at x1,x2,y,z1,z2=1,9,0,1,9
- -- dmg=0 for: bases, blocks and summons
- -- interiors["blocks"][] = {chance,x/{},y,z/{},mat,dmg,[extra]}
- -- interiors["summon"] = summon an entity
- -- interiors["maxCount"][x] = how often is this design allowed on level x
- -- interiors["noExit"] = true=>not allowed as interior in exit room (in defineRooms and for sub-interiors in xxx), nil=>okay
- -- interiors["noRandomLoot"]= (trapped_)chest will not get random loot (hence not reset, loosing existing loot)
- -- interiors["subinterior"] = not a block, but a set of blocks, identified via its name(!) or {name1, name2,...}
- ------- interiors["chest"][c]= {chance
- -- x1=1,x2=9,y=0,z1=1,z2=2
- local interiors={} -- room interiors go from 1 to 10
- -- special interiors go from 11 to 11
- local interiorsData={} -- for reading data file
- local cRoomInteriorMax =0--14 -- used for randomizing rooms
- local cRoomInteriorExit=cRoomInteriorMax+1
- local intBase=0 -- base count within interior
- local intBlock=0 -- block count within interior
- -- changes that are not implemented in older data:
- -- 1) sub-interior do not need x/y/z
- -- 2) base may use x instead of x1=x2
- ---------------------------------------
- ---- EARLY FUNCTIONS ------------------
- ---------------------------------------
- term.clear() term.setCursorPos(1,1)
- local function askForInputText(textt)
- local at=""
- -- check prompting texts
- if textt==nil then textt="Enter text:" end
- -- ask for input
- write(textt)
- at=read()
- return at
- end
- ---------------------------------------
- local function debugPrint(intLevel,strPara1,strPara2,strPara3,strPara4,strPara5,strPara6,strPara7,strPara8,strPara9)
- -- helper function for debug printing
- -- step 1: check debug level
- if not blnDebug then return end
- if intLevel~= nil then
- if intDebugLevel<tonumber(intLevel) then return end
- end
- -- step 2: show message
- local tmpPrintOut=strDebugPrompt
- if strPara1 ~= nil then tmpPrintOut=tmpPrintOut..tostring(strPara1) end
- if strPara2 ~= nil then tmpPrintOut=tmpPrintOut.."("..tostring(strPara2) end
- if strPara3 ~= nil then tmpPrintOut=tmpPrintOut..","..tostring(strPara3) end
- if strPara4 ~= nil then tmpPrintOut=tmpPrintOut..","..tostring(strPara4) end
- if strPara5 ~= nil then tmpPrintOut=tmpPrintOut..","..tostring(strPara5) end
- if strPara6 ~= nil then tmpPrintOut=tmpPrintOut..","..tostring(strPara6) end
- if strPara7 ~= nil then tmpPrintOut=tmpPrintOut..","..tostring(strPara7) end
- if strPara8 ~= nil then tmpPrintOut=tmpPrintOut..","..tostring(strPara8) end
- if strPara9 ~= nil then tmpPrintOut=tmpPrintOut..","..tostring(strPara9) end
- if strPara2 ~= nil then tmpPrintOut=tmpPrintOut..")" end
- print(tmpPrintOut)
- -- step 3: ask for key press every then and now
- intDebugCounter=intDebugCounter+1
- if intDebugCounter>=intDebugStopAt then
- intDebugCounter=0
- intDebugStopCounter=intDebugStopCounter+1
- askForInputText("--> ("..intDebugStopCounter..") hit enter")
- end
- end
- ---------------------------------------
- local function readInterior(strDataLevel,tblData)
- -- reads from either single function calls or (later) from files
- local intInterior =#interiors
- local intBase =0--#interiors[intInterior]["base"]
- local intBlock =0
- local intSubinterior=0--#interiors[intInterior]["subinterior"]
- local intSummon =0--#interiors[intInterior]["summon"]
- local tmpText =""
- if strDataLevel=="interiors" then
- -- infos about last interior
- if intInterior>1 then
- debugPrint(3,"done int"..tostring(intInterior-1).."_"..interiors[intInterior-1]["name"].." ",#interiors[intInterior-1]["base"],#interiors[intInterior-1]["blocks"])--,#interiors[intInterior-1]["subinterior"])--,#interiors[intInterior-1]["summon"])--3
- end
- -- start new interiors
- --if intInterior==nil then intInterior=0 print("interior==nil") end
- intInterior=intInterior+1
- interiors[intInterior]=tblData
- interiors[intInterior]["base"]={}
- interiors[intInterior]["blocks"]={}
- interiors[intInterior]["summon"]={}
- interiors[intInterior]["subinterior"]={}
- if interiors[intInterior]["chance"]==nil then interiors[intInterior]["chance"]=1 end
- --debugPrint(0,"read int"..intInterior.."_"..interiors[intInterior]["name"])--3
- tmpText="new"
- elseif strDataLevel=="base" then
- -- read new base
- intBase=#interiors[intInterior]["base"]+1
- interiors[intInterior]["base"][intBase]=tblData
- if interiors[intInterior]["base"][intBase]["dmg"] ==nil then interiors[intInterior]["base"][intBase]["dmg"] =0 end
- if interiors[intInterior]["base"][intBase]["chance"]==nil then interiors[intInterior]["base"][intBase]["chance"]=1 end
- tmpText=intBase
- elseif strDataLevel=="blocks" then
- -- read new block
- intBlock=#interiors[intInterior]["blocks"]+1
- interiors[intInterior]["blocks"][intBlock]=tblData
- if interiors[intInterior]["blocks"][intBlock]["dmg"] ==nil then interiors[intInterior]["blocks"][intBlock]["dmg"] =0 end
- if interiors[intInterior]["blocks"][intBlock]["chance"]==nil then interiors[intInterior]["blocks"][intBlock]["chance"]=1 end
- tmpText=intBlock
- elseif strDataLevel=="summon" then
- -- read new summon
- intSummon=#interiors[intInterior]["summon"]+1
- interiors[intInterior]["summon"][intSummon]=tblData
- if interiors[intInterior]["summon"][intSummon]["dmg"] ==nil then interiors[intInterior]["summon"][intSummon]["dmg"] =0 end
- if interiors[intInterior]["summon"][intSummon]["chance"]==nil then interiors[intInterior]["summon"][intSummon]["chance"]=1 end
- tmpText=intSummon
- elseif strDataLevel=="subinterior" then
- -- read new subinterior
- intSubinterior=#interiors[intInterior]["subinterior"]+1
- interiors[intInterior]["subinterior"][intSubinterior]=tblData
- if interiors[intInterior]["subinterior"][intSubinterior]["chance"]==nil then interiors[intInterior]["subinterior"][intSubinterior]["chance"]=1 end
- tmpText=intSubinterior
- elseif strDataLevel=="set_cRoomInteriorMaxExit" then
- -- read new subinterior
- cRoomInteriorMax=#interiors
- cRoomInteriorExit=cRoomInteriorMax+1
- tmpText=strDataLevel
- end
- if tmpText~="set_cRoomInteriorMaxExit" then
- debugPrint(4,"read int"..intInterior.."_"..interiors[intInterior]["name"]..":",string.sub(strDataLevel,1,3).."_"..tmpText)--4
- else
- debugPrint(4,"cRoomInteriorMax="..cRoomInteriorMax,"cRoomInteriorExit="..cRoomInteriorExit)--4
- end
- end
- ---------------------------------------
- local function cutString(strInput,strSeperator,blnDeleteSeparator)
- local tmpInt=string.find(strInput,strSeperator)
- local return1=""
- local return2=""
- -- ideas: add more than one separator
- debugPrint(4,strInput,strSeperator) --4
- return1=string.sub(strInput,1,tmpInt-1)
- return2=string.sub(strInput,tmpInt+string.len(strSeperator))
- if blnDeleteSeparator==nil then blnDeleteSeparator=true end
- if not blnDeleteSeparator then return2=strSeperator..return2 end
- return return1,return2
- end
- ---------------------------------------
- local function readInteriorData(strFile)
- debugPrint(2,"readInteriorData",strFile)--2
- local file = io.open(strFile, "r")
- for line in file:lines() do
- table.insert (interiorsData, line)
- end
- file:close()
- end
- ---------------------------------------
- local function transfereInteriorData()
- debugPrint(3,"transfereInteriorData",strFile)--3
- local tmpData
- for i=1,#interiorsData,1 do
- tmpData=interiorsData[i]
- interiorsData[i]=textutils.unserialize(interiorsData[i])
- -- step 1: valid data line?
- if type(interiorsData[i])=="table" then
- debugPrint(4,"Data table in "..i..":",interiorsData[i][1].."...")--4
- readInterior(interiorsData[i][1],interiorsData[i][2])
- else
- debugPrint(3,"No data table in "..i..":",tmpData)--3
- end
- --askForInputText()
- end
- end
- ---------------------------------------
- ---- INTERIOR ROOM DEFINITIONS --------
- ---------------------------------------
- readInteriorData("interiorData.lua")
- transfereInteriorData()
- -- display read interiors
- debugPrint(0,"Interiors = "..cRoomInteriorMax.." ","1 to "..cRoomInteriorMax)
- debugPrint(0,"Sub-int. = "..#interiors-cRoomInteriorMax.." ",tostring(cRoomInteriorMax+1).." to "..#interiors)
- -- initialize counter for implemented interiors
- for i = 1,#interiors,1 do countInteriors[i]=0 end
- ---------------------------------------
- ---- FUNCTIONS ------------------------
- ---------------------------------------
- -- List of functions:
- --local function askForInputText(textt)
- --local function debugPrint(intLevel,strPara1,strPara2,strPara3,strPara4,strPara5,strPara6,strPara7,strPara8,strPara9)
- --local function baseCoordinates(xRoom,zRoom)
- --local function pullTaskComplete()
- --local function makeStringCommand(par1,par2,par3,par4,par5,par6,par7,par8,par9)
- --local function clearRange(xx,yy,zz,optDx,optDy,optDz)
- --local function clearRoom(xx,yy,zz)
- --local function resetRooms()
- --local function randomDoorId()
- --local function randomDoorId()
- --local function ensureCornerDoors(doorX1,doorZ1,doorS1,doorX2,doorZ2,doorS2)
- --local function displayDistance()
- --local function updateDistance()
- --local function addNewDoor()
- --local function defineDoors()
- --local function implementDoors()
- --local function defineRooms()
- --local function implementInterior(xRoom,zRoom,interiorID)
- --local function implementRooms()
- --local function addItemToChest(intChest,intItemId,intItemCount,intItemDmg)
- --local function defineGoldDistribution()
- --local function defineChestItems()
- --local function defineKeyItemDistribution()
- --local function implementChestItems()
- local function askForInputText(textt)
- local at=""
- -- check prompting texts
- if textt==nil then textt="Enter text:" end
- -- ask for input
- write(textt)
- at=read()
- return at
- end
- ---------------------------------------
- local function debugPrint(intLevel,strPara1,strPara2,strPara3,strPara4,strPara5,strPara6,strPara7,strPara8,strPara9)
- -- helper function for debug printing
- -- step 1: check debug level
- if not blnDebug then return end
- if intLevel~= nil then
- if intDebugLevel<tonumber(intLevel) then return end
- end
- -- step 2: show message
- local tmpPrintOut=strDebugPrompt
- if strPara1 ~= nil then tmpPrintOut=tmpPrintOut..tostring(strPara1) end
- if strPara2 ~= nil then tmpPrintOut=tmpPrintOut.."("..tostring(strPara2) end
- if strPara3 ~= nil then tmpPrintOut=tmpPrintOut..","..tostring(strPara3) end
- if strPara4 ~= nil then tmpPrintOut=tmpPrintOut..","..tostring(strPara4) end
- if strPara5 ~= nil then tmpPrintOut=tmpPrintOut..","..tostring(strPara5) end
- if strPara6 ~= nil then tmpPrintOut=tmpPrintOut..","..tostring(strPara6) end
- if strPara7 ~= nil then tmpPrintOut=tmpPrintOut..","..tostring(strPara7) end
- if strPara8 ~= nil then tmpPrintOut=tmpPrintOut..","..tostring(strPara8) end
- if strPara9 ~= nil then tmpPrintOut=tmpPrintOut..","..tostring(strPara9) end
- if strPara2 ~= nil then tmpPrintOut=tmpPrintOut..")" end
- print(tmpPrintOut)
- -- step 3: ask for key press every then and now
- intDebugCounter=intDebugCounter+1
- if intDebugCounter>=intDebugStopAt then
- intDebugCounter=0
- intDebugStopCounter=intDebugStopCounter+1
- askForInputText("--> ("..intDebugStopCounter..") hit enter")
- end
- end
- ---------------------------------------
- local function baseCoordinates(xRoom,zRoom)
- -- returns start coordinates of a room (left, bottom corner, one above floor level)
- debugPrint(4,"baseCoordinates",xRoom,zRoom)
- return xHome+cOffsetX+(xRoom-1)*(cRoomDepth-1), yHome+cOffsetY, zHome+cOffsetZ+(zRoom-1)*(cRoomWidth-1)
- end
- ---------------------------------------
- local function pullTaskComplete()
- while true do
- os.pullEvent("task_complete")
- curCommands = curCommands - 1
- curCounterComplete=curCounterComplete+1
- --write("*")
- end
- end
- ---------------------------------------
- local function makeStringCommand(par1,par2,par3,par4,par5,par6,par7,par8,par9)
- local strCommand=""
- if par1~=nil then
- strCommand=tostring(par1).." "
- if par2~=nil then
- strCommand=strCommand..tostring(par2).." "
- if par3~=nil then
- strCommand=strCommand..tostring(par3).." "
- if par4~=nil then
- strCommand=strCommand..tostring(par4).." "
- if par5~=nil then
- strCommand=strCommand..tostring(par5).." "
- if par6~=nil then
- strCommand=strCommand..tostring(par6).." "
- if par7~=nil then
- strCommand=strCommand..tostring(par7).." "
- if par8~=nil then
- strCommand=strCommand..tostring(par8).." "
- if par9~=nil then
- strCommand=strCommand..tostring(par9).." "
- end
- end
- end
- end
- end
- end
- end
- end
- end
- return strCommand
- end
- ---------------------------------------
- local function execCommand(par1,par2,par3,par4,par5,par6,par7,par8,par9)
- -- command execution is done here
- -- a) to hinder exceeding of task limit
- -- b) (later) to allow competitive 2 player mode
- parallel.waitForAny(
- pullTaskComplete,
- function()
- while curCommands >= maxCommands do
- --behalten print("execCom:",curCommands," ",curCounter," ",curCounterComplete)
- updateMon()
- --debugPrint(0,"execCommand",curCommands)
- os.pullEvent("task_complete")
- end
- --write(par1)
- if part1=="setblock" then
- --commands.setBlock(par2,par3,par4,par5,par6,par7,par8,par9) -- hatte hier async vergessen
- commands.async.setBlock(par2,par3,par4,par5,par6,par7,par8,par9) -- hatte hier async vergessen
- else
- commands.execAsync(makeStringCommand(par1,par2,par3,par4,par5,par6,par7,par8,par9))
- end
- curCounter=curCounter+1
- curCommands = curCommands + 1
- end
- )
- end
- ---------------------------------------
- local function clearRange(x1,y1,z1,x2,y2,z2)
- -- clears defined area
- -- uses absolute parameters
- debugPrint(0,"clearRange",x1,y1,z1,x2,y2,z2)--1
- --os.sleep(10)
- if x2==nil then x2=x1 end
- if y2==nil then y2=y1 end
- if z2==nil then z2=z1 end
- for ix=x1,x2,1 do
- for iy=y2,y1,-1 do
- for iz=z1,z2,1 do
- execCommand("setblock",ix,iy,iz,"minecraft:air",0,"replace")
- end
- end
- --os.sleep(0)
- end
- return true
- end
- ---------------------------------------
- local function clearRoom(xR,zR)
- -- resets room to basic layout, i.e. walls, floor and ceiling
- -- avoids double setting of walls, i.e. not usable for single room reset
- -- anyways wouldn't work because of things on walls
- debugPrint(1,"clearRoom",xR,zR)
- local basisX=0
- local basisY=0
- local basisZ=0
- basisX,basisY,basisZ=baseCoordinates(xR,zR)
- -- step 1: wall north (left)
- for ix=basisX,basisX+cRoomDepth-1,1 do
- for iy=basisY,basisY+cRoomHeight,1 do
- execCommand("setblock",ix,iy,basisZ,cRoomMaterial,cRoomMaterialDmg)
- end
- end
- -- step 2: wall south (right)
- if zR==#rooms[1] then
- for ix=basisX,basisX+cRoomDepth-1,1 do
- for iy=basisY,basisY+cRoomHeight,1 do
- execCommand("setblock",ix,iy,basisZ+cRoomWidth-1,cRoomMaterial,cRoomMaterialDmg)
- end
- end
- else
- -- no need to double set the wall
- end
- -- step 3: walls west (front)
- for iz=basisZ,basisZ+cRoomDepth-2,1 do
- for iy=basisY,basisY+cRoomHeight,1 do
- execCommand("setblock",basisX,iy,iz,cRoomMaterial,cRoomMaterialDmg)
- end
- end
- -- step 4: wall east (back)
- if xR==#rooms then
- for iz=basisZ,basisZ+cRoomDepth-2,1 do
- for iy=basisY,basisY+cRoomHeight,1 do
- execCommand("setblock",basisX+cRoomWidth-1,iy,iz,cRoomMaterial,cRoomMaterialDmg)
- end
- end
- else
- -- no need to double set the wall
- end
- -- step 5: floor and ceiling
- for ix=basisX,basisX+cRoomDepth-1,1 do
- for iz=basisZ,basisZ+cRoomDepth-1,1 do
- execCommand("setblock",ix,basisY,iz,cRoomMaterial,cRoomMaterialDmg)
- if not blnNoGlassRoof then
- execCommand("setblock",ix,basisY+cRoomHeight+1,iz,cRoomMaterialCeiling,cRoomMaterialCeilingDmg)
- end
- end
- end
- return true
- end
- ---------------------------------------
- local function resetRooms()--xx,yy,zz)
- -- prepare fresh and empty default rooms
- debugPrint(1,"resetRooms")
- local basisX=0
- local basisY=0
- local basisZ=0
- basisX,basisY,basisZ=baseCoordinates(1,1)
- -- step 1: clear whole labyrinth in one go (incl. roof and underground)
- if blnClearBeforeBuild then
- -- waterview space
- clearRange(basisX+4,basisY+7 ,basisZ+4,basisX+#rooms*(cRoomDepth-1)-4,basisY+cRoomHeight+1+4,basisZ+#rooms[1]*(cRoomWidth-1)-4)
- -- regular space
- clearRange(basisX, basisY-3-2,basisZ ,basisX+#rooms*(cRoomDepth-1), basisY+cRoomHeight+1 ,basisZ+#rooms[1]*(cRoomWidth-1))
- end
- if blnJustClear then return end
- -- step 2: resets the whole room grid
- debugPrint(1,"resetRooms")--,xx,yy,zz)
- for xRoom=1,#rooms,1 do
- for zRoom=1,#rooms[1],1 do
- clearRoom(xRoom,zRoom)
- --os.sleep(0.1)
- end
- end
- --for xRoom=0,#rooms-1,1 do
- -- for zRoom=0,#rooms[1]-1,1 do
- -- clearRoom(xx+xRoom*(cRoomDepth-1),yy,zz+zRoom*(cRoomWidth-1))
- --end
- -- end
- end
- ---------------------------------------
- local function randomDoorId()
- -- returns a door identifier
- -- so far only a random nummber generator
- debugPrint(4,"randomDoorId")
- return math.random(1,2) -- random door
- -- 1=air
- -- 2=wooden door
- -- 9=iron door for entrance(not a random door)
- -- exit needs 1=air, iron door is placed by sub-interior
- end
- ---------------------------------------
- local function ensureCornerDoors(doorX1,doorZ1,doorS1,doorX2,doorZ2,doorS2)
- -- ensures that at least one of the two walls has a door
- debugPrint(1,"ensureCornerDoors",doorX1,doorZ1,doorS1,doorX2,doorZ2,doorS2)--1
- debugPrint(4,"doorX1,doorZ1,doorS1=",doorX1,doorZ1,doorS1," ",doors[doorX1][doorZ1][doorS1])--4
- debugPrint(4,"doorX2,doorZ2,doorS2=",doorX2,doorZ2,doorS2," ",doors[doorX2][doorZ2][doorS2])--4
- if (doors[doorX1][doorZ1][doorS1]==0) and (doors[doorX2][doorZ2][doorS2]==0) then
- -- both walls do not have a door: put in a door
- debugPrint(2,"...need additional door")
- if math.random() <=0.5 then
- doors[doorX1][doorZ1][doorS1]=randomDoorId()
- else
- doors[doorX2][doorZ2][doorS2]=randomDoorId()
- end
- end
- end
- ---------------------------------------
- local function displayDistance()
- -- prints room distance from entrance
- print("Room distance from entrance:-----")
- for ix=#rooms,1,-1 do
- for iz=1,#rooms[1],1 do
- write(tostring(rooms[ix][iz]["fromEntrance"]).." ")
- end
- print()
- end
- end
- ---------------------------------------
- local function updateDistance()
- -- updates the "fromEntrance" entry of all rooms
- local blnAllAssigned = false -- true if no room has "fromEntrance"=0
- local blnNoChanges = true -- false if in one go a room changed
- local countRoomsNull = 0 -- final check how many are assigned but 0=0
- local tmpFromExit = 0 local tmpFromExit2 = 0
- local tmpNeighbor = 0 local tmpNeighbor2 = 0
- local tmpCounter=0
- local tmpCounterMax=20
- repeat
- -- check may runs
- tmpCounter=tmpCounter+1
- if tmpCounter>tmpCounterMax then
- --debugPrint(0,"updateDistance2",blnAllAssigned,blnNoChanges,tmpCounter)
- break
- end
- blnAllAssigned = true -- assumption
- blnNoChanges = true -- so far
- -- step 1: check bottom neighbor ---------------------------------------
- for ix=2,#rooms,1 do
- for iz=1,#rooms[1],1 do
- -- get data
- tmpFromExit=rooms[ix][iz]["fromEntrance"]
- -- check neighbor
- if doors[ix][iz][1]~=0 then
- -- neighbor at bottom
- tmpNeighbor=rooms[ix-1][iz]["fromEntrance"]
- if tmpFromExit==0 then
- -- I'm not assigned yet
- if tmpNeighbor==0 then
- -- both not assigned
- blnAllAssigned = false
- else
- -- I'm one more far away than my neighbor
- rooms[ix][iz]["fromEntrance"]=tmpNeighbor+1
- blnNoChanges = false
- end
- else
- -- I'm assigned already
- if tmpNeighbor==0 then
- -- I may assign my neighbor
- rooms[ix-1][iz]["fromEntrance"]=tmpFromExit+1
- blnNoChanges = false
- else
- -- hm, which one is closer?
- tmpFromExit2=math.min(tmpFromExit,tmpNeighbor+1)
- tmpNeighbor2=math.min(tmpNeighbor,tmpFromExit+1)
- if tmpFromExit2<tmpFromExit then
- -- I'm closer now
- rooms[ix][iz]["fromEntrance"]=tmpFromExit2
- blnNoChanges = false
- end
- if tmpNeighbor2<tmpNeighbor then
- -- Neighbor is closer now
- rooms[ix-1][iz]["fromEntrance"]=tmpNeighbor2
- blnNoChanges = false
- end
- end
- end
- end
- end
- end
- -- step 2: check left neighbor ---------------------------------------
- for ix=1,#rooms,1 do
- for iz=2,#rooms[1],1 do
- -- get data
- tmpFromExit=rooms[ix][iz]["fromEntrance"]
- -- check neighbor
- if doors[ix][iz][2]~=0 then
- -- neighbor to the left
- tmpNeighbor=rooms[ix][iz-1]["fromEntrance"]
- if tmpFromExit==0 then
- -- I'm not assigned yet
- if tmpNeighbor==0 then
- -- both not assigned
- blnAllAssigned = false
- else
- -- I'm one more far away than my neighbor
- rooms[ix][iz]["fromEntrance"]=tmpNeighbor+1
- blnNoChanges = false
- end
- else
- -- I'm assigned already
- if tmpNeighbor==0 then
- -- I may assign my neighbor
- rooms[ix][iz-1]["fromEntrance"]=tmpFromExit+1
- blnNoChanges = false
- else
- -- hm, which one is closer?
- tmpFromExit2=math.min(tmpFromExit,tmpNeighbor+1)
- tmpNeighbor2=math.min(tmpNeighbor,tmpFromExit+1)
- if tmpFromExit2<tmpFromExit then
- -- I'm closer now
- rooms[ix][iz]["fromEntrance"]=tmpFromExit2
- blnNoChanges = false
- end
- if tmpNeighbor2<tmpNeighbor then
- -- Neighbor is closer now
- rooms[ix][iz-1]["fromEntrance"]=tmpNeighbor2
- blnNoChanges = false
- end
- end
- end
- end
- end
- end
- until (blnAllAssigned and blnNoChanges)
- -- step 3 quick check all rooms for 0
- -- hint: if a 0 room has no doors it might get skipped
- for ix=1,#rooms,1 do
- for iz=1,#rooms[1],1 do
- if rooms[ix][iz]["fromEntrance"]==0 then countRoomsNull=countRoomsNull+1 end
- end
- end
- debugPrint(1,"updateDistance",blnAllAssigned,blnNoChanges,tmpCounter,countRoomsNull)
- if intDebugLevel>=5 then
- displayDistance()
- askForInputText("for debugging...")
- end
- -- return success and number of tries
- if countRoomsNull==0 then
- return true, tmpCounter
- else
- return false, tmpCounter -- may be false if tmpCounterMax triggered
- end
- end
- ---------------------------------------
- local function addNewDoor()
- -- adds one new door in order to make all rooms available
- -- strategy: go from up downwards (should be randomized in a clever way later)
- -- produce only door if exactly one of the two rooms is rated 0
- debugPrint(1,"addNewDoor")
- local iRoom=0
- local iNeighbor=0
- -- loop through all rooms
- for ix=#rooms,1,-1 do
- for iz=#rooms[1],1,-1 do
- -- step 1 check door down (side=1)
- if ix~=1 then -- not first row
- iRoom =rooms[ix][iz]["fromEntrance"]
- iNeighbor=rooms[ix-1][iz]["fromEntrance"]
- if (iRoom==0 and iNeighbor~=0) or (iRoom~=0 and iNeighbor==0) then
- -- gotcha!
- doors[ix][iz][1]=randomDoorId
- debugPrint(2,"..added new door",ix,iz,1)
- return true
- end
- end
- -- step 2 check door left (side=2)
- if iz~=1 then -- not left row
- iRoom =rooms[ix][iz]["fromEntrance"]
- iNeighbor=rooms[ix][iz-1]["fromEntrance"]
- if (iRoom==0 and iNeighbor~=0) or (iRoom~=0 and iNeighbor==0) then
- -- gotcha!
- doors[ix][iz][2]=randomDoorId
- debugPrint(2,"..added new door",ix,iz,2)
- return true
- end
- end
- end
- end
- end
- ---------------------------------------
- local function defineDoors()
- -- defines where there are connections between rooms
- -- including underground tunnels
- -- keep in mind #rooms+1=#doors!
- -- HINT: so far only kind of a simulation by choosing a predefined set / rnd
- debugPrint(1,"defineDoors")
- local cDoorProability=0.4--0.2 --0.5-- chance to get any door in a wall
- local tmpEntranceZ=math.floor(#rooms[1]/2+0.5) -- middle of front
- local tmpExitZ=math.random(1,#rooms[1]) --rnd on back wall
- -- step 1: random doors
- -- so far only random without any checks or any predefined sets
- for xD=1,#doors,1 do
- for zD=1,#doors[1],1 do
- for iSide=1,2,1 do
- if math.random() <= cDoorProability then
- doors[xD][zD][iSide]=randomDoorId()
- end
- end
- end
- end
- -- step 2: delete doors at outer walls
- -- no walls at back and front
- for iz=1,#doors[1],1 do
- doors[1][iz][1]=0 -- lower wall
- doors[#doors][iz][1]=0 -- upper wall
- doors[#doors][iz][2]=0 -- wall between not existing rooms
- end
- for ix=1,#doors,1 do
- doors[ix][1][2]=0 -- left wall
- doors[ix][#doors[1]][2]=0 -- right wall
- doors[ix][#doors[1]][1]=0 -- wall between not existing rooms
- end
- -- step 3: entrance door
- doors[1][tmpEntranceZ][1]=9 -- 9= iron door
- rooms[1][tmpEntranceZ]["fromEntrance"]=1 -- entrance
- entrRoomZ=tmpEntranceZ
- -- step 4: exit door
- doors[#doors][tmpExitZ][1]=1 -- exit needs here 1=air
- exitRoomZ=tmpExitZ -- iron door is set by sub-interior
- -- step 5: check corners to have at least one door
- -- room 1,1
- ensureCornerDoors(2,1,1,1,2,2)
- -- room n,1
- ensureCornerDoors(#doors-1,1,1,#doors-1,2,2)
- -- room 1,n
- ensureCornerDoors(2,#doors[1]-1,1,1,#doors[1]-1,2)
- -- room n,n
- ensureCornerDoors(#doors-1,#doors[1]-1,1,#doors-1,#doors[1]-1,2)
- -- step 6: ensure all rooms are accessible
- while not updateDistance() do --()~=1 do
- addNewDoor()
- end
- displayDistance()
- if blnDebug and false then
- local tmpCount=0
- print("doors[x][y][w]:----------------")
- for xD=1,#doors,1 do
- for zD=1,#doors[1],1 do
- write("["..tostring(xD).."]["..tostring(zD).."]")
- for wD=1,2,1 do
- write(" "..tostring(wD).."="..tostring(doors[xD][zD][wD]))
- end
- tmpCount=tmpCount+1
- if tmpCount>=3 then
- tmpCount=0
- print()
- else
- write(" ")
- end
- end
- end
- if tmpCount~=0 then print() end
- end
- end
- ---------------------------------------
- local function implementDoors()
- -- implements the defined doors
- debugPrint(1,"implementDoors")
- local basisX=0
- local basisY=0
- local basisZ=0
- local tmpDoor=0
- -- so far only basic doorway
- for xD=1,#doors,1 do
- for zD=1,#doors[1],1 do
- for iSide=1,2,1 do
- --if doors[xD][zD][iSide]==3 then print("Found test door at (",xD,",",zD,",",iSide,")") end
- if doors[xD][zD][iSide]~=0 then -- some kind of door
- basisX,basisY,basisZ=baseCoordinates(xD,zD)
- tmpDoor=0
- -- basisY=basisY+1 --hm
- --[[ door orientation info:
- 1) place lower half: it determines the orientation and if it is open
- 2) place upper half: it determines the hinge
- lower part: direction: closed, open
- North: 1, 5
- South: 3, 7
- East: 2, 6
- West: 0, 4
- upper part: hinge:
- Right: 8
- Left: 9
- e.g.: /setblock 0 64 0 wooden_door 1 replace
- /setblock 0 65 0 wooden_door 8 replace
- ]]--
- -- need to do this more general in a function
- if iSide==1 then -- door in x-wall
- -- a wall separating the room towards neg. x
- if doors[xD][zD][iSide]==2 then
- -- wooden door
- -- facing east or west
- tmpDoor=math.random(0,1)*2
- -- closed(3/4) or open (1/4)
- tmpDoor=tmpDoor+math.floor(math.random()+.25)*4
- -- set lower part
- execCommand("setblock",basisX,basisY+1,basisZ+5,"minecraft:wooden_door",tmpDoor,"remove")
- -- set upper part (incl. hinge right or left)
- tmpDoor=math.random(8,9)
- execCommand("setblock",basisX,basisY+2,basisZ+5,"minecraft:wooden_door",tmpDoor,"remove")
- elseif doors[xD][zD][iSide]==3 then
- -- test door (disabled)
- execCommand("setblock",basisX,basisY+1,basisZ+5,"minecraft:wool",14,"remove")
- execCommand("setblock",basisX,basisY+2,basisZ+5,"minecraft:wool",14,"remove")
- elseif doors[xD][zD][iSide]==9 then
- -- iron door for entrance or exit, i.e. always side=1
- -- set lower part
- execCommand("setblock",basisX,basisY+1,basisZ+5,"minecraft:iron_door",0,"remove")
- -- set upper part (incl. hinge right or left)
- tmpDoor=math.random(8,9)
- execCommand("setblock",basisX,basisY+2,basisZ+5,"minecraft:iron_door",tmpDoor,"remove")
- else
- -- only air
- execCommand("setblock",basisX,basisY+1,basisZ+5,0,0,"remove")
- execCommand("setblock",basisX,basisY+2,basisZ+5,0,0,"remove")
- end
- elseif iSide==2 then -- door in z-wall
- -- a wall separating the room towards neg. z
- if doors[xD][zD][iSide]==2 then
- -- wooden door
- -- facing north or south
- tmpDoor=math.random(0,1)*2+1
- -- closed(3/4) or open (1/4)
- tmpDoor=tmpDoor+math.floor(math.random()+0.25)*4
- -- set lower part
- execCommand("setblock",basisX+5,basisY+1,basisZ,"minecraft:wooden_door",tmpDoor,"remove")
- -- set upper part (incl. hinge right or left)
- tmpDoor=math.random(8,9)
- execCommand("setblock",basisX+5,basisY+2,basisZ,"minecraft:wooden_door",tmpDoor,"remove")
- elseif doors[xD][zD][iSide]==3 then
- -- test
- execCommand("setblock",basisX+5,basisY+1,basisZ,"minecraft:wool",14,"remove")
- execCommand("setblock",basisX+5,basisY+2,basisZ,"minecraft:wool",14,"remove")
- else
- -- only air
- execCommand("setblock",basisX+5,basisY+1,basisZ, 0,0,"remove")
- execCommand("setblock",basisX+5,basisY+2,basisZ, 0,0,"remove")
- end
- else
- debugPrint(0,"Unexpected value in implemtnetDoors()")
- end
- end
- end
- end
- end
- end
- ---------------------------------------
- local function defineRooms()
- -- chooses interior for rooms & checks applicability
- debugPrint(1,"defineRooms")
- local tmpInterior=0
- local tmpGo=true
- local tmpStr=""
- for xRoom=1,#rooms,1 do
- for zRoom=1,#rooms[1],1 do
- -- step 1: randomize interior + apply probability
- repeat -- random chance
- repeat -- max counter
- repeat -- check entrance and exit
- impInterior=math.random(1,cRoomInteriorMax) -- =math.random(1,#interiors) not this due to extra interiors
- if intDebugLevel>=3 then tmpStr="["..xRoom..","..zRoom.."] try:"..interiors[impInterior]["name"].."("..countInteriors[impInterior].."/"..interiors[impInterior]["maxCount"][intLabLevel]..")" write(tmpStr) end
- tmpGo=true --3
- -- step 2: check noExit
- if xRoom==#rooms and zRoom==exitRoomZ then
- if interiors[impInterior]["noExit"]~=nil then
- tmpGo=false
- if intDebugLevel>=0 then write(interiors[impInterior]["name"].." > no exit!") end --3
- else
- if intDebugLevel>=3 then write(">exit ok") end --3
- end
- end
- -- step 3: check noEntrance
- if xRoom==1 and zRoom==entrRoomZ then
- if interiors[impInterior]["noEntrance"]~=nil then
- tmpGo=false
- if intDebugLevel>=0 then write(interiors[impInterior]["name"].." > no entrance!") end -- 3
- else
- if intDebugLevel>=3 then write(">entrance ok") end --3
- end
- end
- until tmpGo
- --print(impInterior," ",intLabLevel," ",countInteriors[impInterior])
- -- check maxCount
- until countInteriors[impInterior]<interiors[impInterior]["maxCount"][intLabLevel]
- if intDebugLevel>=3 then write(">max") end
- -- random chance
- --if intDebugLevel>=3 then write(".") end
- until math.random()<interiors[impInterior]["chance"]
- if intDebugLevel>=3 then print(">rnd ok") end
- --if intDebugLevel>=3 then print(impInterior) end
- --found interior id for this room
- rooms[xRoom][zRoom]["interior"]=impInterior
- -- count new interior
- countInteriors[impInterior]=countInteriors[impInterior]+1
- end
- end
- end
- ---------------------------------------
- local function implementInterior(xRoom,zRoom,interiorID)
- -- generic function to implement an interior in a room using the interiors array structure
- -- implements the defined rooms
- -- recursive call by sub-interiors
- local basisX=0
- local basisY=0
- local basisZ=0
- local tmpC=0 -- chance
- local tmpX=0 -- x
- local tmpY=0 -- y
- local tmpZ=0 -- z
- local tmpM="" -- material
- local tmpD=0 -- damage
- local tmpE="" -- extra like "{Items:[:{Count:1,Slot:0,id:35,Damage:1}]}"
- local tmpE_new_all=""
- local tmpE_new={}
- tmpE_new[1]=""
- tmpE_new[2]=""
- tmpE_new[3]=""
- tmpE_new[4]="" -- rest
- tmpE_num=0
- local tmpB=0 -- base
- local tmpBx1=0-- base x1
- local tmpBx2=0-- base x2
- local tmpBy1=0-- base y1
- local tmpBy2=0-- base y2
- local tmpBz1=0-- base z1
- local tmpBz2=0-- base z2
- local tmpBD=0 -- base dmg
- local tmpSubName="" -- name of subinterior
- local blnFoundSubinterior=false
- debugPrint(1,".."..interiors[interiorID]["name"],xRoom,zRoom)
- basisX,basisY,basisZ=baseCoordinates(xRoom,zRoom)
- -- step 1: check for noExit=true in case of sub-interiors
- if xRoom==#rooms and zRoom==exitRoomZ then
- -- check noExit
- -- regular interiors should already be taken care of in defineRooms
- -- here focus is on sub-interiors (e.g., to not make TNT explode near redstone)
- if interiors[interiorID]["noExit"]~=nil then
- debugPrint(0,"..not doing interior at exit!",interiors[interiorID]["name"])
- return
- else
- -- everything is okay
- end
- end
- -- step 2: build all bases
- if interiors[interiorID]["base"]~=nil then
- -- there is a base defined
- execCommand("setblock",basisX,basisY,basisZ,"minecraft:wool",14,"replace")
- for ib=1,#interiors[interiorID]["base"],1 do
- -- one base at a time
- -- apply probability
- tmpC=interiors[interiorID]["base"][ib]["chance"]
- if math.random()<=tmpC or blnAllRndInteriorBases then
- -- prepare+defaults
- --tmpBy=interiors[interiorID]["base"][ib]["y"]
- tmpBy1=interiors[interiorID]["base"][ib]["y1"]
- tmpBy2=interiors[interiorID]["base"][ib]["y2"]
- tmpBx1=interiors[interiorID]["base"][ib]["x1"]
- tmpBx2=interiors[interiorID]["base"][ib]["x2"]
- tmpBz1=interiors[interiorID]["base"][ib]["z1"]
- tmpBz2=interiors[interiorID]["base"][ib]["z2"]
- if tmpBx1==nil then tmpBx1=1 end
- if tmpBx2==nil then tmpBx2=9 end
- if tmpBz1==nil then tmpBz1=1 end
- if tmpBz2==nil then tmpBz2=9 end
- if tmpBy1==nil then tmpBy1=1 end
- if tmpBy2==nil then tmpBy2=5 end
- if interiors[interiorID]["base"][ib]["x"]~=nil then
- -- if x is provided this overwrites x1 and x2
- tmpBx1=interiors[interiorID]["base"][ib]["x"]
- tmpBx2=tmpBx1
- end
- if interiors[interiorID]["base"][ib]["z"]~=nil then
- -- if z is provided this overwrites z1 and z2
- tmpBz1=interiors[interiorID]["base"][ib]["z"]
- tmpBz2=tmpBz1
- end
- if interiors[interiorID]["base"][ib]["y"]~=nil then
- -- if y is provided this overwrites y1 and y2
- tmpBy1=interiors[interiorID]["base"][ib]["y"]
- tmpBy2=tmpBy1
- end
- debugPrint(4,"....base",tmpBx1,tmpBx2,tmpBy1,tmpBy2,tmpBz1,tmpBz2) --4
- -- build it
- for ix=basisX+tmpBx1, basisX+tmpBx2, 1 do
- for iz=basisZ+tmpBz1, basisZ+tmpBz2, 1 do
- for iy=basisY+tmpBy1,basisY+tmpBy2, 1 do
- if type(interiors[interiorID]["base"][ib]["dmg"])=="table" then
- -- dmg has several options, take one
- tmpBD=interiors[interiorID]["base"][ib]["dmg"][math.random(1,#interiors[interiorID]["base"][ib]["dmg"])]
- debugPrint(4,"...Rnd damage value=",tmpBD)
- else
- -- take the one and only value
- tmpBD=interiors[interiorID]["base"][ib]["dmg"]
- end
- execCommand("setblock",ix,iy,iz,interiors[interiorID]["base"][ib]["mat"],tmpBD,"replace")
- end
- end
- end
- end
- end
- else
- -- leave the standard room material
- end
- -- step 3: place all defined blocks
- if interiors[interiorID]["blocks"]~=nil then
- for iBlock = 1,#interiors[interiorID]["blocks"],1 do
- -- apply probability
- tmpC=interiors[interiorID]["blocks"][iBlock]["chance"]
- if math.random()<=tmpC or blnAllRndInteriorBlocks then
- -- prepare data
- if type(interiors[interiorID]["blocks"][iBlock]["x"])=="table" then
- -- x has several options, take one
- tmpX=basisX+interiors[interiorID]["blocks"][iBlock]["x"][math.random(1,#interiors[interiorID]["blocks"][iBlock]["x"])]
- else
- -- take the one and only value
- tmpX=basisX+interiors[interiorID]["blocks"][iBlock]["x"]
- end
- if type(interiors[interiorID]["blocks"][iBlock]["y"])=="table" then
- -- y has several options, take one
- tmpY=basisY+interiors[interiorID]["blocks"][iBlock]["y"][math.random(1,#interiors[interiorID]["blocks"][iBlock]["y"])]
- else
- -- take the one and only value
- tmpY=basisY+interiors[interiorID]["blocks"][iBlock]["y"]
- end
- if type(interiors[interiorID]["blocks"][iBlock]["z"])=="table" then
- -- z has several options, take one
- tmpZ=basisZ+interiors[interiorID]["blocks"][iBlock]["z"][math.random(1,#interiors[interiorID]["blocks"][iBlock]["z"])]
- else
- -- take the one and only value
- tmpZ=basisZ+interiors[interiorID]["blocks"][iBlock]["z"]
- end
- if type(interiors[interiorID]["blocks"][iBlock]["dmg"])=="table" then
- -- dmg has several options, take one
- tmpD=interiors[interiorID]["blocks"][iBlock]["dmg"][math.random(1,#interiors[interiorID]["blocks"][iBlock]["dmg"])]
- debugPrint(4,"...Rnd damage value=",tmpD)--4
- else
- -- take the one and only value
- tmpD=interiors[interiorID]["blocks"][iBlock]["dmg"]
- end
- if type(interiors[interiorID]["blocks"][iBlock]["mat"])=="table" then
- -- mat has several options, take one
- tmpM=interiors[interiorID]["blocks"][iBlock]["mat"][math.random(1,#interiors[interiorID]["blocks"][iBlock]["mat"])]
- debugPrint(4,"...Rnd mat value=",tmpM)--4
- else
- -- take the one and only value
- tmpM=interiors[interiorID]["blocks"][iBlock]["mat"]
- end
- --tmpM=interiors[interiorID]["blocks"][iBlock]["mat"]
- tmpE=interiors[interiorID]["blocks"][iBlock]["extra"]
- debugPrint(4,"....setBlock",tmpX,tmpY,tmpZ,tmpM,tmpD,"replace") --4
- if tmpE==nil then
- execCommand("setblock",tmpX,tmpY,tmpZ,tmpM,tmpD,"replace")
- else
- -- no error checks
- -- there is extra data
- -- check for absolute coordinates in case
- if interiors[interiorID]["blocks"][iBlock]["absolute"]~=nil then
- -- try to replace ~x ~y ~z with absolute coordinates
- debugPrint(1,"Found absolute coordinates in interiorID=",interiorID)--3
- -- e.g.: "{Command:/tp @p ~-1 ~1 ~4 }"
- -- last coordinate MUST have a space after the number!
- tmpE_new_all=tmpE
- --[[
- -- step a1 are there at least three ~ in tmpE
- tmpE_num=string.find(tmpE_new_all,"~")
- tmpE_new_all=string.sub
- tmpE_new[1]=string.sub(tmpE_new_all,tmpE_num)
- tmpE_new[1]=string.sub(tmpE_new[1],1,string.find(tmpE_new[1],"~"))
- -- step a2 are they followed by numbers
- ]]--
- tmpE_new_all,tmpE_new[1]=cutString(tmpE_new_all,"~")
- tmpE_new[1], tmpE_new[2]=cutString(tmpE_new[1],"~")
- tmpE_new[2], tmpE_new[3]=cutString(tmpE_new[2],"~")
- tmpE_new[3], tmpE_new[4]=cutString(tmpE_new[3]," ")
- tmpE_new[1]=tonumber(tmpE_new[1])+tmpX
- tmpE_new[2]=tonumber(tmpE_new[2])+tmpY
- tmpE_new[3]=tonumber(tmpE_new[3])+tmpZ
- -- step a3 replace the numbers with absolute coordinates
- --[[
- print("."..tmpE..".")
- print("."..tmpE_new_all..".")
- print("."..tmpE_new[1]..".")
- print("."..tmpE_new[2]..".")
- print("."..tmpE_new[3]..".")
- print("."..tmpE_new[4]..".")
- --askForInputText()
- ]]--
- tmpE=tmpE_new_all..tmpE_new[1].." "..tmpE_new[2].." "..tmpE_new[3]..tmpE_new[4]
- --print("."..tmpE..".")
- end
- execCommand("setblock",tmpX,tmpY,tmpZ,tmpM,tmpD,"replace",tmpE)
- end
- -- step 3: save chest locations
- if tmpM=="minecraft:trapped_chest" then
- if interiors[interiorID]["blocks"][iBlock]["noRandomLoot"]==nil then
- -- only if chest isn't marked as noRandomLoot
- rooms[xRoom][zRoom]["chest"][#rooms[xRoom][zRoom]["chest"]+1]={tmpX,tmpY,tmpZ,tmpD}
- debugPrint(3,"saved chest data:",xRoom,zRoom,#rooms[xRoom][zRoom]["chest"],tmpX,tmpY,tmpZ,tmpD)
- end
- end
- end
- end
- else
- -- this interior has no defined blocks
- end
- -- step 4: recursive call for sub-interiors
- if interiors[interiorID]["subinterior"]~=nil then
- -- there is a sub-interior
- for iSub=1,#interiors[interiorID]["subinterior"],1 do
- -- array of names?
- if type(interiors[interiorID]["subinterior"][iSub]["name"])=="table" then
- -- x has several options, take one
- tmpSubName=interiors[interiorID]["subinterior"][iSub]["name"][math.random(1,#interiors[interiorID]["subinterior"][iSub]["name"])]
- else
- -- take the one and only value
- tmpSubName=interiors[interiorID]["subinterior"][iSub]["name"]
- end
- debugPrint(2,"..checking sub-interior "..tmpSubName)--2
- -- apply probability
- tmpC=interiors[interiorID]["subinterior"][iSub]["chance"]
- if math.random()<=tmpC or blnAllRndSubinteriors then
- -- get sub-interior id
- blnFoundSubinterior=false
- for iSubId=cRoomInteriorMax+1,#interiors,1 do
- if tmpSubName==interiors[iSubId]["name"] then
- blnFoundSubinterior=true
- -- recursive call
- implementInterior(xRoom,zRoom,iSubId)
- break
- end
- end
- if not blnFoundSubinterior then
- -- didn't fine the sub-interior
- debugPrint(0,"..didn't find sub-interior "..tmpSubName)
- end
- end
- end
- else
- -- no sub-interiors
- end
- -- step 5: summon entities
- if interiors[interiorID]["summon"]~=nil then
- -- there is a summon entry
- for iSummon=1,#interiors[interiorID]["summon"],1 do
- debugPrint(2,"..checking summon "..interiors[interiorID]["summon"][iSummon]["entity"])--2
- -- apply probability
- tmpC=interiors[interiorID]["summon"][iSummon]["chance"]
- if math.random()<=tmpC or blnAllSummons then
- -- summon that entity
- -- might be obstructed(!)
- tmpX=basisX+interiors[interiorID]["summon"][iSummon]["x"]
- tmpY=basisY+interiors[interiorID]["summon"][iSummon]["y"]
- tmpZ=basisZ+interiors[interiorID]["summon"][iSummon]["z"]
- tmpE=interiors[interiorID]["summon"][iSummon]["extra"]
- execCommand("summon",interiors[interiorID]["summon"][iSummon]["entity"],tmpX,tmpY,tmpZ,tmpE)
- end
- end
- else
- -- no entities to summon
- end
- end
- ---------------------------------------
- local function implementRooms()
- -- implements the defined rooms
- debugPrint(1,"implementRooms")
- -- step 1: implement room interiors
- for xRoom=1,#rooms,1 do
- for zRoom=1,#rooms[1],1 do
- implementInterior(xRoom,zRoom,rooms[xRoom][zRoom]["interior"])
- end
- end
- -- step 2: implement exit mechanism
- implementInterior(#rooms,exitRoomZ,cRoomInteriorExit)
- --interiors_addons
- end
- ---------------------------------------
- local function addItemToChest(intChest,intItemId,intItemCount,intItemDmg)
- -- enlarges chests[intChest]["item"] and adds the item and amount
- debugPrint(3,"..adding item to chest "..intChest..":",#chests[intChest]["item"]+1,intItemId,intItemCount,intItemDmg) --3
- --print(#chests[intChest]["item"])
- local tmpItem=#chests[intChest]["item"]+1
- if intItemDmg==nil then intItemDmg=0 end
- if intItemCount==nil then intItemCount=1 end
- chests[intChest]["item"][tmpItem]={}
- chests[intChest]["item"][tmpItem]["id"] =intItemId
- chests[intChest]["item"][tmpItem]["count"]=intItemCount
- chests[intChest]["item"][tmpItem]["dmg"] =intItemDmg
- --print(chests[intChest]["item"][tmpItem]["count"])
- --os.sleep(1)
- end
- ---------------------------------------
- local function defineGoldDistribution()
- -- distributes the ingpt, nuggets etc. onto the rooms
- -- so far only dependant on lab size
- -- not on level
- debugPrint(1,"defineGoldDistribution") --1
- local intIngots=9
- local intNuggets=0
- local intRoomCount=#rooms*#rooms[1]
- local intRoomsLeft=0
- local intAveragNumberOfNuggets=0
- local intNuggetsRemainder=0
- local tmpFrom =0
- local tmpTo =0
- local tmpId =""
- local tmpCount=0
- -- step 1: get right amount of nuggets
- while intRoomCount>intIngots+intNuggets do
- intIngots=intIngots-1
- intNuggets=intNuggets+9
- end
- debugPrint(0,".."..intRoomCount.." rooms: (ingot,nuggets)=",intIngots,intNuggets) --3
- -- step 2: distribute them in random order
- -- step 2.1: gold ingots
- for i=1,intIngots,1 do
- goldDistribution[i]={id=cMatId_GoldIngot,count=1}
- end
- -- step 2.2: gold nuggets
- intRoomsLeft=intRoomCount-intIngots
- intAveragNumberOfNuggets=math.floor(intNuggets/intRoomsLeft)
- intNuggetsRemainder=intNuggets-intAveragNumberOfNuggets*intRoomsLeft
- for i=intIngots+1,intRoomCount,1 do
- goldDistribution[i]={id=cMatId_GoldNugget,count=intAveragNumberOfNuggets}
- if i==intIngots+1 then goldDistribution[i]["count"]=goldDistribution[i]["count"]+intNuggetsRemainder end
- end
- -- step 3: level adjustments
- if intLabLevel>=2 and intIngots>0 then
- -- exchange one ingot with ore (coal is assured in chestItems)
- goldDistribution[1]["id"]=cMatId_GoldOre
- end
- -- step 4: randomize distribution
- for i=1,intRoomCount,1 do -- start exchange once from each room
- tmpFrom=i--math.random(1,#goldDistribution)
- tmpTo =math.random(1,#goldDistribution)
- tmpId =goldDistribution[tmpFrom]["id"]
- tmpCount=goldDistribution[tmpFrom]["count"]
- goldDistribution[tmpFrom]["id"] =goldDistribution[tmpTo]["id"]
- goldDistribution[tmpFrom]["count"]=goldDistribution[tmpTo]["count"]
- goldDistribution[tmpTo]["id"] =tmpId
- goldDistribution[tmpTo]["count"]=tmpCount
- debugPrint(4,"..exchanging goldDistribution:",tmpFrom,tmpTo)--4
- end
- end
- ---------------------------------------
- local function defineChestItems()
- debugPrint(1,"defineChestItems") --1
- -- fill in chests
- local tmpX=0
- local tmpY=0
- local tmpZ=0
- local tmpD=0
- local tmpChest=0
- local tmpNewChest=0
- local tmpNewItem=0
- local tmpBlock={}
- local tmpItemLevelOk=false
- local tmpItemProp=0--0.10 --1--
- local tmpItemCount=0
- local tmpItemDmg=0
- local strItems=""
- local countGoldIndicator=0
- --[[
- -- chests[]
- -- chests[i]["x"]/["y"]/["z"] = coordinates
- -- chests[i]["dmg"] = damage value (direction not working atm)
- -- chests[i]["items"]={}
- -- [1]["id"]=id to be used in command
- -- [1]["count"]=counter to be used in command
- local chests ={}
- ]]--
- -- step 1: assign gold ingots etc. to each room
- for ix=1,#rooms,1 do
- for iz=1,#rooms[1],1 do
- -- pick chest to put the ingot in
- if #rooms[ix][iz]["chest"]==0 then
- debugPrint(0,"ERROR: Probably no chest defined in '"..interiors[rooms[ix][iz]["interior"]]["name"].."'")--0
- end
- tmpChest=math.random(1,#rooms[ix][iz]["chest"])
- -- step 2: create chest array
- for ic=1,#rooms[ix][iz]["chest"],1 do
- tmpNewChest=#chests+1
- chests[tmpNewChest]={}
- chests[tmpNewChest]["x"] =rooms[ix][iz]["chest"][ic][1]
- chests[tmpNewChest]["y"] =rooms[ix][iz]["chest"][ic][2]
- chests[tmpNewChest]["z"] =rooms[ix][iz]["chest"][ic][3]
- chests[tmpNewChest]["dmg"]=rooms[ix][iz]["chest"][ic][4]
- chests[tmpNewChest]["fromEntrance"]=rooms[ix][iz]["fromEntrance"]
- chests[tmpNewChest]["item"]={}
- -- ingot
- if tmpChest==ic then
- countGoldIndicator=countGoldIndicator+1
- addItemToChest(tmpNewChest,goldDistribution[countGoldIndicator]["id"],goldDistribution[countGoldIndicator]["count"])
- end
- end
- end
- end
- --[[
- -- step 3: some random test loot
- for ic=1,#chests,1 do
- -- poppy
- if math.random()<=tmpItemProp then addItemToChest(ic, 38,1) end
- -- carrot
- if math.random()<=tmpItemProp then addItemToChest(ic,391,1) end
- -- stone sword
- if math.random()<=tmpItemProp then addItemToChest(ic,272,1) end
- end
- ]]--
- -- step 3: apply chestItems for randomized level loot
- for iI=1,#chestItems,1 do
- -- check for correct level (single value or array)
- tmpItemLevelOk=false --default
- if type(chestItems[iI]["level"])=="table" then
- for iLevel=1,#chestItems[iI]["level"],1 do
- if chestItems[iI]["level"][iLevel]==intLabLevel then tmpItemLevelOk=true break end
- end
- else
- -- single value
- if chestItems[iI]["level"]==intLabLevel then tmpItemLevelOk=true end
- end
- if tmpItemLevelOk then --chestItems[iI]["level"]==intLabLevel then
- -- right level of item
- if math.random()<=chestItems[iI]["chance"] then
- -- okay, put loot randomly in chest
- -- check for multiple count values
- if type(chestItems[iI]["count"])=="table" then
- -- item count has several options, take one
- tmpItemCount=chestItems[iI]["count"][math.random(1,#chestItems[iI]["count"])]
- else
- -- take the one and only value
- tmpItemCount=chestItems[iI]["count"]
- end
- -- check for multiple dmg values
- if type(chestItems[iI]["dmg"])=="table" then
- -- item dmg has several options, take one
- tmpItemDmg=chestItems[iI]["dmg"][math.random(1,#chestItems[iI]["dmg"])]
- else
- -- take the one and only value
- tmpItemDmg=chestItems[iI]["dmg"]
- end
- -- add it
- addItemToChest(math.random(1,#chests),chestItems[iI]["id"],tmpItemCount,tmpItemDmg)
- end
- end
- --chestItems[1]={level=1,chance=0.5,id= 38,dmg=0,count=1} --poppy
- end
- -- step x: trap some chests
- for ic=1,#chests,1 do
- tmpX=chests[ic]["x"]
- tmpY=chests[ic]["y"]
- tmpZ=chests[ic]["z"]
- tmpD=chests[ic]["dmg"]
- if (tmpY==yHome+cOffsetY+1 or tmpY==yHome+cOffsetY or tmpY==yHome+cOffsetY-1) and math.random()<= cTrapProbability then
- -- trap it
- debugPrint(3," .. trapped chest "..ic.." :D") --3
- -- step x.1: set-up redstone impulse
- execCommand("setblock",tmpX,tmpY-2,tmpZ,"minecraft:command_block","0","replace","{Command:/setblock ~0 ~-1 ~0 minecraft:redstone_block 0 replace}")
- execCommand("setblock",tmpX,tmpY-4,tmpZ,"minecraft:command_block","0","keep","{Command:/setblock ~0 ~1 ~0 minecraft:air 0 replace}")
- -- step x.2: level 1+ mobs
- if math.random()>=0.5 then
- -- Zombie
- execCommand("setblock",tmpX,tmpY-3,tmpZ-1,"minecraft:command_block","0","keep","{Command:/summon Zombie ~0 ~5 ~1 {Equipment:[{},{},{},{},{id:298}]}}")
- else
- -- Skeleton
- execCommand("setblock",tmpX,tmpY-3,tmpZ-1,"minecraft:command_block","0","keep","{Command:/summon Skeleton ~0 ~5 ~1 {Equipment:[{id:271},{},{},{},{Count:1,id:298}],DropChances:[0.0F,0.0F,0.0F,0.0F,0.1F]}}")
- end
- -- step x.3: level 3+ mobs
- if intLabLevel>=3 then
- if math.random()>=0.5 then
- -- bonus slime
- execCommand("setblock",tmpX-1,tmpY-3,tmpZ,"minecraft:command_block","0","keep","{Command:/summon Slime ~1 ~5 ~0}")
- end
- end
- -- ensure there is a block to transmit the rs signal
- execCommand("setblock",tmpX,tmpY-1,tmpZ,"minecraft:stone","0","keep")
- end
- end
- end
- ---------------------------------------
- local function defineKeyItemDistribution()
- -- checks for need of certain key items and distributes them accordingly
- -- so far: 1) flint and steel for sand-TNT
- -- 2) disc far for jukebox
- debugPrint(0,"defineKeyItemDistribution") --1
- local tmpGo=false
- local tmpDistance=0
- local tmpChest=0
- local tmpCount=0
- -- step 1: flint and steel for sand-TNT
- -- step 1.1: sand-TNT in game?
- for xRoom=1,#rooms,1 do
- for zRoom=1,#rooms[1],1 do
- if interiors[rooms[xRoom][zRoom]["interior"]]["name"]=="sand-TNT" then
- tmpGo=true
- tmpDistance=rooms[xRoom][zRoom]["fromEntrance"]
- break
- end
- end
- end
- if tmpGo then
- -- step 1.2: find chest for flint and steel
- tmpCount=0
- repeat
- tmpChest=math.random(1,#chests)
- tmpCount=tmpCount+1
- until chests[tmpChest]["fromEntrance"]<tmpDistance
- -- step 1.3: add item
- addItemToChest(tmpChest,cMatId_FlintAndSteel,1,64)
- debugPrint(2,"Keys: added flint&steel after "..tmpCount.." tries to chest "..tmpChest)--2
- else
- debugPrint(2,"Keys: no sand-TNT, no flint&steel")--2
- end
- -- step 2: disc for jukebox
- tmpGo=false
- tmpDistance=0
- tmpChest=0
- tmpCount=0
- -- step 2.1: jukebox in game?
- for xRoom=1,#rooms,1 do
- for zRoom=1,#rooms[1],1 do
- if interiors[rooms[xRoom][zRoom]["interior"]]["name"]=="jukebox" then
- tmpGo=true
- tmpDistance=rooms[xRoom][zRoom]["fromEntrance"]
- break
- end
- end
- end
- if tmpGo then
- -- step 2.2: find chest for disc
- tmpCount=0
- repeat
- tmpChest=math.random(1,#chests)
- tmpCount=tmpCount+1
- until chests[tmpChest]["fromEntrance"]<tmpDistance
- -- step 2.3: add item
- addItemToChest(tmpChest,cMatId_DiscFar,1,64)
- debugPrint(2,"Keys: added disc far after "..tmpCount.." tries to chest "..tmpChest)--2
- else
- debugPrint(2,"Keys: no jukebox, no discs")--2
- end
- end
- ---------------------------------------
- local function implementChestItems()
- debugPrint(1,"implementChestItems") --1
- -- fill in chests
- local tmpX=0
- local tmpY=0
- local tmpZ=0
- local tmpD=0
- -- step 1: set chests again with the items
- for ic=1,#chests,1 do
- --print("here",ic," ",#chests)
- tmpX=chests[ic]["x"]
- tmpY=chests[ic]["y"]
- tmpZ=chests[ic]["z"]
- tmpD=chests[ic]["dmg"]
- if #chests[ic]["item"]>0 then
- -- there are items to place in the chest
- strItems=""
- -- tmp only first
- -- tmp no rnd slot numbers
- --print(chests[ic]["item"][1])
- for iItem=1,#chests[ic]["item"],1 do
- -- build string for chest items
- if iItem>1 then strItems=strItems.."," end
- --write(chests[ic]["item"][iItem]["count"])
- strItems=strItems.."{id:"..tostring(chests[ic]["item"][iItem]["id"])..",Slot:"..tostring(iItem-1)..",Count:"..tostring(chests[ic]["item"][iItem]["count"])..",Damage:"..tostring(chests[ic]["item"][iItem]["dmg"]).."}"
- end
- debugPrint(4,"..",strItems) --4
- execCommand("setblock",tmpX,tmpY,tmpZ,"minecraft:trapped_chest",0,"replace","{Items:["..strItems.."]}")
- -- info: {Items:[:{Count:1,Slot:0,id:35,Damage:1}]}
- -- info: {Items:[{id:276,Slot:1,Count:1},{id:277,Slot:Β0,Count:2}]}
- --print(ic,": ",tmpX,tmpY,tmpZ,tmpD)
- --"{Items:[{id:"..cMatId_WoodenSword..",Slot:1,Count:1]}}"
- end
- end
- end
- ---------------------------------------
- ------------------------------------------------------------------------------
- ---- MAIN --------------------------------------------------------------------
- ------------------------------------------------------------------------------
- debugPrint(0,"Base coordinates = ",xHome+cOffsetX,yHome+cOffsetY,zHome+cOffsetZ)--1
- debugPrint(0,"Room grid = ",#rooms,#rooms[1])--2
- debugPrint(0,"Door grid = ",#doors,#doors[1])--2
- debugPrint(0,"Level = ",intLabLevel)--2
- ------------------------------------------------------------------------------
- -- reset rooms ---------------------------------------------------------------
- -- walls, floor, air blocks, underground
- resetRooms()--xHome+cOffsetX,yHome+cOffsetY,zHome+cOffsetZ)
- if blnJustClear then return end
- ------------------------------------------------------------------------------
- -- get door distribution -----------------------------------------------------
- -- which rooms are connected
- -- ensure all rooms are accessible
- -- idea: include underground paths
- defineDoors()
- ------------------------------------------------------------------------------
- -- implement doors -----------------------------------------------------------
- -- idea: choose variants for room connections (e.g., door on left, right, double,...)
- -- idea: implement doors and block reserved floor space
- -- idea: choose underground path type
- -- idea: implement underground paths and block reserved floor space
- --implementDoors() => moved to end to give not early access to players
- ------------------------------------------------------------------------------
- -- get room assignment -------------------------------------------------------
- -- idea: should this be dependant on room distance ? => later
- -- assign entry room
- -- idea: check for multi-room constructions
- -- idea: choose and balance room type assignments
- -- idea: including chests (rooms[ix][iz]["chest"])
- defineRooms()
- ------------------------------------------------------------------------------
- -- implement rooms -----------------------------------------------------------
- -- select from different variants available
- -- idea: implement rooms considering reserved floor blocks => atm via design
- implementRooms()
- ------------------------------------------------------------------------------
- -- ensure door accessibility -------------------------------------------------
- -- idea: delete blocking blocks
- -- hm, for now I ensure that there are no blocks (and door pos is fixed)
- ------------------------------------------------------------------------------
- -- define and implement chests -----------------------------------------------
- -- idea: starter chest in rooms near to entrance
- -- chests due to room chest likely-hood
- -- basic supplies
- -- random loot
- -- difficulty dependant loot
- -- labyrinth relevant loot (dependant on certain interior types)
- -- trap some chests with mob spawning
- -- idea: add a do-not-trap attribute to interior chests
- defineGoldDistribution()
- defineChestItems()
- defineKeyItemDistribution()
- implementChestItems()
- ------------------------------------------------------------------------------
- -- populate rooms ------------------------------------------------------------
- -- idea: animals
- -- mobs
- -- idea: despawnable items
- -- atm done with interiors, not sure if I want this or not
- -------------------------------------------------------------------------------
- -- allow access ---------------------------------------------------------------
- implementDoors() -- allow access only at end of construction process
- -------------------------------------------------------------------------------
- -------------------------------------------------------------------------------
- if #tArgs >= 7 then
- --if finalCommand~="" then
- execCommand("say Builder up to do: "..finalCommand)
- --os.sleep(1)
- execCommand(finalCommand) --e.g. set signals
- execCommand("say Builder: done "..cRoomsGridX.."x"..cRoomsGridZ)
- --[[
- commands.execAsync("say up to do: "..finalCommand)
- commands.execAsync(finalCommand) --e.g. set signals
- commands.execAsync("say done!")
- ]]--
- end
- if blnDebug then print("Builder: done ",cRoomsGridX,"x",cRoomsGridZ) end
- -------------------------------------------------------------------------------
Add Comment
Please, Sign In to add comment